Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidcarlisle opened this issue Nov 24, 2024 · 1 comment
Open

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

davidcarlisle opened this issue Nov 24, 2024 · 1 comment
Assignees

Comments

@davidcarlisle
Copy link
Member

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.

@zauguin
Copy link
Member

zauguin commented Nov 25, 2024

Probably best to insert a span by default, then special case simple text and remove it again...

@zauguin zauguin self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants