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

LoadPool('LaTeX');
#**********************************************************************
# Option handling
foreach my $option (qw(10pt 11pt 12pt
  letterpaper legalpaper executivepaper a4paper a5paper b5paper
  landscape
  final draft
  oneside twoside
  openright openany
  notitlepage titlepage)) {
  DeclareOption($option, undef); }

DeclareOption('onecolumn',
  '\@twocolumnfalse\columnwidth\textwidth');
DeclareOption('twocolumn',
  '\@twocolumntrue\columnwidth\textwidth\advance\columnwidth-\columnsep\divide\columnwidth2\relax');
DeclareOption('openbib', sub {
    RequireResource(undef, type => 'text/css', content => '.ltx_bibblock{display:block;}'); });
DeclareOption('leqno', sub { AssignMapping('DOCUMENT_CLASSES', ltx_leqno => 1); });
DeclareOption('fleqn', sub { AssignMapping('DOCUMENT_CLASSES', ltx_fleqn => 1); });

ProcessOptions();

#**********************************************************************
# Document structure.
RelaxNGSchema("LaTeXML");
RequireResource('ltx-article.css');

# This makes the authors appear on 1 line;
# for derived classes with multiple lines, map this to undef and add ltx_authors_multiline

AddToMacro(T_CS('\maketitle'), T_CS('\ltx@authors@oneline'));

DefMacro('\@ptsize',    '0');        # should depend on options...
DefMacro('\@pnumwidth', '1.55em');
DefMacro('\@tocrmarg',  '2.55em');
DefMacro('\@dotsep',    '4.5');

RawTeX(<<'EOTeX');
\newif\if@restonecol
\newif\if@titlepage
\@titlepagefalse
EOTeX

#**********************************************************************
# The core sectioning commands are defined in LaTeX.pm
# but the counter setup, etc, depends on article
SetCounter('secnumdepth', Number(3));
NewCounter('part',          'document',      idprefix => 'Pt',  nested => ['section']);
NewCounter('section',       'document',      idprefix => 'S',   nested => ['subsection']);
NewCounter('subsection',    'section',       idprefix => 'SS',  nested => ['subsubsection']);
NewCounter('subsubsection', 'subsection',    idprefix => 'SSS', nested => ['paragraph']);
NewCounter('paragraph',     'subsubsection', idprefix => 'P',   nested => ['subparagraph']);
NewCounter('subparagraph', 'paragraph', idprefix => 'SP', nested => ['equation', 'figure', 'table']);

DefMacro('\thepart',          '\Roman{part}');
DefMacro('\thesection',       '\arabic{section}');
DefMacro('\thesubsection',    '\thesection.\arabic{subsection}');
DefMacro('\thesubsubsection', '\thesubsection.\arabic{subsubsection}');
DefMacro('\theparagraph',     '\thesubsubsection.\arabic{paragraph}');
DefMacro('\thesubparagraph',  '\theparagraph.\arabic{subparagraph}');
SetCounter(tocdepth => Number(3));

NewCounter('equation',       'document', idprefix => 'E',  idwithin => 'section');
NewCounter('@equationgroup', 'document', idprefix => 'EG', idwithin => 'section');
NewCounter('figure',         'document', idprefix => 'F',  idwithin => 'section');
NewCounter('table',          'document', idprefix => 'T',  idwithin => 'section');

DefMacro('\theequation', '\arabic{equation}');
DefMacro('\thefigure',   '\arabic{figure}');
DefMacro('\thetable',    '\arabic{table}');

DefMacro('\theenumi',   '\arabic{enumi}');
DefMacro('\theenumii',  '\alph{enumii}');
DefMacro('\theenumiii', '\roman{enumiii}');
DefMacro('\theenumiv',  '\Alph{enumiv}');

DefMacro('\refname', 'References');

AssignMapping('BACKMATTER_ELEMENT', 'ltx:bibliography' => 'ltx:section');

Tag('ltx:appendix', autoClose => 1);
DefMacro('\appendix', '\@appendix');
# Actually we should be using section counter
DefPrimitive('\@appendix', sub { startAppendices('section'); });

#**********************************************************************
1;