Skip to content

Commit

Permalink
improve readability, fix code formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pbodnar committed Dec 20, 2023
1 parent 5174389 commit 62d8104
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions mistletoe/contrib/mathjax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def __init__(self, **kwargs):

def render_math(self, token):
"""
Convert single dollar sign enclosed math environments to the \( \) syntax, to support
default mathjax settings which ignore single dollar signs for compatibility.
https://docs.mathjax.org/en/latest/basic/mathematics.html#tex-and-latex-input
Convert single dollar sign enclosed math expressions to the ``\(...\)`` syntax, to support
the default MathJax settings which ignore single dollar signs as described at
https://docs.mathjax.org/en/latest/basic/mathematics.html#tex-and-latex-input.
"""
if token.content.startswith('$$'):
if token.content.startswith('$$'):
return self.render_raw_text(token)
return '\\({}\\)'.format(self.render_raw_text(token).strip('$'))

Expand Down
4 changes: 2 additions & 2 deletions test/test_contrib/test_mathjax.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_render_html(self):

def test_render_math(self):
with MathJaxRenderer() as renderer:
raw = ['# heading 1\n', '$$\sum\limits_{i=1}^{\infty} \frac{1}{i^p}$$\n', 'with $ x_3 2^{x} $\n']
raw = ['math displayed as a block:\n', '$$ \\sum_{i=1}^{\\infty} \\frac{1}{i^p} $$\n', 'math displayed in-line: $ 2^x $\n']
token = Document(raw)
output = renderer.render(token)
target = '<h1>heading 1</h1>\n<p>$$\sum\limits_{i=1}^{\infty} \frac{1}{i^p}$$\nwith \( x_3 2^{x} \)</p>\n'
target = '<p>math displayed as a block:\n$$ \\sum_{i=1}^{\\infty} \\frac{1}{i^p} $$\nmath displayed in-line: \\( 2^x \\)</p>\n'
target += self.mathjax_src
self.assertEqual(output, target)

0 comments on commit 62d8104

Please sign in to comment.