Writing LaTeX inside markdown

If I want to include LaTeX in a markdown literal string, I have to use ${...} to enter in javascript mode, then tex`` to generate the LaTeX formatted letter, eg:

md`The variable ${tex`t`} is the time and ${tex`x`} is the position.`

It’s a bit tedious if you have a lot of variables.

One solution is not to use LaTeX, and write them in normal font

md`The variable t is the time and x is the position.`

What would you do?

My preference is to use ${tex`t`} within Markdown or HTML literals. But if you find that tedious, you could use a wrapper like the following that uses $t$ for something like math mode.

1 Like

Thanks, it’s exactly what I was looking for.

Thanks also for mentioning your preference. I imagine it’s due to the overhead of importing `texmd` and also adding a dependency that might break or diverge from `md` and `tex` implementations.

Personally I use $ as a shortcut for tex and $$ as a shortcut for tex.block.

So then TeX in markdown is ${$`f(x) = y`} or the like.

3 Likes

Now that GitHub markdown, GitLab markdown, and default VS Code markdown preview render math using the $ and $$ markdown syntax, I think Observable should adopt this approach by default.

(Observable and Plot are fantastic!) Thanks.

1 Like