-
Notifications
You must be signed in to change notification settings - Fork 96
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
move PNG generation out of mathjax-node #205
Comments
From F2F: we will be adding |
While working on this, I've been wondering about structure of mj-single and the SVG modifications.
The last two seem like they should be dropped alongside the PNG (since they only come into play there). Any thoughts? I'm also wondering if we should expose both the "HTML5" svg data alongside the namespaced version. Would anyone benefit from having the "HTML5" svg data? |
Or perhaps we should have a more general "standalone (prefixed?)" option affecting both MathML and SVG (and perhaps even CommonHTML?) output. Or maybe I'm just overthinking this 😉 |
The One of the difficulties of pushing this off to the application is the copying of the style attributes from the One solution might be to provide service routines to do some of this so that the application can call them as needed. |
I'm not sure I understand what you are suggesting. Can you be more clear about the difference you have in mind?
Again, I'm not clear on what you are suggesting. Can you give more details about what is included (and not included) in each form? |
If course, if we returned a DOM element (like we are considering for the SVG element itself), it would be easy to do those things.
I had forgotten that you included the CSS text. Of course, if we return the SVG DOM element, then it is easy to get those values from the node itself, and so they may not need to be added to the result in that case.
I'm more and inclined to think that the DOM node is the thing that should be returned. Then the outer application can serialize it as they want, and we can provide functions to call that do the prettifying and xlink adjustments if we want.
Do you mean adding the Again, it seems like service routines to do this given a result object might be the way, rather than returning two forms based on more flags. |
Me too but I don't know what would count as a good DOM object in nodejs land. Of course for now we're stuck with jsdom (which I think means parse5). We should research a few libraries, I guess (also for MathJax v3). Good starting points might be parse5 (jsdom) but also htmlparser2 (e.g., used by cheerio). The only downside I can see is that an application using mathjax-node would need a minimal amount of understanding over the relevant structure (e.g., so as to serialize it).
Pretty much.
I second that. |
I've moved the question of returning an object to #219. So from my questions, this leaves only the question regarding the xlink prefixes added in https://github.com/mathjax/MathJax-node/blob/master/lib/mj-single.js#L587-L593. I'm not sure if they're still needed (or sensible, we don't add the namespace, do we?) but this is more a 1/10 for me. So unless we change that, the PR is ready. |
So here's my simple example (erroneously posted to #206) addressing (I hope) the comments from @dpvc (from that thread). Again, this is meant to be a simple example for people to build on, not a complete replacement for the batik integration. For example, I could easily imagine people wanting to increase the dimensions of the png (svg2png doesn't have any settings so you'd have to increase the dimensions manually which is somewhat tricky since MathJax provides Anyway, I hope this might be a sufficient example for now. var mjAPI = require("mj-single.js");
var svg2png = require('svg2png');
mjAPI.start();
function createPNG(result, callback){
var sourceBuffer = new Buffer(result.svg, "utf-8");
svg2png(sourceBuffer).then(function(buffer){
result.png = "data:image/png;base64," + buffer.toString('base64');
return callback(result);
})
};
exports.math2png = function(options, callback){
var mjConfig = options.config;
var typesetOptions = options.typeset;
// make sure SVG output will be generated and disable mml and html
typesetOptions.svg = true;
typesetOptions.mml = false;
typesetOptions.html = false;
mjAPI.config(mjConfig);
mjAPI.typeset(typesetOptions, function(result){
if (result.errors) return result.errors;
createPNG(result, callback);
});
} Usage: var math2png = require("math2png.js").math2png;
var options = {
config: {
},
typeset: {
math: "x^2",
format: "TeX"
},
png: {}
}
math2png(options, function(result){
console.log(result.png);
console.log("style='" + result.style + "width:" + result.width + "; height:" + result.height +";'");
}); Note: this depends on the changes from PR #213 (width and height). |
A couple of small comments, here. Some configuration options for Your In In your callback to the
and let the user check for Alternatively, your callback could be passed a success/failure value in addition to the |
Thanks for the comments! First off, let me move the code to a gist at https://gist.github.com/pkra/c60098af5c1d8c37473416caad0418f6
I guess I wasn't really aware that some options will "stick" (though it was clear as soon as I read it). Questions:
No, it was just a copied from an older version. (Though I expect that svg-to-png converters might want those or a more advanced module that allows scaling would need options like this.)
Ouch; fixed.
Another Ouch -- fixed. Sorry for missing that among the earlier comments. |
==> Merged. |
I've created another wrapper based on svg2png that can be used as a drop-in for mathjax-node to generate PNG content. |
Hi, I am having trouble getting the SVG output from MathJax-node to be included into pdf files with pdfmake that uses svg-to-PDFKIT, so I thought of making the SVG output into a png, I've noticed MathJax-node does not support this anymore, could you please point out how this could be done? Would I need to pipe MathJax-node's result into some other function that converts it into PNG, would you know any that would work with MathJax-node's outputs? Thank you |
@federicosan, the link in the comment just above yours gives the sag-to-png functionality. Alternatively, the issue you are probably facing is the |
As per F2F, the PNG generation will be moved out of mathjax-node; there will be alternative modules to use.
Cf. the discussion in #174; see also #191.
The text was updated successfully, but these errors were encountered: