Skip to content

Commit

Permalink
bugfix: allow regex characters in environment name (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Oct 20, 2023
1 parent 7dbdfe5 commit 3a9535a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions tests/test_indent_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,42 @@ def test_environment_c(self):
ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

def test_environment_star_a(self):
text = r"""
\begin{figure*}[b]
\centering
\includegraphics[width=\linewidth]{example-image}
\end{figure*}
"""

formatted = r"""
\begin{figure*}[b]
\centering
\includegraphics[width=\linewidth]{example-image}
\end{figure*}
"""

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

def test_environment_star_b(self):
text = r"""
\begin{figure*}[b]
\centering
\includegraphics[width=\linewidth]{example-image}
\end{figure*}
"""

formatted = r"""
\begin{figure*}[b]
\centering
\includegraphics[width=\linewidth]{example-image}
\end{figure*}
"""

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

def test_environment_nested_a(self):
text = r"""
Some text \begin{equation} \begin{split} a = b \end{split} \end{equation} some more text.
Expand Down
4 changes: 2 additions & 2 deletions texplain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,8 +1593,8 @@ def indent(
elif env == "document":
continue
else:
opening = r"\\begin{" + env + r"}"
closing = r"\\end{" + env + r"}"
opening = r"\\begin{" + re.escape(env) + r"}"
closing = r"\\end{" + re.escape(env) + r"}"
indices = find_matching(
text,
opening,
Expand Down

0 comments on commit 3a9535a

Please sign in to comment.