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

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Package Options
RawTeX(<<'EOTeX');
\newif\if@plnewitem\@plnewitemtrue
\newif\if@plnewenum\@plnewenumtrue
\newif\if@plalwaysadjust\@plalwaysadjustfalse
\newif\if@plneveradjust\@plneveradjustfalse
\newif\if@plneverdecrease\@plneverdecreasefalse
\newif\if@pldefblank\@pldefblankfalse
\newif\if@plpointedenum\@plpointedenumfalse
\newif\if@plpointlessenum\@plpointlessenumfalse
\newif\if@plflushright\@plflushrighttrue
\newif\if@plloadcfg\@plloadcfgtrue
EOTeX

DeclareOption('newitem',       '\@plnewitemtrue');
DeclareOption('olditem',       '\@plnewitemfalse');
DeclareOption('newenum',       '\@plnewenumtrue');
DeclareOption('oldenum',       '\@plnewenumfalse');
DeclareOption('alwaysadjust',  '\@plalwaysadjusttrue');
DeclareOption('neveradjust',   '\@plneveradjusttrue');
DeclareOption('neverdecrease', '\@plneverdecreasetrue');
DeclareOption('increaseonly',  '\@plneverdecreasetrue');
DeclareOption('defblank',      '\@pldefblanktrue');
DeclareOption('pointedenum',   '\@plpointedenumtrue');
DeclareOption('pointlessenum', '\@plpointlessenumtrue');
DeclareOption('cfg',           '\@plloadcfgtrue');
DeclareOption('nocfg',         '\@plloadcfgfalse');
DeclareOption('flushright',    '\@plflushrighttrue');
DeclareOption('flushleft',     '\@plflushrightfalse');

ExecuteOptions(qw(newitem newenum cfg flushright));
ProcessOptions();

#======================================================================
# paralist defines 9 environments named:
#  (compact | inpara | aspara)(enum | item | desc)
# The general class is:
#   enum for enumeration,
#   item for itemize,
#   desc for description
# The formatting is
#   inpara : done inline.
#   compact: same as normal, but w/less spacing above & below
#   aspara : same as normal, but each item is formatted as a paragraph
#            (ie. leftmargin is normal)
# These last two can be treated as normally (although some css could be used)
#
# setEnumerationStyle & setItemizationStyle are defined in LaTeX.pool
#======================================================================
DefRegister('\pltopsep'    => Dimension(0));
DefRegister('\plpartopsep' => Dimension(0));
DefRegister('\plitemsep'   => Dimension(0));
DefRegister('\plpaarsep'   => Dimension(0));

DefMacro('\setdefaultleftmargin{}{}{}{}{}{}', '');    # Ignore?
#======================================================================
# Enumerations

DefMacro('\setdefaultenum{}{}{}{}', sub {
    my ($gullet, $tag1, $tag2, $tag3, $tag4) = @_;
    setEnumerationStyle($tag1, 1);
    setEnumerationStyle($tag2, 2);
    setEnumerationStyle($tag3, 3);
    setEnumerationStyle($tag4, 4); });

DefEnvironment('{inparaenum} OptionalUndigested',
  "<ltx:inline-enumerate xml:id='#id'>#body</ltx:inline-enumerate>",
  properties => sub { beginItemize('inline@enumerate', 'enum'); },
  afterDigestBegin => sub { setEnumerationStyle($_[1]->getArg(1)); });
DefEnvironment('{compactenum} OptionalUndigested',
  "<ltx:enumerate xml:id='#id'>#body</ltx:enumerate>",
  properties => sub { beginItemize('enumerate', 'enum'); },
  afterDigestBegin => sub { setEnumerationStyle($_[1]->getArg(1)); });
DefEnvironment('{asparaenum} OptionalUndigested',
  "<ltx:enumerate xml:id='#id'>#body</ltx:enumerate>",
  properties => sub { beginItemize('enumerate', 'enum'); },
  afterDigestBegin => sub { setEnumerationStyle($_[1]->getArg(1)); });

# Possibly redefine stock enumerate to take optional argument
if (IfCondition(T_CS('\if@plnewenum'))) {
  DefEnvironment('{enumerate} OptionalUndigested',
    "<ltx:enumerate xml:id='#id'>#body</ltx:enumerate>",
    properties => sub { beginItemize('enumerate', 'enum'); },
    afterDigestBegin => sub { setEnumerationStyle($_[1]->getArg(1)); }); }

#======================================================================
# Itemizations

DefMacro('\setdefaultitem{}{}{}{}', sub {
    my ($gullet, $tag1, $tag2, $tag3, $tag4) = @_;
    setItemizationStyle($tag1, 1);
    setItemizationStyle($tag2, 2);
    setItemizationStyle($tag3, 3);
    setItemizationStyle($tag4, 4); });

DefEnvironment('{inparaitem} OptionalUndigested',
  "<ltx:inline-itemize xml:id='#id'>#body</ltx:inline-itemize>",
  properties => sub { beginItemize('inline@itemize', '@item'); },
  afterDigestBegin => sub { setItemizationStyle($_[1]->getArg(1)); });
DefEnvironment('{compactitem} OptionalUndigested',
  "<ltx:itemize xml:id='#id'>#body</ltx:itemize>",
  properties => sub { beginItemize('itemize', '@item'); },
  afterDigestBegin => sub { setItemizationStyle($_[1]->getArg(1)); });
DefEnvironment('{asparaitem} OptionalUndigested',
  "<ltx:itemize xml:id='#id'>#body</ltx:itemize>",
  properties => sub { beginItemize('itemize', '@item'); },
  afterDigestBegin => sub { setItemizationStyle($_[1]->getArg(1)); });

if (IfCondition(T_CS('\if@plnewitem'))) {
  DefEnvironment('{itemize} OptionalUndigested',
    "<ltx:itemize xml:id='#id'>#body</ltx:itemize>",
    properties => sub { beginItemize('itemize', '@item'); },
    afterDigestBegin => sub { setItemizationStyle($_[1]->getArg(1)); }); }

#======================================================================
# Descriptions
DefEnvironment('{inparadesc}',
  "<ltx:inline-description xml:id='#id'>#body</ltx:inline-description>",
  properties => sub { beginItemize('inline@description', '@desc'); });

DefEnvironment('{compactdesc}',
  "<ltx:description xml:id='#id'>#body</ltx:description>",
  properties => sub { beginItemize('description', '@desc'); });
DefEnvironment('{asparadesc}',
  "<ltx:description xml:id='#id'>#body</ltx:description>",
  properties => sub { beginItemize('description', '@desc'); });
# \paradescriptionlabel{}

#======================================================================
RawTeX(<<'EOTeX');
\def\pl@pointxxxenum{%
  \def\theenumi{\arabic{enumi}}%
  \def\theenumii{\theenumi.\arabic{enumii}}%
  \def\theenumiii{\theenumii.\arabic{enumiii}}%
  \def\theenumiv{\theenumiii.\arabic{enumiv}}%
  \def\p@enumi{}%
  \def\p@enumii{}%
  \def\p@enumiii{}%
  \def\p@enumiv{}}
\def\pl@pointedenum{%
  \def\labelenumi{\theenumi.}%
  \def\labelenumii{\theenumii.}%
  \def\labelenumiii{\theenumiii.}%
  \def\labelenumiv{\theenumiv.}}
\def\pl@pointlessenum{%
  \def\labelenumi{\theenumi}%
  \def\labelenumii{\theenumii}%
  \def\labelenumiii{\theenumiii}%
  \def\labelenumiv{\theenumiv}}
\def\pointedenum{\pl@pointxxxenum\pl@pointedenum}
\def\pointlessenum{\pl@pointxxxenum\pl@pointlessenum}
\if@plpointedenum\pointedenum\fi
\if@plpointlessenum\pointlessenum\fi
EOTeX

#======================================================================

1;
