Pretty print sympy when not using iPython

137 Views Asked by At

I am using SymPy with PyScript so I cannot use init_printing() in my code as I am not running code cell by cell. How can I still use pprint to make my output look good in Web?

Output I am getting:

Current output

Output I am expecting:

Expected output

1

There are 1 best solutions below

0
On

I wrote a MathJax example that displays formulas correctly: link Right-click on the page to view the source code.

The key is that you must tell MathJax to typeset the answer. This requires dropping down to JavaScript for a simple two line call:

<script>
function draw(str) {
    var math = MathJax.Hub.getAllJax("MathDiv")[0];
    MathJax.Hub.Queue([ "Text", math, str ]);
}
</script>

Example code including initializing MathJax and setting up the display DIV:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<div id="MathDiv">\({}\)</div>

<py-script>
delta__y_l = symbols('Delta__y_l')
latexstr = latex(delta__y_l)
js.draw(latexstr)
</py-script>