Skip to content

Commit

Permalink
feat(math): Support a TeX math like text command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Omikhleia authored and Didier Willis committed Oct 17, 2024
1 parent 3023b93 commit 518e497
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/math/texlike.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ local mathGrammar = function (_ENV)
return ret
end
local group = P"{" * V"mathlist" * (P"}" + E("`}` expected"))
-- Simple amsmath-like \text command (no embedded math)
local textgroup = P"{" * C((1-P"}")^1) * (P"}" + E("`}` expected"))
local element_no_infix =
V"def" +
V"text" + -- Important: before command
V"command" +
group +
V"argument" +
Expand Down Expand Up @@ -115,6 +118,11 @@ local mathGrammar = function (_ENV)
sub = element_no_infix * _ * P"_" * _ * element_no_infix
atom = natural + C(utf8code - S"\\{}%^_&") +
(P"\\{" + P"\\}") / function (s) return string.sub(s, -1) end
text = (
P"\\text" *
Cg(parameters, "options") *
textgroup
)
command = (
P"\\" *
Cg(ctrl_sequence_name, "command") *
Expand Down Expand Up @@ -365,6 +373,8 @@ local function compileToMathML_aux (_, arg_env, tree)
return compileToMathML_aux(nil, compiledArgs, tree[1])
end)
return nil
elseif tree.id == "text" then
tree.command = "mtext"
elseif tree.id == "command" and commands[tree.command] then
local argTypes = commands[tree.command][1]
local cmdFun = commands[tree.command][2]
Expand Down

0 comments on commit 518e497

Please sign in to comment.