# -*- mode: Perl -*-
# /=====================================================================\ #
# |  book                                                               | #
# | 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
  onecolumn twocolumn
  notitlepage titlepage)) {
  DeclareOption($option, undef); }
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-book.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...
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(2));
NewCounter('part',          'document',      idprefix => 'Pt',  nested => ['chapter']);
NewCounter('chapter',       'document',      idprefix => 'Ch',  nested => ['section']);
NewCounter('section',       'chapter',       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']);
NewCounter('footnote', 'chapter');

DefMacro('\thepart',          '\Roman{part}');
DefMacro('\thechapter',       '\arabic{chapter}');
DefMacro('\thesection',       '\thechapter.\arabic{section}');
DefMacro('\thesubsection',    '\thesection.\arabic{subsection}');
DefMacro('\thesubsubsection', '\thesubsection.\arabic{subsubsection}');
DefMacro('\theparagraph',     '\thesubsubsection.\arabic{paragraph}');
DefMacro('\thesubparagraph',  '\theparagraph.\arabic{subparagraph}');

DefMacro('\chaptermark{}', '');

NewCounter('equation',       'chapter',  idprefix => 'E');
NewCounter('@equationgroup', 'document', idprefix => 'EG', idwithin => 'section');
NewCounter('figure',         'chapter',  idprefix => 'F');
NewCounter('table',          'chapter',  idprefix => 'T');
DefMacro('\theequation', '\ifnum\c@chapter>\z@\thechapter.\fi \arabic{equation}');
DefMacro('\thefigure',   '\ifnum\c@chapter>\z@\thechapter.\fi \arabic{figure}');
DefMacro('\thetable',    '\ifnum\c@chapter>\z@\thechapter.\fi \arabic{table}');
SetCounter(tocdepth => Number(2));

NewCounter('enumi',   undef, idwithin => '@itemizei', idprefix => 'i');
NewCounter('enumii',  undef, idwithin => 'enumi',     idprefix => 'i');
NewCounter('enumiii', undef, idwithin => 'enumii',    idprefix => 'i');
NewCounter('enumiv',  undef, idwithin => 'enumiii',   idprefix => 'i');
DefMacro('\theenumi',   '\arabic{enumi}');
DefMacro('\theenumii',  '\alph{enumii}');
DefMacro('\theenumiii', '\roman{enumiii}');
DefMacro('\theenumiv',  '\Alph{enumiv}');

DefMacro('\bibname', 'Bibliography');

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

Tag('ltx:appendix', autoClose => 1);
DefMacro('\appendix', '\@appendix');
DefPrimitive('\@appendix', sub { startAppendices('chapter'); });

# General document structure:
# \documentclass{..}
# preamble
# \begin{document}
# \frontmatter
DefPrimitive('\frontmatter', sub { AssignValue(no_number_sections => 1); });
# frontmatter stuff
# \maketitle
# \include various preface, introduction, etc
# \mainmatter
DefPrimitive('\mainmatter', sub { AssignValue(no_number_sections => 0); });
# \include various chapters, appendices
# \backmatter
DefPrimitive('\backmatter', undef);
# commands for bibliography, indices
# \end{document}

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