2023-07-26 07:10:37 +03:00
---
2024-02-23 23:07:53 +03:00
title: LaTeX
2023-07-26 07:10:37 +03:00
tags:
2024-02-23 23:07:53 +03:00
- feature/transformer
2023-07-26 07:10:37 +03:00
---
2023-07-10 05:32:24 +03:00
Quartz uses [Katex ](https://katex.org/ ) by default to typeset both inline and block math expressions at build time.
2023-08-12 08:47:50 +03:00
## Syntax
2023-07-10 05:32:24 +03:00
### Block Math
2023-07-23 03:27:41 +03:00
2023-07-10 05:32:24 +03:00
Block math can be rendered by delimiting math expression with `$$` .
```
$$
f(x) = \int_{-\infty}^\infty
f\hat(\xi),e^{2 \pi i \xi x}
\,d\xi
$$
```
$$
f(x) = \int_{-\infty}^\infty
f\hat(\xi),e^{2 \pi i \xi x}
\,d\xi
$$
2023-08-11 10:31:44 +03:00
$$
\begin{aligned}
a & = b + c \\ & = e + f \\
\end{aligned}
$$
$$
\begin{bmatrix}
1 & 2 & 3 \\
a & b & c
\end{bmatrix}
$$
2024-02-23 23:07:53 +03:00
> [!warn]
> Due to limitations in the [underlying parsing library](https://github.com/remarkjs/remark-math), block math in Quartz requires the `$$` delimiters to be on newlines like above.
2023-07-10 05:32:24 +03:00
### Inline Math
2023-07-23 03:27:41 +03:00
2023-07-10 05:32:24 +03:00
Similarly, inline math can be rendered by delimiting math expression with a single `$` . For example, `$e^{i\pi} = -1$` produces $e^{i\pi} = -1$
### Escaping symbols
2023-07-23 03:27:41 +03:00
There will be cases where you may have more than one `$` in a paragraph at once which may accidentally trigger MathJax/Katex.
2023-07-10 05:32:24 +03:00
To get around this, you can escape the dollar sign by doing `\$` instead.
For example:
2023-07-23 03:27:41 +03:00
2023-07-10 05:32:24 +03:00
- Incorrect: `I have $1 and you have $2` produces I have $1 and you have $2
- Correct: `I have \$1 and you have \$2` produces I have \$1 and you have \$2
2024-02-24 04:45:41 +03:00
### Using mhchem
Add the following import to the top of `quartz/plugins/transformers/latex.ts` (before all the other
imports):
```ts title="quartz/plugins/transformers/latex.ts"
import "katex/contrib/mhchem"
```
2023-07-10 05:32:24 +03:00
## Customization
2023-07-23 03:27:41 +03:00
2024-02-23 23:07:53 +03:00
Latex parsing is a functionality of the [[plugins/Latex|Latex]] plugin. See the plugin page for customization options.