math_misc

Markdown should ignore tokens within inline $...$ and displaymath $$...$$. https://github.com/mitmproxy/pdoc/issues/639

 1"""
 2Markdown should ignore tokens within inline `$...$` and displaymath `$$...$$`.
 3https://github.com/mitmproxy/pdoc/issues/639
 4"""
 5
 6
 7def test_stars():
 8    r"""
 9    Markdown emphasis tokens (`*`) should not be captured in math mode.
10
11    Currently broken: $*xyz*$
12
13    Workaround (escaping `*`): $\*xyz\*$
14
15    Workaround (extra whitespace): $* xyz *$
16
17    """
18
19
20def test_math_newline():
21    r"""
22    Markdown should not consume double backslashes (math newlines) in math mode.
23
24    Currently broken:
25
26    $$
27    \begin{align\*}
28    f(x) &= x^2\\
29         &= x \cdot x
30    \end{align\*}
31    $$
32
33    Workaround (escaping `\\`):
34
35    $$
36    \begin{align\*}
37    f(x) &= x^2\\\\
38         &= x \cdot x
39    \end{align\*}
40    $$
41    """
42
43
44def test_markdown_newline():
45    r"""
46    Markdown newlines (`\n\n`) should not emit a paragraph break in math mode.
47
48    Currently broken:
49
50    $$
51    x + y
52
53    = z
54    $$
55
56    Workaround (no empty lines in math mode):
57
58    $$
59    x + y
60    % comment
61    = z
62    $$
63    """
64
65
66def test_macros():
67    r"""
68    Markdown should not capture headings (`#`) in math mode.
69    Currently broken:
70
71    $$
72    \newcommand{\define}[2]
73    {
74    #1 \quad \text{#2}
75    }
76    \define{e^{i\pi}+1=0}{Euler's identity}
77    $$
78
79
80    Workaround (no lines with leading `#`):
81
82    $$
83    \newcommand{\define}[2]{#1 \quad \text{#2}}
84    \define{e^{i\pi}+1=0}{Euler's identity}
85    $$
86    """
def test_stars():
 8def test_stars():
 9    r"""
10    Markdown emphasis tokens (`*`) should not be captured in math mode.
11
12    Currently broken: $*xyz*$
13
14    Workaround (escaping `*`): $\*xyz\*$
15
16    Workaround (extra whitespace): $* xyz *$
17
18    """

Markdown emphasis tokens (*) should not be captured in math mode.

Currently broken: $xyz$

Workaround (escaping *): $*xyz*$

Workaround (extra whitespace): $* xyz *$

def test_math_newline():
21def test_math_newline():
22    r"""
23    Markdown should not consume double backslashes (math newlines) in math mode.
24
25    Currently broken:
26
27    $$
28    \begin{align\*}
29    f(x) &= x^2\\
30         &= x \cdot x
31    \end{align\*}
32    $$
33
34    Workaround (escaping `\\`):
35
36    $$
37    \begin{align\*}
38    f(x) &= x^2\\\\
39         &= x \cdot x
40    \end{align\*}
41    $$
42    """

Markdown should not consume double backslashes (math newlines) in math mode.

Currently broken:

$$ \begin{align*} f(x) &= x^2\ &= x \cdot x \end{align*} $$

Workaround (escaping \\):

$$ \begin{align*} f(x) &= x^2\\ &= x \cdot x \end{align*} $$

def test_markdown_newline():
45def test_markdown_newline():
46    r"""
47    Markdown newlines (`\n\n`) should not emit a paragraph break in math mode.
48
49    Currently broken:
50
51    $$
52    x + y
53
54    = z
55    $$
56
57    Workaround (no empty lines in math mode):
58
59    $$
60    x + y
61    % comment
62    = z
63    $$
64    """

Markdown newlines (\n\n) should not emit a paragraph break in math mode.

Currently broken:

$$ x + y

= z $$

Workaround (no empty lines in math mode):

$$ x + y % comment = z $$

def test_macros():
67def test_macros():
68    r"""
69    Markdown should not capture headings (`#`) in math mode.
70    Currently broken:
71
72    $$
73    \newcommand{\define}[2]
74    {
75    #1 \quad \text{#2}
76    }
77    \define{e^{i\pi}+1=0}{Euler's identity}
78    $$
79
80
81    Workaround (no lines with leading `#`):
82
83    $$
84    \newcommand{\define}[2]{#1 \quad \text{#2}}
85    \define{e^{i\pi}+1=0}{Euler's identity}
86    $$
87    """

Markdown should not capture headings (#) in math mode. Currently broken:

$$ \newcommand{\define}[2] {

1 \quad \text{#2}

} \define{e^{i\pi}+1=0}{Euler's identity} $$

Workaround (no lines with leading #):

$$ \newcommand{\define}[2]{#1 \quad \text{#2}} \define{e^{i\pi}+1=0}{Euler's identity} $$