Skip to content

Commit 7a4ba5c

Browse files
author
Gautam Iyer
committed
Make \end{XXX} match the correct environment name
With this a \end{XXX} tag only matches a \begin{...} tag with the same environment name. Effectively, \begin{equation*} I = \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix} \end{equation*} won't result in borked syntax.
1 parent 1da84c6 commit 7a4ba5c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mdx_math.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ def handle_match_inline(m):
2828
def handle_match(m):
2929
node = markdown.util.etree.Element('script')
3030
node.set('type', 'math/tex; mode=display')
31-
node.text = markdown.util.AtomicString(m.group(3))
3231
if '\\begin' in m.group(2):
3332
node.text = markdown.util.AtomicString(m.group(2) +
34-
m.group(3) + m.group(4))
33+
m.group(4) + m.group(5))
34+
else:
35+
node.text = markdown.util.AtomicString(m.group(3))
3536
return node
3637

3738
configs = self.getConfigs()
@@ -42,7 +43,7 @@ def handle_match(m):
4243
mathpatterns = (
4344
markdown.inlinepatterns.Pattern(r'(?<!\\)(\$\$)([^\$]+)(\$\$)'), # $$...$$
4445
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\\[)(.+?)(\\\])'), # \[...\]
45-
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\begin{[a-z]+\*?})(.+)(\\end{[a-z]+\*?})')
46+
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\begin{([a-z]+?\*?)})(.+?)(\\end{\3})')
4647
)
4748
if not configs['enable_dollar_delimiter']:
4849
inlinemathpatterns = inlinemathpatterns[1:]

0 commit comments

Comments
 (0)