Skip to content

Commit f82b733

Browse files
authored
Everymath (#2461)
* Use \everymath, \everydisplay correctly (latter without former) * Update test case to test \everymath,\everydisplay * Use \everymath,\everydisplay as part of Stomach->setMode * Math entering commands no longer need to handle \everymath,\everydisplay, just beginMode appropriately * Update and enrich \everymath,\everydisplay tests
1 parent 74c0e05 commit f82b733

File tree

6 files changed

+207
-40
lines changed

6 files changed

+207
-40
lines changed

lib/LaTeXML/Core/Stomach.pm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,18 @@ sub setMode {
364364
# and save the text font for any embedded text.
365365
$STATE->assignValue(savedfont => $curfont, 'local');
366366
$STATE->assignValue(script_base_level => scalar(@{ $$self{boxing} })); # See getScriptLevel
367-
my $mathfont = $STATE->lookupValue('mathfont')->merge(
367+
my $isdisplay = $mode =~ /^display/;
368+
my $mathfont = $STATE->lookupValue('mathfont')->merge(
368369
color => $curfont->getColor, background => $curfont->getBackground,
369370
size => $curfont->getSize,
370-
mathstyle => ($mode =~ /^display/ ? 'display' : 'text'));
371+
mathstyle => ($isdisplay ? 'display' : 'text'));
371372
$STATE->assignValue(font => $mathfont, 'local');
372373
$STATE->assignValue(initial_math_font => $mathfont, 'local');
373-
$STATE->assignValue(fontfamily => -1, 'local'); }
374+
$STATE->assignValue(fontfamily => -1, 'local');
375+
my $every = ($isdisplay ? T_CS('\everydisplay') : T_CS('\everymath'));
376+
my $ereg = $STATE->lookupDefinition($every);
377+
if (my $toks = $ereg && $ereg->isRegister && $ereg->valueOf()) {
378+
$self->getGullet->unread($toks); } }
374379
else {
375380
# When entering text mode, we should set the font to the text font in use before the math
376381
# but inherit color and size

lib/LaTeXML/Engine/LaTeX.pool.ltxml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,15 +2050,9 @@ DefConstructorI('\lx@begin@display@math', undef,
20502050
. "</ltx:Math>"
20512051
. "</ltx:equation>",
20522052
alias => '$$',
2053-
beforeDigest => sub {
2054-
$_[0]->beginMode('display_math');
2055-
if (my @everymath_toks = $STATE->lookupDefinition(T_CS('\everymath'))->valueOf->unlist()) {
2056-
$_[0]->getGullet->unread(@everymath_toks); }
2057-
if (my @everydisplay_toks = $STATE->lookupDefinition(T_CS('\everydisplay'))->valueOf->unlist()) {
2058-
$_[0]->getGullet->unread(@everydisplay_toks); }
2059-
return; },
2060-
properties => sub { RefStepID('equation') },
2061-
captureBody => 1);
2053+
beforeDigest => sub { $_[0]->beginMode('display_math'); },
2054+
properties => sub { RefStepID('equation') },
2055+
captureBody => 1);
20622056

20632057
DefEnvironment('{displaymath}',
20642058
"<ltx:equation xml:id='#id'>"
@@ -2077,8 +2071,7 @@ DefEnvironment('{math}',
20772071
. "#body"
20782072
. "</ltx:XMath>"
20792073
. "</ltx:Math>",
2080-
mode => 'inline_math',
2081-
);
2074+
mode => 'inline_math');
20822075

20832076
Let('\curr@math@size', '\@empty');
20842077

