/usr/share/perl5/LaTeXML/Package/latexml.sty.ltxml is in latexml 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | # -*- CPERL -*-
# /=====================================================================\ #
# | latexml.ltxml | #
# | Style file for latexml documents | #
# |=====================================================================| #
# | 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;
no warnings 'redefine'; # ????
#======================================================================
# LaTeXML Implementation of latexml customization bindings
# * controlling various conversion options
# * presentation customization
# * semantic enhancement macros
# * exposing internal functionality
#======================================================================
DefConditional('\iflatexml', sub { 1; });
#======================================================================
# Package Options
DeclareOption('ids', sub { AssignValue('GENERATE_IDS' => 1, 'global'); });
DeclareOption('noids', sub { AssignValue('GENERATE_IDS' => 0, 'global'); });
DeclareOption('comments', sub { AssignValue('INCLUDE_COMMENTS' => 1, 'global'); });
DeclareOption('nocomments', sub { AssignValue('INCLUDE_COMMENTS' => 0, 'global'); });
ProcessOptions();
#======================================================================
# From latexml.sty
# [does this really belong here? or should this be disableable?]
DefConstructor('\URL[] Semiverbatim', "<ltx:ref href='#href'>?#1(#1)(#href)</ltx:ref>",
properties => sub { (href => CleanURL($_[2])); });
DefMacro('\XML', '\URL[\texttt{XML}]{http://www.w3.org/XML/}');
DefMacro('\SGML', '\URL[\texttt{HTML}]{http://www.w3.org/MarkUp/SGML/}');
DefMacro('\HTML', '\URL[\texttt{HTML}]{http://www.w3.org/html/}');
DefMacro('\XHTML', '\URL[\texttt{XHTML}]{http://www.w3.org/TR/xhtml11/}');
DefMacro('\XSLT', '\URL[\texttt{XSLT}]{http://www.w3.org/Style/XSL/}');
DefMacro('\CSS', '\URL[\texttt{CSS}]{http://www.w3.org/Style/CSS/}');
DefMacro('\MathML', '\URL[\texttt{MathML}]{http://www.w3.org/Math/}');
DefMacro('\OpenMath', '\URL[\texttt{OpenMath}]{http://www.openmath.org/}');
DefMacro('\LaTeXML', '\URL[\texttt{LaTeXML}]{http://dlmf.nist.gov/LaTeXML/}');
#DefMacro('\BibTeX','BibTeX');
#======================================================================
# id related features
# Set the id to used for the top-level document
DefMacro('\lxDocumentID{}', '\def\thedocument@ID{#1}');
# \LXMID{id}{math} Associate the identifier id with the given math expression.
DefMacro('\LXMID{}{}', '\@XMArg{#1}{#2}');
# \LXRef{id} Refer to the math expression associated with id.
# In presentation, this is similar to using a shorthand macro.
# In content situations, an XMRef is generated.
DefMacro('\LXMRef{}', '\@XMRef{#1}');
#======================================================================
# class related features
Let('\lxAddClass', '\@ADDCLASS');
DefConstructor('\lxAddClass Semiverbatim', sub {
addClass($_[0]->getElement, ToString($_[1])); });
DefConstructor('\lxWithClass Semiverbatim {}', sub {
my ($document, $class, $box) = @_;
my $context = $document->getElement; # Where we originally start inserting.
my @nodes = ();
if (isTextNode($document->getNode)) {
push(@nodes, $document->openElement('ltx:text')); }
push(@nodes, $document->absorb($box));
@nodes = $document->filterChildren($document->filterDeletions(@nodes));
$document->closeToNode($context);
addClass($nodes[0], ToString($class)) if @nodes; });
#======================================================================
# links
# Similar to stuff from hyperref, but more straightforward
DefConstructor('\lxRef Semiverbatim {}',
"<ltx:ref labelref='#label'>#2</ltx:ref>",
properties => sub { (label => CleanLabel($_[1])); });
#======================================================================
# Resources
# \lxResource[options]{name}
# RequireResource($name,%options);
#======================================================================
# Page customization
# options to create or customize
# navbar: full content, context TOC, ...
# headers, footers
DefMacro('\lxKeywords{}',
'\@add@frontmatter{ltx:keywords}[name={keywords}]{#1}');
DefConstructor('\lxContextTOC',
"<ltx:TOC format='context'/>");
AssignValue('navigation' => [], 'global');
sub insertNavigation {
my ($document) = @_;
if (my @items = @{ LookupValue('navigation') }) {
$document->appendTree($document->getDocument->documentElement,
['ltx:navigation', {}, @items]); }
return; }
Tag('ltx:document', 'afterClose' => \&insertNavigation);
DefEnvironment('{lxNavbar}', sub { },
beforeDigest => sub { AssignValue(inPreamble => 1); },
beforeConstruct => sub {
my ($document, $whatsit) = @_;
PushValue('navigation',
['ltx:inline-para', { class => 'ltx_page_navbar' }, $whatsit->getBody]);
return; });
# Of course, it would be more interesting to supply a "template"
# for header & footer that would show where the next link goes,
# rather than predict what the next link will be! (after splitting!)
# Repeated header/footers should give multiple header/footer lines ?
# or do they just arrange the lines within it?
DefEnvironment('{lxHeader}', sub { },
beforeDigest => sub { AssignValue(inPreamble => 1); },
beforeConstruct => sub {
my ($document, $whatsit) = @_;
PushValue('navigation',
['ltx:inline-para', { class => 'ltx_page_header' }, $whatsit->getBody]);
return; });
DefEnvironment('{lxFooter}', sub { },
beforeDigest => sub { AssignValue(inPreamble => 1); },
beforeConstruct => sub {
my ($document, $whatsit) = @_;
PushValue('navigation',
['ltx:inline-para', { class => 'ltx_page_footer' }, $whatsit->getBody]);
return; });
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Declarative information for Mathematics
# particularly those that assist parsing.
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#======================================================================
# Marking the type of particular instances of a symbol.
# \LxFcn{f} treat f as a function here (only).
DefConstructor('\lxFcn{}', "<ltx:XMWrap role='FUNCTION'>#1</ltx:XMWrap>",
requireMath => 1, reversion => '#1', alias => '');
DefConstructor('\lxID{}', "<ltx:XMWrap role='ID'>#1</ltx:XMWrap>",
requireMath => 1, reversion => '#1', alias => '');
DefConstructor('\lxPunct{}', "<ltx:XMWrap role='PUNCT'>#1</ltx:XMWrap>",
requireMath => 1, reversion => '#1', alias => '');
#======================================================================
# Define a mathematical object with both presentation & content information
# \lxDefMath{\name}[nargs][optional]{presentation body}[content keywords]
# The first part is essentially equivalent to \newcommand, it defines
# an expansion for \name used for the presentation.
# The content keywords are used to define the semantics of the object.
# See DefMath in LaTeXML::Package for more information.
DefPrimitive('\lxDefMath{}[][]{} OptionalKeyVals:XMath', sub {
my ($stomach, $cs, $nargs, $opt, $presentation, $params) = @_;
my ($name, $meaning, $cd, $role) =
$params && map { $_ && ToString($_) } map { $params->getValue($_) } qw(name meaning cd role);
DefMathI($cs, convertLaTeXArgs($nargs, $opt), $presentation,
name => $name, meaning => $meaning, omcd => $cd, role => $role);
});
#DefKeyVal('XMath',name,string);
#======================================================================
# NOTE: I'm concerned about the order of applying these filters.
# even though it seems right so far.
# Keyword options:
# scope=<scope> : Specifies the scope of the declaration, ie. to what portion of
# the document the declarations apply
# You can specify one of the counters associated with sections,
# equations, etc.
# If unspecified, the declaration is scoped to the current unit.
# Note that this applies to equations, as well.
# label=<label> : assigns a label to the declaration so that it can be reused
# at another point in the document (with \lxRefDeclaration), particularly when
# that point is not otherwise within the scope of the original declaration.
# To effect the declaration:
# role=<role> : Assigns a grammatical role to the matched item for parsing.
# name=<name> : Assigns a name to the matched item.
# meaning=<meaning> : Assigns a semantic name to the matched item.
# Alternatively, use
# replace : provides a replacement for the matched expression, rather than adding attributes.
# Potential keywords/operations needed(?)
# nodef : inhibits the marking of the current point as the `definition' of the expression.
# (a ref declaration would normally not be a def anyway)
DefKeyVal('Declare', 'wrap', '{}', 1);
DefKeyVal('Declare', 'trace', '{}', 1);
DefKeyVal('Declare', 'replace', 'UndigestedKey');
our $declare_keys = { scope => 1, role => 1, tag => 1, name => 1, meaning => 1,
trace => 1, wrap => 1, replace => 1, label => 1 };
DefConstructor('\lxDeclare OptionalMatch:* OptionalKeyVals:Declare {}',
sub { my ($document, $flag, $kv, $pattern, %props) = @_;
if (my $id = $props{id}) {
my $save = $document->floatToElement('ltx:declare');
$document->openElement('ltx:declare', 'xml:id' => $id);
if (my $tag = $kv->getValue('tag')) {
$document->insertElement('ltx:tag', $tag); }
$document->closeElement('ltx:declare');
$document->setNode($save); } },
mode => 'text',
# Screwy bit to `neutralize' the font in the matches.
beforeDigest => sub { AssignValue(font => LaTeXML::Common::Font->textDefault(), 'local');
AssignValue(mathfont => LaTeXML::Common::Font->mathDefault(), 'local');
return; },
afterDigest => sub { my ($stomach, $whatsit) = @_;
my ($star, $keys, $pattern) = $whatsit->getArgs;
return unless $keys;
CheckOptions("\\lxDeclare keys", $declare_keys, %{ $keys->getKeyVals });
foreach my $key (qw(role tag name meaning replace)) {
if (my $value = $keys->getValue($key)) {
Warn('unexpected', $key, $stomach,
"Repeated $key: " . join('; ', map { Stringify($_) } @$value))
if ref $value eq 'ARRAY'; } }
my $id = ($keys->getValue('tag') ? next_declaration_id() : undef);
if ($id && LookupValue('InPreamble')) {
Warn('unexpected', 'tag', $stomach,
"Declaration with tag cannot appear in preamble"
. Stringify($whatsit)); }
$whatsit->setProperties(scope => getDeclarationScope($keys),
role => ToString($keys->getValue('role')),
name => ToString($keys->getValue('name')),
meaning => ToString($keys->getValue('meaning')),
trace => defined $keys->getValue('trace'),
wrap => defined $keys->getValue('wrap'),
id => $id,
match => $pattern,
replace => $keys->getValue('replace'));
if (my $label = ToString($keys->getValue('label'))) {
PushValue("Declaration_$label", $whatsit); }
return; },
afterConstruct => sub { my ($document, $whatsit) = @_;
my $scope = $whatsit->getProperty('scope');
createDeclarationRewrite($document, $scope, $whatsit); },
properties => { alignmentSkippable => 1 },
reversion => '');
DefConstructor('\lxRefDeclaration OptionalKeyVals:Declare {}', '',
afterDigest => sub { my ($stomach, $whatsit) = @_;
my ($keys, $labels) = $whatsit->getArgs;
$whatsit->setProperties(scope => getDeclarationScope($keys),
labels => [split(',', ToString($labels))]); },
afterConstruct => sub { my ($document, $whatsit) = @_;
my $scope = $whatsit->getProperty('scope');
foreach my $label (@{ $whatsit->getProperty('labels') }) {
if (my $declaration = LookupValue("Declaration_$label")) {
map { createDeclarationRewrite($document, $scope, $_) } @$declaration; }
else {
Warn('unexpected', $label, $document,
"No Declaration with label=$label was found"); } } },
properties => { alignmentSkippable => 1 },
reversion => '');
sub next_declaration_id {
StepCounter('@XMDECL');
DefMacroI(T_CS('\@@XMDECL@ID'), undef,
Tokens(Explode(LookupValue('\c@@XMDECL')->valueOf)),
scope => 'global');
return ToString(Expand(T_CS('\the@XMDECL@ID'))); }
sub getDeclarationScope {
my ($keys) = @_;
# Sort out the scope.
my $scope = $keys && $keys->getValue('scope');
$scope = ($scope ? ToString($scope) : LookupValue('current_counter'));
if ($scope && LookupValue("\\c\@$scope")) { # Scope is some counter.
$scope = "id:" . ToString(Digest(Expand(T_CS("\\the$scope\@ID")))); }
return $scope; }
sub createDeclarationRewrite {
my ($document, $scope, $whatsit) = @_;
my %props = $whatsit->getProperties;
my ($id, $match, $wrap, $role, $name, $meaning, $ref, $trace, $replace)
= map { $props{$_} } qw(id match wrap role name meaning ref trace replace);
### print STDERR "REWRITER: scope=>$scope, match=>$match, role=>$role, dec_id=>$id\n";
# Put this rule IN FRONT of other rules!
UnshiftValue('DOCUMENT_REWRITE_RULES',
LaTeXML::Core::Rewrite->new('math',
($trace ? (trace => $trace) : ()),
($scope ? (scope => $scope) : ()),
($match ? (match => $match) : ()),
($wrap ? (wrap => $wrap) : ()),
($replace
? (replace => $replace)
: attributes => { ($role ? (role => $role) : ()),
($name ? (name => $name) : ()),
($meaning ? (meaning => $meaning) : ()),
($id ? (dec_id => $id) : ()),
}),
));
return; }
#======================================================================
1;
|