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 {}',
"\n"
. "?#1(#1\n)()"
. "#body\n"
. "");
DefEnvironment('{tgroup} OptionalKeyVals:omgroup {}',
"\n"
. "?#1(#1\n)()"
. "#body\n"
. "");
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 {}',
""
. "?#1(#1)()"
. "",
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'); });
Let('group@item@maybe@unwrap','\relax');
Let('\itemize@item'=>'\group@item');
Let('\enumerate@item'=>'\group@item');
Let('\description@item'=>'\group@item');
DefEnvironment('{itemize}',
"#body",
properties=>sub { beginItemize('itemize'); },
beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{enumerate}',
"#body",
properties=>sub { beginItemize('enumerate'); },
beforeDigestEnd=>sub { Digest(T_CS('\group@item@maybe@unwrap')); });
DefEnvironment('{description}',
"#body",
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}',
"#body",
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}',
"#body",
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}',
"#body",
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[]',
''
. '?#1(#1)()',
properties=>sub{ RefStepItemCounter(); });
DefConstructor('\CMP@enumerate@item[]',
''
. '?#1(#1)()',
properties=>sub{ RefStepItemCounter(); });
DefConstructor('\CMP@description@item[]',
''
. '?#1(#1)()', # trust di and dt to autoclose
properties=>sub{ RefStepItemCounter(); });
DefEnvironment('{CMP@itemize}',
"#body",
properties=>sub { beginItemize('CMP@itemize'); },
beforeDigest=>sub { Let(T_CS('\end{itemize}') =>T_CS('\end{CMP@itemize}')); });
DefEnvironment('{CMP@enumerate}',
"#body",
properties=>sub { beginItemize('CMP@enumerate'); },
beforeDigest=>sub { Let(T_CS('\end{enumerate}') =>T_CS('\end{CMP@enumerate}')); });
DefEnvironment('{CMP@description}',
"#body",
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',
""
. "?&KeyVal(#1,'title')(&KeyVal(#1,'title'))()"
. "#body"
. "\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{}',"");
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 {}',
"#body");
DefConstructor('\nlex{}',"#1");
DefConstructor('\nlcex{}',"#1");
DefConstructor('\inlinequote{}',"#1");
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)(#2)");
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{}',"#1");
DefConstructor('\em',"");
Tag('omdoc:phrase', autoClose=>1);
DefEnvironment('{center}','#body');
DefEnvironment('{minipage}{}','#body');
DefEnvironment('{quote}',"#body");
DefEnvironment('{quotation}',"#body");
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[]{}',
"");
DefConstructor('\footnotemark[]',"");
DefConstructor('\footnotetext[]{}',
"");
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',"#1");
1;