Skip to content

handling nested math (and other markup) in text. #5

@davidcarlisle

Description

@davidcarlisle

nested math is currently generating <math> child of <mtext> which is invalid

\DocumentMetadata{pdfversion = 2.0, testphase = {phase-III,title,math}, lang = en, uncompress}
\documentclass{article}
\usepackage{unicode-math}

\begin{document}

\[
  x + \text{ something about $x$}
\]

\end{document}

Produces

<mtext>
  something about 
 <math xmlns="http://www.w3.org/1998/Math/MathML">
 <mi>𝑥</mi>
 </math>
 </mtext>

in the -luamml-mathml.html file.

I can wrap the math in an html span which makes it valid again

 <mtext>
  something about 
 <span xmlns="http://www.w3.org/1999/xhtml">
 <math xmlns="http://www.w3.org/1998/Math/MathML">
 <mi>𝑥</mi>
 </math>
 </span>
 </mtext>

with

local function to_math(root, style)
  if root[0] == 'mrow' then
    root[0] = 'math'
  else
    root = {[0] = 'math', root}
  end
  root.xmlns = 'http://www.w3.org/1998/Math/MathML'
  root['xmlns:tex'] = 'http://typesetting.eu/2021/LuaMathML'
  if style < 2 then
    root.display = 'block'
  end
  root = {[0] = 'span', ['xmlns']='http://www.w3.org/1999/xhtml',root}
  return root
end

but then it does this also on top level math elements. I got lost trying to see the best way of just detecting these nested cases.
Ideally if \text has just text it would just make an mtext but if it has any document-level markup, including nested math, then there should be an html span to get back to document level tagging.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions