From 80f95f575ae9cb1730c949c1e1d4e469c62c21c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 30 May 2021 20:37:03 +0200 Subject: [PATCH] Support sized delimiters --- luamml-convert.lua | 44 ++++++++++++++++++++++++++++++++------ luamml-patches-amsmath.sty | 8 +++++++ parse_showlists.lua | 5 ++++- test_tex.tex | 2 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/luamml-convert.lua b/luamml-convert.lua index b59b58f..2dfa8b0 100644 --- a/luamml-convert.lua +++ b/luamml-convert.lua @@ -248,11 +248,18 @@ end local function noad_to_table(noad, sub, cur_style, mn) local nucleus, core = kernel_to_table(noad.nucleus, sub == noad_over and cur_style//2*2+1 or cur_style) + if core and core[0] == 'mo' and core.minsize and not core.maxsize then + core.maxsize = core.minsize -- This happens when a half-specified delimiter appears alone in a list. + -- If it has a minimal size, it should be fixed to that size (since there is nothing bigger in it's list) + end if sub == noad_ord then if core and core[0] == 'mo' then - core[0] = 'mi' - core.mathvariant = #core == 1 and type(core[1]) == 'string' and utf8.len(core[1]) == 1 and utf8.codepoint(core[1]) < 0x10000 and 'normal' or nil - core['tex:class'], core.stretchy, core.lspace, core.rspace = nil + core['tex:class'] = nil + if not core.minsize then + core[0] = 'mi' + core.mathvariant = #core == 1 and type(core[1]) == 'string' and utf8.len(core[1]) == 1 and utf8.codepoint(core[1]) < 0x10000 and 'normal' or nil + core.stretchy, core.lspace, core.rspace = nil + end end if nucleus == core and #core == 1 then if mn and core[0] == 'mi' and (core[1] == '.' or core[1] == ',') and maybe_to_mn(noad, core) or core[0] == 'mn' then @@ -275,7 +282,9 @@ local function noad_to_table(noad, sub, cur_style, mn) -- TODO else core[0] = 'mo' - if stretchy[core[1]] then core.stretchy = false end + if not core.minsize then + if stretchy[core[1]] then core.stretchy = false end + end if core.mathvariant == 'normal' then core.mathvariant = nil end core.lspace, core.rspace = 0, 0 end @@ -385,8 +394,31 @@ end local function fence_to_table(fence, sub, cur_style) local delim, core = delim_to_table(fence.delim) - if delim[0] == 'mo' then - delim.fence = 'true' + if core[0] ~= 'mo' then + return delim, core + end + core.fence, core.symmetric = 'true', 'true' + local options = fence.options + local axis + if fence.height ~= 0 or fence.depth ~= 0 then + axis = 0xA == options & 0xA + local exact = 0x18 == options & 0x18 + -- We treat them always as exact. mpadded would allow us to support + -- non-exact ones too and I will implement that if I ever encounter + -- someone who does that intentionally. Until then, we warn people + -- since such fences are absurd. + if not exact then + texio.write_nl'luamml: The document uses a fence with \z + explicit dimensions but without the "exact" option. \z + This is probably a mistake.' + end + core.minsize = string.format("%.3fpt", (fence.height + fence.depth)/65781.76) + core.maxsize = core.minsize + else + axis = 0xC ~= options & 0xC + end + if not axis then + texio.write_nl'luamml: Baseline centered fence will be centered around math axis instead' end return delim, core end diff --git a/luamml-patches-amsmath.sty b/luamml-patches-amsmath.sty index 421f47d..daabb73 100644 --- a/luamml-patches-amsmath.sty +++ b/luamml-patches-amsmath.sty @@ -107,3 +107,11 @@ \fi \ignorespacesafterend } + +\cs_set:Npn \bBigg@ #1 #2 { + { + \ensuremath { + \Uvextensible height~#1 \big@size axis~exact~#2 + } + } +} diff --git a/parse_showlists.lua b/parse_showlists.lua index b6589d8..321aa6d 100644 --- a/parse_showlists.lua +++ b/parse_showlists.lua @@ -39,7 +39,10 @@ local simple_noad = l.Ct( + '\\accent' * l.Cg(math_char, 'accent') * l.Cg(l.Cc(0), 'subtype') * l.Cg(l.Cc'accent', 'id') + l.Cg('\\left' * l.Cc(1) + '\\middle' * l.Cc(2) - + '\\right' * l.Cc(3), 'subtype') * l.Cg(delimiter_code, 'delim') * l.Cg(l.Cc(0), 'class') * l.Cg(l.Cc'fence', 'id') + + '\\right' * l.Cc(3), 'subtype') * l.Cg(delimiter_code, 'delim') + * l.Cg(l.Cc(0), 'options') * l.Cg(l.Cc(0), 'height') + * l.Cg(l.Cc(0), 'depth') * l.Cg(l.Cc(0), 'height') + * l.Cg(l.Cc(-1), 'class') * l.Cg(l.Cc'fence', 'id') + '\\' * l.Cg( 'display' * l.Cc(0) + 'text' * l.Cc(2) diff --git a/test_tex.tex b/test_tex.tex index eb305dd..3b021a9 100644 --- a/test_tex.tex +++ b/test_tex.tex @@ -39,7 +39,7 @@ \begin{align} abc&=def & e^{\mathrm{i}\pi}&=-1\\ - 1+2&=3\\ + \Big(1+2&=3\Big)\\ 5 \end{align}