executablebooks / MyST-Parser

An extended commonmark compliant parser, with bridges to docutils/sphinx
https://myst-parser.readthedocs.io
MIT License
741 stars 196 forks source link

Re-add support for \[, \], \(, and \) #941

Open ethanc8 opened 3 months ago

ethanc8 commented 3 months ago

Describe the feature you'd like to request

I'd like to be able to start and end equations using \[ \] and \( \). This was removed in 34.1. This would increase consistency with the amsmath extension, as users could then feel free to use all of the most common equation delimiters, $, $$, \(, \[, \begin{equation}, and \begin{equation*}, in either LaTeX or MyST. This is especially important given that it's considered bad style or deprecated to use $ and $$ in LaTeX.

My current use case is in generating API documentation from docstrings which were generated using Doxygen Markdown. I don't strictly need this feature, as I've just been replacing \[ with \begin{equation*} using a Python script (https://github.com/ethanc8/opencv-doc-parser), but it generally seems useful and reduces astonishment. Additionally, various other Markdown extensions include \[ \] and \( \), for example Mathpix Markdown, which Facebook's Nougat OCR outputs to.

Describe the solution you'd like

A syntax extension bracketmath that can be turned on when dollarmath is turned on, which allows to start and end equations using \[ \] and \( \). When amsmath is turned on, bracketmath should also be turned on, so that all of the LaTeX equation-starting macros are supported.

Describe alternatives you've considered

No response

chrisjsewell commented 2 months ago

I'm afraid I'm -1 on this; backslashes \ in commonmark have a special meaning of "escaping syntax" so these syntaxes would have a clear incompatibility with spec examples like https://spec.commonmark.org/0.30/#example-562

More so, there should really just be one clear way to add math in myst, and that is with the math directive:

```{math}
a + b = c


the dollar syntax, which was already moved out of "core" myst and into an extension, is really just there as a compromise for people writing jupyter notebooks, where dollar math is unfortunately the norm.
Even this is already problematic in the way it defers parsing to mathjax: https://github.com/jupyterlab/jupyterlab/issues/8645