asciimath to svg

150 views
Skip to first unread message

Geddes

unread,
Apr 4, 2021, 6:07:27 AM4/4/21
to MathJax Users
Hello. I would like to convert asciimath to svg. Is there a similar function to tex2svg that would work for asciimath? If not, can this be considered when version 3 includes asciimath? Many thanks and best wishes.

Davide Cervone

unread,
Apr 4, 2021, 11:36:30 AM4/4/21
to mathja...@googlegroups.com
I would like to convert asciimath to svg. Is there a similar function to tex2svg that would work for asciimath? If not, can this be considered when version 3 includes asciimath? Many thanks and best wishes.

When you load the legacy v2 AsciiMath input jax in v3, you will get a MathJax.asciimath2svg() method.  You don't say if you are doing this in the browser or in a node application, but as a node program, you could use 

npm install mathjax-full

and then do something like

const math = 'x+y';

require('mathjax-full').init({
  loader: {
    load:['input/asciimath', 'output/svg']
  }
}).then((MathJax) => {
  const adaptor = MathJax.startup.adaptor;
  const html = MathJax.asciimath2svg(math);
  console.log(adaptor.innerHTML(html));
}).catch((err) => console.error(err));

of course, you probably want to get the math to process either from the command line, from standard input, or from a file.  This is just an example to 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/127ca7d9-edca-4f65-baf7-4582d20d3bdan%40googlegroups.com.

Geddes

unread,
Apr 4, 2021, 2:32:38 PM4/4/21
to MathJax Users
Thank you so much Davide - that works perfectly!

At the moment I'm using the following loader which seems to do the trick:

<script>
  window.MathJax = {
    loader: {
      load: ['input/asciimath', 'output/svg']
    },
    asciimath: {
      delimiters: [
        ['`', '`']
      ]
    }
  };
</script>
<script type="text/javascript" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>



Davide Cervone

unread,
Apr 5, 2021, 10:52:51 AM4/5/21
to mathja...@googlegroups.com
You could just load https://cdn.jsdelivr.net/npm/mathjax@3/es5/startup.js rather than loading all the TeX input code that you don't need.  You could also leave off the asciimath block of your configuration, since the delimiters are already the defaults, so no need to specify them.

Davide



Reply all
Reply to author
Forward
0 new messages