How to get SVG as a file in/from MathJax?

1,379 views
Skip to first unread message

Emre Koçyatağı

unread,
Jun 30, 2022, 9:27:50 AM6/30/22
to MathJax Users
Hey Guys!
I am trying to get SVG as a file with using MathJax.
I have MathML equations. I can see them in my browser as SVG but when I click on it i can only get MathML Code or Original MathML code there is no option that i can save as a .svg.
Do you have any idea?
Message has been deleted

Murray

unread,
Jul 1, 2022, 4:24:48 AM7/1/22
to MathJax Users
Emre

(I earlier posted a reply but realised some of the things I suggested were never going to work for you. Here's a revised version.)

You're right - there's no option in MathJax for downloading the resulting SVG. Here are some alternatives.

(1) API call

These 2 sites allow you to include your math in the URL and it will give you an SVG you can download.




(2) SVG Math

You may be interested in my SVG Math. In the "embed SVG in <img> tags" version, you are able to right click the math and "Save as..." the SVG.


This page explains how it works:



Hope it helps

Regards
Murray

Emre Koçyatağı

unread,
Jul 1, 2022, 5:18:07 AM7/1/22
to mathja...@googlegroups.com
Thank you so much for your time and Knowledge. It’s really special for and it’s really nice from you :)Murray 🧿
But I had a big misunderstood the task given to me.
I need to use Mathjax(or any alternative) as a tool that I can use in CLI.
Do you have any idea ?
Have you ever use those kind of tools(such as MathJax&Inkscape)with CLI?
I wish you a lot of achievements Dear Murray.

--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/Tc4xbm61CqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/435bb8b1-6cfc-4d7c-8ca8-c5b202adcda7n%40googlegroups.com.

Murray

unread,
Jul 1, 2022, 5:35:28 AM7/1/22
to MathJax Users
I've played around with headless Chrome and had some success ouputting pages that involve MathJax.

Perhaps this library may be of interest: https://github.com/ambar/puptex

I haven't used it, but it appears to have SVG output options.

Davide Cervone

unread,
Jul 1, 2022, 11:32:36 AM7/1/22
to mathja...@googlegroups.com

I need to use Mathjax(or any alternative) as a tool that I can use in CLI.
Do you have any idea ?

Why not use one of the examples in 


There are lots of options about how to do it.  Look at the various mml2svg alternatives.   Most of them use a limited DOM implementation that works well if you stick to characters in the MathJax fonts, but not so well if you need ones outside that set.  If you want to use a headless chrome to overcome those issues, there are examples in


You will need to modify the tex2svg example, but can use that as a starting point and use one of the mml2svg examples from another directory to make the needed changes.

Davide

Emre Koçyatağı

unread,
Jul 1, 2022, 3:12:17 PM7/1/22
to mathja...@googlegroups.com
Hello Davide,
Thank you so much for your email :)
Could you please have any suggestions to work with this node package?
I haven’t got any experience to work with them.
Actually now I needed to use Mathjax with CLI.
So please tell me how can I work with this node&Mathjax$CLI

--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/Tc4xbm61CqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.

Davide Cervone

unread,
Jul 1, 2022, 3:18:05 PM7/1/22
to mathja...@googlegroups.com
All of the examples in


are command-line tools that you can run to convert either a single expression to SVG or HTML, or a whole HTML page to include SVG or HTML versions of the math.

The README explains how to install and run the commands.  There are several different ways of calling MathJax from node, so the different directories illustrate those approaches.  If you just want to run the commands and don't need to modify them, then it doesn't really matter which directory you use.

For example, you could use

node -r esm components/mml2svg '<math><mi>x</mi></math>' > x.svg

(on a unix system) to convert a MathML expression to an .svg file.

That should get you started.

Davide


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.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/CA%2BXLcAqCRkG4QOqZgtFC3A%2B9a2OMNwEcANnPi7ks56Ep8eJ8fg%40mail.gmail.com.

