Search code examples
pythonmaximaascii-art

converting plain ascii math or ascii art to mathml / latex


I'v been trying to determine the best way to convert the output from some computer algebra systems to some presentable format (mathml, latex), what would be the bestway?

i tried using the plain ascii representation, and converting to mathml, but the results are not always correct, i'v been thinking of getting the 2-d ascii art representation and changing it to mathml, are there libraries out there that can do this (im working with python) i tried one and two, but they only work with simple ascii not 2-d ascii.

                                      %pi
                                  3 %e      3
(%o1)                             ------- - -
                                     5      5

(%o3) 3*%e^%pi/5-3/5

both of the above are pretty much the same according to maxima, but converting them to mathml yields imperfect results, because of the '%' the order of precedence is messed up and pi ends up multiplying e rather than superscipt. Would substituting '%pi' for 'pi' be sufficient?


Solution

  • It should be easy to convert that linear % form to asciimath, basically just remove the % and surround with backticks.

    Using the MathJax version of Asciimath

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript"
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_HTMLorMML">
    </script>
    <title></title>
    </head>
    <body>
    
    `3*e^pi/5-3/5`
    
    
    </body>
    </html>
    

    Produces

    enter image description here