LaTeX for Roam from non-math perspective

Use it for interesting font creations, simple diagrams and fun

In this short article, I intend to look at one part of Roam that is usually overlooked by non-technical users: it comes under weirdly written name LaTeX. But don’t worry, this is nothing about tightly fitting sexy clothes and catsuits.

Meme comparing latex (material) and LaTeX (programming language)
Know the difference! (Source for the upper right latex image — Zencat2006.)

As Wikipedia states, LaTeX (pronounced by Greek aficionados rightly as /ˈlɑːtɛx/) is “a document preparation system and markup language”. In other words, it allows you to write, e.g., your whole article in a text file and get as an output a professionally looking PDF prepared for printing. LaTeX is mainly popular among scientist because of its great support for typesetting mathematical formulas. However, you can use it for many different things. Your humble Roaman duckling used it, e.g., for typesetting his master thesis from humanities (and I regretted it dearly).

LaTeX does contain an unbelievable number of various packages — little libraries — that you can easily download and fulfil your weirdest typesetting dreams. Like three rows of footnotes? That is no problem for LaTeX! Five tables of contents? Go on! Writing your own special commands for formatting? You are welcome! However, we are not going so far today. Instead, we will look at some basics of LaTeX for Roam that everybody can use.

Remember, you can find the code used here also on my public Roam page.

LaTeX in Roam

Roam does not include the whole power of LaTeX. That would be insane (and great!) but it focuses only on its use for mathematical expressions.

As with other parts of Roam, it uses an external library for rendering LaTeX, in this case, it is so-called KaTeX. This gives us a set of supported commands (called functions in LaTeX).

To insert a LaTeX code into your Roam, simply write two openings $$ and then two closing $$. Between them, you can insert a code. Instead of a typical “Hello, World”, you can try “Hello, Roam”!

$$\text{Hello, Roam}$$

No, click outside the block and the result should be displayed.

Animation showing that it is necessary to click outside the block to display the result of LaTeX code.
Click outside the block to display the result of the LaTeX code.

How well is LaTeX integrated into Roam environment?

Worse than I wished, better than I expected.

First, the bad news:

  • We cannot use any page references, block references or any other Roam commands within $$ $$ .

Now, the good news:

  1. $$ $$ can be combined with any text in the block
  2. Surprisingly, $$ $$ can be a part of the page title. This page title can be referenced using [[ ]] (but curiously not as #[[ ]]).

The second point is completely unexpected. There is no other rendered element that would work like this in Roam (like tables, kanban, diagrams, mermaid graphs etc.). This gives us the possibility to use LaTeX for native formatting of page titles, like this:

Page title created in LaTeX
Page title created in LaTeX

We will look below how to achieve this.

Basic structure

The good starting point is different online editors for equations that you can freely use. These make the creation of LaTeX code much easier.

Then, remember, LaTeX usually works on the following principles:

  • Functions start with \ followed by their name, like \color
  • The parameters of functions, incl. the content, are put inside {} . In the case of \color we can simply write, e.g.: \color{red}{text} .
LaTeX code for colored text.
  • You can often put functions into other functions, like this: \color{red}{\underline{text}}
LaTeX code for colored underline text.

However, there are some limitations on that. Just try it and see what works :).

What is specific for Roam, that we are by default in the math mode. This has a couple of consequences, one of them is that if we write a blank space, it will not be displayed:

LaTeX code showing that Roam by default does not show white spaces in the LaTeX code

Thus put the text into, e.g., a \text function. This ensures the proper rendering of spaces.

Use \text{} to show white spaces in LaTeX in Roam

Of course, this is the very same thing as this, i.e. we can put either \text inside \color, or vice versa:

You can use \text{} either within or outside other functions.

What can we do with it?

It is interesting and useful for anybody doing math but what non-math folks can do with that?

Underlining the formatting

Currently, Roam does not support any advanced formatting. You cannot choose the color of the font, you cannot pick up different highlighting colors, there is no upper index, no underline. A typical way around it is to use a custom CSS code. This works very well and there are different solutions for various issues (e.g. see my custom colors for Roam). However, you might want to use the vanilla version of Roam. In that case, you can use LaTeX!

We have already seen the colored font, it is a simple function \color , check the supported colors. However, we can also create borders around the text:

Underlined text: \underline{text} .

LaTeX code for the underlined text — \underline{text}

But you can also do \overline{text} :

LaTeX code for the overlined text: \overline{text}

Or even you can cross out the text:

LaTeX code for crossed out text — \xcancel{text}

Superscript and subscript are even easier to create with simple ^ or _ characters:

LaTeX code for superscript
Superscript
LaTeX code for subscript
Subscript

We can even put things into a box! Without a color:

LaTeX for a text in a box.
This is not a box… in a box

Without a border but with a background color:

LaTeX code for a box with a background color.
This is not a box… with a background-colour

Or with both:

This is not a box… with a border and a background color

Ad font(e)s — using different fonts

There are, actually, quite a nice gallery of different fonts we can use in LaTeX:

Table showing different fonts supported by KaTeX.
Supported fonts in KaTeX, source KaTeX docs (MIT license)

So you can create, e.g., a little bit spooky looking:

Roam in franktur script.
Roam after the acquisition by medievalists

It is also possible to use different sizes for fonts:

Table showing different font sizes supported by KaTeX.
Sizes in KaTeX, source KaTeX docs (MIT license)

With results like this:

LaTeX code for huge text in fraktura.
Roam grows every day…

And you can, of course, combine it with colors!

Combination of different fonts, font sizes and colors.
Roam after the acquisition by Google…

I think this is a good moment to move on!

Power of brackets and matrices

If we look at the structure of Roam, despite being very free in the aspects of references, it is still basically a tree structure. We are going from the root down:

Example of horizontal structure of Roam.

However, our mind does not work this way. We might often want to join different ideas in the list again, or write a note between lines. For such cases, we can use LaTeX and its power of matrices. A very simple diagram can look like this:

LaTeX code showing a simple curly bracket left followed by two rows.

Note a couple of important things: We start the block with the matrix using \begin{cases} and end it with \end{cases} — these are called environments. Similar syntax is typical for various blocks or tables in LaTeX, we just change the keyword. In this case, cases (how appropriate!) means that we will get the left bracket but no right bracket.

Then you simply write so many rows as you wish, important is:

  • & separates different columns
  • \\ creates a new row/line
  • \text{} creates a text that can contain white spaces

Now we can take the same code a simply change cases to Bmatrix and we will get arrows on both sides:

LaTeX code showing curly brackets around a matrix.

Not everything from KaTeX seems to work well in Roam but the vast majority is fine. The easiest way how to do this is to use one of the existing editors, as mentioned above.

We can actually combine it within the text. What comes before and after the $$ $$ . We can go into absurd lengths:

An insanely complicated nested matrices in LaTeX.

What is nice, we don’t have to go necessarily just in the horizontal direction but arrow brackets can also point up:

LaTeX for a curly brace above the text.

Or they can point down:

LaTeX for a curly brace under the text.

Notice that we use ^ and _ in a similar way as for a superscript and subscript.

Finally, we can combine everything we learnt and create silly diagrams like this and use them as our page titles. Can you figure out what is its code?

A funny final LaTeX code.
Can you figure out how it is done? If note, you can check my public Roam page. :)

Only your imagination (and your skills, time, KaTeX support, Roam, and reality…) are your limits! So, go on. You can find all supported functions in KaTeX documentation.

And that is all for today. If you like my work, follow me on Twitter, check the public Roam database Roam-tricks, my personal public collection of my hacks, and yes, you can support me on Patreon or through PayPal. I would really appreciate it and you would help to make future articles happen. And remember: If it looks like a duck, if it writes like a duck, it’s probably me. [[QUACK]]!

Just a humble Roaman duck.