If you want to save the image to a file you can use this function:
def latex2png(latex, filename, fontsize=300):"""Render latex code to png image"""from sympy import previewreturn preview(latex,viewer='file',filename=filename,euler=False,dvioptions=['-D', f'{str(fontsize)}'])