-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Invalid SVG markup in MathJax 4.0.0-beta6 #3226
Comments
Thanks for the report. You are correct, there is an error in producing the SVG: I called the HTML serializer rather than the XML serializer in error. I will make a PR to fix it. In the meantime, there are two approaches you could take.
MathJax = {
startup: {
ready() {
const {Menu} = MathJax._.ui.menu.Menu;
Menu.prototype.toSVG = function (math) {
const jax = this.jax.SVG;
if (!jax) return Promise.resolve('SVG can\'t be produced.<br>Try switching to SVG output first.');
const adaptor = jax.adaptor;
const cache = jax.options.fontCache;
const breaks = !!math.root.getProperty('process-breaks');
if (cache !== 'global' && (math.display || !breaks) &&
adaptor.getAttribute(math.typesetRoot, 'jax') === 'SVG') {
for (const child of adaptor.childNodes(math.typesetRoot)) {
if (adaptor.kind(child) === 'svg') {
return Promise.resolve(this.formatSvg(adaptor.serializeXML(child)));
}
}
}
return this.typesetSVG(math, cache, breaks);
}
MathJax.startup.defaultReady();
}
}
}; See if that does the trick for you. |
Thank you for your thorough response! I didn’t want to complicate things in the report, so I didn’t mention that I retrieve some SVG renders programmatically with MathJax.tex2svgPromise(latex).then(function(svg) {
svg.querySelectorAll("*").forEach(element =>
Object.keys(element.dataset).forEach(dataKey => delete element.dataset[dataKey])
);
// do stuff with the svg
}); |
Use XML serialization not HTML serialization for SVG images. (mathjax/MathJax#3226)
Issue Summary
When using MathJax to render maths as SVG, there are various "data-" attributes on the tags, some of which contain illegal characters for XML (namely "<" and ">"). "data-semantic-speech" is one such attribute. SVG files need to be valid XML, therefore using MathJax to produce SVG files yields invalid results.
Steps to Reproduce:
Technical details:
I am not using any MathJax configuration.
and loading MathJax via
Supporting information:
The text was updated successfully, but these errors were encountered: