.docname {TeX formulae}
.include {docs}

Quarkdown natively supports TeX math equations and formulae. When rendering to HTML, this feature is powered by [KaTeX](https://www.katex.org).

## Inline

Inline equations can be created by wrapping text between two `$` symbols. Both delimiters must be preceded and followed by a whitespace (or beginning/end of the line).

.examplemirror
    Let $ \overline v = \frac {\Delta x} {\Delta t} $ be the **average velocity** of an object.

## One-line block

Block equations are usually visually centered and share the same syntax as inline ones, but need to be isolated from other content:

.examplemirror
    The following function is a **Fourier Transform**:

    $ F(u) = \int^{+\infty}_{-\infty} f(x) e^{-i 2\pi x} dx $

> Note: This syntax does **not** interrupt paragraphs, so make sure to space blocks properly. If the paragraph is not interrupted, the formula is recognized as inline due to Markdown's *lazy lines*.
>
> .examplemirror
>     The following function is a **Fourier Transform**:
>     $ F(u) = \int^{+\infty}_{-\infty} f(x) e^{-i 2\pi x} dx $

## Multiline block

A block formula can span over multiple lines thanks to a syntax similar to fenced code blocks, using three `$` symbols as delimiters.

.examplemirror
    $$$
    f(x) =
    \begin{cases}
        0 & \text{if } x = 0 \\
        1 & \text{if } x \neq 0
    \end{cases}
    $$$

## The `.math` function

Equations can also be created via the **`.math`** [primitive function](primitives.qd). This is useful when the equation content is computed from other functions, or when you want to apply styling to a specific formula.

.examplemirror
    .math
        E = mc^2

    <!-- or, equivalently -->

    .math {E = mc^2}

By default, `.math` produces a block formula when produced by a [block function call](syntax-of-a-function-call.qd#block-vs-inline-function-calls). You can force one or the other via the `block` parameter:

.examplemirror
    Inline: .math {2 + 2}

The content is evaluated as Quarkdown, so nested function calls are evaluated, contrary to the `$`-based syntax.

.examplemirror
    .var {n} {5}

    .math
        f(.n) = .n::multiply {2}

### Styling

Both inline and block equations accept the same [styling properties](element-styling-properties.qd) as containers.

.examplemirror
    .math fontsize:{larger}
        \pi \approx 3.14

### Extending

`.math` backs the standard `$ ... $` syntax, so [extending it](element-styling.qd) affects every equation in the document at once.

.exampleoutput {
    .math fontsize:{larger} foreground:{skyblue}
        a^2 + b^2 = c^2

    Inline: .math {a^2 + b^2 = c^2} foreground:{skyblue}
}
    .extend {math}
        .super foreground:{skyblue}

    .extend {math} where:{block: .block}
        .super fontsize:{larger}

    $ a^2 + b^2 = c^2 $

    Inline: $ a^2 + b^2 = c^2 $

## Macros

Quarkdown supports the creation of TeX macros via the `.texmacro` function. See [*TeX macros*](tex-macros.qd) for more information.
