-
Notifications
You must be signed in to change notification settings - Fork 42
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
SVG output not showing in XHTML #58
Comments
I suspect that the |
Actually, you don't need to set it in the file, you can use the |
@dpvc Indeed, I also had realized that disabling the global caching makes it work but I forgot to mention this in the question. The issue without global cache is that it makes the file size significantly larger (about 5 times for one of my use cases). I think I found the issue: https://stackoverflow.com/a/77891891/2131200. It looks like |
Thanks for the link to stackoverflow that points out the issue. Yes, this is a bug, and I have made a PR to fix it. In the meantime, you can add Object.assign(svg, {
_pageElements: svg.pageElements,
pageElements(html) {
const cache = this._pageElements(html);
if (cache) {
this.adaptor.setAttribute(cache, 'xmlns', 'http://www.w3.org/2000/svg');
}
return cache;
}
}); to the const html = mathjax.document(htmlfile, {InputJax: tex, OutputJax: svg}); to patch the SVG output. |
@dpvc Works like a charm. Thank you very much! There are still two issues with
For your convenience, here's an HTML for testing: <html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Test</title>
</head>
<body>
<span>This is some text followed by an equation: $a < b + c$.</span>
</body>
</html> |
… and protect attribute values better. (mathjax/MathJax-demos-node#58)
OK, I've made a PR to resolve these two issues. Here is a patch that you can use for now: First, add import {LiteParser} from 'mathjax-full/js/adaptors/lite/Parser.js'; to the imports section. Then add Object.assign(LiteParser.prototype, {
serialize(adaptor, node, xml = false) {
const SELF_CLOSING = this.constructor.SELF_CLOSING;
const tag = adaptor.kind(node);
const attributes = this.allAttributes(adaptor, node, xml).map(
(x) => x.name + '="' + this.protectAttribute(x.value, xml) + '"'
).join(' ');
const content = this.serializeInner(adaptor, node, xml);
const html =
'<' + tag + (attributes ? ' ' + attributes : '')
+ ((!xml || content) && !SELF_CLOSING[tag] ? `>${content}</${tag}>` : xml ? '/>' : '>');
return html;
},
allAttributes(adaptor, node, xml) {
let attributes = adaptor.allAttributes(node);
const kind = adaptor.kind(node);
if (!xml || (kind !== 'svg' && kind !== 'math' && kind !== 'html')) {
return attributes;
}
for (const {name} of attributes) {
if (name === 'xmlns') {
return attributes;
}
}
attributes.push({
name: 'xmlns',
value: ({
svg: 'http://www.w3.org/2000/svg',
math: 'http://www.w3.org/1998/Math/MathML',
html: 'http://www.w3.org/1999/xhtml'
})[kind]
});
return attributes;
},
_protectAttribute: LiteParser.prototype.protectAttribute,
protectAttribute(text, xml) {
text = this._protectAttribute(text, xml);
if (xml) {
text = text.replace(/</g, '<').replace(/>/g, '>');
}
return text;
}
}); instantiating the LiteAdaptor ( This is a bit long, but the |
PS, it also adds missing |
@dpvc It worked! Thanks a lot! |
Is this with [email protected]? It looks like a reference from an earlier version. But it might be that there is a path that hasn't been updated somewhere in the font configuration code in beta.4. In any case, if you are at beta.4 with mathjax-full, there is a configuration parameter that can be set for the path to the dynamic directory. |
Yes that was with {
"name": "MathJax-demos-node",
"version": "4.0.0",
"description": "Demos using MathJax v4 in node",
"dependencies": {
"esm": "^3.2.25",
"mathjax-full": "4.0.0-beta.4",
"mathjax-modern-font": "^4.0.0-beta.4",
"yargs": "^17.7.2"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.5",
"babel-loader": "^8.2.2",
"terser-webpack-plugin": "5.3.0",
"webpack": "5.88.2",
"webpack-cli": "^5.1.1"
},
"repository": {
"type": "git",
"url": "https://github.com/mathjax/MathJax-demos-node/"
},
"keywords": [
"MathJax",
"examples",
"nodejs"
],
"license": "Apache-2.0"
}
I tried removing |
Can you provide your MathJax configuration? I'm not able to find a reference that should lead to that URL, so I'm wondering if there is something in the configuration leading to that. Also, can you give the traceback from the error message? |
@dpvc As you suggested earlier, manually setting the path to the dynamic directory did help: const svg = new SVG({
fontCache: argv.fontCache,
exFactor: argv.ex / argv.em,
dynamicPrefix: 'mathjax-modern-font/cjs/svg/dynamic'
}); Thanks! Removing the line Error: Cannot find module '/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/output/svg/fonts/svg/dynamic/calligraphic'
Require stack:
- /Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/util/asyncLoad/node.js
- /Users/name/projects/epubs/mathjax/v4/direct/tex2svg-page-epub
at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
at Module._load (node:internal/modules/cjs/loader:990:27)
at Module.require (node:internal/modules/cjs/loader:1237:19)
at require (node:internal/modules/helpers:176:18)
at mathjax_js_1.mathjax.asyncLoad (/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/util/asyncLoad/node.js:31:16)
at /Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/util/AsyncLoad.js:10:43
at new Promise (<anonymous>)
at asyncLoad (/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/util/AsyncLoad.js:9:12)
at MathJaxModernFont.<anonymous> (/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/output/common/FontData.js:477:68)
at step (/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/output/common/FontData.js:44:23) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/name/projects/epubs/mathjax/v4/node_modules/mathjax-full/cjs/util/asyncLoad/node.js',
'/Users/name/projects/epubs/mathjax/v4/direct/tex2svg-page-epub'
]
} |
Sorry please hold on, I think there is some issue with the header of my script, all the import paths start with |
Hmm... Changing all |
The MathJax Thanks for the stack trace. The |
PS, I notice that the path in the error in your message here is different than the one you gave earlier. Did you change anything else that might account for that? |
Sorry, the path in that previous message was because I set |
Was that other path an alpha.1 path? Just curious, as that is would correspond to the wrong path in the error message. |
I don't know which version exactly but definitely from a previous version. It took it from your answer here: #55 (comment) |
OK, that explains where the |
Thanks for the clarification! And sorry for the confusion as well, I should have specified that I had copied your code :p |
Add xmlns for global cache svg element. (mathjax/MathJax-demos-node#58)
Update LiteParser's serializeXML. (mathjax/MathJax-demos-node#58)
I tried using
direct/tex2svg-page
to output XHTML and found that the images are not showing.To ensure syntax correctness, I replaced the last line:
with
An example of the output SVG is as follows:
Could you please help? Thank you very much in advance!
The text was updated successfully, but these errors were encountered: