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
|
# -*- mode: Perl -*-
# /=====================================================================\ #
# | ntheorem | #
# | 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;
#**********************************************************************
# Basically, this package is similar to amsthm.sty (or theorem.sty)
# with two main enhancements:
# endmarks
# list of theorem (which should actually be covered in some postprocessor?)
RequirePackage('amsthm');
# but re-redefine from amsthm from LaTeX; use save note font as head font
DefRegister('\thm@notefont' => Tokens(T_CS('\the'), T_CS('\thm@headfont')));
# options....
DefConditional('\if@thref', undef);
DefConditional('\ifthm@inframe', undef);
DefConditional('\ifthm@tempif', undef);
# thmmarks, leqno, fleqn, thref
# standard, noconfig, amsthm,
# framed (needs framed.sty)
#======================================================================
foreach my $option (qw(leqno fleqn
amsmath amsthm hyperref)) {
DeclareOption($option, undef); }
DeclareOption('standard', sub { AssignValue('thm@usestd' => 1); }); # ?
DeclareOption('noconfig', sub { }); # ?
DeclareOption('framed', sub { }); # ? [and needs framed.sty to be loaded]
DeclareOption('thmmarks', sub { }); # ?
DeclareOption('thref', sub {
# Redefine \label to take 2nd optional argument, being the type of thing.
# [seems out-of-place here, but...]
# [Nominally would require support from aux file, but we'll have to see...]
Let('\orig@label', '\label');
# Perhaps this type could be attached somehow?
# [too bad there's no way to record the type of objects...(too verbose)]
DefMacro('\label Semiverbatim []', '\orig@label{#1}');
# \thref{} should also output the type from the above.
# We'll use latexml's show attribute to mimic the effect
DefConstructor('\thref OptionalMatch:* Semiverbatim',
"<ltx:ref labelref='#label' show='typerefnum' _force_font='true'/>",
properties => sub { (label => CleanLabel($_[2])); });
});
ProcessOptions();
#, \InTheoType should be set within theorem environment to the theorem
# \<type>Keyword
# \<type>Symbol
# , \Oldeqnnum, \OrganizeTheoremSymbol, \PotEndMark,
# \RestoreTags,
# \SetEndMark, \SetOnlyEndMark, \SetTagPlusEndMark, \TagsPlusEndmarks,
# \endalign, \endalignat, \endflalign, \endgather, \endmathdisplay, \endxalignat, \endxxalignat,
# \getKeywordOf,
# \mysavskip,
# \newframedtheorem, \newshadedtheorem,
# \FrameCommand
# \proofSymbol,
#, \renewtheoremstyle,
# \shadecolor,
# \theoremframecommand, \theoremkeyword,
# Note:
# * the namespace of \theoremstyle{<theoremstyle>}, \newtheoremstyle{name}
# is distinct from the namespace of newtheorem{<theoremclass>} ,\begin{<theoremclass>}
# theoremstyle{nmae}
# should set a recorded (sub?)set of params
# newtheoremstyle{name}<params...>
# should associate ALL (?) params with the named style?
# newtheorem{name}
# should record all(?) current params for that name
# \begin{name} should merge current values with ones recorded for name
DefRegister('\theoremindent' => Dimension('0em'));
DefRegister('\theoremrightindent' => Dimension('0em'));
DefRegister('\theorempreskipamount' => Dimension('0em'));
DefRegister('\theorempostskipamount' => Dimension('0em'));
DefRegister('\theoremframepreskipamount' => Dimension('0em'));
DefRegister('\theoremframepostskipamount' => Dimension('0em'));
DefRegister('\theoreminframepreskipamount' => Dimension('0em'));
DefRegister('\theoreminframepostskipamount' => Dimension('0em'));
DefMacro('\theorempreskip{}', '');
DefMacro('\theorempostskip{}', '');
DefMacro('\theoremframepreskip{}', '');
DefMacro('\theoremframepostskip{}', '');
DefMacro('\theoreminframepreskip{}', '');
DefMacro('\theoreminframepostskip{}', '');
DefMacro('\None', 'None');
DefMacro('\NoneSymbol', 'None');
DefMacro('\NoneKeyword', 'None');
DefRegister('\shadecolor' => Tokens());
# Include a few other theorem paramters in definitions
setSavableTheoremParameters(qw(
\thm@headfont \thm@bodyfont \thm@headpunct
\thm@styling \thm@headstyling thm@swap
\thm@numbering \thm@prework \thm@postwork \thm@symbol));
DefMacro('\theoremheaderfont{}', sub {
AssignValue('\thm@headfont' => $_[1]); });
DefMacro('\theoremseparator{}', sub {
AssignValue('\thm@headpunct' => $_[1]); });
DefMacro('\theoremsymbol{}', sub {
AssignValue('\thm@symbol' => $_[1]); });
# ???
DefMacro('\theoremprework{}', sub {
AssignValue('\thm@prework' => $_[1]); });
DefMacro('\theorempostwork{}', sub {
AssignValue('\thm@postwork' => $_[1]); });
DefMacro('\theoremnumbering{}', sub {
AssignValue('\thm@numbering' => T_CS('\\' . ToString($_[1]))); });
# This should turn on the same parameters as the env,
# much like \theoremstyle{style} does, givcen a theoremstyle
DefPrimitive('\theoremclass{}', sub {
return; });
#======================================================================
# ???
###DefMacro('\TheoremSymbol','');
# need some styling here to put at right...
DefMacro('\TheoremSymbol', '\@qedbox{\the\thm@symbol}');
DefConstructor('\@qedbox{}', "<ltx:text class='ltx_align_floatright'>#1</ltx:text>");
RawTeX('\newif\ifsetendmark\setendmarktrue');
DefMacro('\NoEndMark', '\global\setendmarkfalse');
DefMacroI('\thm@doendmark', undef, '\ifsetendmark\TheoremSymbol\fi');
DefRegister('\qedsymbol' => Tokens());
DefMacro('\qed', '\@qedbox{\the\qedsymbol}');
#======================================================================
Let('\orig@newtheorem', '\newtheorem');
# This defines BOTH thm & thm* envs, but note that the *'d form of theorem uses same counter!
DefMacro('\newtheorem OptionalMatch:* {}[]{}[]',
'\orig@newtheorem#1{#2}[#3]{#4}[#5]'
. '\ifx.#3.\orig@newtheorem#1{#2*}[#2]{#4}[#5]'
. '\else\orig@newtheorem#1{#2*}[#3]{#4}[#5]\fi'
);
DefMacro('\Theoremname', '\lx@thistheorem');
Let('\renewtheorem', '\newtheorem');
#======================================================================
# do something about recording & adding frame
# This needs to tie into framed.sty!!!!
# Really should execute \theoremframecommand in isolation,
# then copy the relevant attributes (framing, spacing, color, ...) to the theorem!
### NEEDS TO integrate with framed.sty better
### AND in the meantime, this needs a better API
DefConstructorI('\lx@addframing', undef, sub {
my ($doc, %props) = @_;
my $node = $doc->getElement;
$doc->addClass($node, 'ltx_framed');
my $css = $node->getAttribute('cssstyle');
my $pad = 'padding:' . $props{margin} . 'pt;';
$doc->setAttribute($node, cssstyle => ($css ? $css . ';' . $pad : $pad)); },
properties => sub { (framecolor => Black,
margin => LookupValue('\FrameSep')->ptValue); });
# Since \theoremframecommand can be defined to be pretty much anything,
# we don't have a good handle on what colors, etc, it may use.
# Here we try something pretty bizarre:
# We execute the theoremframecommand on some dummy text, capture the result,
# and copy the relevent attributes to the theorem.
DefMacroI('\lx@snapshot@framing', undef, '\lx@@snapshot@framing{\theoremframecommand{foo}}');
DefConstructor('\lx@@snapshot@framing{}', sub {
my ($document, $framebox) = @_;
my $theorem = $document->getElement;
my $capture = $document->openElement('_Capture_');
my ($frame, @rest) = $document->absorb($framebox);
$document->closeElement('_Capture_');
if (my $c = join(' ', grep { $_ } $theorem->getAttribute('class'), $frame->getAttribute('class'))) {
$document->setAttribute($theorem, class => $c); }
if (my $c = join(';', grep { $_ } $theorem->getAttribute('cssstyle'),
$frame->getAttribute('cssstyle'))) {
$document->setAttribute($theorem, cssstyle => $c); }
if (my $b = $frame->getAttribute('backgroundcolor')
|| $document->getNodeFont($frame)->getBackground) {
$document->setAttribute($theorem, backgroundcolor => $b); }
foreach my $attr (qw(framed framecolor)) {
if (my $v = $frame->getAttribute($attr)) {
$document->setAttribute($theorem, $attr => $v); } }
$document->removeNode($capture);
},
reversion => '');
DefMacro('\newframedtheorem{}[]{}[]',
'\begingroup'
. '\thm@styling{\lx@addframing}'
. '\newtheorem{#1}[#2]{#3}[#4]'
. '\endgroup');
DefMacro('\newshadedtheorem{}[]{}[]',
'\begingroup'
. '\ifx\theoremframecommand\relax'
. '\def\theoremframecommand{\colorbox{shadecolor}}\fi'
. '\thm@styling{\lx@snapshot@framing}'
. '\newtheorem{#1}[#2]{#3}[#4]'
. '\endgroup');
#======================================================================
DefPrimitive('\lx@ntheorem@newtheoremstyle{}{}{}{}{}{}', sub {
my ($stomach, $name, $headfont, $bodyfont, $headstyle, $swap, $numbering) = @_;
$name = ToString($name);
saveTheoremStyle($name,
'\thm@bodyfont' => $bodyfont,
'\thm@headfont' => $headfont,
'\thm@headstyling' => $headstyle,
'thm@swap' => ToString($swap) eq 'S',
'\thm@numbering' => $numbering,
'\thm@symbol' => LookupValue('\thm@symbol'),
);
DefMacroI(T_CS('\th@' . $name), undef, sub { useTheoremStyle($name); });
return; });
RawTeX(<<'EoTeX');
\lx@ntheorem@newtheoremstyle{plain}{\bfseries}{\itshape}{\lx@makerunin}{N}{\arabic}
\lx@ntheorem@newtheoremstyle{break}{\bfseries}{\slshape}{}{N}{\arabic}
\lx@ntheorem@newtheoremstyle{change}{\bfseries}{\slshape}{\lx@makerunin}{S}{\arabic}
\lx@ntheorem@newtheoremstyle{margin}{\bfseries}{\slshape}{\lx@makerunin\lx@makeoutdent}{S}{\arabic}
\lx@ntheorem@newtheoremstyle{marginbreak}{\bfseries}{\slshape}{\lx@makeoutdent}{S}{\arabic}
\lx@ntheorem@newtheoremstyle{changebreak}{\bfseries}{\slshape}{}{S}{\arabic}
\lx@ntheorem@newtheoremstyle{nonumberplain}{\bfseries}{\itshape}{\lx@makerunin}{N}{}
\lx@ntheorem@newtheoremstyle{nonumberbreak}{\bfseries}{\slshape}{}{N}{}
\lx@ntheorem@newtheoremstyle{empty}{}{}{\lx@makerunin}{N}{}
\lx@ntheorem@newtheoremstyle{emptybreak}{}{}{}{N}{}
EoTeX
# Load the other styles from the ntheorem's standard defintions
InputDefinitions('ntheorem.std') if LookupValue('thm@usestd');
# Start off as plain style.
useTheoremStyle('plain');
#======================================================================
# Lists of Theorems.
DefMacro('\addtheoremline OptionalMatch:* {}{}', '');
DefMacro('\addtotheoremfile[]{}', '');
DefMacro('\theoremlisttype{}', '');
DefMacro('\newtheoremlisttype{}{}{}{}', '');
DefMacro('\renewtheoremlisttype{}{}{}{}', '');
# This is Wrong!
# It should list only specific subsets
# TOC needs to be generalized to allow more flexiblity, maybe XPath?
# Should accept comma separated list of theorem classes, including 'all'
# (theorem class being the 1st arg to \newtheorem)
DefConstructor('\listtheorems{}',
"<ltx:TOC lists='#lists' name='#name'/>",
properties => sub {
my @types = split(/\s*,\s*/, ToString($_[1]));
(lists => join(' ', map { ($_ eq 'all' ? 'thm' : 'theorem:' . $_) } @types));
});
# \theoremlistdo,
# Presumably a user never needs to call these?
# [they implement the predefined theorem list types]
DefMacro('\theoremlistall', '');
DefMacro('\theoremlistallname', '');
DefMacro('\theoremlistalloptional', '');
DefMacro('\theoremlistalloptname', '');
#======================================================================
# Add capability for greek numbering
DefMacro('\greek{}', sub {
ExplodeText(radix_greek(CounterValue(ToString(Expand($_[1])))->valueOf)); });
DefMacro('\Greek{}', sub {
ExplodeText(radix_Greek(CounterValue(ToString(Expand($_[1])))->valueOf)); });
#======================================================================
1;
|