# -*- mode: Perl -*-
# /=====================================================================\ #
# |  marginnote                                                         | #
# | 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.     | #
# |---------------------------------------------------------------------| #
# | Tim Prescott <teepeemm@gmail.com>                           #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;

DefConditional('\if@mn@verbose');

# not documented, but in the implementation
DeclareOption('quiet',   sub { Let('\if@mn@verbose', '\iffalse'); });
DeclareOption('verbose', sub { Let('\if@mn@verbose', '\iftrue'); });

DeclareOption('parboxrestore',   sub { DefMacro('\mn@parboxrestore', '\@parboxrestore'); });
DeclareOption('noparboxrestore', sub { DefMacro('\mn@parboxrestore', Tokens()); });

foreach my $ignoredOption (qw(fulladjust heightadjust depthadjust noadjust)) {
  DeclareOption($ignoredOption, undef); }
ExecuteOptions('verbose', 'fulladjust', 'parboxrestore');
ProcessOptions();

DefMacro('\marginfont',            '\normalcolor');
DefMacro('\raggedleftmarginnote',  '\raggedleft');
DefMacro('\raggedrightmarginnote', '\raggedright');

# marginnote is marginpar shifted vertically by #3 (which we ignore)
DefMacro('\marginnote[]{}[]', sub {
    TokenizeInternal('\marginpar'
        . ($_[1] ? '[\mn@parboxrestore\marginfont\raggedleftmarginnote ' . $_[1]->toString . ']' : '')
        . '{\mn@parboxrestore\marginfont\raggedrightmarginnote ' . $_[2]->toString . '}'); });

DefMacro('\@mn@if@RTL', sub {
    if (LookupValue('\if@RTL') and IfCondition('\if@RTL')) {
      return T_CS('\@firstoftwo'); }
    else {
      return T_CS('\@secondoftwo'); } });

# stubs that could do something but do not
DefRegister('\marginnotevadjust'   => Dimension(0));
DefRegister('\marginnotetextwidth' => LookupRegister('\textwidth'));
Let('\newmarginnote', '\newlabel');
Let('\mn@lastxpos',   '\lastxpos');
Let('\mn@savepos',    '\savepos');
Let('\mn@pagewidth',  '\pagewidth');
Let('\mn@strut',      '\strut');
Let('\mn@vadjust',    '\vadjust');

# stubs that do nothing
DefMacro('\@mn@marginnote []{}',     Tokens());
DefMacro('\@mn@@marginnote []{}[]',  Tokens());
DefMacro('\@mn@@@marginnote []{}[]', Tokens());
DefMacro('\@mn@margintest',          Tokens());
DefMacro('\@mn@thispage',            Tokens());
DefMacro('\@mn@atthispage',          Tokens());
DefMacro('\@mn@currpage',            Tokens());
DefMacro('\@mn@currxpos',            Tokens());
DefMacro('\mn@vlap {}',              Tokens());
DefMacro('\mn@zbox {}',              Tokens());

NewCounter('mn@abspage');

1;