lib/LaTeXML/Engine/TeX_Math.pool.ltxml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,8 @@ DefConstructorI('\lx@begin@display@math', undef,
134134
. "</ltx:Math>"
135135
. "</ltx:equation>",
136136
reversion => Tokens(T_MATH, T_MATH),
137-
beforeDigest => sub {
138-
$_[0]->beginMode('display_math');
139-
if (my @everymath_toks = $STATE->lookupDefinition(T_CS('\everymath'))->valueOf->unlist()) {
140-
$_[0]->getGullet->unread(@everymath_toks); }
141-
if (my @everydisplay_toks = $STATE->lookupDefinition(T_CS('\everydisplay'))->valueOf->unlist()) {
142-
$_[0]->getGullet->unread(@everydisplay_toks); }
143-
return; }, captureBody => 1);
137+
beforeDigest => sub { $_[0]->beginMode('display_math'); },
138+
captureBody => 1);
144139
DefConstructorI('\lx@end@display@math', undef, "",
145140
reversion => Tokens(T_MATH, T_MATH),
146141
beforeDigest => sub { $_[0]->endMode('display_math'); });
@@ -152,11 +147,8 @@ DefConstructorI('\lx@begin@inline@math', undef,
152147
. "</ltx:XMath>"
153148
. "</ltx:Math>",
154149
reversion => Tokens(T_MATH),
155-
beforeDigest => sub {
156-
$_[0]->beginMode('inline_math');
157-
if (my @everymath_toks = $STATE->lookupDefinition(T_CS('\everymath'))->valueOf->unlist()) {
158-
$_[0]->getGullet->unread(@everymath_toks); }
159-
return; }, captureBody => 1);
150+
beforeDigest => sub { $_[0]->beginMode('inline_math'); },
151+
captureBody => 1);
160152
DefConstructorI('\\lx@end@inline@math', undef, "",
161153
reversion => Tokens(T_MATH),
162154
beforeDigest => sub { $_[0]->endMode('inline_math'); });
@@ -911,26 +903,26 @@ Let('\vcenter', '\vbox');
911903
# Note that (over|under) brace accents act like \limit, but lines, arrows do NOT!
912904
DefMath('\lx@math@overline{}', UTF(0xAF),
913905
operator_role => 'OVERACCENT', operator_stretchy => 'true',
914-
name => 'overline', alias => '\overline');
906+
name => 'overline', alias => '\overline');
915907
DefConstructor('\lx@text@overline{}',
916908
"<ltx:text framed='overline' _noautoclose='1'>#1</ltx:text>");
917909
DefMath('\lx@math@underline{}', UTF(0xAF),
918910
operator_role => 'UNDERACCENT', operator_stretchy => 'true',
919-
name => 'underline', alias => '\underline');
911+
name => 'underline', alias => '\underline');
920912
DefConstructor('\lx@text@underline{}',
921913
"<ltx:text framed='underline' _noautoclose='1'>#1</ltx:text>");
922914
DefMath('\lx@math@overrightarrow{}', "\x{2192}",
923915
operator_role => 'OVERACCENT', operator_stretchy => 'true',
924-
name => 'overrightarrow', alias => '\overrightarrow');
916+
name => 'overrightarrow', alias => '\overrightarrow');
925917
DefMath('\lx@math@overleftarrow{}', "\x{2190}",
926918
operator_role => 'OVERACCENT', operator_stretchy => 'true',
927-
name => 'overleftarrow', alias => '\overleftarrow');
919+
name => 'overleftarrow', alias => '\overleftarrow');
928920
DefMath('\lx@math@underrightarrow{}', "\x{2192}",
929921
operator_role => 'UNDERACCENT', operator_stretchy => 'true',
930-
name => 'underrightarrow', alias => '\underrightarrow');
922+
name => 'underrightarrow', alias => '\underrightarrow');
931923
DefMath('\lx@math@underleftarrow{}', "\x{2190}",
932924
operator_role => 'UNDERACCENT', operator_stretchy => 'true',
933-
name => 'underleftarrow', alias => '\underleftarrow');
925+
name => 'underleftarrow', alias => '\underleftarrow');
934926
DefMath('\lx@math@overbrace{}', "\x{23DE}",
935927
operator_role => 'OVERACCENT', scriptpos => 'mid', operator_stretchy => 'true',
936928
name => 'overbrace', alias => '\overbrace', robust => 1);

t/expansion/aftergroup.pdf

16 KB
Binary file not shown.

t/expansion/aftergroup.tex

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,25 @@ \section{Every Box}
102102
\everyhbox={}
103103
\everyvbox={}
104104

105-
106-
% \everymath is NOT (yet) supported.
107-
% \section{EveryMath}
108-
% \everymath={.}
109-
% $a+b$
110-
111-
% \everymath={}
112-
% $a+b$
105+
\section{Every Math/Display}
106+
{
107+
\everymath={\rightarrow}
108+
$a+b$
109+
\begin{math} a + b \end{math}
110+
$$a+b$$
111+
\[a+b\]
112+
\begin{displaymath} a + b \end{displaymath}
113+
\begin{equation} a + b \end{equation}
114+
}
115+
{
116+
\everydisplay={\rightarrow}
117+
$a+b$
118+
\begin{math} a + b \end{math}
119+
$$a+b$$
120+
\[a+b\]
121+
\begin{displaymath} a + b \end{displaymath}
122+
\begin{equation} a + b \end{equation}
123+
}
113124

114125
% $ a + \everymath={} b$
115126

