Skip to main content

Transform LaTeX to Unicode

parsing
programming
Published

April 10, 2023

It is possible to transform a subset of LaTeX to Unicode, as demonstrated by unicodeit website. Unfortunately, unicodeit only works on short LaTeX strings.

Here, I write a simple parser with Lark to process more complex LaTeX strings. A more complete version of this prototype is available as unicodeitplus.

Lark is awesome, because it generates the parser from an EMBL string, is fast and lightweight.

Let’s see how well (or not) this works on a few examples.

foo?!-1+2. \}  \\ $\left(\mathbf{\alpha + 1}^2_x y\right)$ bar $\beta^{12}$ $\bar p {}^foo$ $\bar \mathrm{t}$ 
'foo?!-1+2. } \\ (𝛂+πŸΒ²β‚“π‘¦) bar 𝛽¹² π‘Μ„αΆ π‘œπ‘œ tΜ„ '
'𝐷**β†’β„Žβ„Žπ‘’π‘’'
'𝐱𝐲𝐳+𝟏'
'√1Μ…π΄Μ…π‘ŽΜ…π‘ Μ…π›ΌΜ…'
'π‘₯βƒ—π‘Β²π›Όβƒ—π›ΌΜ…πΎβ°β‚›π‘β‚œT'
'βˆšπ‘ŽΜ…π‘Μ…π‘Μ…π‘‘Μ…'
'π‘β‚œ/GeV𝑐⁻¹'
'Search for resonant ttΜ… production in proton-proton collisions at βˆšπ‘ Μ…=13 TeV'