Blog Home RSS Kelvin Jackson

On Treating HTML and LaTeX as Compilation Targets

2024-03-06

I feel that I reached a new level of programming skill when I began to see LaTeX and HTML primarily as compilation targets rather than languages to write by hand.

For years, writing documents in either from scratch has been painful. Not impossible, of course, but there are enough tricky things that are easy to get wrong that I sometimes shy away from these undertakings if I don't have a ready-made template somewhere to copy. Sure, you can go to the documentation and spend time digging, but do you actually want to do that when you have something to say that has nothing to do with typesetting or web design? And even once you have the basics memorized, there are still numerous packages to install and <link> and <meta> tags to write that feel more and more superfluous as the years go by.

Furthermore, while I would not go so far as to say that more complex LaTeX is unwritable, sometimes it feels like that, even after staring at documentation for quite some time. It is unnecessarily clumsy, and often I have found myself wondering if I really have to type a backslash, the better part of a word, and a complete pair of curly braces just to mark a piece of text as emphasized or strong — a task accomplished with a simple pair of underscores or stars on most modern chat platforms and social media. HTML, while easier and more logical to read, requires even more typing if writing in a traditional editor.

Why not, then, just write markdown and let a program handle the transformation? The things you actually want to tweak by hand go into a template, and your text or images go into a file you can actually read. It isn't a WYSIWYG editor by any means, but if you're still reading this, you, like me, probably have reasons not to just use a WYSIWYG editor.

Personally, I've spent quite a bit of time writing scripts to transform a personal markdown language into both LaTeX and HTML. While I would recommend using traditional markdown and an existing processor if you don't already have a large body of files following a different, organically evolved convention that you started using before you realized that you were writing markdown (as was the case for me), don't let the wordiness of HTML or lack of readability of LaTeX deter you — you can let the computer do the typing for you.

Additionally, taking a step back for a moment, we can pause and contemplate the true purpose of a wrapper (any wrapper) around an existing software implementation or language: not to extend the functionality of that particular tool, but to constrain the options available to those that you are actually going to use. Writing a web page or typesettable document in markdown achieves the same purpose by abstracting away the formatting and/or styling, leaving you with plain headings and paragraphs and minimal clutter.

So: if you want the simplest static site possible, but also don't relish the idea of writing everything in plain HTML, or you want the beauty of a LaTeX document without the trouble of writing LaTeX, consider that both languages may be easier to generate than to write, especially for longer texts. Markdown doesn't have to just be for GitHub README files — it can also be the key to writing pretty, well-formatted, and universally accessible documents without too much mucking around in complex markup and typesetting languages. You wouldn't write a program in assembly unless you needed to do something C couldn't handle, so why not take the same approach for text content?