summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/stex/sty/omdoc/omdoc.dtx
blob: 5cc680fc252510de432e117f6823da4ec4fb7e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
% \iffalse meta-comment
% A LaTeX Class and Package for OMDoc Document Structures
% Copyright (c) 2016 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
%
% The original of this file is in the public repository at 
% http://github.com/KWARC/sTeX/
% \fi
%   
% \iffalse
%<package|cls>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{omdoc}[2019/03/20 v1.3 OMDoc document Structure]
%<cls>\ProvidesClass{omdoc}[2019/03/20 v1.3 OMDoc Documents]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage{url,array,float}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\addbibresource{kwarcpubs.bib}
\addbibresource{extpubs.bib}
\addbibresource{kwarccrossrefs.bib}
\addbibresource{extcrossrefs.bib}
\usepackage{stex-logo}
\usepackage{omdoc}
\usepackage{omtext}
\usepackage{ctangit}
\usepackage{hyperref}
\usepackage{paralist}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\begin{document}
\RecordChanges
\DocInput{omdoc.dtx}
\end{document}
%</driver>
% \fi
% 
%\CheckSum{385}
%
% \changes{v0.1}{2006/1/17}{First Version}
% \changes{v0.2}{2006/7/11}{added OMDoc class}
% \changes{v0.3}{2007/09/09}{moved omtext and friends here from the statements package}
% \changes{v0.4}{2008/09/06}{added quotes}
% \changes{v0.5}{2008/03/28}{more package/class options}
% \changes{v0.7}{2009/11/24}{giving keyval arguments to the document environment}
% \changes{v1.0}{2010/05/25}{separated out \texttt{omtext.dtx}}
% \changes{v1.1}{2012/02/14}{integrated \texttt{etoolbox} package}
% \changes{v1.2}{2014/01/12}{front/backmatter}
% \changes{v1.3}{2015/11/18}{removing keyval arg from document in favor of
% \texttt{\textbackslash documentkeys} macro}
% \changes{v1.3}{2018/09/10}{global variables and switches}
% \changes{v1.3}{2018/12/03}{changed to keyval class/package options, allowed arbitrary classes}
%
% 
% \MakeShortVerb{\|}
%
% \def\omdoc{OMDoc}
% \def\latexml{{\LaTeX}ML}
% \title{{\texttt{omdoc.sty/cls}}: Semantic Markup for Open Mathematical Documents in {\LaTeX}}
%    \author{Michael Kohlhase\\
%            FAU Erlangen-N\"urnberg\\
%            \url{http://kwarc.info/kohlhase}}
% \maketitle
%
% \begin{abstract}
%   The |omdoc| package is part of the {\sTeX} collection, a version of {\TeX/\LaTeX} that
%   allows to markup {\TeX/\LaTeX} documents semantically without leaving the document
%   format, essentially turning {\TeX/\LaTeX} into a document format for mathematical
%   knowledge management (MKM).
%
%   This package supplies an infrastructure for writing {\omdoc} documents in {\LaTeX}.
%   This includes a simple structure sharing mechanism for {\sTeX} that allows to to move
%   from a copy-and-paste document development model to a copy-and-reference model, which
%   conserves space and simplifies document management. The augmented structure can be
%   used by MKM systems for added-value services, either directly from the {\sTeX}
%   sources, or after translation.
% \end{abstract}
%
%\newpage\tableofcontents\newpage
% 
%\begin{omgroup}[id=sec:STR]{Introduction}
% 
%  {\sTeX} is a version of {\TeX/\LaTeX} that allows to markup {\TeX/\LaTeX} documents
%  semantically without leaving the document format, essentially turning {\TeX/\LaTeX}
%  into a document format for mathematical knowledge management (MKM). The package
%  supports direct translation to the {\omdoc} format~\cite{Kohlhase:OMDoc1.2}
%
%  The |omdoc| package supplies macros and environment that allow to label document
%  fragments and to reference them later in the same document or in other documents. In
%  essence, this enhances the document-as-trees model to
%  documents-as-directed-acyclic-graphs (DAG) model. This structure can be used by MKM
%  systems for added-value services, either directly from the {\sTeX} sources, or after
%  translation. Currently, trans-document referencing provided by this package can only
%  be used in the {\sTeX} collection.
%
%  DAG models of documents allow to replace the ``Copy and Paste'' in the source document
%  with a label-and-reference model where document are shared in the document source and
%  the formatter does the copying during document
%  formatting/presentation.\ednote{integrate with latexml's XMRef in the Math mode.}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user]{The User Interface}
% 
%   The |omdoc| package generates two files: |omdoc.cls|, and |omdoc.sty|. The {\omdoc}
%   class is a minimally changed variant of the standard |article| class that includes the
%   functionality provided by |omdoc.sty|. The rest of the documentation pertains to the
%   functionality introduced by |omdoc.sty|.
%
% \begin{omgroup}[id=sec:user:options]{Package and Class Options}
% 
%   The |omdoc| class accept the following options: 
%   \begin{center}
%     \begin{tabular}{|l|p{10cm}|}\hline
%         \texttt{class=\meta{name}} & load \meta{name}|.cls| instead of |article.cls|\\\hline 
%         \texttt{topsect=\meta{sect}} & The top-level sectioning level; the default for
%         \meta{sect} is \texttt{section}\\\hline 
%         \texttt{showignores} & show the the contents of the |ignore| environment after all \\\hline
%         \texttt{showmeta} & show the metadata; see |metakeys.sty|\\\hline
%         \texttt{showmods} & show modules; see |modules.sty|\\\hline
%         \texttt{extrefs} & allow external references; see |sref.sty|\\\hline
%         \texttt{defindex} & index definienda; see |statements.sty|\\\hline
%         \texttt{mh} & MathHub support; see~\cite{Kohlhase:mss:ctan}\\\hline
%     \end{tabular}
%   \end{center}
%   The |omdoc| package accepts the same except the first two.
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:struct]{Document Structure}
% 
%   The top-level \DescribeEnv{document}|document| environment can be given key/value
%   information by the \DescribeMacro{\documentkeys}|\documentkeys| macro in the
%   preamble\footnote{We cannot patch the document environment to accept an optional
%   argument, since other packages we load already do; pity.}. This can be used to give
%   metadata about the document. For the moment only the \DescribeMacro{id}|id| key is
%   used to give an identifier to the \texttt{omdoc} element resulting from the {\latexml}
%   transformation.
% 
%   The structure of the document is given by the \DescribeEnv{omgroup}|omgroup|
%   environment just like in {\omdoc}. In the {\LaTeX} route, the |omgroup| environment is
%   flexibly mapped to sectioning commands, inducing the proper sectioning level from the
%   nesting of |omgroup| environments. Correspondingly, the |omgroup| environment takes an
%   optional key/value argument for metadata followed by a regular argument for the
%   (section) title of the omgroup. The optional metadata argument has the keys
%   \DescribeMacro{id}|id| for an identifier, \DescribeMacro{creators}|creators| and
%   \DescribeMacro{contributors}|contributors| for the Dublin Core
%   metadata~\cite{DCMI:dmt03}; see~\ctancite{Kohlhase:dcm} for details of the format. The
%   \DescribeMacro{short}|short| allows to give a short title for the generated
%   section. If the title contains semantic macros, they need to be protected by
%   |\protect|, and we need to give the \DescribeMacro{loadmodules}|loadmodules| key it
%   needs no value. For instance we would have
%   \begin{verbatim}
%   \begin{module}{foo}
%   \symdef{bar}{B^a_r}
%    ...
%   \begin{omgroup}[id=barderiv,loadmodules]
%     {Introducing $\protect\bar$ Derivations}
%   \end{verbatim}
% 
%   \sTeX automatically computes the sectioning level, from the nesting of |omgroup|
%   environments. But sometimes, we want to skip levels (e.g. to use a subsection* as an
%   introduction for a chapter). Therefore the |omdoc| package provides a variant
%   \DescribeEnv{blindomgroup}|blindomgroup| that does not produce markup, but increments
%   the sectioning level and logically groups document parts that belong together, but
%   where traditional document markup relies on convention rather than explicit
%   markup. The |blindomgroup| environment is useful e.g. for creating frontmatter at the
%   correct level. Example~\ref{fig:docstruct} shows a typical setup for the outer
%   document structure of a book with parts and chapters. We use two levels of
%   |blindomgroup|:
%   \begin{itemize}
%   \item The outer one groups the introductory parts of the book (which we assume to have
%     a sectioning hierarchy topping at the part level). This |blindomgroup| makes sure
%     that the introductory remarks become a ``chapter'' instead of a ``part''.
%   \item Th inner one groups the frontmatter\footnote{We shied away from redefining the
%     |frontmatter| to induce a blindomgroup, but this may be the ``right'' way to go in
%     the future.} and makes the preface of the book a section-level construct. Note that
%     here the |display=flow| on the |omgroup| environment prevents numbering as is
%     traditional for prefaces. 
%   \end{itemize}
%   \begin{exfig}
% \begin{verbatim}
% \begin{document}
% \begin{blindomgroup}
% \begin{blindomgroup}
% \begin{frontmatter}
% \maketitle\newpage
% \begin{omgroup}[display=flow]{Preface}
% ... <<preface>> ...
% \end{omgroup}
% \clearpage\setcounter{tocdepth}{4}\tableofcontents\clearpage
% \end{frontmatter}
% \end{blindomgroup}
% ... <<introductory remarks>> ...
% \end{blindomgroup}
% \begin{omgroup}{Introduction}
% ... <<intro>> ...
% \end{omgroup}
% ... <<more chapters>> ... 
% \bibliographystyle{alpha}\bibliography{kwarc}
% \end{document}
% \end{verbatim}\vspace*{-2em}
%   \caption{A typical Document Structure of a Book}\label{fig:docstruct}
% \end{exfig}
%
%
%   The \DescribeMacro{\currentsectionlevel}|\currentsectionlevel| macro supplies the name
%   of the current sectioning level, e.g. ``chapter'', or
%   ``subsection''. \DescribeMacro{\CurrentSectionLevel}|\CurrentSectionLevel| is the
%   capitalized variant. They are useful to write something like ``In this
%   |\currentsectionlevel|, we will\ldots'' in an |omgroup| environment, where we do not
%   know which sectioning level we will end up.
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:ignore]{Ignoring Inputs}
% 
% The \DescribeEnv{ignore}|ignore| environment can be used for hiding text parts from the
% document structure. The body of the environment is not PDF or DVI output unless the
% \DescribeMacro{showignores}|showignores| option is given to the |omdoc| class or
% |package|. But in the generated {\omdoc} result, the body is marked up with a |ignore|
% element. This is useful in two situations. For
% \begin{description}
% \item[editing] One may want to hide unfinished or obsolete parts of a document
% \item[narrative/content markup] In {\stex} we mark up narrative-structured documents. In
%   the generated {\omdoc} documents we want to be able to cache content objects that are
%   not directly visible. For instance in the |statements|
%   package~\ctancite{Kohlhase:smms} we use the |\inlinedef| macro to mark up phrase-level
%   definitions, which verbalize more formal definitions. The latter can be hidden by an
%   ignore and referenced by the |verbalizes| key in |\inlinedef|.
% \end{description}
% 
% \end{omgroup}
%
% \begin{omgroup}[id=sec:user:sharing]{Structure Sharing}
%
%   The \DescribeMacro{\STRlabel}|\STRlabel| macro takes two arguments: a label and the
%   content and stores the the content for later use by
%   \DescribeMacro{\STRcopy}|\STRcopy[|\meta{URL}|]{|\meta{label}|}|, which expands to the
%   previously stored content. If the |\STRlabel| macro was in a different file, then we
%   can give a URL \meta{URL} that lets {\latexml} generate the correct reference.
%
%   \DescribeMacro{\STRsemantics} The |\STRlabel| macro has a variant |\STRsemantics|,
%   where the label argument is optional, and which takes a third argument, which is
%   ignored in {\LaTeX}. This allows to specify the meaning of the content (whatever that
%   may mean) in cases, where the source document is not formatted for presentation, but
%   is transformed into some content markup format.\ednote{document LMID und LMXREf here
%   if we decide to keep them.}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:gvars]{Global Variables}
% 
%   Text fragments and modules can be made more re-usable by the use of global
%   variables. For instance, the admin section of a course can be made course-independent
%   (and therefore re-usable) by using variables (actually token registers)
%   |courseAcronym| and |courseTitle| instead of the text itself. The variables can then
%   be set in the \sTeX preamble of the course notes file.
%   \DescribeMacro{\setSGvar}|\setSGvar{|\meta{vname}|}{|\meta{text}|}| to set the global
%   variable \meta{vname} to \meta{text} and
%   \DescribeMacro{\useSGvar}|\useSGvar{|\meta{vname}|}| to reference it.
%
%   With \DescribeMacro{\ifSGvar}|\ifSGvar| we can test for the contents of a global
%   variable: the macro call |\ifSGvar{|\meta{vname}|}{|\meta{val}|}{|\meta{ctext}|}|
%   tests the content of the global variable \meta{vname}, only if (after expansion) it is
%   equal to \meta{val}, the conditional text \meta{ctext} is formatted.
% \end{omgroup}
%
% \begin{omgroup}[id=sec:user:colors]{Colors}
% 
%   For convenience, the |omdoc| package defines a couple of color macros for the |color|
%   package: For instance \DescribeMacro{\blue}|\blue| abbreviates |\textcolor{blue}|, so
%   that |\blue{|\meta{something}|}| writes \meta{something} in blue. The macros
%   \DescribeMacro{\red}|\red| \DescribeMacro{...}|\green|, |\cyan|, |\magenta|, |\brown|,
%   |\yellow|, |\orange|, |\gray|, and finally \DescribeMacro{\black}|\black| are
%   analogous.
% \end{omgroup}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:limitations]{Limitations}
% 
% In this section we document known limitations. If you want to help alleviate them,
% please feel free to contact the package author. Some of them are currently discussed in
% the \sTeX GitHub repository~\cite{sTeX:github:on}. 
% \begin{enumerate}
% \item when option |book| which uses |\pagestyle{headings}| is given and semantic macros
%   are given in the |omgroup| titles, then they sometimes are not defined by the time the
%   heading is formatted. Need to look into how the headings are made. 
% \end{enumerate}
% \end{omgroup}
% 
% \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\newpage\printbibliography}\newpage
%
% \begin{omgroup}[id=sec:impl:cls]{Implementation: The OMDoc Class}
%
%   The functionality is spread over the |omdoc| class and package. The class provides the
%   |document| environment and the |omdoc| element corresponds to it, whereas the
%   package provides the concrete functionality.
% 
% \begin{omgroup}[id=sec:impl:cls:options]{Class Options}
%   To initialize the |omdoc| class, we declare and process the necessary options using
%   the |kvoptions| package for  key/value options handling. For
%   |omdoc.cls| this is quite simple. We have options |report| and |book|, which set the
%   \DescribeMacro{\omdoc@cls@class}|\omdoc@cls@class| macro and pass on the macro to |omdoc.sty|
%   for further processing. 
% 
%    \begin{macrocode}
%<*cls>
\RequirePackage{etoolbox}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=omdoc@cls,prefix=omdoc@cls@}
\DeclareStringOption[article]{class}
\AddToKeyvalOption*{class}{\PassOptionsToPackage{class=\omdoc@cls@class}{omdoc}}
%    \end{macrocode}
%
% the following options are deprecated.
%
%    \begin{macrocode}
\DeclareVoidOption{report}{\def\omdoc@cls@class{report}%
\ClassWarning{omdoc}{the option 'report' is deprecated, use 'class=report', instead}}
\DeclareVoidOption{book}{\def\omdoc@cls@class{book}%
\ClassWarning{omdoc}{the option 'part' is deprecated, use 'class=book', instead}}
\DeclareVoidOption{bookpart}{\def\omdoc@cls@class{book}%
\PassOptionsToPackage{topsect=chapter}{omdoc}%
\ClassWarning{omdoc}{the option 'bookpart' is deprecated, use 'class=book,topsect=chapter', instead}}
%    \end{macrocode}
% the rest of the options are only passed on to |omdoc.sty| and the class selected by the
% first options.  We need to load the |etoolbox| package early for |\@xappto|. 
%    \begin{macrocode}
\def\@omdoc@cls@docopt{}
\DeclareDefaultOption{%
\ifx\@omdoc@cls@docopt\@empty%
\xdef\@omdoc@cls@docopt{\CurrentOption}%
\else\xappto\@omdoc@cls@docopt{,\CurrentOption}%
\fi}%
\PassOptionsToPackage{\CurrentOption}{omdoc}
\PassOptionsToPackage{\CurrentOption}{stex}
\ProcessKeyvalOptions{omdoc@cls}
%    \end{macrocode}
%
% We load |article.cls|, and the desired packages. For the {\latexml} bindings, we make
% sure the right packages are loaded.
%
%    \begin{macrocode}
\LoadClass[\@omdoc@cls@docopt]{\omdoc@cls@class}
\RequirePackage{omdoc}
\RequirePackage{stex}
%    \end{macrocode}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:cls:document]{Beefing up the \texttt{document} environment}
%
% Now, we will define the environments we need.  The top-level one is the |document|
% environment, which we redefined so that we can provide keyval arguments.
%
% \begin{environment}{document}
%   For the moment we do not use them on the {\LaTeX} level, but the document identifier
%   is picked up by {\latexml}.\ednote{faking documentkeys for now. @HANG, please implement}
%    \begin{macrocode}
\srefaddidkey{document}
\newcommand\documentkeys[1]{\metasetkeys{document}{#1}}
\let\orig@document=\document
\renewcommand{\document}[1][]{\metasetkeys{document}{#1}\orig@document}
%</cls>
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:sty]{Implementation: OMDoc Package}
%
% \begin{omgroup}[id=sec:impl:options]{Package Options}
%
%   We declare some switches which will modify the behavior according to the package
%   options. Generally, an option |xxx| will just set the appropriate switches to true
%   (otherwise they stay false).
%
%    \begin{macrocode}
%<*package>
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=omdoc@sty,prefix=omdoc@sty@}
\DeclareBoolOption{mh}
\DeclareStringOption[article]{class}
\DeclareBoolOption{showignores}
\DeclareStringOption[section]{topsect}
\newcount\section@level 
\DeclareDefaultOption{\PassOptionsToPackage{\CurrentOption}{sref}}
\ProcessKeyvalOptions{omdoc@sty}
%    \end{macrocode}
%
% Then we need to set up the packages by requiring the |sref| package to be loaded.
%
%    \begin{macrocode}
\ifomdoc@sty@mh\RequirePackage{omdoc-mh}\fi
\RequirePackage{sref}
\RequirePackage{xspace}
\RequirePackage{comment}
\RequirePackage{pathsuris}
%    \end{macrocode}
%
% Finally, we set the \DescribeMacro{\section@level}|\section@level| macro that governs
% sectioning. The default is two (corresponding to the |article| class), then we set the
% defaults for the standard classes |book| and |report| and then we take care of the
% levels passed in via the |topsect| option.
%
%    \begin{macrocode}
\section@level=2
\ifdefstring{\omdoc@sty@class}{book}{\section@level=0}{}
\ifdefstring{\omdoc@sty@class}{report}{\section@level=0}{}
\ifdefstring{\omdoc@sty@topsect}{part}{\section@level=0}{}
\ifdefstring{\omdoc@sty@topsect}{chapter}{\section@level=1}{}
%    \end{macrocode}
%
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:struct]{Document Structure}
% 
%   The structure of the document is given by the |omgroup| environment just like in
%   OMDoc. The hierarchy is adjusted automatically according to the {\LaTeX} class in
%   effect. 
% \begin{macro}{\currentsectionlevel}
%   For the |\currentsectionlevel| and |\Currentsectionlevel| macros we use an internal
%   macro |\current@section@level| that only contains the keyword (no markup). We
%   initialize it with ``document'' as a default. In the generated OMDoc, we only generate
%   a text element of class |omdoc_currentsectionlevel|, wich will be instantiated by CSS
%   later.\ednote{MK: we may have to experiment with the more powerful uppercasing macro
%   from \texttt{mfirstuc.sty} once we internationalize.}
%    \begin{macrocode}
\def\current@section@level{document}%
\newcommand\currentsectionlevel{\lowercase\expandafter{\current@section@level}\xspace}%
\newcommand\Currentsectionlevel{\expandafter\MakeUppercase\current@section@level\xspace}%
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{blindomgroup}
% \begin{macrocode}
\newcommand\at@begin@blindomgroup[1]{}
\newenvironment{blindomgroup}
{\advance\section@level by 1\at@begin@blindomgroup\setion@level}
{\advance\section@level by -1}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\omgroup@nonum}
%   convenience macro: |\omgroup@nonum{|\meta{level}|}{|\meta{title}|}| makes an unnumbered
%   sectioning with title \meta{title} at level \meta{level}.
%    \begin{macrocode}
\newcommand\omgroup@nonum[2]{%
\ifx\hyper@anchor\@undefined\else\phantomsection\fi%
\addcontentsline{toc}{#1}{#2}\@nameuse{#1}*{#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\omgroup@num}
%   convenience macro: |\omgroup@nonum{|\meta{level}|}{|\meta{title}|}| makes numbered
%   sectioning with title \meta{title} at level \meta{level}. We have to check the |short|
%   key was given in the |omgroup| environment and -- if it is use it. But how to do that
%   depends on whether the |rdfmeta| package has been loaded. In the end we call
%   |\sref@label@id| to enable crossreferencing.
%    \begin{macrocode}
\newcommand\omgroup@num[2]{%
\edef\@@ID{\sref@id}
\ifx\omgroup@short\@empty% no short title
\@nameuse{#1}{#2}%
\else% we have a short title
\@ifundefined{rdfmeta@sectioning}%
  {\@nameuse{#1}[\omgroup@short]{#2}}%
  {\@nameuse{rdfmeta@#1@old}[\omgroup@short]{#2}}%
\fi%
\sref@label@id@arg{\omdoc@sect@name~\@nameuse{the#1}}\@@ID}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{omgroup}
%    \begin{macrocode}
\def\@true{true}
\def\@false{false}
\srefaddidkey{omgroup}
\addmetakey{omgroup}{date}
\addmetakey{omgroup}{creators}
\addmetakey{omgroup}{contributors}
\addmetakey{omgroup}{srccite}
\addmetakey{omgroup}{type}
\addmetakey*{omgroup}{short}
\addmetakey*{omgroup}{display}
\addmetakey[false]{omgroup}{loadmodules}[true]
%    \end{macrocode}
% we define a switch for numbering lines and a hook for the beginning of groups: The
% \DescribeMacro{\at@begin@omgroup}|\at@begin@omgroup| macro allows customization. It is
% run at the beginning of the |omgroup|, i.e. after the section heading.
%    \begin{macrocode}
\newif\if@@num\@@numtrue
\newif\if@mainmatter\@mainmattertrue
\newcommand\at@begin@omgroup[3][]{}
%    \end{macrocode}
%
% Then we define a helper macro that takes care of the sectioning magic. It comes with its
% own key/value interface for customization.
%
%    \begin{macrocode}
\addmetakey{omdoc@sect}{name}
\addmetakey[false]{omdoc@sect}{clear}[true]
\addmetakey{omdoc@sect}{ref}
\addmetakey[false]{omdoc@sect}{num}[true]
\newcommand\omdoc@sectioning[3][]{\metasetkeys{omdoc@sect}{#1}%
\ifx\omdoc@sect@clear\@true\cleardoublepage\fi%
\if@@num% numbering not overridden by frontmatter, etc.
\ifx\omdoc@sect@num\@true\omgroup@num{#2}{#3}\else\omgroup@nonum{#2}{#3}\fi%
\def\current@section@level{\omdoc@sect@name}%
\else\omgroup@nonum{#2}{#3}%
\fi}% if@@num
%    \end{macrocode}
% and another one, if redefines the |\addtocontentsline| macro of {\LaTeX} to import the
% respective macros. It takes as an argument a list of module names.\ednote{MK: the
% extension sms is hard-coded here, but should not be. This will not work in multilingual
% settings.}
%    \begin{macrocode}
\newcommand\omgroup@redefine@addtocontents[1]{%
\edef\@@import{#1}%
\@for\@I:=\@@import\do{%
\edef\@path{\csname module@\@I  @path\endcsname}%
\@ifundefined{tf@toc}\relax%
     {\protected@write\tf@toc{}{\string\@requiremodules{\@path}{sms}}}}
\ifx\hyper@anchor\@undefined% hyperref.sty loaded?
\def\addcontentsline##1##2##3{%
\addtocontents{##1}{\protect\contentsline{##2}{\string\withusedmodules{#1}{##3}}{\thepage}}}
\else% hyperref.sty not loaded
\def\addcontentsline##1##2##3{%
\addtocontents{##1}{\protect\contentsline{##2}{\string\withusedmodules{#1}{##3}}{\thepage}{\@currentHref}}}%
\fi}% hypreref.sty loaded?
%    \end{macrocode}
% now the |omgroup| environment itself. This takes care of the table of contents via the
% helper macro above and then selects the appropriate sectioning command from
% |article.cls|.
%    \begin{macrocode}
\newenvironment{omgroup}[2][]% keys, title
{\metasetkeys{omgroup}{#1}\sref@target%
\ifx\omgroup@display\st@flow\@@numfalse\fi
\if@mainmatter\else\@@numfalse\fi
%    \end{macrocode}
% If the |loadmodules| key is set on |\begin{omgroup}|, we redefine the |\addcontetsline|
%   macro that determines how the sectioning commands below construct the entries for the
%   table of contents.
%    \begin{macrocode}
\ifx\omgroup@loadmodules\@true%
\omgroup@redefine@addtocontents{\@ifundefined{mod@id}\used@modules%
{\@ifundefined{module@\mod@id @path}{\used@modules}\mod@id}}\fi%
%    \end{macrocode}
% now we only need to construct the right sectioning depending on the value of
% |\section@level|.
%    \begin{macrocode}
\advance\section@level by 1\relax%
\ifcase\section@level%
\or\omdoc@sectioning[name=Part,clear,num]{part}{#2}%
\or\omdoc@sectioning[name=Chapter,clear,num]{chapter}{#2}%
\or\omdoc@sectioning[name=Section,num]{section}{#2}%
\or\omdoc@sectioning[name=Subsection,num]{subsection}{#2}%
\or\omdoc@sectioning[name=Subsubsection,num]{subsubsection}{#2}%
\or\omdoc@sectioning[name=Paragraph,ref=this paragraph]{paragraph}{#2}%
\or\omdoc@sectioning[name=Subparagraph,ref=this subparagraph]{paragraph}{#2}%
\fi% \ifcase
\at@begin@omgroup[#1]\section@level{#2}}% for customization
{\advance\section@level by -1}
%    \end{macrocode}
% \end{environment}
% 
% \end{omgroup}
%
% \begin{omgroup}[id=sec:user:docmatter]{Front and Backmatter}
% 
%   Index markup is provided by the |omtext| package~\cite{Kohlhase:smmtf:ctan}, so in the
%   |omdoc| package we only need to supply the corresponding |\printindex| command, if it
%   is not already defined
% \begin{macro}{\printindex}
%    \begin{macrocode}
\providecommand\printindex{\IfFileExists{\jobname.ind}{\input{\jobname.ind}}{}}
%</package>
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{frontmatter}
%   some classes (e.g. |book.cls|) already have |\frontmatter|, |\mainmatter|, and
%   |\backmatter| macros. As we want to define |frontmatter| and |backmatter|
%   environments, we save their behavior (possibly defining it) in |orig@*matter| macros
%   and make them undefined (so that we can define the environments).
%    \begin{macrocode}
%<*cls>
\ifcsdef{frontmatter}% to redefine if necessary
  {\cslet{orig@frontmatter}{\frontmatter}\cslet{frontmatter}{\relax}}
  {\cslet{orig@frontmatter}{\clearpage\@mainmatterfalse\pagenumbering{roman}}}
\ifcsdef{backmatter}% to redefine if necessary
  {\cslet{orig@backmatter}{\backmatter}\cslet{backmatter}{\relax}}
  {\cslet{orig@backmatter}{\clearpage\@mainmatterfalse\pagenumbering{roman}}}
%    \end{macrocode}
% \end{environment}
% 
% \begin{environment}{frontmatter}
%   now we can define the environments
%    \begin{macrocode}
\newenvironment{frontmatter}
{\orig@frontmatter}
{\ifcsdef{mainmatter}{}{\clearpage\@mainmattertrue\pagenumbering{arabic}}}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{backmatter}
%   some classes (e.g. |book.cls|) already have a |\backmatter| macro. We use that
%   (possibly defining it). 
%    \begin{macrocode}
\newenvironment{backmatter}
{\orig@backmatter}
{\ifcsdef{mainmatter}{}{\clearpage\@mainmattertrue\pagenumbering{arabic}}}
%    \end{macrocode}
%
% finally, we make sure that page numbering is arabic.
%
%    \begin{macrocode}
\pagenumbering{arabic}
%</cls> 
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:ignore]{Ignoring Inputs}
% \begin{environment}{ignore}
%    \begin{macrocode}
%<*package>
\ifomdoc@sty@showignores
\addmetakey{ignore}{type}
\addmetakey{ignore}{comment}
\newenvironment{ignore}[1][]
{\metasetkeys{ignore}{#1}\textless\ignore@type\textgreater\bgroup\itshape}
{\egroup\textless/\ignore@type\textgreater}
\renewenvironment{ignore}{}{}\else\excludecomment{ignore}\fi
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:share]{Structure Sharing}
%   \ednote{The following is simply copied over from the |latexml| package, which we
%   eliminated, we should integrate better.}
%    \begin{macrocode}
\providecommand{\lxDocumentID}[1]{}%
\def\LXMID#1#2{\expandafter\gdef\csname xmarg#1\endcsname{#2}\csname xmarg#1\endcsname}
\def\LXMRef#1{\csname xmarg#1\endcsname}
%    \end{macrocode}
%
% \begin{macro}{\STRlabel}
%    The main macro, it it used to attach a label to some text expansion. Later on, using the
%    |\STRcopy| macro, the author can use this label to get the expansion originally assigned.
%    \begin{macrocode}
\long\def\STRlabel#1#2{\STRlabeldef{#1}{#2}{#2}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\STRcopy}
%   The |\STRcopy| macro is used to call the expansion of a given label. In case the label
%   is not defined it will issue a warning.\ednote{MK: we need to do something about the
%   ref!}
%    \begin{macrocode}
\newcommand\STRcopy[2][]{\expandafter\ifx\csname STR@#2\endcsname\relax
\message{STR warning: reference #2 undefined!}
\else\csname STR@#2\endcsname\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\STRsemantics}
%    if we have a presentation form and a semantic form, then we can use
%    \begin{macrocode}
\newcommand\STRsemantics[3][]{#2\def\@test{#1}\ifx\@test\@empty\STRlabeldef{#1}{#2}\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\STRlabeldef}
%    This is the macro that does the actual labeling. Is it called inside |\STRlabel|
%    \begin{macrocode}
\def\STRlabeldef#1{\expandafter\gdef\csname STR@#1\endcsname}
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:gvars]{Global Variables}
%
% \begin{macro}{\setSGvar}
%   set a global variable
%    \begin{macrocode}
\newcommand\setSGvar[1]{\@namedef{sTeX@Gvar@#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\useSGvar}
%   use a global variable
%    \begin{macrocode}
\newcommand\useSGvar[1]{\@nameuse{sTeX@Gvar@#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSGvar}
%   set a global variable
%    \begin{macrocode}
\newcommand\ifSGvar[3]{\def\@test{#2}\expandafter\ifx\csname sTeX@Gvar@#1\endcsname\@test #3\fi}
%    \end{macrocode}
% \end{macro}
%
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:colors]{Colors}
% 
% \begin{environment}{blue, red, green, magenta}
%    We will use the following abbreviations for colors from |color.sty|
%    \begin{macrocode}
\def\black#1{\textcolor{black}{#1}}
\def\gray#1{\textcolor{gray}{#1}}
\def\blue#1{\textcolor{blue}{#1}}
\def\red#1{\textcolor{red}{#1}}
\def\green#1{\textcolor{green}{#1}}
\def\cyan#1{\textcolor{cyan}{#1}}
\def\magenta#1{\textcolor{magenta}{#1}}
\def\brown#1{\textcolor{brown}{#1}}
\def\yellow#1{\textcolor{yellow}{#1}}
\def\orange#1{\textcolor{orange}{#1}}
%</package>
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
% \end{omgroup}
% \Finale
\endinput
% \iffalse
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi
% LocalWords:  GPL structuresharing STR omdoc dtx stex CPERL LoadClass url dc filedate om 
% LocalWords:  RequirePackage RegisterNamespace namespace xsl DocType ltxml dtd DAG hline
% LocalWords:  ltx DefEnvironment beforeDigest AssignValue inPreamble getGullet rangle
% LocalWords:  afterDigest keyval omgroup DefKeyVal Semiverbatim KeyVal srcf frontmatter
% LocalWords:  OptionalKeyVals DefParameterType IfBeginFollows skipSpaces CMP rangle xdef
% LocalWords:  ifNext DefMacro needwrapper unlist DefConstructor omtext bgroup showmods
% LocalWords:  useCMPItemizations RefStepItemCounter egroup beginItemize li di pathsuris
% LocalWords:  beforeDigestEnd dt autoclose ul ol dl env showignores srcref Cwd rdfmeta
% LocalWords:  afterOpen LastSeenCMP autoClose DefCMPEnvironment proto ToString st@flow
% LocalWords:  addAttribute nlex nlcex omdocColorMacro args tok MergeFont qw setion@level
% LocalWords:  TokenizeInternal toString isMath foreach maybeCloseElement id'd Backmatter
% LocalWords:  autoOpen minipage footnotesize scriptsize numberIt whatsit href endinput
% LocalWords:  getAttribute setAttribute OMDoc RelaxNGSchema noindex xml lec KeyVals
% LocalWords:  Subsubsection useDefaultItemizations refundefinedtrue sblockquote defindex
% LocalWords:  DefCMPConstructor sinlinequote idx idt ide idp emph  extrefs sref Tokenize
% LocalWords:  flushleft flushright DeclareOption PassOptions undef cls iffalse noauxreq
% LocalWords:  ProcessOptions subparagraph ignoresfalse ignorestrue texttt ttin behavior
% LocalWords:  texttt latexml fileversion maketitle newpage tableofcontents cwd srccite
% LocalWords:  newpage ednote ctancite dmt03 smms inlinedef STRlabel STRcopy loadmodules
% LocalWords:  STRlabel STRsemantics STRsemantics textcolor printbibliography loadmodules
% LocalWords:  textsf langle textsf langle respetively orig renewcommand cdir capitalized
% LocalWords:  baseuri baseuri baselocal baselocal SOURCEFILE cooluri newif ifx tf@toc
% LocalWords:  SOURCEBASE chapterfalse partfalse newcount ifshow chaptertrue initialize
% LocalWords:  parttrue srefaddidkey newenvironment textbf compactenum showmeta tf@toc
% LocalWords:  noindent noindent ignorespaces ifnum thepart thechapter regexp color.sty
% LocalWords:  thesection thesubsection thesubsubsection needswrapper itshape xmarg xmarg
% LocalWords:  textgreater renewenvironment excludecomment STRlabeldef csname Section,num
% LocalWords:  expandafter endcsname xref newcommand gdef doctex metakeys Hacky arabic
% LocalWords:  metasetkeys addmetakey printindex providecommand jobname.ind importmodules
% LocalWords:  jobname.ind tocdepth hateq ensuremath xspace hatequiv equiv NeedsTeXFormat
% LocalWords:  textleadsto leadsto etoolbox blindomgroup blindomgroup docstruct setSGvar
% LocalWords:  compactitem exfig vspace currentsectionlevel currentsectionlevel setSGvar
% LocalWords:  ldots URLBASE ifclass bookfalse booktrue currentsetionlevel thedocument@ID
% LocalWords:  nonum phantomsection nameuse numtrue numfalse contentsline unnum vname
% LocalWords:  thepage hypreref.sty ifcase cleardoublepage frontmatterfalse customization
% LocalWords:  frontmattertrue pagenumbering setcounter hyperref.sty addcontetsline ctext
%  LocalWords:  mfirstuc.sty internationalize documentkeys withusedmodules Part,clear,num

% \endinput
% Local Variables:
% mode: doctex
% TeX-master: t
% End:
%  LocalWords:  crossreferencing Chapter,clear,num Subsection,num Subsubsection,num cslet
%  LocalWords:  Paragraph,ref Subparagraph,ref useSGvar useSGvar ifSGvar ifSGvar topsect
%  LocalWords:  sTeX@Gvar kvoptions omdoc@cls,prefix book,topsect xappto omdoc@sty,prefix
%  LocalWords:  ifdefstring ifcsdef cslet