2023-07-26 11:10:37 +07:00
---
2024-02-24 03:07:53 +07:00
title: LaTeX
2023-07-26 11:10:37 +07:00
tags:
2024-02-24 03:07:53 +07:00
- feature/transformer
2023-07-26 11:10:37 +07:00
---
2023-07-10 09:32:24 +07:00
Quartz uses [Katex ](https://katex.org/ ) by default to typeset both inline and block math expressions at build time.
2023-08-12 12:47:50 +07:00
## Syntax
2023-07-10 09:32:24 +07:00
### Block Math
2023-07-23 07:27:41 +07:00
2023-07-10 09:32:24 +07: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 14:31:44 +07:00
$$
\begin{aligned}
a & = b + c \\ & = e + f \\
\end{aligned}
$$
$$
\begin{bmatrix}
1 & 2 & 3 \\
a & b & c
\end{bmatrix}
$$
2024-02-24 03:07:53 +07: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 09:32:24 +07:00
### Inline Math
2023-07-23 07:27:41 +07:00
2023-07-10 09:32:24 +07: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 07:27:41 +07: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 09:32:24 +07:00
To get around this, you can escape the dollar sign by doing `\$` instead.
For example:
2023-07-23 07:27:41 +07:00
2023-07-10 09:32:24 +07: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 08:45:41 +07: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 09:32:24 +07:00
## Customization
2023-07-23 07:27:41 +07:00
2024-02-24 03:07:53 +07:00
Latex parsing is a functionality of the [[plugins/Latex|Latex]] plugin. See the plugin page for customization options.