# -*- mode: Perl -*-
# /=====================================================================\ #
# | exam.cls.ltxml                                                      | #
# | LaTeXML Binding for the exam document class                        | #
# |=====================================================================| #
# | 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;

# Load article class as base
LoadClass('article');

#======================================================================
# Questions and Parts environments - map to standard enumerate
#======================================================================

# Map questions environment to enumerate
Let('\questions', '\enumerate');
Let('\endquestions', '\endenumerate');

# Map parts environment to enumerate
Let('\parts', '\enumerate');
Let('\endparts', '\endenumerate');

# Map subparts environment to enumerate
Let('\subparts', '\enumerate');
Let('\endsubparts', '\endenumerate');

# Map subsubparts environment to enumerate
Let('\subsubparts', '\enumerate');
Let('\endsubsubparts', '\endenumerate');

# Map choices environment to enumerate
Let('\choices', '\enumerate');
Let('\endchoices', '\endenumerate');

# Map oneparchoices environment to enumerate
Let('\oneparchoices', '\enumerate');
Let('\endoneparchoices', '\endenumerate');

# Map checkboxes environment to enumerate
Let('\checkboxes', '\enumerate');
Let('\endcheckboxes', '\endenumerate');

# Map oneparcheckboxes environment to enumerate
Let('\oneparcheckboxes', '\enumerate');
Let('\endoneparcheckboxes', '\endenumerate');

#======================================================================
# Question commands - map to \item
#======================================================================

DefMacro('\question[]', '\item');
DefMacro('\part[]', '\item');
DefMacro('\subpart[]', '\item');
DefMacro('\subsubpart[]', '\item');
DefMacro('\choice', '\item');
DefMacro('\CorrectChoice', '\item');
DefMacro('\correctchoice', '\item');

#======================================================================
# Cover pages
#======================================================================

DefEnvironment('{coverpages}',
  '<ltx:block class="coverpages" xml:id="#id">#body</ltx:block>');

#======================================================================
# Solutions
#======================================================================

# Redefine solution environments to inject the label
DefEnvironment('{solution}[]',
  '<ltx:block class="exam-solution" xml:id="#id">#body</ltx:block>',
  afterDigestBegin => sub {
    my ($stomach) = @_;
    $stomach->getGullet->unread(T_CS('\textbf'), T_BEGIN, Explode('Solution:'), T_END, T_SPACE);
    return; });

DefEnvironment('{solutionorlines}[]',
  '<ltx:block class="exam-solution" xml:id="#id">#body</ltx:block>',
  afterDigestBegin => sub {
    my ($stomach) = @_;
    $stomach->getGullet->unread(T_CS('\textbf'), T_BEGIN, Explode('Solution:'), T_END, T_SPACE);
    return; });

DefEnvironment('{solutionorbox}[]',
  '<ltx:block class="exam-solution" xml:id="#id">#body</ltx:block>',
  afterDigestBegin => sub {
    my ($stomach) = @_;
    $stomach->getGullet->unread(T_CS('\textbf'), T_BEGIN, Explode('Solution:'), T_END, T_SPACE);
    return; });

DefEnvironment('{solutionorgrid}[]',
  '<ltx:block class="exam-solution" xml:id="#id">#body</ltx:block>',
  afterDigestBegin => sub {
    my ($stomach) = @_;
    $stomach->getGullet->unread(T_CS('\textbf'), T_BEGIN, Explode('Solution:'), T_END, T_SPACE);
    return; });

DefEnvironment('{solutionbox}{}',
  '<ltx:block class="exam-solutionbox" xml:id="#id">#body</ltx:block>',
  afterDigestBegin => sub {
    my ($stomach) = @_;
    $stomach->getGullet->unread(T_CS('\textbf'), T_BEGIN, Explode('Solution:'), T_END, T_SPACE);
    return; });

#======================================================================
# Grading tables and point commands
#======================================================================

DefMacro('\gradetable[][]', '');
DefMacro('\bonusgradetable[][]', '');
DefMacro('\pointtable[][]', '');
DefMacro('\bonuspointtable[][]', '');
DefMacro('\partialgradetable[][]', '');
DefMacro('\partialbonusgradetable[][]', '');
DefMacro('\partialpointtable[][]', '');
DefMacro('\partialbonuspointtable[][]', '');
DefMacro('\gradetablestretch{}', '');

# Point commands
DefMacro('\points{}', '(#1 points)');
DefMacro('\point', '(1 point)');
DefMacro('\bonuspoints{}', '(#1 bonus points)');
DefMacro('\bonuspoint', '(1 bonus point)');
DefMacro('\droppoints', '');
DefMacro('\bonusdroppoints', '');
DefMacro('\addpoints', '');
DefMacro('\noaddpoints', '');

DefMacro('\pointsofquestion{}', '');
DefMacro('\pointsonpage{}', '');
DefMacro('\bonuspointsonpage{}', '');

#======================================================================
# Answer lines and boxes
#======================================================================

DefMacro('\fillwithlines{}', '');
DefMacro('\fillwithdottedlines{}', '');
DefMacro('\fillwithgrid{}', '');
DefMacro('\answerline[]', '\hrulefill');

#======================================================================
# Formatting commands
#======================================================================

DefMacro('\bracketedpoints', '');
DefMacro('\boxedpoints', '');
DefMacro('\marginpointname{}', '');
DefMacro('\pointname{}', '');
DefMacro('\pointsinmargin', '');
DefMacro('\pointsinrightmargin', '');
DefMacro('\nopointsinmargin', '');
DefMacro('\pointstwosided', '');

DefMacro('\qformat{}', '');
DefMacro('\bonusqformat{}', '');
DefMacro('\noqformat', '');

#======================================================================
# Grading table customization words
#======================================================================

# Vertical table words
DefMacro('\vqword{}', '');
DefMacro('\vpword{}', '');
DefMacro('\vsword{}', '');
DefMacro('\vtword{}', '');
DefMacro('\vhword{}', '');
DefMacro('\vbonusword{}', '');

# Horizontal table words
DefMacro('\hqword{}', '');
DefMacro('\hpword{}', '');
DefMacro('\hsword{}', '');
DefMacro('\htword{}', '');
DefMacro('\hhword{}', '');
DefMacro('\hbonusword{}', '');

#======================================================================
# Header and footer
#======================================================================

DefMacro('\firstpageheader{}{}{}', '');
DefMacro('\runningheader{}{}{}', '');
DefMacro('\firstpagefooter{}{}{}', '');
DefMacro('\runningfooter{}{}{}', '');
DefMacro('\header{}{}{}', '');
DefMacro('\footer{}{}{}', '');
DefMacro('\coverheader{}{}{}', '');

DefMacro('\extraheadheight[]{}', '');
DefMacro('\extrafootheight[]{}', '');

DefMacro('\lhead[]{}', '');
DefMacro('\chead[]{}', '');
DefMacro('\rhead[]{}', '');
DefMacro('\lfoot[]{}', '');
DefMacro('\cfoot[]{}', '');
DefMacro('\rfoot[]{}', '');

#======================================================================
# Multiple choice customization
#======================================================================

DefMacro('\CorrectChoiceEmphasis{}', '');
DefMacro('\correctchoiceemphasis{}', '');
DefMacro('\checkedchar{}', '');
DefMacro('\circledchar{}', '');

#======================================================================
# Miscellaneous
#======================================================================

DefMacro('\numquestions', '0');
DefMacro('\numpoints', '0');
DefMacro('\numbonuspoints', '0');
DefMacro('\numparts', '0');
DefMacro('\numsubparts', '0');
DefMacro('\numsubsubparts', '0');
DefMacro('\numpages', '0');

DefMacro('\uplevel{}', '#1');
DefMacro('\fullwidth{}', '#1');

DefMacro('\printanswers', '');
DefMacro('\noprintanswers', '');
DefMacro('\cancelspace', '');

DefMacro('\half', '\ensuremath{\frac{1}{2}}');
DefMacro('\blankpage', '');

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

1;