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.

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.

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:
$$ $$
can be combined with any text in the block- 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:

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}
.

- You can often put functions into other functions, like this:
\color{red}{\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:

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

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

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}
.

But you can also do \overline{text}
:

Or even you can cross out the text:

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


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

Without a border but with a background color:

Or with both:

Ad font(e)s — using different fonts
There are, actually, quite a nice gallery of different fonts we can use in LaTeX:

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

It is also possible to use different sizes for fonts:

With results like this:

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

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:

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:

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:

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:

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

Or they can point down:

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?
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]]!