Regular expressions for normalizing common Markdown math delimiters.
Canonical Form
#| Type | Delimiter |
|---|
| Inline | $...$ |
| Display | $$...$$ |
Inline Math
#| Input | Regular expression |
|---|
\(...\) | (?<!\\)\\\((.*?)\\\) |
\\(...\\) | (?<!\\)\\\\\((.*?)\\\\\) |
$...$ | (?<!\$)\$(?!\$)(.*?)(?<!\$)\$(?!\$) |
Display Math
#| Input | Regular expression |
|---|
\[...\] | (?s)(?<!\\)\\\[\s*(.*?)\s*\\\] |
\\[...\\] | (?s)(?<!\\)\\\\\[\s*(.*?)\s*\\\\\] |
$$...$$ | (?s)(?<!\$)\$\$(?!\$)\s*(.*?)\s*(?<!\$)\$\$(?!\$) |
equation environment | (?s)\\begin\{equation\*?\}\s*(.*?)\s*\\end\{equation\*?\} |
Each expression captures the formula body in group 1. Depending on the tool,
reference it as $1 or \1.