Message has been deleted

Emre Koçyatağı

unread,
Jul 2, 2022, 4:09:17 AM7/2/22
to MathJax Users
C:\Users\Emre\MathJax-demos-node>node -r esm direct/mml2svg "<math><mi>x</mi></math>" > x90.svg
it works when i write this.
I could see the x in the browser. But when i try to get MathML code from the file math.mml ------------>
C:\Users\Emre\MathJax-demos-node>node -r esm direct/mml2svg "math.mml" > x990.svg
ERRORS --------------->
Error: MathML must be formed by a <math> element, not <#text>
    at MathML.error (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\input\mathml.js:96:15)
    at MathML.compile (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\input\mathml.js:79:22)
    at HTMLMathItem.AbstractMathItem.compile (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\core\MathItem.js:56:39)
    at Object.renderMath (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\core\MathDocument.js:119:65)
    at RenderList.renderConvert (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\core\MathDocument.js:171:35)
    at HTMLMathItem.AbstractMathItem.convert (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\core\MathItem.js:52:32)
    at HTMLDocument.AbstractMathDocument.convert (C:\Users\Emre\MathJax-demos-node\node_modules\mathjax-full\js\core\MathDocument.js:329:15)
    at Object.<anonymous> (C:\Users\Emre\MathJax-demos-node\direct\mml2svg:111:19)

I got this errors:
Do you have any idea to solve it?


C:\Users\Emre\MathJax-demos-node>node -r esm component/mml2svg "<math><mi>x</mi></math>" > x90.svg
No version information available for component input/mml/entities
i got this error.... (with double quotes)

C:\Users\Emre\MathJax-demos-node>node -r esm component/mml2svg '<math><mi>x</mi></math>' > x90.svg
< was unexpected at this time.
with single quotte

1 Temmuz 2022 Cuma tarihinde saat 22:18:05 UTC+3 itibarıyla Davide Cervone şunları yazdı:

Davide Cervone

unread,
Jul 5, 2022, 8:11:27 AM7/5/22
to mathja...@googlegroups.com
when i try to get MathML code from the file math.mml ------------>
C:\Users\Emre\MathJax-demos-node>node -r esm direct/mml2svg "math.mml" > x990.svg
ERRORS --------------->
Error: MathML must be formed by a <math> element, not <#text> ...

The first argument to the mml2svg command is supposed to be the actual MathML expression, not a file name.  The error message you are getting is because "math.mml" is a text string, not MathML tags, and so gets parsed as an HTML #text element, so the program complains that it did not get a <math> tag.

If you want to process MathML from a file, you will either need to write a script that reads the file and passes each expression to mml2svg individually, or modify mml2svg to use its argument as a file name and read the expression it processes from that.

C:\Users\Emre\MathJax-demos-node>node -r esm component/mml2svg "<math><mi>x</mi></math>" > x90.svg
No version information available for component input/mml/entities
i got this error.... (with double quotes)

This is just a warning, and the output should be produced anyway.  You can ignore the message (I will fix it in the next release).  Alternatively, you can remove the 'input/mml/entities' from the "load" array in the "loader" section of the MathJax configuration in the component/mml2svg file, which will make the message go away, but may mean that some entity names will not be processed, in case you are using those.

C:\Users\Emre\MathJax-demos-node>node -r esm component/mml2svg '<math><mi>x</mi></math>' > x90.svg
< was unexpected at this time.
with single quotte

Since you are working on Windows, single quotes work differently on the command line than they do in unix, so you need to use double quotes, as you did in your earlier example.

Davide

Emre Koçyatağı

unread,
Jul 7, 2022, 2:40:45 AM7/7/22
to mathja...@googlegroups.com
Hey Davide,
Thank you so much for these explanations.Now it is working well.

Davide Cervone <dpv...@gmail.com>, 5 Tem 2022 Sal, 15:11 tarihinde şunu yazdı:
--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/Tc4xbm61CqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages