# Math blocks `$$…$$`

Math blocks encode mathematical formulas to be displayed separately from text on the webpage like this:

The related math string markup can be used to write formulas compactly within lines of text.

## How to

Choose and add a math module to your Aneamal installation, if you haven’t already. You can find free modules in the math modules inventory. Adding one to Aneamal is as easy as pie.

Then mark both the start and the end of a mathematical formula with double dollar signs like in the examples below.

You have the option to add a label at the end, separated by white space from the double dollar signs. If you mark the label as a target like in the third example, you can use it to link to the math block.

Due to being block markup, a math block usually needs to be preceded and followed by a blank line except when it is at the start or end of a file respectively. Unusually, a math block can also be used as list item. It is not accompanied by blank lines then.

Because the content of a math block is processed by a math module, its internal syntax is beyond the scope of Aneamal. Math modules should support the syntax of AMS-LaTeX. They usually omit some rarely used functions and add others. Consult their respective documentation, for example the supported functions in KaTeX.

## Examples

```
$$
\begin{aligned}
365&=31+28+31+30+31+30+31+31+30+31+30+31\\
&=13\times\underbrace{4\times 7}_{28}+1
\end{aligned}
$$
```

### Example with math label

`$$A=\frac{d^2}{r+r^{-1}}$$ (2)`

### Example with a target

`$$\phi^n=F_n\phi+F_{n-1}$$ #(3)`

## For developers

When Aneamal is translated to HTML, a processed math block is enclosed in an HTML *div* element with a *math* role. The optional math label is included at the end as a *span* element with the class `_label`

. The above examples become:

`<div role='math'>…</div>`

`<div role='math'>… <span class='_label'>(2)</span></div>`

`<div id='3' role='math'>… <span class='_label'>(3)</span></div>`

Note how in the last example the *id* attribute, which is derived from the target at the start of the math label, is added to the *div* element instead of to the *span* element.

Different math modules translate the same mathematical formulas differently to HTML, so the content of the *div* element will vary from module to module.