Skip to content

Instantly share code, notes, and snippets.

View ochoadavid's full-sized avatar

David Ochoa ochoadavid

View GitHub Profile
@ochoadavid
ochoadavid / latex_to_canvas.py
Last active October 11, 2021 11:16
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
@ochoadavid
ochoadavid / html_to_canvas.py
Last active October 11, 2021 11:16
Jupyter notebook with Latex to Canvas html equation converter
import urllib.parse as parse
import sys
infile = sys.argv[1]
def to_canvas(latex, inline = False):
'''Converts Latex expression to canvas used <img> class.'''
modelo = '<img class="equation_image" title="{0}" src="/equation_images/{1}" alt="Latex: {0}" data-equation-content="{0}" />'
out = modelo.format(latex.replace('&amp;','&'),parse.quote(parse.quote(latex.replace('&amp;','&'), safe='()'), safe='()&'))
if not inline: