Inline math goes between $` characters, and display math in fenced code
blocks with the info string math:
$ comrak -e math-code -t commonmark -t xml
Let $`x`$ and $`y`$ be integers such that
```math
x=y + 2
```
Let x and y be integers such that
x=y + 2
<p>Let <codedata-math-style="inline">x</code> and <codedata-math-style="inline">y</code> be integers such that</p><pre><codeclass="language-math"data-math-style="display">x=y + 2
</code></pre>
Let $`x`$ and $`y`$ be integers such that
```math
x=y + 2
```
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">Let </text><mathmath_style="inline"xml:space="preserve">x</math><textxml:space="preserve"> and </text><mathmath_style="inline"xml:space="preserve">y</math><textxml:space="preserve"> be integers such that</text></paragraph><code_blockinfo="math"math_style="display"xml:space="preserve">x=y + 2
</code_block></document>
In inline math, it behaves just like inline code:
$ comrak -e math-code -t commonmark -t xml
This is math:$`2000`$.
This is math:2000.
<p>This is math:<codedata-math-style="inline">2000</code>.</p>
This is math:$`2000`$.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">This is math:</text><mathmath_style="inline"xml:space="preserve">2000</math><textxml:space="preserve">.</text></paragraph></document>
Note that math can contain embedded math:
$ comrak -e math-code -t commonmark -t xml
This is display math:
```math
\text{Hello $x^2$}
```
And this is inline math:
$`\text{Hello $x$ there!}`$
This is display math:
\text{Hello $x^2$}
And this is inline math:
\text{Hello $x$ there!}
<p>This is display math:</p><pre><codeclass="language-math"data-math-style="display">\text{Hello $x^2$}
</code></pre><p>And this is inline math:
<codedata-math-style="inline">\text{Hello $x$ there!}</code></p>
This is display math:
```math
\text{Hello $x^2$}
```
And this is inline math:
$`\text{Hello $x$ there!}`$
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">This is display math:</text></paragraph><code_blockinfo="math"math_style="display"xml:space="preserve">\text{Hello $x^2$}
</code_block><paragraph><textxml:space="preserve">And this is inline math:</text><softbreak/><mathmath_style="inline"xml:space="preserve">\text{Hello $x$ there!}</math></paragraph></document>
Dollar signs are not required to be escaped with backslashes. They may be
required to render the math properly, but it’s not required for parsing:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><mathmath_style="inline"xml:space="preserve">\text{$}</math></paragraph></document>
Everything inside the math construct is treated as math, and not given its
normal CommonMark meaning:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><mathmath_style="inline"xml:space="preserve">b<a>c</math></paragraph></document>
Double dollar signs are not supported:
$ comrak -e math-code -t commonmark -t xml
$$`1 + 2`$$
$$1 + 2$$
<p>$$<code>1 + 2</code>$$</p>
\$\$`1 + 2`\$\$
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">$$</text><codexml:space="preserve">1 + 2</code><textxml:space="preserve">$$</text></paragraph></document>