hey guys so im trying to convert my mathjax to svg and then convert it to png but im running into a problem, and the problem is that i cant convert my mathjax to svg i tried to use this solution
but it's working as i get the variable is undefined error (mjOut is undefined) :/. and the weird thing is that im able to render mathjax perfectly fine. to elaborate a bit more here is my code (its almost the same) also a screenshot:
var mj2img = function(texstring, callback) {
var input = texstring;
var wrapper = document.createElement("div");
wrapper.innerHTML = input;
var output = { svg: "", img: ""};
MathJax.Hub.Queue(["Typeset", MathJax.Hub, wrapper]);
MathJax.Hub.Queue(function() {
//This is where the error is (mjOut is undefined)
var mjOut = wrapper.getElementsByTagName("svg")[0];
console.log(wrapper.getElementsByTagName("svg"));
mjOut.setAttribute("xmlns", "http://www.w3.org/2000/svg");
// thanks, https://spin.atomicobject.com/2014/01/21/convert-svg-to-png/
output.svg = mjOut.outerHTML;
var image = new Image();
image.src = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(output.svg)));
image.onload = function() {
var canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
output.img = canvas.toDataURL('image/png');
callback(output);
};
});
}
$("#equation-write").click(function()
{
//Let's assume its sin(30) = 0.5.
var TeX = $("#MathInput").val();
var jax = MathJax.Hub.getAllJax()[0];
mj2img(TeX, function(output){
// console.log(texstring);
console.log(output.img);
}