LaTeXML
view release on metacpan or search on metacpan
lib/LaTeXML/Package/LaTeX.pool.ltxml view on Meta::CPAN
DefMacroI('\thempfootnote', undef, '\arabic{mpfootnote}');
DefMacroI('\footnotetyperefname', undef, 'footnote');
sub makeNoteTags {
my ($counter, $mark, $tag) = @_;
if ($tag) {
return (
RefStepID($counter),
mark => $mark || $tag,
tags => Digest(T_BEGIN,
T_CS('\def'), T_CS('\the' . $counter), T_BEGIN, Revert($tag), T_END,
T_CS('\def'), T_CS('\typerefnum@' . $counter),
T_BEGIN, T_CS('\\' . $counter . 'typerefname'), T_SPACE, Revert($tag), T_END,
Invocation(T_CS('\lx@make@tags'), T_OTHER($counter)),
T_END)); }
else {
return (RefStepCounter($counter),
mark => $mark || DigestText(T_CS('\the' . $counter))); } }
DefMacroI('\ext@footnote', undef, undef);
DefConstructor('\lx@note[]{}[]{}',
"^<ltx:note role='#role' mark='#mark' xml:id='#id' inlist='#list'>"
. "#tags"
. "#4"
. "</ltx:note>",
mode => 'text', bounded => 1,
sizer => '#mark',
beforeDigest => sub { reenterTextMode(1); neutralizeFont(); },
properties => sub {
my $type = ToString($_[2]);
(role => $type,
list => DigestText(T_CS('\ext@' . $type)),
makeNoteTags($type, $_[1], $_[3])); },
reversion => '');
DefConstructor('\lx@notemark[]{}[]',
"^<ltx:note role='#role' mark='#mark' xml:id='#id' inlist='#list'>"
. "#tags"
. "</ltx:note>",
mode => 'text',
properties => sub {
my $type = ToString($_[2]);
(role => $type . 'mark',
list => DigestText(T_CS('\ext@' . $type)),
makeNoteTags($type, $_[1], $_[3])); },
reversion => '');
DefConstructor('\lx@notetext[]{}[]{}',
"^<ltx:note role='#role' mark='#mark' xml:id='#id'>#4</ltx:note>",
mode => 'text',
properties => sub {
my $type = ToString($_[2]);
(role => $type . 'text', makeNoteTags($type, $_[1], $_[3] || Digest(T_CS('\the' . $type)))); },
reversion => '');
DefMacro('\footnote', '\lx@note{footnote}', locked => 1);
DefMacro('\footnotemark', '\lx@notemark{footnote}', locked => 1);
DefMacro('\footnotetext', '\lx@notetext{footnote}', locked => 1);
DefMacro('\@footnotetext', '\lx@notetext{footnote}', locked => 1);
# we don't implement the internals directly, so lock them to the latexml variant
Let('\@thefnmark', '\lx@notemark{footnote}', locked => 1);
Tag('ltx:note', afterClose => \&relocateFootnote);
# Find any pairs of footnotemark & footnotetext;
# Move the contents of the text to the mark, removing the text node.
sub relocateFootnote {
my ($document, $node) = @_;
if (($node->getAttribute('role') || '') =~ /^(\w+?)text$/) {
my $notetype = $1; # Eg "footnote", "endnote",...
if (my $mark = $node->getAttribute('mark')) {
foreach my $marknote ($document->findnodes(".//ltx:note[\@role='${notetype}mark'][\@mark='$mark']")) {
relocateFootnote_aux($document, $notetype, $marknote, $node); } } }
elsif (($node->getAttribute('role') || '') =~ /^(\w+?)mark$/) {
my $notetype = $1; # Eg "footnote", "endnote",...
if (my $mark = $node->getAttribute('mark')) {
foreach my $textnote ($document->findnodes(".//ltx:note[\@role='${notetype}text'][\@mark='$mark']")) {
relocateFootnote_aux($document, $notetype, $node, $textnote); } } }
return; }
# Move the contents of the $textnote to the $marknote, remove $textnote.
sub relocateFootnote_aux {
my ($document, $notetype, $marknote, $textnote) = @_;
$textnote->parentNode->removeChild($textnote);
$document->appendClone($marknote, $textnote->childNodes);
$document->setAttribute($marknote, role => $notetype);
if (my $labels = $textnote->getAttribute('labels')) {
GenerateID($document, $marknote);
$document->setAttribute($marknote, labels => $labels); }
return; }
# Style parameters
DefRegister('\footnotesep' => Dimension(0));
DefPrimitiveI('\footnoterule', undef, undef);
#======================================================================
# C.3.4 Accents and Special Symbols
#======================================================================
# See TeX.pool.ltxml
# See Section 3.3.2 Mathematical Symbols, below
# Should this be here?
DefMath('\mathring{}', "\x{030A}", operator_role => 'OVERACCENT');
#**********************************************************************
# C.4 Sectioning and Table of Contents
#**********************************************************************
#======================================================================
# C.4.1 Sectioning Commands.
#======================================================================
# Note that LaTeX allows fairly arbitrary stuff in \the<ctr>, although
# it can get you in trouble. However, in almost all cases, the result
# is plain text. So, I'm putting refnum as an attribute, where I like it!
# You want something else? Redefine!
# Also, we're adding an id to each, that is parallel to the refnum, but
# valid as an ID. You can tune the representation by defining, eg. \thesection@ID
# A little more messy than seems necessary:
# We don't know whether to step the counter and update \@currentlabel until we see the '*',
# but we have to know it before we digest the title, since \label can be there!
# These are defined in terms of \@startsection so that
# casual user redefinitions work, too.
DefMacroI('\chapter', undef, '\@startsection{chapter}{0}{}{}{}{}', locked => 1);
DefMacroI('\part', undef, '\@startsection{part}{-1}{}{}{}{}'); # not locked since sometimes redefined as partition?
DefMacroI('\section', undef, '\@startsection{section}{1}{}{}{}{}', locked => 1);
DefMacroI('\subsection', undef, '\@startsection{subsection}{2}{}{}{}{}', locked => 1);
DefMacroI('\subsubsection', undef, '\@startsection{subsubsection}{3}{}{}{}{}', locked => 1);
DefMacroI('\paragraph', undef, '\@startsection{paragraph}{4}{}{}{}{}', locked => 1);
DefMacroI('\subparagraph', undef, '\@startsection{subparagraph}{5}{}{}{}{}', locked => 1);
map { Tag("ltx:$_", autoClose => 1) }
qw(part chapter section subsection subsubsection paragraph subparagraph);
DefMacro('\secdef {}{} OptionalMatch:*', sub { ($_[3] ? ($_[2]) : ($_[1])); });
DefMacroI('\@startsection@hook', undef, Tokens());
NewCounter('secnumdepth');
SetCounter('secnumdepth', Number(3));
DefMacro('\@startsection{}{}{}{}{}{} OptionalMatch:*', sub {
( run in 0.850 second using v1.01-cache-2.11-cpan-71847e10f99 )