summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/modules/modules.sty.ltxml
blob: 39d1584c14bfc52b7ea51d85e98a90a5d4052934 (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
# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Global;
use LaTeXML::Package;
DefEnvironment('{module} OptionalKeyVals:Module',
       "?#excluded()(<omdoc:theory "
             . "?&defined(&KeyVal(#1,'id'))(xml:id='&KeyVal(#1,'id')')(xml:id='#id')>#body</omdoc:theory>)",
#     beforeDigest=>\&useTheoryItemizations,
       afterDigestBegin=>sub {
       my($stomach, $whatsit)=@_;
       $whatsit->setProperty(excluded=>LookupValue('excluding_modules'));

       my $keys = $whatsit->getArg(1);
       my($id, $cd)=$keys
  && map(ToString($keys->getValue($_)),qw(id cd));
        #make sure we have an id or give a stub one otherwise:
if (not $id) {
#do magic to get a unique id for this theory
$whatsit->setProperties(beginItemize('theory'));
$id = ToString($whatsit->getProperty('id'));
}
       $cd = $id unless $cd;
       # update the catalog with paths for modules
       my $module_paths = LookupValue('module_paths') || {};
       $module_paths->{$id} = LookupValue('last_module_path');
       AssignValue('module_paths', $module_paths, 'global');

       #Update the current module position
       AssignValue(current_module => $id);
       AssignValue(module_cd => $cd) if $cd;

       #activate the module in our current scope
       $STATE->activateScope("module:".$id);

       #Activate parent scope, if present
       my $parentmod = LookupValue('parent_module');
       use_module($parentmod) if $parentmod;
       #Update the current parent module
       AssignValue("parent_of_$id"=>$parentmod,'global');
       AssignValue("parent_module" => $id);
       return; },
     afterDigest => sub {
       #Move a step up on the module ancestry
       AssignValue("parent_module" => LookupValue("parent_of_".LookupValue("parent_module")));
       return;
     });
sub use_module {
  my($module,%ancestors)=@_;
  $module = ToString($module);
  if (defined $ancestors{$module})  {
    Fatal(":module \"$module\" leads to import cycle!");
  }
  $ancestors{$module}=1;
  # Depth-first load definitions from used modules, disregarding cycles
  foreach my $used_module (@{ LookupValue("module_${module}_uses") || []}){
    use_module($used_module,%ancestors);
  }
  # then load definitions for this module
  $STATE->activateScope("module:$module"); }#$
DefMacro('\coolurion',sub {AssignValue('cooluri'=>1);});
DefMacro('\coolurioff',sub {AssignValue('cooluri'=>0);});
sub omext {
  my ($mod)=@_; my $dest='';
  if (ToString($mod)) {
    #We need a constellation of abs_path invocations
    # to make sure that all symbolic links get resolved
    my ($d,$f,$t) = pathname_split(abs_path(ToString($mod)));
    $d = pathname_relative(abs_path($d),abs_path(cwd()));
    $dest=$d."/".$f;
  }
  $dest.=".omdoc" if (ToString($mod) && !LookupValue('cooluri'));
  return Tokenize($dest);}
sub importmoduleI {
   my($stomach,$whatsit)=@_;
   my $file = $whatsit->getArg(1);
   my $omdocmod = $file.".omdoc" if $file;
   my $module = $whatsit->getArg(2);
   $module = ToString($module);
   my $containing_module = LookupValue('current_module');
   #set the relation between the current module and the one to be imported
   PushValue("module_".$containing_module."_uses"=>$module) if $containing_module;
  #check if we've already loaded this module file or no file path given
  if((!$file) || (LookupValue('file_'.$module.'_loaded'))) {use_module($module);} #if so activate it!
  else {
    #if not:
    my $gullet = $stomach->getGullet;
    #1) mark as loaded
    AssignValue('file_'.$module.'_loaded' => 1, 'global');
    #open a group for its definitions so that they are localized
    $stomach->bgroup;
    #update the last module path
    AssignValue('last_module_path', $file);
    #queue the closing tag for this module in the gullet where it will be executed
    #after all other definitions of the imported module have been taken care of
    $gullet->unread(Invocation(T_CS('\end@requiredmodule'), T_OTHER($module))->unlist);
    #we only need to load the sms definitions without generating any xml output, so we set the flag to 1
    AssignValue('excluding_modules' => 1);
    #queue this module's sms file in the gullet so that its definitions are imported
    $gullet->input($file,['sms']);
   }
   return;}
DefConstructor('\importmodule OptionalSemiverbatim {}',
   "<omdoc:imports from='?#1(&omext(#1))\##2'/>",
   afterDigest=>sub{ importmoduleI(@_)});
DefConstructor('\importOMDocmodule OptionalSemiverbatim {}{}',"<omdoc:imports from='#3\##2'/>",
afterDigest=>sub{
  #Same as \importmodule, just switch second and third argument.
  my ($stomach,$whatsit) = @_;
  my $path = $whatsit->getArg(1);
  my $ouri = $whatsit->getArg(2);
  my $module = $whatsit->getArg(3);
  $whatsit->setArgs(($path, $module,$ouri));
  importmoduleI($stomach,$whatsit);
  return;
});
DefConstructor('\metalanguage OptionalSemiverbatim {}',
   "<omdoc:imports type='metalanguage' from='?#1(&omext(#1))\##2'/>",
   afterDigest=>sub{ importmoduleI(@_)});
DefMacro('\DefMathOp OptionalKeyVals:symdef {}',
 sub {
   my($self,$keyval,$pres)=@_;
   my $name = KeyVal($keyval,'name') if $keyval;
   #Rewrite this token
   my $scopes = $STATE->getActiveScopes;
   DefMathRewrite(active=>$scopes,xpath=>'descendant-or-self::ltx:XMath',match=>ToString($pres),replace=>"\\".ToString($name));
   #Invoke symdef
   (Invocation(T_CS('\symdef'),$keyval,$name,undef,undef,$pres)->unlist);
 });
DefMacro('\symdef OptionalKeyVals:symdef {}[][]{}',
      sub {
  my($self,@args)=@_;
  ((Invocation(T_CS('\@symdef'),@args)->unlist),
   (LookupValue('excluding_modules') ? ()
     : (Invocation(T_CS('\@symdef@pres'), @args)->unlist))); });

#Current list of recognized formatter command sequences:
our @PresFormatters = qw (infix prefix postfix assoc mixfixi mixfixa mixfixii mixfixia mixfixai mixfixaii mixfixiii);
DefPrimitive('\@symdef OptionalKeyVals:symdef {}[][]{}', sub {
  my($stomach,$keys,$cs,$nargs,$opt,$presentation)=@_;
  my($name,$cd,$role,$bvars,$bvar)=$keys
    && map($_ && $_->toString,map($keys->getValue($_), qw(name cd role
    bvars bvar)));
  $cd = LookupValue('module_cd') unless $cd;
  $name = $cs unless $name;
  #Store for later lookup
  AssignValue("symdef.".ToString($cs).".cd"=>ToString($cd),'global');
  AssignValue("symdef.".ToString($cs).".name"=>ToString($name),'global');
  $nargs = (ref $nargs ? $nargs->toString : $nargs || 0);
  my $module = LookupValue('current_module');
  my $scope = (($keys && ($keys->getValue('local') || '' eq 'true')) ? 'module_local' : 'module').":".$module;

 #The DefConstructorI Factory is responsible for creating the \symbol command sequences as dictated by the \symdef
 DefConstructorI("\\".$cs->toString,convertLaTeXArgs($nargs,$opt), sub {
    my ($document,@args) = @_;
    my @props = @args;
    my $localpres = $presentation;
    @args = splice(@props,0,$nargs);
    my %prs = @props;
    $prs{isbound} = "BINDER" if ($bvars || $bvar);
    my $wrapped;
    my $parent=$document->getNode;
    if(! defined $parent->lookupNamespacePrefix("http://omdoc.org/ns")){ # namespace not already declared?
      $document->getDocument->documentElement->setNamespace("http://omdoc.org/ns","omdoc",0); }
    my $symdef_scope=$parent->exists('ancestor::omdoc:rendering'); #Are we in a \symdef rendering?
    if (($localpres =~/^LaTeXML::Token/) && $symdef_scope) {
      #Note: We should probably ask Bruce whether this maneuver makes sense
      # We jump back to digestion, at a processing stage where it has been already completed
      # Hence need to reinitialize all scopes and make a new group. This is probably expensive to do.

      my @toks = $localpres->unlist;
      while(@toks && $toks[0]->equals(T_SPACE)){ shift(@toks); }  # Remove leading space
      my $formatters = join("|",@PresFormatters);
      $formatters = qr/$formatters/;
      $wrapped = (@toks && ($toks[0]->toString =~ /^\\($formatters)$/));
      $localpres = Invocation(T_CS('\@use'),$localpres) unless $wrapped;
      # Plug in the provided arguments, doing a nasty reversion:
      my @sargs = map (Tokens($_->revert),  @args);
      $localpres = Tokens(LaTeXML::Expandable::substituteTokens($localpres,@sargs)) if $nargs>0;
      #Digest:
      my $stomach = $STATE->getStomach;
      $stomach->beginMode('inline-math');
      $STATE->activateScope($scope);
      use_module($module);
      use_module(LookupValue("parent_of_".$module)) if LookupValue("parent_of_".$module);
      $localpres=$stomach->digest($localpres);
      $stomach->endMode('inline-math');
    }
    else { #Some are already digested to Whatsit, usually when dropped from a wrapping constructor
    }
    if ($nargs == 0) {
      if (!$symdef_scope) { #Simple case - discourse flow, only a single XMTok
        #Referencing XMTok when not in \symdefs:
        $document->insertElement('ltx:XMTok',undef,(name=>$cs->toString, meaning=>$name,omcd=>$cd,role => $role,scriptpos=>$prs{'scriptpos'}));
      }
      else {
        if ($symdef_scope && ($localpres =~/^LaTeXML::Whatsit/) && (!$wrapped)) {#1. Simple case: converts to a single token
          $localpres->setProperties((name=>$cs->toString, meaning=>$name,omcd=>$cd,role => $role,scriptpos=>$prs{'scriptpos'}));
        }
        else {
          #Experimental treatment - COMPLEXTOKEN
          #$role=$role||'COMPLEXTOKEN';
          #$document->openElement('ltx:XMApp',role=>'COMPLEXTOKEN');
          #$document->insertElement('ltx:XMTok',undef,(name=>$cs->toString, meaning=>$name, omcd=>$cd, role=>$role, scriptpos=>$prs{'scriptpos'}));
          #$document->openElement('ltx:XMWrap');
          #$document->absorb($localpres);
          #$document->closeElement('ltx:XMWrap');
          #$document->closeElement('ltx:XMApp');
        }
        #We need expanded presentation when invoked in \symdef scope:

        #Suppress errors from rendering attributes when absorbing.
        #This is bad style, but we have no way around it due to the digestion acrobatics.
        my $verbosity = $LaTeXML::Global::STATE->lookupValue('VERBOSITY');
        my $errors = $LaTeXML::Global::STATE->getStatus('error');
        $LaTeXML::Global::STATE->assignValue('VERBOSITY',-5);

        #Absorb presentation:
        $document->absorb($localpres);

        #Return to original verbosity and error state:
        $LaTeXML::Global::STATE->assignValue('VERBOSITY',$verbosity);
        $LaTeXML::Global::STATE->setStatus('error',$errors);

        #Strip all/any <rendering><Math><XMath> wrappers:
        #TODO: Ugly LibXML work, possibly do something smarter
        my $parent = $document->getNode;
        my @renderings=$parent->findnodes(".//omdoc:rendering");
        foreach my $render(@renderings) {
          my $content=$render;
          while ($content && $content->localname =~/^rendering|[X]?Math/) {
            $content = $content->firstChild;
          }
          my $sibling = $content->parentNode->lastChild;
          my $localp = $render->parentNode;
          while ((defined $sibling) && (!$sibling->isSameNode($content))) {
            my $clone = $sibling->cloneNode(1);
            $localp->insertAfter($clone,$render);
            $sibling = $sibling->previousSibling;
          }
          $render->replaceNode($content);
        }
      }
    }
    else {#2. Constructors with arguments
      if (!$symdef_scope) { #2.1 Simple case, outside of \symdef declarations:
        #Referencing XMTok when not in \symdefs:
        $document->openElement('ltx:XMApp',scriptpos=>$prs{'scriptpos'},role=>$prs{'isbound'});
        $document->insertElement('ltx:XMTok',undef,(name=>$cs->toString, meaning=>$name, omcd=>$cd, role=>$role, scriptpos=>$prs{'operator_scriptpos'}));
        foreach my $carg (@args) {
          if ($carg =~/^LaTeXML::Token/) {
            my $stomach = $STATE->getStomach;
            $stomach->beginMode('inline-math');
            $carg=$stomach->digest($carg);
            $stomach->endMode('inline-math');
          }
          $document->openElement('ltx:XMArg');
          $document->absorb($carg);
          $document->closeElement('ltx:XMArg');
        }
        $document->closeElement('ltx:XMApp');
      }
      else { #2.2 Complex case, inside a \symdef declaration
        #We need expanded presentation when invoked in \symdef scope:

        #Suppress errors from rendering attributes when absorbing.
        #This is bad style, but we have no way around it due to the digestion acrobatics.
        my $verbosity = $LaTeXML::Global::STATE->lookupValue('VERBOSITY');
        my $errors = $LaTeXML::Global::STATE->getStatus('error');
        $LaTeXML::Global::STATE->assignValue('VERBOSITY',-5);

        #Absorb presentation:
        $document->absorb($localpres);

        #Return to original verbosity and error state:
        $LaTeXML::Global::STATE->assignValue('VERBOSITY',$verbosity);
        $LaTeXML::Global::STATE->setStatus('error',$errors);

        #Strip all/any <rendering><Math><XMath> wrappers:
        #TODO: Ugly LibXML work, possibly do something smarter?
        my $parent = $document->getNode;
        if(! defined $parent->lookupNamespacePrefix("http://omdoc.org/ns")){ # namespace not already declared?
          $document->getDocument->documentElement->setNamespace("http://omdoc.org/ns","omdoc",0); }
        my @renderings=$parent->findnodes(".//omdoc:rendering");
        foreach my $render(@renderings) {
          my $content=$render;
          while ($content && $content->localname =~/^rendering|[X]?Math/) {
            $content = $content->firstChild;
          }
          my $sibling = $content->parentNode->lastChild;
          my $localp = $render->parentNode;
          while ((defined $sibling) && (!$sibling->isSameNode($content))) {
            my $clone = $sibling->cloneNode(1);
            $localp->insertAfter($clone,$render);
            $sibling = $sibling->previousSibling;
          }
          $render->replaceNode($content);
        }
      }
    }},
  properties => {name=>$cs->toString, meaning=>$name,omcd=>$cd,role => $role},
  scope=>$scope);
  return; });
DefPrimitive('\abbrdef OptionalKeyVals:symdef {}[][]{}', sub {
  my($stomach,$keys,$cs,$nargs,$opt,$presentation)=@_;
  my $module = LookupValue('current_module');
  my $scope = (($keys && ($keys->getValue('local') || '' eq 'true')) ? 'module_local' : 'module').":$module";
  DefMacroI("\\".$cs->toString,convertLaTeXArgs($nargs,$opt),$presentation,
   scope=>$scope);
  return; });
DefMacro('\defpath{}{}', sub {
   my ($gullet,$arg1,$arg2)=@_;
   $arg1 = ToString($arg1);
   $arg2 = ToString($arg2);
   my $paths = LookupValue('defpath')||{};
   $$paths{"$arg1"}=$arg2;
   AssignValue('defpath'=>$paths,'global');
   DefMacro('\\'.$arg1.' {}',$arg2."/#1");
 });#$
DefPrimitive('\requiremodules{}', sub {
  my($stomach,$module)=@_;
  my $GULLET = $stomach->getGullet;
  $module = Digest($module)->toString;
  if(LookupValue('file_'.$module.'_loaded')) {}
  else {
    AssignValue('file_'.$module.'_loaded' => 1, 'global');
    $stomach->bgroup;
    AssignValue('last_module_path', $module);
    $GULLET->unread(T_CS('\end@requiredmodule'));
    AssignValue('excluding_modules' => 1);
    $GULLET->input($module,['sms']);
       }
  return;});

DefPrimitive('\end@requiredmodule{}',sub {
 #close the group
 $_[0]->egroup;
 #print STDERR "END: ".ToString(Digest($_[1])->toString);
 #Take care of any imported elements in this current module by activating it and all its dependencies
 #print STDERR "Important: ".ToString(Digest($_[1])->toString)."\n";
 use_module(ToString(Digest($_[1])->toString));
 return; });#$
DefPrimitive('\sinput Semiverbatim', sub {
  my($stomach,$module)=@_;
  my $GULLET = $stomach->getGullet;
  $module = Digest($module)->toString;
  AssignValue('file_'.$module.'_loaded' => 1, 'global');
  $stomach->bgroup;
  AssignValue('last_module_path', $module);
  $GULLET->unread(Invocation(T_CS('\end@requiredmodule'),T_OTHER($module))->unlist);
  $GULLET->input($module,['tex']);
  return;});#$
DefConstructor('\sinputref{}',"<omdoc:ref xref='#1.omdoc' type='include'/>");
DefMacro('\@symdef@pres  OptionalKeyVals:symdef {}[][]{}', sub {
  my($self,$keys, $cs,$nargs,$opt,$presentation)=@_;

  my($name,$cd,$role)=$keys
   && map($_ && $_->toString,map($keys->getValue($_), qw(name cd role)));
  $cd = LookupValue('module_cd') unless $cd;
  $name = $cs unless $name;
  AssignValue('module_name'=>$name) if $name;
  $nargs = 0 unless ($nargs);
  my $nargkey = ToString($name).'_args';
  AssignValue($nargkey=>ToString($nargs)) if $nargs;
  $name=ToString($name);

  Invocation(T_CS('\@symdef@pres@aux'),
     $cs,
     ($nargs || Tokens(T_OTHER(0))),
     symdef_presentation_pmml($cs,ToString($nargs)||0,$presentation),
#     symdef_presentation_TeX($presentation),
     (Tokens(T_OTHER($name))),
     (Tokens(T_OTHER($cd))),
     $keys)->unlist; });#$
sub symdef_presentation_pmml {
  my($cs,$nargs,$presentation)=@_;
  my @toks = $presentation->unlist;
  while(@toks && $toks[0]->equals(T_SPACE)){ shift(@toks); }  # Remove leading space
  $presentation = Tokens(@toks);
  # Wrap with \@use, unless already has a recognized formatter.
  my $formatters = join("|",@PresFormatters);
  $formatters = qr/$formatters/;
  $presentation = Invocation(T_CS('\@use'),$presentation)
    unless (@toks && ($toks[0]->toString =~ /^\\($formatters)$/));
  # Low level substitution.
  my @args = map(Invocation(T_CS('\@SYMBOL'),T_OTHER("arg:".($_))),1..$nargs);
  $presentation = Tokens(LaTeXML::Expandable::substituteTokens($presentation,@args));
  $presentation; }#$
sub  getSymmdefProperties {
  my $cd = LookupValue('module_cd');
  my $name = LookupValue('module_name');
  my $nargkey = ToString($name).'_args';
  my $nargs = LookupValue($nargkey);
  $nargs = 0 unless ($nargs);
  my %props = ('cd'=>$cd,'name'=>$name,'nargs'=>$nargs);
  return %props;}
DefConstructor('\@use{}', sub{
  my ($document,$args,%properties) = @_;
  #Notation created at \@symdef@pres@aux
  #Create the rendering:
  $document->openElement('omdoc:rendering');
  $document->openElement('ltx:Math');
  $document->openElement('ltx:XMath');
  if ($args->isMath) {$document->absorb($args);}
  else {  $document->insertElement('ltx:XMText',$args);}
  $document->closeElement('ltx:XMath');
  $document->closeElement('ltx:Math');
  $document->closeElement('omdoc:rendering');
},
properties=>sub { getSymmdefProperties($_[1]);},
               mode=>'inline_math');
sub get_cd {
   my($name,$cd,$role)=@_;
   return $cd;}
DefConstructor('\@symdef@pres@aux{}{}{}{}{} OptionalKeyVals:symdef', sub {
   my ($document,$cs,$nargs,$pmml,$name,$cd,$keys)=@_;
   my $assocarg = ToString($keys->getValue('assocarg')) if $keys;
   $assocarg = $assocarg||"0";
   my $bvars = ToString($keys->getValue('bvars')) if $keys;
   $bvars = $bvars||"0";
   my $bvar = ToString($keys->getValue('bvar')) if $keys;
   $bvar = $bvar||"0";
   my $appElement = 'om:OMA'; $appElement = 'om:OMBIND' if ($bvars || $bvar);

   $document->insertElement("omdoc:symbol",undef,(name=>$cs,"xml:id"=>ToString($cs).".sym"));
   $document->openElement("omdoc:notation",(name=>$name,cd=>$cd));
   #First, generate prototype:
   $nargs = ToString($nargs)||0;
   $document->openElement('omdoc:prototype');
   $document->openElement($appElement) if $nargs;
   my $cr="fun" if $nargs;
   $document->insertElement('om:OMS',undef,
    (cd=>$cd,
     name=>$name,
     "cr"=>$cr));
   if ($bvar || $bvars) {
     $document->openElement('om:OMBVAR');
     if ($bvar) {
       $document->insertElement('omdoc:expr',undef,(name=>"arg$bvar"));
     } else {
       $document->openElement('omdoc:exprlist',(name=>"args"));
       $document->insertElement('omdoc:expr',undef,(name=>"arg"));
       $document->closeElement('omdoc:exprlist');
     }
     $document->closeElement('om:OMBVAR');
   }
   for my $id(1..$nargs) {
     next if ($id==$bvars || $id==$bvar);
     if ($id!=$assocarg) {
       my $argname="arg$id";
       $document->insertElement('omdoc:expr',undef,(name=>"$argname"));
     }
     else {
       $document->openElement('omdoc:exprlist',(name=>"args"));
       $document->insertElement('omdoc:expr',undef,(name=>"arg"));
       $document->closeElement('omdoc:exprlist');
     }
   }
   $document->closeElement($appElement) if $nargs;
   $document->closeElement('omdoc:prototype');
   #Next, absorb rendering:
   $document->absorb($pmml);
   $document->closeElement("omdoc:notation");
 }, afterDigest=>sub { my ($stomach, $whatsit) = @_;
  my $keys = $whatsit->getArg(6);
  my $module = LookupValue('current_module');
  $whatsit->setProperties(for=>ToString($whatsit->getArg(1)));
  $whatsit->setProperty(role=>($keys ? $keys->getValue('role')
       : (ToString($whatsit->getArg(2)) ? 'applied'
  : undef))); });
sub symdef_presentation_TeX {
  my($presentation)=@_;
  my @tokens = $presentation->unlist;
  my(@frag,@frags) = ();
  while(my $tok = shift(@tokens)){
    if($tok->equals(T_PARAM)){
      push(@frags,Invocation(T_CS('\@symdef@pres@text'),Tokens(@frag))) if @frag;
      @frag=();
      my $n = shift(@tokens)->getString;
      push(@frags,Invocation(T_CS('\@symdef@pres@arg'),T_OTHER($n+1))); }
    else {
      push(@frag,T_OTHER($tok->getString)); }} # IMPORTANT! Neutralize the tokens!
  push(@frags,Invocation(T_CS('\@symdef@pres@text'),Tokens(@frag))) if @frag;
  Tokens(map($_->unlist,@frags)); }
DefConstructor('\@symdef@pres@arg{}', "<omdoc:recurse select='#select'/>",
       afterDigest=>sub { my ($stomach, $whatsit) = @_;
  my $select = $whatsit->getArg(1);
  $select = ref $select ? $select->toString : '';
  $whatsit->setProperty(select=>"*[".$select."]"); });
DefConstructor('\@symdef@pres@text{}', "<omdoc:text>#1</omdoc:text>");
DefConstructor('\requirepackage{} Semiverbatim',"<omdoc:imports from='#2'/>",
       afterDigest=>sub { my ($stomach, $whatsit) = @_;
  my $select = $whatsit->getArg(1);
  RequirePackage($select->toString); });#$
Tag('omdoc:recurse',afterOpen=>\&numberIt,afterClose=>\&locateIt);
Tag('omdoc:imports',afterOpen=>\&numberIt,afterClose=>\&locateIt);
Tag('omdoc:theory',afterOpen=>\&numberIt,afterClose=>\&locateIt);
1;