-- Leo's gemini proxy

-- Connecting to gemi.dev:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Math into Gemtext. LaTeX into Unicode

2022-06-11 | #Gemtext #Gemipedia | @Acidus


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


DJ Chase's post on Math in pre-formatted 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 knowledge of the unicode characters you have available. Unfortunately for me, I'm dealing with arbitrary math formulas in 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 formaulas are 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 HTML subscripts and superscripts. It supports some fractions, superscripts, subscripts, and symbols like Δ. I should be able to adapt 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:

Continue to use my code that handles <SUB> and <SUP> via Unicode symbols.

If I encounter a math forumula, try to convert the Latex to Unicode.

If I can convert all the characters to unicode, so that

Otherwise, fallback to using link line pointing to a PNG rendering

-- Response ended

-- Page fetched on Tue May 21 17:44:56 2024