| 1 |
--- |
| 2 |
title: Dollar Math |
| 3 |
based_on: https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/math.md |
| 4 |
--- |
| 5 |
|
| 6 |
# TeX Math |
| 7 |
|
| 8 |
Inline math goes between `$` characters, and display math |
| 9 |
goes between `$$`: |
| 10 |
|
| 11 |
```````````````````````````````` example |
| 12 |
Let $x$ and $y$ be integers such that |
| 13 |
$$x=y + 2$$ |
| 14 |
. |
| 15 |
<p>Let <span data-math-style="inline">x</span> and <span data-math-style="inline">y</span> be integers such that |
| 16 |
<span data-math-style="display">x=y + 2</span></p> |
| 17 |
```````````````````````````````` |
| 18 |
|
| 19 |
In inline math, the opening `$` must not be followed by |
| 20 |
a whitespace, and the closing `$` must not be |
| 21 |
preceded by whitespace. |
| 22 |
|
| 23 |
```````````````````````````````` example |
| 24 |
This is not math: 2000$. |
| 25 |
And neither is this $ 4 $. |
| 26 |
Or this $4 |
| 27 |
$. |
| 28 |
. |
| 29 |
<p>This is not math: 2000$. |
| 30 |
And neither is this $ 4 $. |
| 31 |
Or this $4 |
| 32 |
$.</p> |
| 33 |
```````````````````````````````` |
| 34 |
|
| 35 |
Display math delimiters can be surrounded by whitespace: |
| 36 |
|
| 37 |
```````````````````````````````` example |
| 38 |
This is display math: |
| 39 |
$$ |
| 40 |
e=mc^2 |
| 41 |
$$ |
| 42 |
. |
| 43 |
<p>This is display math: |
| 44 |
<span data-math-style="display"> |
| 45 |
e=mc^2 |
| 46 |
</span></p> |
| 47 |
```````````````````````````````` |
| 48 |
|
| 49 |
Note that math can contain embedded math. In scanning |
| 50 |
for a closing delimiter, we skip material in balanced |
| 51 |
curly braces: |
| 52 |
|
| 53 |
```````````````````````````````` example disabled |
| 54 |
This is display math: |
| 55 |
$$ |
| 56 |
\text{Hello $x^2$} |
| 57 |
$$ |
| 58 |
And this is inline math: |
| 59 |
$\text{Hello $x$ there!}$ |
| 60 |
. |
| 61 |
<p>This is display math: |
| 62 |
<span class="math display">\[ |
| 63 |
\text{Hello $x^2$} |
| 64 |
\]</span> |
| 65 |
And this is inline math: |
| 66 |
<span class="math inline">\(\text{Hello $x$ there!}\)</span></p> |
| 67 |
```````````````````````````````` |
| 68 |
|
| 69 |
To avoid treating currency signs as math delimiters, |
| 70 |
one may occasionally have to backslash-escape them: |
| 71 |
|
| 72 |
```````````````````````````````` example |
| 73 |
The cost is between \$10 and 30$. |
| 74 |
. |
| 75 |
<p>The cost is between $10 and 30$.</p> |
| 76 |
```````````````````````````````` |
| 77 |
|
| 78 |
Dollar signs must also be backslash-escaped if they |
| 79 |
occur within math: |
| 80 |
|
| 81 |
```````````````````````````````` example |
| 82 |
$\text{\$}$ |
| 83 |
. |
| 84 |
<p><span data-math-style="inline">\text{\$}</span></p> |
| 85 |
```````````````````````````````` |
| 86 |
|
| 87 |
Everything inside the math construction is treated |
| 88 |
as math, and not given its normal commonmark meaning. |
| 89 |
|
| 90 |
```````````````````````````````` example |
| 91 |
$b<a>c$ |
| 92 |
. |
| 93 |
<p><span data-math-style="inline">b<a>c</span></p> |
| 94 |
```````````````````````````````` |
| 95 |
|
| 96 |
Block math can directly follow a paragraph. |
| 97 |
|
| 98 |
```````````````````````````````` example |
| 99 |
This is inline display math |
| 100 |
$$1+2$$ |
| 101 |
|
| 102 |
This is block math |
| 103 |
$$ |
| 104 |
1+2 |
| 105 |
$$ |
| 106 |
. |
| 107 |
<p>This is inline display math |
| 108 |
<span data-math-style="display">1+2</span></p> |
| 109 |
<p>This is block math |
| 110 |
<span data-math-style="display"> |
| 111 |
1+2 |
| 112 |
</span></p> |
| 113 |
```````````````````````````````` |