TeX Math

Inline math goes between $ characters, and display math goes between $$:

$ comrak -e math-dollars
Let $x$ and $y$ be integers such that
$$x=y + 2$$

In inline math, the opening $ must not be followed by a whitespace, and the closing $ must not be preceded by whitespace.

$ comrak -e math-dollars
This is not math: 2000$.
And neither is this $ 4 $.
Or this $4
$.

Display math delimiters can be surrounded by whitespace:

$ comrak -e math-dollars
This is display math:
$$
e=mc^2
$$

Unlike in commonmark-hs, inline math cannot contain embedded math:

$ comrak -e math-dollars
This is display math:
$$
\text{Hello $x^2$}
$$
And this is inline math:
$\text{Hello $x$ there!}$

To avoid treating currency signs as math delimiters, one may occasionally have to backslash-escape them:

$ comrak -e math-dollars
The cost is between \$10 and 30$.

Dollar signs must also be backslash-escaped if they occur within math:

$ comrak -e math-dollars
$\text{\$}$

Everything inside the math construct is treated as math, and not given its normal CommonMark meaning:

$ comrak -e math-dollars
$b<a>c$

Block math can directly follow a paragraph:

$ comrak -e math-dollars
This is inline display math
$$1+2$$

This is block math
$$
1+2
$$