t/expansion/aftergroup.xml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,170 @@ No quirks</p>
119119
<p>VBOX HBOX An Hbox HBOX Another Hbox</p>
120120
</para>
121121
</section>
122+
<section inlist="toc" xml:id="S5">
123+
<tags>
124+
<tag>5</tag>
125+
<tag role="refnum">5</tag>
126+
<tag role="typerefnum">§5</tag>
127+
</tags>
128+
<title><tag close=" ">5</tag>Every Math/Display</title>
129+
<para xml:id="S5.p1">
130+
<p><Math mode="inline" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.p1.m1">
131+
<XMath>
132+
<XMApp>
133+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
134+
<XMTok meaning="absent"/>
135+
<XMApp>
136+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
137+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
138+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
139+
</XMApp>
140+
</XMApp>
141+
</XMath>
142+
</Math>
143+
<Math mode="inline" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.p1.m2">
144+
<XMath>
145+
<XMApp>
146+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
147+
<XMTok meaning="absent"/>
148+
<XMApp>
149+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
150+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
151+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
152+
</XMApp>
153+
</XMApp>
154+
</XMath>
155+
</Math></p>
156+
<equation xml:id="S5.Ex1">
157+
<Math mode="display" tex="a+b" text="a + b" xml:id="S5.Ex1.m1">
158+
<XMath>
159+
<XMApp>
160+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
161+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
162+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
163+
</XMApp>
164+
</XMath>
165+
</Math>
166+
</equation>
167+
<equation xml:id="S5.Ex2">
168+
<Math mode="display" tex="a+b" text="a + b" xml:id="S5.Ex2.m1">
169+
<XMath>
170+
<XMApp>
171+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
172+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
173+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
174+
</XMApp>
175+
</XMath>
176+
</Math>
177+
</equation>
178+
<equation xml:id="S5.Ex3">
179+
<Math mode="display" tex="a+b" text="a + b" xml:id="S5.Ex3.m1">
180+
<XMath>
181+
<XMApp>
182+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
183+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
184+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
185+
</XMApp>
186+
</XMath>
187+
</Math>
188+
</equation>
189+
<equation xml:id="S5.E1">
190+
<tags>
191+
<tag>(1)</tag>
192+
<tag role="refnum">1</tag>
193+
</tags>
194+
<Math mode="display" tex="a+b" text="a + b" xml:id="S5.E1.m1">
195+
<XMath>
196+
<XMApp>
197+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
198+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
199+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
200+
</XMApp>
201+
</XMath>
202+
</Math>
203+
</equation>
204+
<p><Math mode="inline" tex="a+b" text="a + b" xml:id="S5.p1.m3">
205+
<XMath>
206+
<XMApp>
207+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
208+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
209+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
210+
</XMApp>
211+
</XMath>
212+
</Math>
213+
<Math mode="inline" tex="a+b" text="a + b" xml:id="S5.p1.m4">
214+
<XMath>
215+
<XMApp>
216+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
217+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
218+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
219+
</XMApp>
220+
</XMath>
221+
</Math></p>
222+
<equation xml:id="S5.Ex4">
223+
<Math mode="display" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.Ex4.m1">
224+
<XMath>
225+
<XMApp>
226+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
227+
<XMTok meaning="absent"/>
228+
<XMApp>
229+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
230+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
231+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
232+
</XMApp>
233+
</XMApp>
234+
</XMath>
235+
</Math>
236+
</equation>
237+
<equation xml:id="S5.Ex5">
238+
<Math mode="display" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.Ex5.m1">
239+
<XMath>
240+
<XMApp>
241+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
242+
<XMTok meaning="absent"/>
243+
<XMApp>
244+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
245+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
246+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
247+
</XMApp>
248+
</XMApp>
249+
</XMath>
250+
</Math>
251+
</equation>
252+
<equation xml:id="S5.Ex6">
253+
<Math mode="display" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.Ex6.m1">
254+
<XMath>
255+
<XMApp>
256+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
257+
<XMTok meaning="absent"/>
258+
<XMApp>
259+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
260+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
261+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
262+
</XMApp>
263+
</XMApp>
264+
</XMath>
265+
</Math>
266+
</equation>
267+
<equation xml:id="S5.E2">
268+
<tags>
269+
<tag>(2)</tag>
270+
<tag role="refnum">2</tag>
271+
</tags>
272+
<Math mode="display" tex="\rightarrow a+b" text="absent rightarrow a + b" xml:id="S5.E2.m1">
273+
<XMath>
274+
<XMApp>
275+
<XMTok name="rightarrow" role="ARROW">→</XMTok>
276+
<XMTok meaning="absent"/>
277+
<XMApp>
278+
<XMTok meaning="plus" role="ADDOP">+</XMTok>
279+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
280+
<XMTok font="italic" role="UNKNOWN">b</XMTok>
281+
</XMApp>
282+
</XMApp>
283+
</XMath>
284+
</Math>
285+
</equation>
286+
</para>
287+
</section>
122288
</document>

0 commit comments

Comments
 (0)