Skip to content

Instantly share code, notes, and snippets.

@ochoadavid
Last active October 11, 2021 11:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochoadavid/d937a9653ef6991f027b807c5eb298c8 to your computer and use it in GitHub Desktop.
Save ochoadavid/d937a9653ef6991f027b807c5eb298c8 to your computer and use it in GitHub Desktop.
Function to convert Latex to Canvas html equation format.
import urllib.parse as parse
def to_canvas(latex, inline = False):
'''Converts Latex expression to canvas used <img> class.'''
model = '<img class="equation_image" title="{0}" src="/equation_images/{1}" alt="Latex: {0}" data-equation-content="{0}" />'
out = model.format(latex.replace('&amp;','&'),parse.quote(parse.quote(latex.replace('&amp;','&'), safe='()'), safe='()&'))
if not inline:
out = '</p>' + out + '</p>'
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment