diff --git a/luamml-patches-amstext.sty b/luamml-patches-amstext.sty new file mode 100644 index 0000000..d4d15ca --- /dev/null +++ b/luamml-patches-amstext.sty @@ -0,0 +1,37 @@ +\ProvidesExplPackage {luamml-patches-amstext} {2021-04-23} {0.0.1-alpha} + {Feel free to add a description here} + +\int_new:N \g__luamml_amsmath_text_struct_int +\cs_set:Npn \textdef@ #1 #2 #3 { + \int_if_odd:nTF { \int_div_truncate:nn { \l__luamml_flag_int } { 8 } } { + \int_gincr:N \g__luamml_amsmath_text_struct_int + \tag_struct_begin:n { + tag = mtext/mathml, + stash, + label = __luamml_amsmath_text_ \int_use:N \g__luamml_amsmath_text_struct_int + } + \tag_mc_begin:n { + tag = mtext + } + \AnnotateFormula { + nucleus = true, + struct = "__luamml_amsmath_text_ \int_use:N \g__luamml_amsmath_text_struct_int" + } + } { + \use_i:n + } + { + \hbox { + { + \everymath {#1} + \let \f@size #2 + \selectfont + #3 + } + } + } + \int_if_odd:nT { \int_div_truncate:nn { \l__luamml_flag_int } { 8 } } { + \tag_mc_end: + \tag_struct_end: + } +} diff --git a/luamml-tex-annotate.lua b/luamml-tex-annotate.lua index 0f852ad..4b22374 100644 --- a/luamml-tex-annotate.lua +++ b/luamml-tex-annotate.lua @@ -59,7 +59,21 @@ local function annotate() props = {} properties[marked] = props end - props.mathml_core = annotation.core + if annotation.core then + props.mathml_core = annotation.core + end + if annotation.struct then + local saved = props.mathml_filter + local struct = annotation.struct + function props.mathml_filter(mml, core) + mml[':struct'] = struct + if saved then + return saved(mml, core) + else + return mml, core + end + end + end else tex.error'Unable to annotate nucleus of node without nucleus' end diff --git a/luamml.dtx b/luamml.dtx index 4d6f84e..72b9561 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -450,6 +450,7 @@ % \begin{macrocode} \RequirePackage { luamml-patches-kernel } %<*luatex> +\__luamml_patch_package:n {amstext} \__luamml_patch_package:n {amsmath} \__luamml_patch_package:n {array} % diff --git a/testfiles-lua/test_struct.pvt b/testfiles-lua/test_struct.pvt index bfc1ae0..2abba81 100644 --- a/testfiles-lua/test_struct.pvt +++ b/testfiles-lua/test_struct.pvt @@ -18,6 +18,13 @@ \begin{document} \tagstructbegin{tag=Document} + +\tagstructbegin{tag=P} +\tagmcbegin{tag=P} +hello +\tagmcend +\tagstructend + \LuaMMLTagAF{} { \[ \begin{pmatrix} @@ -27,8 +34,8 @@ \end{pmatrix} = \begin{cases} - 1 & $if $a=b\\ - 2 & $else$ + 1 & \text{if $a=b$} \\ + 2 & \text{else} \end{cases} \] }