summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/stex/omdoc/omdoc.dtx
blob: cc6166803db04ef7cb5b22b0fca8da4d43311935 (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
% \iffalse meta-comment
% A LaTeX Class and Package for OMDoc Document Structures
% Copyright (c) 2009 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
%
% The development version of this file can be found at
% $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/omdoc/omdoc.dtx $
% \fi
%   
% \iffalse
%<package|cls>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{omdoc}[2012/01/28 v1.0 OMDoc document Structure]
%<cls>\ProvidesClass{omdoc}[2012/01/28 v1.0 OMDoc Documents]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{url,array,omdoc,omtext,float}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\bibliography{kwarc}
\usepackage[eso-foot,today]{svninfo}
\svnInfo $Id: omdoc.dtx 1999 2012-01-28 07:32:11Z kohlhase $
\svnKeyword $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/omdoc/omdoc.dtx $
\usepackage{stex-logo}
\usepackage{../ctansvn}
\usepackage{hyperref}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\def\tracissue#1{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}}
\begin{document}\DocInput{omdoc.dtx}\end{document}
%</driver>
% \fi
% 
%\CheckSum{364}
% 
% \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}}
%
% 
% \GetFileInfo{omdoc.sty}
% 
% \MakeShortVerb{\|}
%
% \def\omdoc{OMDoc}
% \def\latexml{{\LaTeX}ML}
% \title{{\texttt{omdoc.sty/cls}}: Semantic Markup for Open Mathematical Documents in {\LaTeX}\thanks{Version {\fileversion} (last revised
%        {\filedate})}}
%    \author{Michael Kohlhase\\
%            Jacobs University, Bremen\\
%            \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}
%
%  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.
%
%  {\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}
%
%  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{talk
%    about the advantages and give an example.}\ednote{is there a way to load documents at
%    URIs in LaTeX?}\ednote{integrate with latexml's XMRef in the Math mode.}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user]{The User Interface}\
% 
% The |omdoc| package generates four files: |omdoc.cls|, |omdoc.sty| and their {\latexml}
% bindings |omdoc.cls.ltxml| and |omdoc.sty.ltxml|. We keep the corresponding code
% fragments together, since the documentation applies to both of them and to prevent them
% from getting out of sync. The {\omdoc} class is a minimally changed variant of the
% standard |article| class that includes the functionality provided by |omdoc.sty|. Most
% importantly, |omdoc.cls| sets up the {\latexml} infrastructure and thus should be used
% if {\omdoc} is to be generated from the {\sTeX} sources. The rest of the documentation
% pertains to the functionality introduced by |omdoc.sty|.
%
% \begin{omgroup}[id=sec:user:options]{Package and Class Options}
% 
%   |omdoc.sty| has the \DescribeMacro{noindex}|noindex| package option, which allows to
%   suppress the creation of index entries. The \DescribeMacro{extrefs} option can be set
%   to activate multifile support, see~\ctancite{Kohlhase:sref} for details. 
% 
%   |omdoc.cls| accepts all options of the |omdoc.sty| (see~\sref{sec:user:options}) and
%   |article.cls| and just passes them on to these.  \ednote{describe them}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:struct]{Document Structure}
% 
%   The top-level \DescribeEnv{document}|document| environment is augmented with an
%   optional key/value argument that 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.
% 
%   \DescribeEnv{omgroup} The structure of the document is given by the |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.
%
%   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{label}|, which expands to the previously stored
%   content.
%
% \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{make an example}
% \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:user:misc]{Miscellaneous}
% \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 TRAC~\cite{sTeX:online}. 
% \begin{compactenum}
% \item none reported yet
% \end{compactenum}
% \end{omgroup}
% 
% \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\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.
% 
% |omdoc.dtx| generates four files: |omdoc.cls| (all the code between
% {\textsf{$\langle$*cls$\rangle$}} and {\textsf{$\langle$/cls$\rangle$}}), |omdoc.sty|
% (between {\textsf{$\langle$*package$\rangle$}} and
% {\textsf{$\langle$/package$\rangle$}}) and their {\latexml} bindings (between
% {\textsf{$\langle$*ltxml.cls$\rangle$}} and {\textsf{$\langle$/ltxml.cls$\rangle$}} and
% {\textsf{$\langle$*ltxml.sty$\rangle$}} and {\textsf{$\langle$/ltxml.sty$\rangle$
% respetively}}). We keep the corresponding code fragments together, since the
% documentation applies to both of them and to prevent them from getting out of sync.
%
% \begin{omgroup}[id=sec:impl:cls:options]{Class Options}
% To initialize the |omdoc| class, we declare and process the necessary options.  
% 
%    \begin{macrocode}
%<*cls>
\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}}
\def\omdoc@class{article}
\DeclareOption{report}{\def\omdoc@class{report}\PassOptionsToPackage{\CurrentOption}{omdoc}}
\DeclareOption{book}{\def\omdoc@class{book}\PassOptionsToPackage{\CurrentOption}{omdoc}}
\DeclareOption{chapter}{\PassOptionsToPackage{\CurrentOption}{omdoc}}
\DeclareOption{part}{\PassOptionsToPackage{\CurrentOption}{omdoc}}
\DeclareOption{showignores}{\PassOptionsToPackage{\CurrentOption}{omdoc}}
\DeclareOption{extrefs}{\PassOptionsToPackage{\CurrentOption}{sref}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
%</cls>
%<*ltxml.cls>
# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use LaTeXML::Util::Pathname;
use Cwd qw(cwd abs_path);
DeclareOption('report',sub {PassOptions('omdoc','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption('book',sub {PassOptions('omdoc','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption('chapter',sub {PassOptions('omdoc','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption('part',sub {PassOptions('omdoc','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption('showignores',sub {PassOptions('omdoc','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption('extrefs',sub {PassOptions('sref','sty',ToString(Digest(T_CS('\CurrentOption')))); }); 
DeclareOption(undef,sub {PassOptions('article','cls',ToString(Digest(T_CS('\CurrentOption')))); });
ProcessOptions();
%</ltxml.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}
%<*cls>
\LoadClass{\omdoc@class}
\RequirePackage{omdoc}
%</cls>
%<*ltxml.cls>
LoadClass('article');
RequirePackage('sref');
%</ltxml.cls>
%    \end{macrocode}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:cls:namespaces]{Setting up Namespaces and Schemata for LaTeXML}
%
% Now, we also need to register the namespace prefixes for {\latexml} to use. 
%    \begin{macrocode}
%<*ltxml.cls>
RegisterNamespace('omdoc'=>"http://omdoc.org/ns");
RegisterNamespace('om'=>"http://www.openmath.org/OpenMath");
RegisterNamespace('m'=>"http://www.w3.org/1998/Math/MathML");
RegisterNamespace('dc'=>"http://purl.org/dc/elements/1.1/");
RegisterNamespace('cc'=>"http://creativecommons.org/ns");
RegisterNamespace('stex'=>"http://kwarc.info/ns/sTeX");
RegisterNamespace('ltx'=>"http://dlmf.nist.gov/LaTeXML");
%</ltxml.cls>
%    \end{macrocode}
% Since we are dealing with a class, we need to set up the document type in the {\latexml}
% bindings. 
%    \begin{macrocode}
%<*ltxml.cls>
RelaxNGSchema('omdoc+ltxml',
        '#default'=>"http://omdoc.org/ns",
        'om'=>"http://www.openmath.org/OpenMath",
        'm'=>"http://www.w3.org/1998/Math/MathML",
        'dc'=>"http://purl.org/dc/elements/1.1/",
        'cc'=>"http://creativecommons.org/ns",
       'stex'=>"http://kwarc.info/ns/sTeX",
       'ltx'=>"http://dlmf.nist.gov/LaTeXML");
%</ltxml.cls>
%    \end{macrocode}
% Then we load the |omdoc| package, which we define separately in the next section so that
% it can be loaded separately\ednote{reword}
%    \begin{macrocode}
%<*ltxml.cls>
RequirePackage('omdoc');
%</ltxml.cls>
%    \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}.
%    \begin{macrocode}
%<*cls>
\let\orig@document=\document
\srefaddidkey{document}
\renewcommand{\document}[1][]{\metasetkeys{document}{#1}\orig@document}
%</cls>
%<*ltxml.cls>
sub xmlBase {
  my $baseuri = LookupValue('baseuri');
  my $baselocal = LookupValue('baselocal');
  my $cdir = abs_path(cwd());
  $cdir =~ s/^$baselocal// if $baselocal;
  #DG: Make this more robust!
  my ($d,$f,$t);
  my $srcf = LookupValue('SOURCEFILE');
  if ( $srcf =~ /^(\w+):\/\//) {
    $srcf =~ s/^(\w+):\///;
  } # TODO: Hacky, do something better
  ($d, $f,$t) = pathname_split(LookupValue('SOURCEFILE'));
  $t = '' if LookupValue('cooluri');
  Tokenize($baseuri.$cdir.'/'.$f.$t); }
DefEnvironment('{document} OptionalKeyVals:omdoc',
       "<omdoc:omdoc "
      .    "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')')"
      .     "(?&Tokenize(&LookupValue('SOURCEBASE'))"
      .      "(xml:id='&Tokenize(&LookupValue('SOURCEBASE')).omdoc')()) "
      .    "?&Tokenize(&LookupValue('baseuri'))"
      .    "(xml:base='&xmlBase()')()>"
     .  "#body"
      ."</omdoc:omdoc>",
  beforeDigest=> sub { AssignValue(inPreamble=>0); },
  afterDigest=> sub { $_[0]->getGullet->flush; return; });#$
%</ltxml.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}
% 
% The initial setup for {\latexml}: 
%
%    \begin{macrocode}
%<*ltxml.sty>
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use Cwd qw(cwd abs_path);
%</ltxml.sty>
%    \end{macrocode}
%
% 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).\ednote{need an implementation for {\latexml}}
%
%    \begin{macrocode}
%<*package>
\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}}
\newif\if@chapter\@chapterfalse
\newif\if@part\@partfalse
\newcount\section@level\section@level=3
\newif\ifshow@ignores\show@ignoresfalse
\def\omdoc@class{article}
\DeclareOption{report}{\def\omdoc@class{report}\section@level=2}
\DeclareOption{book}{\def\omdoc@class{book}\section@level=1}
\DeclareOption{chapter}{\section@level=2\@chaptertrue}
\DeclareOption{part}{\section@level=1\@chaptertrue\@parttrue}
\DeclareOption{showignores}{\show@ignorestrue}
\DeclareOption{extrefs}{\PassOptionsToPackage{\CurrentOption}{sref}}
\ProcessOptions
%</package>
%<*ltxml.sty>
DeclareOption('report','');
DeclareOption('book','');
DeclareOption('chapter','');
DeclareOption('part','');
DeclareOption('showignores','');
DeclareOption('extrefs','');
%</ltxml.sty>
%    \end{macrocode}
%
% Then we need to set up the packages by requiring the |sref| package to be loaded.
%
%    \begin{macrocode}
%<*package>
\RequirePackage{sref}
\RequirePackage{xspace}
\RequirePackage{comment}
%</package>
%<*ltxml.sty>
RequirePackage('sref'); 
RequirePackage('xspace'); 
RequirePackage('omtext');
%</ltxml.sty>
%    \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\ednote{maybe define the toplevel
%   according to a param, need to know how to detect that the chapter macro exists.}
% \begin{macro}{\currentsectionlevel}
%    \begin{macrocode}
%<*package>
\def\level@section#1{\ifcase#1\or{part}\or{chapter}\or{section}\or{subsection}\or{subsubsection}\or{paragraph}\or{subparagraph}\fi}
\def\Level@Section#1{\ifcase#1\or{Part}\or{Chapter}\or{Section}\or{Subsection}\or{Subsubsection}\or{Paragraph}\or{Subparagraph}\fi}
\def\in@level@section#1{\ifcase#1\or{this document}\or{part}\or{chapter}\or{section}\or{subsection}\or{subsubsection}\or{paragraph}\or{subparagraph}\fi}
\def\In@Level@Section#1{\ifcase#1\or{This document}\or{Part}\or{Chapter}\or{Section}\or{Subsection}\or{Subsubsection}\or{Paragraph}\or{Subparagraph}\fi}
\def\currentsectionlevel{\in@level@section\section@level\xspace}
\def\CurrentSectionLevel{\In@Level@Section\section@level\xspace}
%</package>
%<*ltxml.sty>
%</ltxml.sty>
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{omgroup}
%   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}
%<*package>
\srefaddidkey{omgroup}
\addmetakey{omgroup}{creators}
\addmetakey{omgroup}{date}
\addmetakey{omgroup}{contributors}
\addmetakey{omgroup}{type}
\addmetakey*{omgroup}{short}
\addmetakey*{omgroup}{display}
\def\at@begin@omgroup#1{}
\newenvironment{omgroup}[2][]% keys, title
{\metasetkeys{omgroup}{#1}\sref@target%
\ifx\omgroup@display\st@flow\noindent{\Large\textbf{#2}\\[.3ex]\noindent\ignorespaces}%
\else%
\if@part\ifnum\section@level=1\part{#2}\sref@label@id{Part \thepart}\fi\fi%
\if@chapter\ifnum\section@level=2\chapter{#2}\sref@label@id{Chapter \thechapter}\fi\fi%
\ifnum\section@level=3\section{#2}\sref@label@id{Section \thesection}\fi%
\ifnum\section@level=4\subsection{#2}\sref@label@id{Subsection \thesubsection}\fi%
\ifnum\section@level=5\subsubsection{#2}\sref@label@id{Subsubsection \thesubsubsection}\fi%
\ifnum\section@level=6\paragraph{#2}\sref@label@id{this paragraph}\fi%
\ifnum\section@level=7\subparagraph{#2}\sref@label@id{this subparagraph}\fi%
\at@begin@omgroup\section@level% for customization
\advance\section@level by 1%
\fi}{\advance\section@level by -1}
%</package>
%<*ltxml.sty> 
DefEnvironment('{omgroup} OptionalKeyVals:omgroup {}',
               "<omdoc:omgroup layout='sectioning'"
               .   "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')')()"
               .   "?&KeyVal(#1,'type')(type='&KeyVal(#1,'type')')()>\n"
  	       . "<dc:title>#2</dc:title>\n"
	       . "#body\n"
	     . "</omdoc:omgroup>");
%</ltxml.sty>
%    \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}
%<*package>
\providecommand\printindex{\IfFileExists{\jobname.ind}{\input{\jobname.ind}}{}} 
%</package>
%<*ltxml.sty>
DefConstructor('\printindex','<omdoc:index/>');
%</ltxml.sty>
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\tableofcontents}
%   The table of contents already exists in {\LaTeX}, so we only need to provide a
%   {\latexml} binding for it.
%    \begin{macrocode}
%<*ltxml.sty>
DefConstructor('\tableofcontents',"<omdoc:tableofcontents level='&ToString(&CounterValue('tocdepth'))'/>");
%</ltxml.sty>
%    \end{macrocode}
% \end{macro}
%
% The case of the |\bibliography| command is similar
%
% \begin{macro}{\bibliography}
%    \begin{macrocode}
%<*ltxml.sty>
DefConstructor('\bibliography{}',"<omdoc:bibliography files='#1'/>");
%</ltxml.sty>
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:ignore]{Ignoring Inputs}
% \begin{environment}{ignore}
%    \begin{macrocode}
%<*package>
\ifshow@ignores
\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
%</package>
%<*ltxml.sty>
DefKeyVal('ignore','type','Semiverbatim');
DefKeyVal('ignore','comment','Semiverbatim');
DefEnvironment('{ignore} OptionalKeyVals:ignore',
               "<omdoc:ignore  %&KeyVals(#1)>#body</omdoc:ignore>");
%</ltxml.sty>
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:share]{Structure Sharing}
%
% \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}
%<*package>
\long\def\STRlabel#1#2{\STRlabeldef{#1}{#2}{#2}}
%</package>
%<*ltxml.sty>
DefConstructor('\STRlabel{}{}', sub {
  my($document,$label,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
%</ltxml.sty>
%    \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.
%    \begin{macrocode}
%<*package>
\def\STRcopy#1{\expandafter\ifx\csname STR@#1\endcsname\relax
\message{STR warning: reference #1 undefined!}
\else\csname STR@#1\endcsname\fi}
%</package>
%<*ltxml.sty>
DefConstructor('\STRcopy{}',"<omdoc:ref xref='##1'/>");
%</ltxml.sty>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\STRsemantics}
%    if we have a presentation form and a semantic form, then we can use
%    \begin{macrocode}
%<*package>
\newcommand{\STRsemantics}[3][]{#2\def\@test{#1}\ifx\@test\@empty\STRlabeldef{#1}{#2}\fi}
%</package>
%<*ltxml.sty>
DefConstructor('\STRsemantics[]{}{}', sub {
  my($document,$label,$ignore,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
%</ltxml.sty>#$
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\STRlabeldef}
%    This is the macro that does the actual labeling. Is it called inside |\STRlabel|
%    \begin{macrocode}
%<*package>
\def\STRlabeldef#1{\expandafter\gdef\csname STR@#1\endcsname}
%</package>
%<*ltxml.sty>
DefMacro('\STRlabeldef{}{}', "");
%</ltxml.sty>
%    \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}
%<*package>
\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}
% For the {\latexml} bindings, we go a generic route, we replace |\blue{#1}| by 
% |{\@omdoc@color{blue}\@omdoc@color@content{#1}}|. 
%    \begin{macrocode}
%<*ltxml.sty>
sub omdocColorMacro {
  my ($color, @args) = @_;
  my $tok_color = TokenizeInternal($color);
  (T_BEGIN, T_CS('\@omdoc@color'), T_BEGIN, $tok_color->unlist,
   T_END, T_CS('\@omdoc@color@content'), T_OTHER('['), $tok_color->unlist, T_OTHER(']'),
   T_BEGIN, $args[1]->unlist, T_END, T_END); }
DefMacro('\@omdoc@color{}', sub { MergeFont(color=>$_[1]->toString); return; });#$
%</ltxml.sty>
%    \end{macrocode}
% Ideally, here we will remove the optional argument and have a conversion module
% add the attribute at the end (or maybe add it just for math?)
% or, we can take the attributes for style from the current font ?
%    \begin{macrocode}
%<*ltxml.sty>
DefConstructor('\@omdoc@color@content[]{}',
  "?#isMath(#2)(<ltx:text ?#1(style='color:#1')()>#2</ltx:text>)");
foreach my $color(qw(black gray blue red green cyan magenta brown yellow orange)) {
  DefMacro("\\".$color.'{}', sub { omdocColorMacro($color, @_); }); }#$
%</ltxml.sty>
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:commands]{{\LaTeX} Commands we interpret differently}
%
%   The reinterpretations are quite simple, we either disregard presentational markup or
%   we re-interpret it in terms of {\omdoc}.
%    \begin{macrocode}
%<*ltxml.sty>
DefConstructor('\newpage','');
%</ltxml.sty>
%    \end{macrocode}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:ids]{Providing IDs for {\omdoc} Elements}
% 
%   To provide default identifiers, we tag all {\omdoc} elements that allow |xml:id|
%   attributes by executing the |numberIt| procedure below.
% 
%    \begin{macrocode}
%<*ltxml.sty>
Tag('omdoc:ignore',afterOpen=>\&numberIt,afterClose=>\&locateIt);
Tag('omdoc:ref',afterOpen=>\&numberIt,afterClose=>\&locateIt);
%</ltxml.sty>
%    \end{macrocode}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:misc]{Miscellaneous}
% Some shortcuts that use math symbols but are not mathematical at all; in particular,
% they should not be translated by {\latexml}.
%
%    \begin{macrocode}
%<*package>
\newcommand\hateq{\ensuremath{\hat=}\xspace}
\newcommand\hatequiv{\ensuremath{\hat\equiv}\xspace}
\newcommand\textleadsto{\ensuremath{\leadsto}\xspace}
%</package>
%<*ltxml.sty>
DefConstructor('\hateq',"\x{2259}");
DefConstructor('\hatequiv',"\x{2A6F}");
DefConstructor('\textleadsto',"\x{219D}");
%</ltxml.sty>
%    \end{macrocode}
%
% \end{omgroup}
% 
% \begin{omgroup}{Leftovers}
%
%    \begin{macrocode}
%<*package>
\newcommand{\baseURI}[2][]{}
%</package>
%<*ltxml.sty>
DefMacro('\baseURI []Semiverbatim', sub {
  if (LookupValue('SOURCEFILE')!~/^(\w+):\/\//) {
    my $baselocal = ToString(Expand($_[1]));
    $baselocal = abs_path($baselocal) unless $baselocal=~/^(\w+):\/\//;
    AssignValue('baselocal'=>$baselocal);
    AssignValue('baseuri'=>ToString(Expand($_[2])));}
  else {
    AssignValue('baselocal'=>undef);
    AssignValue('baseuri'=>ToString(Expand($_[2])));
  }});
DefConstructor('\url Semiverbatim',"<omdoc:link href='#1'>#1</omdoc:link>");
DefConstructor('\href Semiverbatim {}',"<omdoc:link href='#1'>#2</omdoc:link>");
%</ltxml.sty>
%    \end{macrocode}
% \ednote{this should be handled differently, omdoc.sty should include url and give a new
% macro for it, which we then use in omdoc}
% and finally, we need to terminate the file with a success mark for perl.
%    \begin{macrocode}
%<ltxml.sty|ltxml.cls>1;
%    \end{macrocode}
% \end{omgroup}
% \end{omgroup}
% \Finale
\endinput
% \iffalse
% LocalWords:  GPL structuresharing STR omdoc dtx stex CPERL LoadClass url dc
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi
% LocalWords:  RequirePackage RegisterNamespace namespace xsl DocType ltxml dtd
% LocalWords:  ltx DefEnvironment beforeDigest AssignValue inPreamble getGullet
% LocalWords:  afterDigest keyval omgroup DefKeyVal Semiverbatim KeyVal srcf
% LocalWords:  OptionalKeyVals DefParameterType IfBeginFollows skipSpaces CMP
% LocalWords:  ifNext DefMacro needwrapper unlist DefConstructor omtext bgroup
% LocalWords:  useCMPItemizations RefStepItemCounter egroup beginItemize li di
% LocalWords:  beforeDigestEnd dt autoclose ul ol dl env showignores srcref Cwd
% LocalWords:  afterOpen LastSeenCMP autoClose DefCMPEnvironment proto ToString
% LocalWords:  addAttribute nlex nlcex omdocColorMacro args tok MergeFont qw
% LocalWords:  TokenizeInternal toString isMath foreach maybeCloseElement id'd
% LocalWords:  autoOpen minipage footnotesize scriptsize numberIt whatsit href
% LocalWords:  getAttribute setAttribute OMDoc RelaxNGSchema noindex xml lec
% LocalWords:  Subsubsection useDefaultItemizations refundefinedtrue sblockquote
% LocalWords:  DefCMPConstructor sinlinequote idx idt ide idp emph  extrefs sref
% LocalWords:  flushleft flushright DeclareOption PassOptions undef cls iffalse
% LocalWords:  ProcessOptions subparagraph ignoresfalse ignorestrue texttt ttin
% LocalWords:  texttt latexml fileversion maketitle newpage tableofcontents cwd
% LocalWords:  newpage ednote ctancite dmt03 smms inlinedef STRlabel STRcopy
% LocalWords:  STRlabel STRsemantics STRsemantics textcolor printbibliography
% LocalWords:  textsf langle textsf langle respetively orig renewcommand cdir
% LocalWords:  baseuri baseuri baselocal baselocal SOURCEFILE cooluri newif ifx
% LocalWords:  SOURCEBASE chapterfalse partfalse newcount ifshow chaptertrue
% LocalWords:  parttrue srefaddidkey newenvironment textbf compactenum showmeta
% LocalWords:  noindent noindent ignorespaces ifnum thepart thechapter regexp
% LocalWords:  thesection thesubsection thesubsubsection needswrapper itshape
% LocalWords:  textgreater renewenvironment excludecomment STRlabeldef csname
% LocalWords:  expandafter endcsname xref newcommand gdef doctex metakeys Hacky
% LocalWords:  metasetkeys addmetakey printindex providecommand jobname.ind
% LocalWords:  jobname.ind tocdepth hateq ensuremath xspace hatequiv equiv
% LocalWords:  textleadsto leadsto