javascriptmathjaxasciimath

ASCIIMath: JS method to get TeX value of rendered expression?


This JSFiddle is using ASCIIMath to show the expression 1+x^2.

How can I get TeX value of ASCIIMath expression after it has been rendered? I want to save that value into myTeX div?

Is there an ASCIIMath method or MathJax.Hub method to retrieve TeX?

HTML + JavaScript:

 <script type="text/javascript" src="js/jquery-1.4.1.js"></script>
 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML-full">  
 </script>

 <div id="myExpr">`1+x^2`</div>
 <div id="myTeX"></div>

 <script type="text/x-mathjax-config">
      MathJax.Hub.Config({ 
           messageStyle: 'none', 
           tex2jax: { preview: 'none'}   
      });
 </script>

UPDATE:

Here is how its done:

JavaScript:

 <script src="ASCIIMathTeXImg.js"></script>

 <script>
      var x = AMTparseAMtoTeX('1+5/4^2');
      console.log(x);
 </script>

Solution

  • You probably don't want to deal with the rendering but with the ASCIImath source.

    The asciimath repository includes a PHP script for converting asciimath to LaTeX, see https://github.com/asciimath/asciimathml/tree/master/asciimath-based.

    There is nothing built into MathJax yet but a feature request at https://github.com/mathjax/MathJax/issues/1124.