# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
RequirePackage('keyval');
RegisterNamespace('cnx'=>"http://cnx.rice.edu/cnxml");
RegisterNamespace('md'=>"http://cnx.rice.edu/mdml/0.4");
RegisterNamespace('bib'=>"http://bibtexml.sf.net/");
RegisterNamespace('m'=>"http://www.w3.org/1998/Math/MathML");
DocType("cnx:document",
"-//CNX//DTD CNXML 0.5 plus LaTeXML//EN",
"../dtd/cnxml+ltxml.dtd",
'#default'=>"http://cnx.rice.edu/cnxml",
'md'=>"http://cnx.rice.edu/mdml/0.4",
'bib'=>"http://bibtexml.sf.net/",
'm'=>"http://www.w3.org/1998/Math/MathML",
'ltx'=>"http://dlmf.nist.gov/LaTeXML");
NewCounter('@itemizei', 'document', idprefix=>'I');
NewCounter('@itemizeii', '@itemizei', idprefix=>'I');
NewCounter('@itemizeiii', '@itemizeii', idprefix=>'I');
NewCounter('@itemizeiv', '@itemizeiii',idprefix=>'I');
NewCounter('@itemizev', '@itemizeiv', idprefix=>'I');
NewCounter('@itemizevi', '@itemizev', idprefix=>'I');
NewCounter('enumi', '@itemizei', idprefix=>'i');
NewCounter('enumii', '@itemizeii', idprefix=>'i');
NewCounter('enumiii','@itemizeiii', idprefix=>'i');
NewCounter('enumiv', '@itemizeiv', idprefix=>'i');
# A couple of more levels, since we use these for ID's!
NewCounter('enumv', '@itemizev', idprefix=>'i');
NewCounter('enumvi', '@itemizevi', idprefix=>'i');
DefMacro('\theenumi', '\arabic{enumi}');
DefMacro('\theenumii', '\alph{enumii}');
DefMacro('\theenumiii', '\roman{enumiii}');
DefMacro('\theenumiv', '\Alph{enumiv}');
NewCounter('equation', 'document', idprefix=>'E');
DefMacro('\theequation', '\arabic{equation}');
DefMacro('\textwidth','16cm');
Let('\thedocument@ID','\@empty');
DefKeyVal('cnxmodule','name','Semiverbatim');
DefKeyVal('cnxmodule','id','Semiverbatim');
DefEnvironment('{document}','#body',
beforeDigest=> sub { AssignValue(inPreamble=>0); },
afterDigest=> sub { $_[0]->getGullet->flush; return; });
DefEnvironment('{cnxmodule} OptionalKeyVals:cnxmodule',
"&KeyVal('#1','name')\n#body\n",
afterDigestBegin => sub {
AssignValue('cnxmodule_id',
KeyVal($_[1]->getArg(1), 'id')->toString,
'global');
});
Tag('cnx:document', afterClose => sub {
$_[1]->setAttribute('id', LookupValue('cnxmodule_id'));
});
DefEnvironment('{ccontent}',"#body");
DefKeyVal('sectioning','id','Semiverbatim');
DefEnvironment('{csection}OptionalKeyVals:sectioning{}',
"\n"
. "?#2(#2\n)()"
. "#body\n\n");
DefEnvironment('{csubsection}OptionalKeyVals:sectioning{}',
"\n"
. "?#2(#2\n)()"
. "#body\n\n");
DefEnvironment('{csubsubsection}OptionalKeyVals:sectioning{}',
"\n"
. "?#2(#2\n)()"
. "#body\n\n");
DefKeyVal('para','id','Semiverbatim');
DefEnvironment('{cpara} OptionalKeyVals:para','#body');
sub number_para {
my($document,$node,$whatsit)=@_;
# Get prefix from first parent with an id.
my(@parents)=$document->findnodes('ancestor::*[@id]',$node); # find 1st id'd parent.
my $prefix= (@parents ? $parents[$#parents]->getAttribute('id')."." : '');
# Get the previous number within parent; Worried about intervening elements around para's, but...
my(@siblings)=$document->findnodes("preceding-sibling::cnx:para",$node);
my $n=1;
$n = $1+1 if(@siblings && $siblings[$#siblings]->getAttribute('id')=~/(\d+)$/);
$node->setAttribute(id=>$prefix."p$n"); }
Tag('cnx:para',afterOpen=>\&number_para);
DefConstructor('\par',sub { $_[0]->maybeCloseElement('cnx:para'); },alias=>"\\par\n");
Tag('cnx:para', autoClose=>1, autoOpen=>1);
DefKeyVal('note','id','Semiverbatim');
DefKeyVal('note','type','Semiverbatim');
DefEnvironment('{cnote}OptionalKeyVals:note','#body');
DefKeyVal('equation','id','Semiverbatim');
DefEnvironment('{cequation} OptionalKeyVals:equation',
""
. ""
. "#body"
. "",
mode=>'display_math');
DefKeyVal('cquote','id','Semiverbatim');
DefKeyVal('cquote','type','Semiverbatim');
DefKeyVal('cquote','src','Semiverbatim');
DefEnvironment('{cquote} OptionalKeyVals:cquote',
"#body");
DefConstructor('\footnote[]{}',"#2");
DefConstructor('\emph{}',"#1");
DefConstructor('\[',
""
. ""
. ""
. "#body"
. ""
. ""
."",
beforeDigest=> sub{ $_[0]->beginMode('display_math'); },
captureBody=>1,
properties=> sub { RefStepID('equation') });
DefConstructor('\]' ,"",beforeDigest=> sub{ $_[0]->endMode('display_math'); });
DefConstructor('\[',
""
. ""
. ""
. "#body"
. ""
. ""
."",
beforeDigest=> sub{ $_[0]->beginMode('display_math'); },
captureBody=>1,
properties=> sub { RefStepID('equation') });
DefConstructor('\]' ,"",beforeDigest=> sub{ $_[0]->endMode('display_math'); });
DefMacro('\eqnarray', '\@@eqnarray\@start@alignment');
DefMacro('\endeqnarray', '\@finish@alignment\end@eqnarray');
DefMacro('\csname eqnarray*\endcsname', '\@@eqnarray*\@start@alignment');
DefMacro('\csname endeqnarray*\endcsname', '\@finish@alignment\end@eqnarray');
DefConstructor('\@@eqnarray OptionalMatch:* AlignmentBody:\end@eqnarray',
sub {
my($document,$star,$body,%props)=@_;
$document->openElement('cnx:equation',refnum=>$props{refnum},id=>$props{id});
$document->openElement('ltx:Math',mode=>'display');
$document->openElement('ltx:XMath');
constructAlignment($document,$body,attributes=>{name=>'eqnarray'});
$document->closeElement('ltx:XMath');
$document->closeElement('ltx:Math');
$document->closeElement('cnx:equation'); },
mode=>'display_math',
beforeDigest=>sub { alignmentBindings('rcl'); },
properties=> sub { ($_[1] ? RefStepID('equation') : RefStepCounter('equation')); },
afterDigest=>sub {
$_[1]->setProperty(body=>$_[1]->getArg(2));}, # So we get TeX
reversion=>'\begin{eqnarray#1}#2\end{eqnarray#1}');
Tag('cnx:item', autoClose=>1);
DefConstructor('\item[]',"?#1(#1)");
DefConstructor('\litem[]{}',"?#1(#1)");
DefConstructor('\itemize@item[]',
"?#1(#1)",
properties=>sub{ RefStepItemCounter(); });
DefConstructor('\enumerate@item[]',
"?#1(#1)",
properties=>sub{ RefStepItemCounter(); });
DefConstructor('\description@item[]',
"?#1(#1)",
properties=>sub{ RefStepItemCounter(); });
AssignValue(itemlevel=>0);
DefEnvironment('{itemize}',
"#body",
properties=>sub { beginItemize('itemize'); });
DefEnvironment('{enumerate}',
"#body",
properties=>sub { beginItemize('enumerate'); });
DefEnvironment('{description}',
"#body",
properties=>sub { beginItemize('description'); });
DefEnvironment('{center}','#body');
DefEnvironment('{minipage}{}','#body');
DefEnvironment('{small}','#body');
DefEnvironment('{footnotesize}','#body');
DefEnvironment('{tiny}','#body');
DefEnvironment('{scriptsize}','#body');
DefConstructor('\ref Semiverbatim', "&LookupValue('LABEL@#1')");
DefKeyVal('example','id','Semiverbatim');
DefEnvironment('{cexample}OptionalKeyVals:example',
"#body");
DefKeyVal('cexercise','id','Semiverbatim');
DefKeyVal('cexercise','name','Semiverbatim');
DefEnvironment('{cexercise}OptionalKeyVals:exercise',
""
. "#body"
. "");
DefKeyVal('cproblem','id','Semiverbatim');
DefKeyVal('cproblem','name','Semiverbatim');
DefEnvironment('{cproblem}OptionalKeyVals:cproblem',
""
. "?&KeyVal(#1,'name')(&KeyVal(#1,'name')\n)()"
. "#body"
. "");
DefKeyVal('csolution','id','Semiverbatim');
DefKeyVal('csolution','name','Semiverbatim');
DefEnvironment('{csolution}OptionalKeyVals:cproblem',
""
. "?&KeyVal(#1,'name')(&KeyVal(#1,'name')\n)()"
. "#body"
. "");
DefKeyVal('rule','id','Semiverbatim');
DefKeyVal('rule','name','Semiverbatim');
DefKeyVal('rule','type','Semiverbatim');
DefEnvironment('{crule}OptionalKeyVals:rule',
"\n"
. "?&KeyVal(#1,'name')(&KeyVal(#1,'name')\n)()"
. "\n#body\n"
. "\n");
DefKeyVal('statement','id','Semiverbatim');
DefEnvironment('{statement}OptionalKeyVals:statement','#body');
DefKeyVal('proof','id','Semiverbatim');
DefEnvironment('{proof}OptionalKeyVals:proof','#body');
DefKeyVal('definition','id','Semiverbatim');
DefKeyVal('definition','term','Semiverbatim');
DefKeyVal('definition','seealso','Semiverbatim');
DefEnvironment('{definition}OptionalKeyVals:definition',
"\n"
. "?&KeyVal(#1,'term')(&KeyVal(#1,'term')\n)()"
. "\n#body\n"
. "?&KeyVal(#1,'seealso')(&KeyVal(#1,'term')\n)()"
. "\n");
DefKeyVal('meaning','id','Semiverbatim');
DefEnvironment('{cmeaning}OptionalKeyVals:meaning','#body');
DefKeyVal('cnxn','document','Semiverbatim');
DefKeyVal('cnxn','target','Semiverbatim');
DefKeyVal('cnxn','strength','Semiverbatim');
DefConstructor('\cnxn OptionalKeyVals:cnxn {}','#1');
DefKeyVal('link','src','Semiverbatim');
DefConstructor('\link OptionalKeyVals:link {}','#2');
DefKeyVal('cfigure','id','Semiverbatim');
DefKeyVal('cfigure','name','Semiverbatim');
DefKeyVal('cfigure','type','Semiverbatim');
DefKeyVal('cfigure','caption','Semiverbatim');
DefConstructor('\cfigure OptionalKeyVals:cfigure Semiverbatim Semiverbatim',
""
. "?&KeyVal(#1,'name')(&KeyVal(#1,'name')\n)()"
. ""
. "?&KeyVal(#1,'caption')(&KeyVal(#1,'caption')\n)()"
. "");
DefKeyVal('ccite','src','Semiverbatim');
DefConstructor('\ccite OptionalKeyVals:ccite {}','#2');
DefConstructor('\term[]{}',"#2");
DefKeyVal('metadata','version','Semiverbatim');
DefKeyVal('metadata','created','Semiverbatim');
DefKeyVal('metadata','revised','Semiverbatim');
DefEnvironment('{metadata}OptionalKeyVals:metadata',
"\n"
. "&KeyVal('#1','version')\n"
. "&KeyVal('#1','created')\n"
. "&KeyVal('#1','revised')\n"
. "#body\n"
. "");
DefEnvironment('{authorlist}',"#body");
DefEnvironment('{maintainerlist}',"#body");
DefKeyVal('auth','id','Semiverbatim');
DefKeyVal('auth','firstname','Semiverbatim');
DefKeyVal('auth','surname','Semiverbatim');
DefKeyVal('auth','email','Semiverbatim');
DefConstructor('\cnxauthor OptionalKeyVals:auth',
"\n"
. "?&KeyVal(#1,'honorific')(&KeyVal('#1','honorific')\n)()"
. "?&KeyVal(#1,'firstname')(&KeyVal('#1','firstname')\n)()"
. "?&KeyVal(#1,'other')(&KeyVal('#1','other')\n)()"
. "?&KeyVal(#1,'surname')(&KeyVal('#1','surname')\n)()"
. "?&KeyVal(#1,'lineage')(&KeyVal('#1','lineage')\n)()"
. "?&KeyVal(#1,'email')(&KeyVal('#1','email')\n)()"
. "\n");
DefConstructor('\maintainer OptionalKeyVals:auth',
"\n"
. "?&KeyVal(#1,'honorific')(&KeyVal('#1','honorific')\n)()"
. "?&KeyVal(#1,'firstname')(&KeyVal('#1','firstname')\n)()"
. "?&KeyVal(#1,'other')(&KeyVal('#1','other')\n)()"
. "?&KeyVal(#1,'surname')(&KeyVal('#1','surname')\n)()"
. "?&KeyVal(#1,'lineage')(&KeyVal('#1','lineage')\n)()"
. "?&KeyVal(#1,'email')(&KeyVal('#1','email')\n)()"
. "\n");
DefEnvironment('{keywordlist}',"\n#body\n");
DefConstructor('\keyword {}',"#1");
DefEnvironment('{cnxabstract} OptionalKeyVals:cnxabstract',
"\n#body\n\n");
1;