executablebooks / MyST-Parser

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

```math code block syntax #798

Closed njzjz closed 1 year ago

njzjz commented 1 year ago

Describe the feature you'd like to request

Currently GitHub markdown supports ```math code block syntax as shown below:

```math
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)

```math
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)

I'd like to know if Myst could implement the same syntax to make the behavior between GitHub and Sphinx consistent.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

chrisjsewell commented 1 year ago

Heya, See myst_fence_as_directive in https://myst-parser.readthedocs.io/en/latest/configuration.html#global-configuration, which I believe will achieve the same thing and was added for the similar case of mermaid (https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams#creating-mermaid-diagrams)

I am not in favor of having these special Github cases supported in the "base" MyST configuration, since:

  1. MyST is not only used by Github users
  2. They effectively break the syntax semantics of code fences, i.e. that ```name always means "this block is syntax highlighted in the name format" (with the singular, special MyST case that ```{name} always means "this block is treated as a name directive")

It's unfortunate that Github does take a particulary rigorous approach to adding new syntax features (they seem to not even maintain https://github.github.com/gfm/ anymore), but obviously I can understand the desire to want to have compatibility. If myst_fence_as_directive is not enough, I could imagine adding an additional extension to cover these cases: https://myst-parser.readthedocs.io/en/latest/configuration.html#id1

njzjz commented 1 year ago

See myst_fence_as_directive

Thanks, it works for me.