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

Unknown node type "body" when compiling MathML in v3.0.1 #2330

Closed
hubgit opened this issue Feb 13, 2020 · 3 comments
Closed

Unknown node type "body" when compiling MathML in v3.0.1 #2330

hubgit opened this issue Feb 13, 2020 · 3 comments
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Needed v3
Milestone

Comments

@hubgit
Copy link

hubgit commented Feb 13, 2020

Using mathjax-full@3.0.0 it was possible to use this code to convert MathML to SVG:

import { MathML } from 'mathjax-full/js/input/mathml'
import { SVG } from 'mathjax-full/js/output/svg'
import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor'
import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument'

const doc = new HTMLDocument(document, new HTMLAdaptor(window), {
  InputJax: new MathML(),
  OutputJax: new SVG(),
})

const svg = doc.convert(`<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>A</mi><mo>=</mo></mrow></math>`)

console.log(svg.innerHTML)

Using mathjax-full@3.0.1 an error is thrown when using the same code:

Uncaught Error: Unknown node type "body"
    at MathMLCompile.error (MathMLCompile.ts:320)
    at MathMLCompile.makeNode (MathMLCompile.ts:125)
    at MathMLCompile.compile (MathMLCompile.ts:95)
    at MathML.compile (mathml.ts:145)
    at HTMLMathItem.AbstractMathItem.compile (MathItem.ts:327)
    at Object.renderMath (MathDocument.ts:167)
    at RenderList.renderConvert (MathDocument.ts:211)
    at HTMLMathItem.AbstractMathItem.convert (MathItem.ts:319)
    at HTMLDocument.AbstractMathDocument.convert (MathDocument.ts:633)

It seems to go wrong around this line in MathDocument:

mitem.start.node = this.adaptor.body(this.document)

which sets mitem.start.node to the body of this.document, which suggests that this commit might be to blame.

@dpvc
Copy link
Member

dpvc commented Feb 14, 2020

Thanks for the report. I can reproduce the problem, and will check into it.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team Investigate labels Feb 14, 2020
@dpvc
Copy link
Member

dpvc commented Feb 14, 2020

Your are right, the setting of math.start.node turns out to be the culprit. For the MathML input jax, that node usually points to the MathML node in the document, and its absence meant that the MathML was in math.math as a string that needed to be parsed in order to get the MathML tree. Setting the start node prevented that parsing from being performed, and its content was taken as the MathML itself (the body not that is reported in the error). The start node was being set appropriately for TeX strings, but not MathML strings.

If you use

  InputJax: new MathML({forceReparse: true}),

that should get around the problem for now.

dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 14, 2020
…nvert() calls, where start is defined but not end). Resolves issue mathjax/MathJax#2330.
@dpvc
Copy link
Member

dpvc commented Feb 14, 2020

I've created a pull request to resolve the issue.

@dpvc dpvc added this to the 3.0.2 milestone Mar 5, 2020
dpvc added a commit to mathjax/MathJax-src that referenced this issue Mar 30, 2020
Fix problem with convert() call with MathML input. mathjax/MathJax#2330
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Mar 30, 2020
@dpvc dpvc added the Fixed label Apr 10, 2020
@dpvc dpvc closed this as completed Apr 10, 2020
@dpvc dpvc removed the Merged Merged into develop branch label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Needed v3
Projects
None yet
Development

No branches or pull requests

2 participants