Skip to content

Commit bfd41c0

Browse files
OmikhleiaDidier Willis
authored andcommitted
feat(math): Add (AMS)LaTeX-like stackrel, overset and underset
1 parent 3263be3 commit bfd41c0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/math/texlike.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,22 @@ local commands = {}
258258
local objType = {
259259
tree = 1,
260260
str = 2,
261+
unknown = 3,
261262
}
262263

263264
local function inferArgTypes_aux (accumulator, typeRequired, body)
264265
if type(body) == "table" then
265266
if body.id == "argument" then
266267
local ret = accumulator
267-
table.insert(ret, body.index, typeRequired)
268+
while #ret < body.index do
269+
-- Don't leave holes in the argument list.
270+
-- This may happen if the argument are not used orderly, and the
271+
-- entry might later be filled with the appropriate type... unless
272+
-- the argument is not used at all.
273+
-- CODE SMELL, but this recursive inference is hard to assess.
274+
table.insert(ret, objType.unknown)
275+
end
276+
ret[body.index] = typeRequired
268277
return ret
269278
elseif body.id == "command" then
270279
if commands[body.command] then
@@ -831,6 +840,20 @@ compileToMathML(
831840
\def{phantom}{\mphantom{#1}}
832841
\def{hphantom}{\mpadded[height=0, depth=0]{\mphantom{#1}}}
833842
\def{vphantom}{\mpadded[width=0]{\mphantom{#1}}}
843+
844+
% Stacking commands
845+
% Plain LaTeX \stackrel is only supposed to be used on binary relations.
846+
% It's a poor naming choice, and a poor design choice as well.
847+
% Package "stackrel" on CTAN redefine its for relational operators, and
848+
% provides a \stackbin for binary operators.
849+
% Users would, without respect for semantics, use them interchangeably.
850+
% We use the same definition for both, and expect the MathML layer to handle
851+
% the content as appropriate based on the actual operators...
852+
\def{stackrel}{\mover{#2}{#1}}
853+
\def{stackbin}{\mover{#2}{#1}}
854+
% Package "amsmath" went with its own generic \overset and \underset.
855+
\def{overset}{\mover{#2}{#1}}
856+
\def{underset}{\munder{#2}{#1}}
834857
]==],
835858
})
836859
)

0 commit comments

Comments
 (0)