Skip to content

Instantly share code, notes, and snippets.

@fish8
Created February 19, 2020 03:15
Show Gist options
  • Save fish8/3e717381a671a9d6ea80e9e284849824 to your computer and use it in GitHub Desktop.
Save fish8/3e717381a671a9d6ea80e9e284849824 to your computer and use it in GitHub Desktop.
sympy string expression to latex
import sympy as sp
from collections import defaultdict
class GenerateSymbols(defaultdict):
def __missing__(self, key):
self[key] = sp.Symbol(key)
return self[key]
#global symbols in dictionary
gl = GenerateSymbols()
sp.latex(eval ('x1**2+alpha*y_i',gl)) #'\\alpha y_{i} + x_{1}^{2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment