Skip to content

Commit

Permalink
math extension: don't fail when display math contains...
Browse files Browse the repository at this point in the history
...embedded inline math.  See jgm/pandoc#7942.

Note, however, that there's a larger issue this doesn't
solve.  For in principle you could have embedded math
in inline math, e.g.

```
$\text{hi $x$ there}$
```

Pandoc's markdown parser gets this right, but that's
because it uses a LaTeX tokenizer.
  • Loading branch information
jgm committed Feb 28, 2022
1 parent 02f5735 commit e136525
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions commonmark-extensions/src/Commonmark/Extensions/Math.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pDisplayMath = try $ do
(_, toks) <- withRaw $ many1 $
choice [ () <$ symbol '\\' >> anyTok
, noneOfToks [Symbol '$']
, try (symbol '$' <* notFollowedBy (symbol '$'))
]
count 2 $ symbol '$'
return $! displayMath (untokenize toks)
16 changes: 16 additions & 0 deletions commonmark-extensions/test/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ e=mc^2
\]</span></p>
````````````````````````````````

Note that display math can contain embedded inline math:

```````````````````````````````` example
This is display math:
$$
\text{Hello $x^2$}
$$
.
<p>This is display math:
<span class="math display">\[
\text{Hello $x^2$}
\]</span></p>
````````````````````````````````



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

Expand Down

0 comments on commit e136525

Please sign in to comment.