packages = ["whl/ziafont-0.9-py3-none-any.whl", "whl/ziamath-0.11-py3-none-any.whl", "latex2mathml"] [[fetch]] files = ["fonts/Asana-Math.ttf", "fonts/Concrete-Math.otf", "fonts/DejaVuMathTeXGyre.ttf", "fonts/Erewhon-Math.otf", "fonts/FiraMath-Regular.otf", "fonts/Garamond-Math.otf", "fonts/LeteSansMath.otf", "fonts/LibertinusMath-Regular.otf"]

Loading...

Ziamath LaTeX Rendering Demo

Enter a LaTeX math expression







import asyncio from pyscript import document, display from js import console, window, Uint8Array, File, URL from io import BytesIO import ziamath def getfont(): name = document.querySelector("#mathfont").value return {'asana': 'fonts/Asana-Math.ttf', 'concrete': 'fonts/Concrete-Math.otf', 'dejavu': 'fonts/DejaVuMathTeXGyre.ttf', 'erewhon': 'fonts/Erewhon-Math.otf', 'fira': 'fonts/FiraMath-Regular.otf', 'garamond': 'fonts/Garamond-Math.otf', 'lete': 'fonts/LeteSansMath.otf', 'liber': 'fonts/LibertinusMath-Regular.otf' }.get(name, None) # stix is default/None def drawit(*args): expr = document.querySelector("#expression").value inline = document.querySelector("#inline").checked try: mathsvg = ziamath.Latex(expr, font=getfont(), inline=inline) except Exception as e: console.log('Math Exception: ' + str(e.args)) else: display(mathsvg, target='mathout', append=False) async def file_save(*args): expr = document.querySelector("#expression").value inline = document.querySelector("#inline").checked mathsvg = ziamath.Latex(expr, font=getfont(), inline=inline).svg() stream = BytesIO(mathsvg.encode('utf-8')) js_array = Uint8Array.new(len(mathsvg)) js_array.assign(stream.getbuffer()) file = File.new([js_array], "ziamath.svg", {type: "text/plain"}) url = URL.createObjectURL(file) hidden_link = document.createElement("a") hidden_link.setAttribute("download", "ziamath.svg") hidden_link.setAttribute("href", url) hidden_link.click() drawit()