summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/omdoc/omdoc.sty.ltxml
blob: 13fa706247e6c6fced455b5767bbd8e5832454cb (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
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use Cwd qw(cwd abs_path);
DeclareOption('report','');
DeclareOption('book','');
DeclareOption('chapter','');
DeclareOption('part','');
DeclareOption('showignores','');
DeclareOption('extrefs','');
RequirePackage('sref');
RequirePackage('omtext');
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 ?#locator(stex:srcref='#locator')()>#2</dc:title>\n"
       . "#body\n"
     . "</omdoc:omgroup>");
DefParameterType('IfBeginFollows', sub {
   my ($gullet) = @_;
   $gullet->skipSpaces;
                   my $next = $gullet->readToken;
                   $gullet->unread($next);
                   $next = ToString($next);
                   #Hm, falling back to regexp handling, the $gullet->ifNext approach didn't work properly
                   return 1 unless ($next=~/^\\begin/);
                   return;
                 },
 reversion=>'', optional=>1);#$
Let('\group@item@maybe@unwrap','\relax');
DefMacro('\group@item[] IfBeginFollows', sub {
  my($gullet,$tag,$needswrapper)=@_;
  ( T_CS('\group@item@maybe@unwrap'),
    ($needswrapper ? (Invocation(T_CS('\group@item@wrap'),$tag)->unlist) : ()) ); });
DefConstructor('\group@item@wrap {}',
       "<omdoc:omtext>"
       . "?#1(<dc:title>#1</dc:title>)()"
               . "<omdoc:CMP><omdoc:p>",
       beforeDigest=>sub {
 Let('\group@item@maybe@unwrap','\group@item@unwrap');
 #$_[0]->bgroup;
 useCMPItemizations();
 return; },
       properties=>sub{ RefStepItemCounter(); });
DefConstructor('\group@item@unwrap',
               "",
               beforeDigest=>sub {
                 # $_[0]->egroup;#$
                 Let('\group@item@maybe@unwrap','\relax'); },
               beforeConstruct=>sub {
                 $_[0]->maybeCloseElement('omdoc:p');
                 $_[0]->maybeCloseElement('omdoc:CMP');
                 $_[0]->maybeCloseElement('omdoc:omtext');
               });
Let('group@item@maybe@unwrap','\relax');
Let('\itemize@item'=>'\group@item');
Let('\enumerate@item'=>'\group@item');
Let('\description@item'=>'\group@item');
DefEnvironment('{itemize}',
       "<omdoc:omgroup xml:id='#id' layout='itemize'>"
              .  "#body"
              ."</omdoc:omgroup>",
       properties=>sub { beginItemize('itemize'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{enumerate}',
       "<omdoc:omgroup xml:id='#id' layout='enumerate'>#body</omdoc:omgroup>",
       properties=>sub { beginItemize('enumerate'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{description}',
       "<omdoc:omgroup xml:id='#id' layout='description'>"
              .  "#body"
              ."</omdoc:omgroup>",
       properties=>sub { beginItemize('description'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefConstructor('\printindex','<omdoc:index/>');
DefConstructor('\tableofcontents',"<omdoc:tableofcontents level='2'/>");
DefConstructor('\bibliography{}',"<omdoc:bibliography files='#1'/>");
DefKeyVal('ignore','type','Semiverbatim');
DefKeyVal('ignore','comment','Semiverbatim');
DefEnvironment('{ignore} OptionalKeyVals:ignore',
               "<omdoc:ignore  %&KeyVals(#1)>#body</omdoc:ignore>");
DefConstructor('\STRlabel{}{}', sub {
  my($document,$label,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
DefConstructor('\STRcopy{}',"<omdoc:ref xref='##1'/>");
DefConstructor('\STRsemantics[]{}{}', sub {
  my($document,$label,$ignore,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
DefMacro('\STRlabeldef{}{}', "");
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; });#$
DefConstructor('\@omdoc@color@content[]{}',
   "?#isMath(#2)(<omdoc:phrase ?#1(style='color:#1')()>#2</omdoc:phrase>)");
foreach my $color(qw(black gray blue red green cyan magenta brown yellow orange)) {
  DefMacro("\\".$color.'{}', sub { omdocColorMacro($color, @_); }); }#$
DefConstructor('\newpage','');
Tag('omdoc:ignore',afterOpen=>\&numberIt,afterClose=>\&locateIt);
Tag('omdoc:ref',afterOpen=>\&numberIt,afterClose=>\&locateIt);
DefMacro('\baseURI []Semiverbatim', sub {
    AssignValue('baselocal'=>abs_path(ToString(Expand($_[1]))));
    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>");
1;