packages = ["whl/ziafont-0.10a0-py3-none-any.whl", "whl/ziamath-0.12a0-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 MathML Rendering Demo
Enter a MathML expression
MathML Expression:
Font:
<math> <msqrt><mi>x</mi></msqrt> </math>
Stix2
Asana-Math
Concrete-Math
DejaVu Math Tex Gyre
Erewhon-Math
FiraMath
Garamond-Math
Lete Sans Math
LibertinusMath
Download SVG
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 try: mathsvg = ziamath.Math(expr, font=getfont()) 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 mathsvg = ziamath.Latex(expr, font=getfont()).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()