summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/omdoc.sty.ltxml
blob: 24c3ca3b1195b129bed39dcff129d290ac887cda (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
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
RequirePackage('keyval');
DefKeyVal('omgroup','id','Semiverbatim');
DefKeyVal('omgroup','type','Semiverbatim');
DefKeyVal('omgroup','display','Semiverbatim');
DefEnvironment('{omgroup} OptionalKeyVals:omgroup {}',
               "<omdoc:omgroup ?&KeyVal(#1,'id')(xml:id='#1')() ?&KeyVal(#1,'type')(type='#1')()>\n"
          . "?#1(<omdoc:metadata><dc:title>#1</dc:title></omdoc:metadata>\n)()"
       . "#body\n"
     . "</omdoc:omgroup>");

DefEnvironment('{tgroup} OptionalKeyVals:omgroup {}',
               "<omdoc:tgroup ?&KeyVal(#1,'id')(xml:id='#1')() ?&KeyVal(#1,'type')(type='#1')()>\n"
          . "?#1(<omdoc:metadata><dc:title>#1</dc:title></omdoc:metadata>\n)()"
       . "#body\n"
     . "</omdoc:tgroup>");
DefParameterType('IfBeginFollows', sub {
   my ($gullet) = @_;
   $gullet->skipSpaces;
   return 1 unless $gullet->ifNext(T_CS('\begin'));
   return; },
 reversion=>'', optional=>1);

Let('\group@item@maybe@unwrap','\relax');

DefMacro('\group@item[] IfBeginFollows', sub {
  my($gullet,$tag,$needwrapper)=@_;
  ( T_CS('\group@item@maybe@unwrap'),
    ($needwrapper ? (Invocation(T_CS('\group@item@wrap'),$tag)->unlist) : ()) ); });

DefConstructor('\group@item@wrap {}',
       "<omdoc:omtext>"
       . "?#1(<omdoc:metadata><dc:title>#1</dc:title></omdoc:metadata>)()"
               . "<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',
       "</omdoc:p></omdoc:CMP></omdoc:omtext>",
       beforeDigest=>sub {
 $_[0]->egroup;
 Let('\group@item@maybe@unwrap','\relax'); });

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' type='itemize'>#body</omdoc:omgroup>",
       properties=>sub { beginItemize('itemize'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{enumerate}',
       "<omdoc:omgroup xml:id='#id' type='enumerate'>#body</omdoc:omgroup>",
       properties=>sub { beginItemize('enumerate'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{description}',
       "<omdoc:omgroup xml:id='#id' type='description'>#body</omdoc:omgroup>",
       properties=>sub { beginItemize('description'); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
Let('\tgroup@itemize@item'=>'\group@item');
Let('\tgroup@enumerate@item'=>'\group@item');
Let('\tgroup@description@item'=>'\group@item');

DefEnvironment('{tgroup@itemize}',
       "<omdoc:tgroup xml:id='#id' type='itemize'>#body</omdoc:tgroup>",
       properties=>sub { beginItemize('tgroup@itemize'); },
       beforeDigest=>sub { Let(T_CS('\end{itemize}') =>T_CS('\end{tgroup@itemize}')); },
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{tgroup@enumerate}',
       "<omdoc:tgroup xml:id='#id' type='enumerate'>#body</omdoc:tgroup>",
       properties=>sub { beginItemize('tgroup@enumerate'); },
       beforeDigest=>sub{ Let(T_CS('\end{enumerate}') =>T_CS('\end{tgroup@enumerate}'));},
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{tgroup@description}',
       "<omdoc:tgroup xml:id='#id' type='description'>#body</omdoc:tgroup>",
       properties=>sub { beginItemize('tgroup@description'); },
       beforeDigest=>sub{ Let(T_CS('\end{description}') =>T_CS('\end{tgroup@description}'));},
       beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });

sub useTheoryItemizations {
    Let(T_CS('\begin{itemize}')    =>T_CS('\begin{tgroup@itemize}'));
    Let(T_CS('\begin{enumerate}')  =>T_CS('\begin{tgroup@enumerate}'));
    Let(T_CS('\begin{description}')=>T_CS('\begin{tgroup@description}'));
    return; }
DefConstructor('\CMP@itemize@item[]',
       '<omdoc:li>'
       . '?#1(<omdoc:metadata><dc:title>#1</dc:title></omdoc:metadata>)()',
       properties=>sub{ RefStepItemCounter(); });

DefConstructor('\CMP@enumerate@item[]',
       '<omdoc:li>'
       . '?#1(<omdoc:metadata><dc:title>#1</dc:title></omdoc:metadata>)()',
       properties=>sub{ RefStepItemCounter(); });

DefConstructor('\CMP@description@item[]',
       '<omdoc:di>'
       . '?#1(<omdoc:dt>#1</omdoc:dt>)()<omdoc:dd>', # trust di and dt to autoclose
       properties=>sub{ RefStepItemCounter(); });

DefEnvironment('{CMP@itemize}',
       "<omdoc:ul xml:id='#id'>#body</omdoc:ul>",
       properties=>sub { beginItemize('CMP@itemize'); },
       beforeDigest=>sub { Let(T_CS('\end{itemize}') =>T_CS('\end{CMP@itemize}')); });
DefEnvironment('{CMP@enumerate}',
       "<omdoc:ol  xml:id='#id'>#body</omdoc:ol>",
       properties=>sub { beginItemize('CMP@enumerate'); },
       beforeDigest=>sub { Let(T_CS('\end{enumerate}') =>T_CS('\end{CMP@enumerate}')); });
DefEnvironment('{CMP@description}',
       "<omdoc:dl  xml:id='#id'>#body</omdoc:dl>",
       properties=>sub { beginItemize('CMP@description'); },
       beforeDigest=>sub { Let(T_CS('\end{description}') =>T_CS('\end{CMP@description}'));});

sub useCMPItemizations {
    Let(T_CS('\begin{itemize}')    =>T_CS('\begin{CMP@itemize}'));
    Let(T_CS('\begin{enumerate}')  =>T_CS('\begin{CMP@enumerate}'));
    Let(T_CS('\begin{description}')=>T_CS('\begin{CMP@description}'));
    return; }

Tag('omdoc:CMP', afterOpen => sub {
      AssignValue('_LastSeenCMP', $_[1], 'global');
      return; });

Tag('omdoc:li', autoClose=>1);
Tag('omdoc:dd', autoClose=>1);
Tag('omdoc:di', autoClose=>1);
DefKeyVal('stat','id','Semiverbatim');
DefKeyVal('stat','for','Semiverbatim');
DefKeyVal('stat','title','Semiverbatim');
DefKeyVal('stat','from','Semiverbatim');
DefKeyVal('stat','type','Semiverbatim');
DefKeyVal('stat','display','Semiverbatim'); # not used at the moment
DefCMPEnvironment('{omtext} OptionalKeyVals:stat',
  "<omdoc:omtext "
     . "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')')() "
     . "?&KeyVal(#1,'type')(type='&KeyVal(#1,'type')')() "
     . "?&KeyVal(#1,'for')(for='&KeyVal(#1,'for')')() "
             . "?&KeyVal(#1,'from')(from='&KeyVal(#1,'from')')()>"
  . "?&KeyVal(#1,'title')(<omdoc:metadata><dc:title>&KeyVal(#1,'title')</dc:title></omdoc:metadata>)()"
  . "<omdoc:CMP><omdoc:p>#body</omdoc:p></omdoc:CMP>"
  . "</omdoc:omtext>\n");
sub DefCMPEnvironment {
  my ($proto, $replacement, %options) = @_;
  my @before = $options{beforeDigest} ? ($options{beforeDigest}) : ();
  push(@before, \&useCMPItemizations);
  $options{beforeDigest} = \@before;
  DefEnvironment($proto, $replacement, %options);
}
DefConstructor('\STRlabel{}{}', sub {
  my($document,$label,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
DefConstructor('\STRcopy{}',"<omdoc:ref xref='#1'/>");
DefMacro('\STRlabeldef{}{}', "");
DefConstructor('\STRsemantics[]{}{}', sub {
  my($document,$label,$ignore,$object)=@_;
  $document->absorb($object);
  $document->addAttribute('xml:id'=>ToString($label)) if $label; });
DefKeyVal('phrase','id','Semiverbatim');
DefKeyVal('phrase','style','Semiverbatim');
DefKeyVal('phrase','class','Semiverbatim');
DefKeyVal('phrase','index','Semiverbatim');
DefKeyVal('phrase','verbalizes','Semiverbatim');
DefKeyVal('phrase','type','Semiverbatim');
DefConstructor('\phrase OptionalKeyVals:phrase {}',
       "<omdoc:phrase %&KeyVals(#1)>#body</omdoc:phrase>");
DefConstructor('\nlex{}',"<omdoc:phrase type='nlex'>#1</omdoc:phrase>");
DefConstructor('\nlcex{}',"<omdoc:phrase type='nlcex'>#1</omdoc:phrase>");
DefConstructor('\inlinequote{}',"<omdoc:phrase type='inlinequote'>#1</omdoc:phrase>");
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(blue red green magenta cyan brown yellow)) {
  DefMacro("\\".$color.'{}', sub { omdocColorMacro($color, @_); }); }
DefConstructor('\par',sub { $_[0]->maybeCloseElement('omdoc:p'); },alias=>"\\par\n");
Tag('omdoc:p', autoClose=>1, autoOpen=>1);
DefConstructor('\omspace{}','');
DefConstructor('\emph{}',"<omdoc:phrase class='emphasis'>#1</omdoc:phrase>");
DefConstructor('\em',"<omdoc:phrase class='emphasis'>");
Tag('omdoc:phrase', autoClose=>1);
DefEnvironment('{center}','#body');
DefEnvironment('{minipage}{}','#body');
DefEnvironment('{quote}',"<omdoc:phrase type='quote' style='display:block'>#body</omdoc:phrase>");
DefEnvironment('{quotation}',"<omdoc:phrase type='quote' style='display:block'>#body</omdoc:phrase>");
DefEnvironment('{small}','#body');
DefEnvironment('{footnotesize}','#body');
DefEnvironment('{tiny}','#body');
DefEnvironment('{scriptsize}','#body');
DefConstructor('\LARGE','');
DefConstructor('\Large','');
DefConstructor('\large','');
DefConstructor('\small','');

DefConstructor('\fbox{}','#1');

DefConstructor('\footnote[]{}',
       "<omdoc:note class='foot' ?#1(mark='#1')>#2</omdoc:note>");
DefConstructor('\footnotemark[]',"");
DefConstructor('\footnotetext[]{}',
       "<omdoc:note class='foot' ?#1(mark='#1')>#2</omdoc:note>");

DefConstructor('\sf', '');
DefConstructor('\sc', '');
Tag('omdoc:p',afterOpen=>\&numberIt);
Tag('omdoc:omtext',afterOpen=>\&numberIt);
Tag('omdoc:omgroup',afterOpen=>\&numberIt);
Tag('omdoc:tgroup',afterOpen=>\&numberIt);
Tag('omdoc:CMP',afterOpen=>\&numberIt);
sub numberIt {
  my($document,$node,$whatsit)=@_;
  my(@parents)=$document->findnodes('ancestor::*[@xml:id]',$node); # find 1st id'd parent.
  my $prefix= (@parents ? $parents[$#parents]->getAttribute('xml:id')."." : '');
  my(@siblings)=$document->findnodes('preceding-sibling::*[@xml:id]',$node);
  my $n = scalar(@siblings)+1;
  my $id = ($node -> getAttribute('xml:id'));
  $node->setAttribute('xml:id'=>$prefix."p$n") unless $id; }
DefConstructor('\url Semiverbatim',"<omdoc:link href='#1'>#1</omdoc:link>");
1;