'Pretty print sympy when not using iPython
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:
Output I am expecting:
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | John Hanley |