Math in Gemtext. LaTeX in Unicode

2022-06-11 | #XKCD

@dj-chase had piece about a super clever way to display complex math formulas in plain gemtext: Using preformatted text!

DJ Chase's post on Math in preformatted text

This is a great solution for people who are writing their own gemtext and wanting to include math. However it requires a fair amount of manual work to make it look right, and a good know of the unicode characters you have available. Unfortunately for me, I'm dealing with arbitrary math formulas Wikipedia content. I think it would be really difficult to write code that could do this conversion automatically.

Luckily for me, most of these math formaula's a defined using LaTeX, which is exactly made for this, and Wikipedia gets me access to PNG with beautifully rendered LaTeX

Math Formula from the "Uncertainty principle" article

Gemipedia: "Uncertainty principle"

... ... you know...

I do have the LaTeX code...

... and while some formulas are pretty complex, many of them aren't, like the area of a triangle. I wonder if someone has thought of a way to turn LaTeX into a Unicode string just using native unicode symbols...

It turns out, people have:

Latex-to-unicode (Python)

Latex-to-unicode.js

This code is pretty similar to how I handled subscripts and superscripts. It supports some fractions, superscripts, subscripts, and symbols like Δ. I should be able to adopt this code into something that tries to convert LaTeX to Unicode, and know if I was able to fully convert all parts of the formula:

So now I'm thinking: