Skip to content

Commit 518e497

Browse files
OmikhleiaDidier Willis
authored andcommitted
feat(math): Support a TeX math like text command
Similar to the `\text` command in amsmath, but does not support internal embedding of math equations. Yet it covers the usual need for some bits of regular text inside math formula.
1 parent 3023b93 commit 518e497

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

packages/math/texlike.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ local mathGrammar = function (_ENV)
4242
return ret
4343
end
4444
local group = P"{" * V"mathlist" * (P"}" + E("`}` expected"))
45+
-- Simple amsmath-like \text command (no embedded math)
46+
local textgroup = P"{" * C((1-P"}")^1) * (P"}" + E("`}` expected"))
4547
local element_no_infix =
4648
V"def" +
49+
V"text" + -- Important: before command
4750
V"command" +
4851
group +
4952
V"argument" +
@@ -115,6 +118,11 @@ local mathGrammar = function (_ENV)
115118
sub = element_no_infix * _ * P"_" * _ * element_no_infix
116119
atom = natural + C(utf8code - S"\\{}%^_&") +
117120
(P"\\{" + P"\\}") / function (s) return string.sub(s, -1) end
121+
text = (
122+
P"\\text" *
123+
Cg(parameters, "options") *
124+
textgroup
125+
)
118126
command = (
119127
P"\\" *
120128
Cg(ctrl_sequence_name, "command") *
@@ -365,6 +373,8 @@ local function compileToMathML_aux (_, arg_env, tree)
365373
return compileToMathML_aux(nil, compiledArgs, tree[1])
366374
end)
367375
return nil
376+
elseif tree.id == "text" then
377+
tree.command = "mtext"
368378
elseif tree.id == "command" and commands[tree.command] then
369379
local argTypes = commands[tree.command][1]
370380
local cmdFun = commands[tree.command][2]

0 commit comments

Comments
 (0)