Last active
October 11, 2021 11:16
-
-
Save ochoadavid/d937a9653ef6991f027b807c5eb298c8 to your computer and use it in GitHub Desktop.
Function to convert Latex to Canvas html equation format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('&','&'),parse.quote(parse.quote(latex.replace('&','&'), 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