Adapt phantom patches for pdfTeX

This commit is contained in:
Marcel Fabian Krüger 2021-06-28 06:33:49 +02:00
parent 5252cbc90d
commit 235815eb98
3 changed files with 29 additions and 43 deletions

View File

@ -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

View File

@ -1,17 +1,35 @@
\ProvidesExplPackage {luamml-patches-kernel} {2021-05-30} {0.0.1-alpha} \ProvidesExplPackage {luamml-patches-kernel} {2021-05-30} {0.0.1-alpha}
{Feel free to add a description here} {Feel free to add a description here}
\lua_now:n { require'luamml-kernel' } \cs_new:Npn \__luamml_kernel_phantom:nnn #1#2#3 {
\cs_set:Npn \mathph@nt #1 #2 {
\hbox_set:Nn \c_zero_int { \hbox_set:Nn \c_zero_int {
$ $
\m@th \m@th
#1 #2
{#2} {#3}
\luamml_flag_save:nNn {} #1 {mphantom} \luamml_flag_save:nNn {mathphant_#1} #2 {mphantom}
\luamml_pdf_write:
$ $
} }
\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 \finph@nt
\__luamml_kernel_finalize_phantom: }
}
\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
} }

View File

@ -439,10 +439,11 @@
% \end{macrocode} % \end{macrocode}
% \end{macro} % \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} % \begin{macrocode}
%<*luatex>
\RequirePackage { luamml-patches-kernel } \RequirePackage { luamml-patches-kernel }
%<*luatex>
\__luamml_patch_package:n {amsmath} \__luamml_patch_package:n {amsmath}
\__luamml_patch_package:n {array} \__luamml_patch_package:n {array}
%</luatex> %</luatex>