package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
DeclareOption('extrefs','');
RequirePackage('metakeys');
sub withhash {'#';}
DefConstructor('\sref[]{}',
 "<omdoc:oref href='&withhash()#2'/>");
DefConstructor('\srefs[]{}',
 "<omdoc:oref href='&withhash()#2'/>");
DefConstructor('\srefl[]{}',
 "<omdoc:oref href='&withhash()#2'/>");
DefConstructor('\spageref{}',
 "<omdoc:oref href='&withhash()#1'/>");
DefConstructor('\makeextrefs{}','');
DefConstructor('\extref[]{}{}',
  "<omdoc:oref href='#2@#3'/>");
DefConstructor('\theextref','');
DefConstructor('\extpageref[]{}{}',
  "<omdoc:oref href='#2@#3'/>");
DefConstructor('\theextref','');
DefConstructor('\extrefstyle{}{}',"");
DefConstructor('\extrefstyle{}{}',"");
DefConstructor('\inputrefs{}{}','');
DefEnvironment('{sequation} OptionalKeyVals',
       "<ltx:equation "
             .     "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')' "
             .     "refnum='#refnum')(xml:id='#id')>"
     .   "<ltx:Math mode='display'>"
     .     "<ltx:XMath>#body</ltx:XMath>"
     .   "</ltx:Math>"
     . "</ltx:equation>",
       mode=>'display_math',
       properties=> sub { RefStepCounter('equation') },
       locked=>1);
DefMacro('\seqnarray OptionalKeyVals','\begin{eqnarray*}');
DefMacro('\endseqnarray','\end{eqnarray*}');
DefMacro('\withcite{}{}','\begin{withcitation}{#1}#2\citeit\end{withcitation}');
DefConstructor('\citeit',"<omdoc:citation/> ",
afterConstruct => sub {
  my ($document,$whatsit) = @_;
  # LibXML acrobatics, since we can't talk about the xml:id prior to construction's end
  # (and please do correct me if this is inaccurate)
  my $node = $document->getNode;
  my ($citenode) = $document->findnodes('preceding-sibling::omdoc:citation',$node);
 my ($phrase_parent) = $document->findnodes('ancestor::ltx:text[@xml:id]',$node);
  return unless (defined $phrase_parent) && (defined $citenode);
  my $id = $phrase_parent->getAttribute('xml:id');
  my $refs = $phrase_parent->getAttribute('citeit-refs');
  $phrase_parent->removeAttribute('citeit-refs');
  $citenode->setAttribute('for',$id);
  $citenode->setAttribute('refs',$refs);
});#$
DefEnvironment('{withcitation}{}',
   "<ltx:text citeit-refs='#1'>#body</ltx:text>");
1;
