From 235815eb98009b78be191605f61e75521a7d532d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Mon, 28 Jun 2021 06:33:49 +0200 Subject: [PATCH] Adapt phantom patches for pdfTeX --- luamml-kernel.lua | 33 --------------------------------- luamml-patches-kernel.sty | 34 ++++++++++++++++++++++++++-------- luamml.dtx | 5 +++-- 3 files changed, 29 insertions(+), 43 deletions(-) delete mode 100644 luamml-kernel.lua diff --git a/luamml-kernel.lua b/luamml-kernel.lua deleted file mode 100644 index 678fce1..0000000 --- a/luamml-kernel.lua +++ /dev/null @@ -1,33 +0,0 @@ -local properties = node.get_properties_table() -local if_vertical = token.create'ifv@' -local if_horizontal = token.create'ifh@' -local iftrue_index = token.create'iftrue'.index - -local funcid = luatexbase.new_luafunction'__luamml_kernel_finalize_phantom:' -token.set_lua('__luamml_kernel_finalize_phantom:', funcid, 'protected') -lua.get_functions_table()[funcid] = function() - -- TODO: Error handling etc - -- At this point, box 0 contains the inner expression and the curent list ends with the noad whose nucleus should get replaced - local boxnum = 0 - local startmath = tex.box[boxnum].list - assert(startmath.id == node.id"math") - local nucl = assert(tex.nest.top.tail.nucleus) - local props = properties[nucl] - if not props then -- very likely - props = {} - properties[nucl] = props - end - assert(not props.mathml_table) - local saved_props = assert(properties[startmath]) - local saved_core = saved_props.saved_mathml_core - local saved = assert(saved_props.saved_mathml_table or saved_core) - -- The following could be optimized for the case that both if_vertical and if_horizontal - -- are set, but that should't happen ayway and is just supported for consistency. - if if_vertical.index ~= iftrue_index then - saved = {[0] = 'mpadded', height = 0, depth = 0, saved} - end - if if_horizontal.index ~= iftrue_index then - saved = {[0] = 'mpadded', width = 0, saved} - end - props.mathml_table, props.mathml_core = saved, saved_core -end diff --git a/luamml-patches-kernel.sty b/luamml-patches-kernel.sty index 1ae497a..e150a33 100644 --- a/luamml-patches-kernel.sty +++ b/luamml-patches-kernel.sty @@ -1,17 +1,35 @@ \ProvidesExplPackage {luamml-patches-kernel} {2021-05-30} {0.0.1-alpha} {Feel free to add a description here} -\lua_now:n { require'luamml-kernel' } - -\cs_set:Npn \mathph@nt #1 #2 { +\cs_new:Npn \__luamml_kernel_phantom:nnn #1#2#3 { \hbox_set:Nn \c_zero_int { $ \m@th - #1 - {#2} - \luamml_flag_save:nNn {} #1 {mphantom} + #2 + {#3} + \luamml_flag_save:nNn {mathphant_#1} #2 {mphantom} + \luamml_pdf_write: $ } - \finph@nt - \__luamml_kernel_finalize_phantom: + \luamml_annotate:nen {1} { + nucleus = true, + core = {[0] = 'mpadded', + \ifh@\else + width = 0, + \fi + \ifv@\else + height = 0, depth = 0, + \fi + data.mathml.mathphant_#1, + } + } { + \finph@nt + } +} +\cs_generate_variant:Nn \__luamml_kernel_phantom:nnn {V} + +\int_new:N \g__luamml_kernel_phantom_int +\cs_set:Npn \mathph@nt { + \int_gincr:N \g__luamml_kernel_phantom_int + \__luamml_kernel_phantom:Vnn \g__luamml_kernel_phantom_int } diff --git a/luamml.dtx b/luamml.dtx index 9606158..e577199 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -439,10 +439,11 @@ % \end{macrocode} % \end{macro} % -% +% We currently provide minimal patching for the kernel, \pkg{amsmath} and \pkg{array}. +% Currently only the kernel code supports pdf\TeX, but it's planned to extend this. % \begin{macrocode} -%<*luatex> \RequirePackage { luamml-patches-kernel } +%<*luatex> \__luamml_patch_package:n {amsmath} \__luamml_patch_package:n {array} %