# -*- mode: Perl -*-
# /=====================================================================\ #
# |  elsarticle.cls                                                     | #
# | 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.     | #
# |---------------------------------------------------------------------| #
# | 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;

# Generally ignorable options
foreach my $option (qw(preprint final review
  5p 3p 1p
  12pt 11pt 10pt
  endfloat endfloats numafflabel doubleblind
  oneside twoside onecolumn twocolumn
  longtitle lefttitle centertitle reversenotenum nopreprintline
  symbold ussrhead nameyear doublespacing reviewcopy)) {
  DeclareOption($option, undef); }

DeclareOption('times', sub { AddToMacro(T_CS('\elsarticle.cls-h@@k'), '\RequirePackage{txfonts}'); });

DeclareOption("seceqn",     sub { AssignValue('@seceqn' => 1); });
DeclareOption("secthm",     sub { AssignValue('@secthm' => 1); });
DeclareOption("amsthm",     sub { AssignValue('@amsthm' => 1); });
DeclareOption('authoryear', sub { AssignValue('@biboptions', 'round,authoryear'); });
DeclareOption('number',     sub { AssignValue('@biboptions', 'numbers'); });
DeclareOption('numbers',    sub { AssignValue('@biboptions', 'numbers'); });

# Anything else is for article.
DeclareOption(undef, sub {
    PassOptions('article', 'cls', ToString(Expand(T_CS('\CurrentOption')))); });

ProcessOptions();
LoadClass('article');
RequirePackage('elsart_support_core');    # Hopefully, this covers elsarticle
# RequirePackage('geometry');
RequirePackage('fleqn');
RequirePackage('graphicx');
RequirePackage('pifont');
# number style inline citations by default
my $natbib_opts = LookupValue('@biboptions') || 'numbers';
PassOptions('natbib', 'sty', split(/\s*,\s*/, $natbib_opts));
RequirePackage('natbib');
RequirePackage('hyperref');
# RequirePackage('endfloat');
DefMacro('\biboptions{}', '\setcitestyle{#1}');

# Redefine these, since in elsarticle, they two get optional arguments
# (not even sure what the intended effect is)
DefEnvironment('{enumerate}[]',
  "<ltx:enumerate  xml:id='#id'>#body</ltx:enumerate>",
  properties      => sub { beginItemize('enumerate', 'enum'); },
  beforeDigestEnd => sub { Digest('\par'); },
  locked          => 1, mode => 'text');
DefEnvironment('{itemize}[]',
  "<ltx:itemize xml:id='#id'>#body</ltx:itemize>",
  properties      => sub { beginItemize('itemize', 'enum'); },
  beforeDigestEnd => sub { Digest('\par'); },
  locked          => 1, mode => 'text');

1;
