Getting SVG representation after MathJax have finished rendering

571 views
Skip to first unread message

k.ken

unread,
Jun 17, 2013, 4:06:36 PM6/17/13
to mathja...@googlegroups.com
Hello Everyone,

I have a quick question, how do I retrieve the SVG representation of a rendered Latex expression? I was following this reply post by David Cervone: https://groups.google.com/forum/#!msg/mathjax-users/unL8IjcrTto/DjHpH4BbPRcJ and I was able to get all the Jax and 'navigate' to the root but the root.toSVG() function when called yields an error message. The error message says "TypeError: t is undefined". My default output format before MathJax starts is HTML-CSS. Does it have anything to do with this error? I basically want the SVG representation of the rendered Latex equation. Any help is greatly appreciated.

Frédéric WANG

unread,
Jun 19, 2013, 10:57:28 AM6/19/13
to mathja...@googlegroups.com
On 17/06/2013 22:06, k.ken wrote:
> Hello Everyone,
>
> I have a quick question, how do I retrieve the SVG representation of a
> rendered Latex expression? I was following this reply post by David
> Cervone:
> https://groups.google.com/forum/#!msg/mathjax-users/unL8IjcrTto/DjHpH4BbPRcJ
> <https://groups.google.com/forum/#%21msg/mathjax-users/unL8IjcrTto/DjHpH4BbPRcJ> and
> I was able to get all the Jax and 'navigate' to the root but the
> root.toSVG() function when called yields an error message. The error
> message says "TypeError: t is undefined". My default output format
> before MathJax starts is HTML-CSS. Does it have anything to do with
> this error? I basically want the SVG representation of the rendered
> Latex equation. Any help is greatly appreciated.
You might want to switch the renderer to SVG and rerender the formula
before calling toSVG():

http://docs.mathjax.org/en/latest/api/hub.html#setRenderer

Also, using the MathJax 's unpacked version could give you a more
explicit error message...


--
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

k.ken

unread,
Jun 19, 2013, 8:31:16 PM6/19/13
to mathja...@googlegroups.com
Thanks for replying. I was able to change the renderer to SVG and download the unpacked version from Git and the error message changed to "span element is not define from line 1941 in jax.js" I'm currently trying to track down where span was set. Quick thought, is retrieving the svg and the position of the elements possible? I'm digging deep into the code specifically the jax file for svg output to understand the order in which the code appends the "<use href ="#MJSZ2-2211">" into the g element for in the html. 
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

k.ken

unread,
Jun 19, 2013, 9:01:05 PM6/19/13
to mathja...@googlegroups.com
Update: Seems the toSVG function needs a span element and a node element in order to work.

Frédéric WANG

unread,
Jun 20, 2013, 2:39:48 AM6/20/13
to mathja...@googlegroups.com
(Note that you could have used http://cdn.mathjax.org/mathjax/latest/unpacked/MathJax.js to get the unpacked version.)

As you noticed, the function called is
https://github.com/mathjax/MathJax/blob/master/unpacked/jax/output/SVG/jax.js#L1896

I don't remember exactly which span/div are passed, but a quick look at the source shows that you can pass dummy elements for your purpose. So insert two HTML nodes <span>, <div> in the <body> of your page (via Javascript if you want) and pass them to the function. The return value will be the span node whose child will be the <svg> element.
--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic
Reply all
Reply to author
Forward
0 new messages