TeX Math

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

Example 1
$ 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.

Example 2
$ 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:

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

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

Example 4
$ 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:

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

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

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

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

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

Block math can directly follow a paragraph:

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

This is block math
$$
1+2
$$