POSTS

[Ruby] A tool to convert LaTeX-style macrons to macron characters, html entities, or UTF-8 escape codes

Blog

When I write my Latin homework in LaTeX, the source winds up looking like this:

\item[13.]  Am\={\i}c\={o}s tr\={\i}st\={e}s exc\={e}pit, ad m\={e}nsam inv\={\i}t\={a}vit, et e\={\i}s perfugium ac s\={o}l\={a}cium h\={\i}c dedit.

Aside: You might be thinking that entering \={\i} just to get a single character would be a drag, but thanks to Textmate I have created snippets such that Control + letter does all that typing for me }

Now if I want to post this to the web, I need to convert those characters from say \={\i} to \&\#x12b;. I would like it to go through the sentence and change each of those LaTeX-macron characters to HTML entities.

Similarly, I occasionally have need to convert LaTeX-macron sequences to UTF-8 codes.

And yet other times I want it to convert those codes to macron-ized characters.

So I wrote a script that takes input of the LaTeX form and will let you specify if you want the output in HTML entity (default), macron characters, or utf8 characters.

The best part is that I’ve written this function into Textmate as an extension so for me conversion is:

Default String

Highlight the LaTeX string

Choose my command with this script in it

Text is replaced, magically!

And it looks like this in a browser…

>\item[13.]  Amīcōs trīstēs excēpit, ad mēnsam invītāvit, et eīs perfugium ac sōlācium hī