Skip to content

Instantly share code, notes, and snippets.

@nikibobi
Created November 3, 2018 14:06
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nikibobi/025750022c0b774d9c96c76b03e712cd to your computer and use it in GitHub Desktop.
Add LaTeX support to a Colab notebook for SymPy
import sympy
def custom_latex_printer(exp, **options):
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
javascript(url=url)
return sympy.printing.latex(exp, **options)
sympy.init_printing(use_latex="mathjax", latex_printer=custom_latex_printer)
@tonigi
Copy link

tonigi commented Feb 6, 2020

Great! Should be more prominent.

Used config=TeX-MML-AM_HTMLorMML to avoid \operatorname not defined errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment