Skip to content

Commit eb402c5

Browse files
Omikhleiaalerque
authored andcommitted
feat(math): Support TeX-like math limits
As in amsmath: lim, limsup, liminf, projlim, injlim.
1 parent 3a0ef46 commit eb402c5

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

packages/math/texlike.lua

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,23 @@ local compileToStr = function (argEnv, mathlist)
252252
end
253253
end
254254

255+
local function isBigOperator (tree)
256+
if tree.command ~= "mo" then
257+
return false
258+
end
259+
-- Case \mo[atom=big]{ops}
260+
-- E.g. \mo[atom=big]{lim}
261+
if tree.options and tree.options.atom == "big" then
262+
return true
263+
end
264+
-- Case \mo{ops} where ops is registered as big operator (unicode-symbols)
265+
-- E.g. \mo{∑) or \sum
266+
if tree[1] and symbolDefaults[tree[1]] and symbolDefaults[tree[1]].atom == atomType.bigOperator then
267+
return true
268+
end
269+
return false
270+
end
271+
255272
local function compileToMathML_aux (_, arg_env, tree)
256273
if type(tree) == "string" then
257274
return tree
@@ -328,21 +345,13 @@ local function compileToMathML_aux (_, arg_env, tree)
328345
tree.options = {}
329346
-- Translate TeX-like sub/superscripts to `munderover` or `msubsup`,
330347
-- depending on whether the base is a big operator
331-
elseif tree.id == "sup" and tree[1].command == "mo" and tree[1].atom == atomType.bigOperator then
348+
elseif tree.id == "sup" and isBigOperator(tree[1]) then
332349
tree.command = "mover"
333-
elseif tree.id == "sub" and tree[1].command == "mo" and symbolDefaults[tree[1][1]].atom == atomType.bigOperator then
350+
elseif tree.id == "sub" and isBigOperator(tree[1]) then
334351
tree.command = "munder"
335-
elseif
336-
tree.id == "subsup"
337-
and tree[1].command == "mo"
338-
and symbolDefaults[tree[1][1]].atom == atomType.bigOperator
339-
then
352+
elseif tree.id == "subsup" and isBigOperator(tree[1]) then
340353
tree.command = "munderover"
341-
elseif
342-
tree.id == "supsub"
343-
and tree[1].command == "mo"
344-
and symbolDefaults[tree[1][1]].atom == atomType.bigOperator
345-
then
354+
elseif tree.id == "supsub" and isBigOperator(tree[1]) then
346355
tree.command = "munderover"
347356
local tmp = tree[2]
348357
tree[2] = tree[3]
@@ -480,6 +489,16 @@ compileToMathML(
480489
\def{bi}{\mi[mathvariant=bold-italic]{#1}}
481490
\def{dsi}{\mi[mathvariant=double-struck]{#1}}
482491
492+
\def{lim}{\mo[atom=big]{lim}}
493+
494+
% From amsmath:
495+
\def{to}{\mo[atom=bin]{→}}
496+
% Those use U+202F NARROW NO-BREAK SPACE in their names
497+
\def{limsup}{\mo[atom=big]{lim sup}}
498+
\def{liminf}{\mo[atom=big]{lim inf}}
499+
\def{projlim}{\mo[atom=big]{proj lim}}
500+
\def{injlim}{\mo[atom=big]{inj lim}}
501+
483502
% Standard spaces gleaned from plain TeX
484503
\def{thinspace}{\mspace[width=thin]}
485504
\def{negthinspace}{\mspace[width=-thin]}

0 commit comments

Comments
 (0)