Latex output from sympy does not correctly display in Google Colaboratory Jupyter notebooks

后端 未结 3 1712
夕颜
夕颜 2021-01-11 16:19

I am using Google\'s Colaboratory platform to run python in a Jupyter notebook. In standard Jupyter notebooks, the output of sympy functions is correctly typeset Latex, but

3条回答
  •  佛祖请我去吃肉
    2021-01-11 16:38

    Using colab's mathjax and setting the configuration file to TeX-MML-AM_HTMLorMML worked for me. Below is the code:

    from sympy          import init_printing
    from sympy.printing import latex
    
    def colab_LaTeX_printer(exp, **options):  
        from google.colab.output._publish import javascript 
    
        url_ = "https://colab.research.google.com/static/mathjax/MathJax.js?"
        cfg_ = "config=TeX-MML-AM_HTMLorMML" # "config=default"
    
        javascript(url=url_+cfg_)
    
        return latex(exp, **options)
    # end of def
    
    init_printing(use_latex="mathjax", latex_printer=colab_LaTeX_printer) 
    

提交回复
热议问题