macdown
macdown copied to clipboard
Support for GitLab flavored markdown math syntax
GitLab now supports embedded KaTeX rendering but uses a different syntax:
Inline:
$`x^2`$
Block:
```math
x^2
```
It would be nice if there was an option to enable this syntax variant so that I can use MacDown to edit my GitLab-hosted markdown documents.
See https://docs.gitlab.com/ee/user/markdown.html#math
Hmm, really odd syntax…
Yup.
I really hate the triple tick + name syntax here. I mentioned this in #625#issuecomment-238119135, but this is more pervasive than I thought.
Anyway I think this is currently not structurally possible because we can’t route block syntax to two (or more) different semantics. The code block rendering feature needs a rewrite anyway, but I can’t find time (and energy) to do it… :(
Would it be feasible to just support the inline syntax?
@analog-cbarber That seems possible. Could you provide some insights on how edge cases should be rendered? Some examples from the top of my head:
$` math `$(also variants with only space on one side, or multiple spaces on one of both sides)$``math`$$`math``$(also more unmatched ticks)$``math``$(matching multiple ticks)
I don't know if this is documented anywhere but here is what I can observe experimentally:
It appears that any number of backticks may be used as long as they are matched and there is no space between the ticks and the $.
Spaces between the ticks and the math expression are thrown away when rendered.
Cool, thanks! It seems GitLab use the same rules for inline code and math backticks (yes, inline code has the same behaviour; not many people know this). I’ll try and see what I can come up with this rule.
It is not be hard to extend hoedown to support both the backtick syntax and the fenced syntax, but you probably don't want to depend on a forked version, so I guess I should see if I can get this into hoedown?
I forked hoedown and implemented this feature, but it doesn't look like the original project is actively maintained anymore. I doubt they will accept a pull request.
see analog-cbarber/hoedown@d97e1938
The best option is probably to officially (@MacDownApp) maintain a fork for now, and prepare to move to another Markdown parser in the future (see #704). I’m doing that now so you can submit a pull request there.
Any chance this will move forward anytime soon? AFAICT GitLab is the only service which supports rendering of LaTeX in any form (at least, in .md files, I think through GitHub you can view Jupyter notebooks with Latex in them but that's a bit of a bother).
For now it seems the only reasonable workflow is to use the online GitLab editor to modify a raw .md file and switch to the preview to check the math rendering.
It would be great if there was a way to do this offline. Interested in any workarounds that people are using..