# -*- mode: Perl -*-
# /=====================================================================\ #
# |  revtex3 support                                                    | #
# | Implementation for LaTeXML                                          | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Thanks to Catalin David <c.david@jacobs-university.de>              | #
# | of the arXMLiv group for initial implementation                     | #
# |    http://arxmliv.kwarc.info/                                       | #
# | Released to the Public Domain                                       | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;

DeclareOption('amsfonts', sub { RequirePackage('amsfonts'); });
DeclareOption('amssymb',  sub { RequirePackage('amssymb'); });
DeclareOption('amsmath',  sub { RequirePackage('amsmath'); });
ProcessOptions();

RequirePackage('revtex4_support');

#======================================================================
# The following are additional or different definitions from revtex4_support

RawTeX('\newif\ifpreprintsty\newif\ifsecnumbers\newif\ifsegabssty');
# \overlay seems to be yet another of these stacked things...
# \vereq also
DefMacro('\eqsecnum',     '');    # ?
DefMacro('\tightenlines', '');
DefMacro('\wideabs',      '');    # wide abstract? takes an arg, but avoid reading it

# RevTeX's subequation numbering environment.
# Hmm, this seems to allow random chunks of text within;
# it really only specifies the numbering, not alignment or ...
DefMacro('\mathletters',    '\lx@equationgroup@subnumbering@begin');
DefMacro('\endmathletters', '\lx@equationgroup@subnumbering@end');

#======================================================================
# Apparently, you can use single $ within equations to switch back to text

DefMacro('\@dollar@in@oldrevtex', '\bgroup\hbox\bgroup\let$\@eegroup');
DefMacro('\@eegroup',             '\egroup\egroup');
DefEnvironment('{equation}',
  "<ltx:equation xml:id='#id'>"
    . "#tags"
    . "<ltx:Math mode='display'>"
    . "<ltx:XMath>"
    . "#body"
    . "</ltx:XMath>"
    . "</ltx:Math>"
    . "</ltx:equation>",
  mode         => 'display_math',
  beforeDigest => sub { Let(T_MATH, '\@dollar@in@oldrevtex'); },
  properties   => sub { RefStepCounter('equation'); },
  locked       => 1);
DefEnvironment('{equation*}',
  "<ltx:equation xml:id='#id'>"
    . "<ltx:Math mode='display'>"
    . "<ltx:XMath>"
    . "#body"
    . "</ltx:XMath>"
    . "</ltx:Math>"
    . "</ltx:equation>",
  mode         => 'display_math',
  beforeDigest => sub { Let(T_MATH, '\@dollar@in@oldrevtex'); },
  properties   => sub { RefStepID('equation') },
  locked       => 1);
DefConstructorI('\[', undef,
  "<ltx:equation xml:id='#id'>"
    . "<ltx:Math mode='display'>"
    . "<ltx:XMath>"
    . "#body"
    . "</ltx:XMath>"
    . "</ltx:Math>"
    . "</ltx:equation>",
  beforeDigest => sub { $_[0]->beginMode('display_math');
    Let(T_MATH, '\@dollar@in@oldrevtex'); },
  captureBody => 1,
  properties => sub { RefStepID('equation') });

#**********************************************************************

1;