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