Home Comments Thread
New Thread

The Best Way to Support LaTeX Math in Markdown with MathJax - Protect math as code, and remove those code tags via JavaScript later | /en/2018/07/latex-math-markdown/

yihui yihui 2022-12-17 05:39:20

The Best Way to Support LaTeX Math in Markdown with MathJax - Protect math as code, and remove those code tags via JavaScript later

https://yihui.org/en/2018/07/latex-math-markdown/

👍 1

8 Comments

giscus-bot giscus-bot 2022-12-17 05:39:21
Guest *Ha-yeon Deborah Lee* @ 2019-02-12 17:59:35 originally posted:

Good! Thanks

giscus-bot giscus-bot 2022-12-17 05:39:21
Guest *João Carvalho* @ 2019-11-25 13:20:32 originally posted:

Hi Xie and thanks for the great article and the Xmin theme (I've borrowed it and add some modification for my website).
Just a question, when using a typical markdown editor, if you write the math expressions in between backticks everything gets badly formatted. Do you have any solution for this, or just check your rendered output in a browser?

yihui yihui 2022-12-17 05:39:27

Check the rendered output in a browser. LiveReload can help a lot: https://bookdown.org/yihui/blogdown/livereload.html

Originally posted on 2019-11-25 15:10:19

giscus-bot giscus-bot 2022-12-17 05:39:22
Guest *Gu Junhua* @ 2019-11-25 15:28:11 originally posted:

Thank you for this article and I steal the code :-)

giscus-bot giscus-bot 2022-12-17 05:39:23
Guest *Matthijs Kooijman* @ 2019-12-09 17:50:00 originally posted:

Great writeup! I've been trying your script and it works fine. However, it does not exactly what I want (I would like to use indented blocks for centered formulas rather than backticks). I considered modifying the script, but also wondered: Would it not be possible to, rather than preprocess the document to let MathJax find the math text normally, to call MathJax directly and maybe pass a list of nodes to process, or otherwise configure it to just process the code as expected?

Turns out this is indeed possible, so I wrote a small blogpost with an alternative implementation here: https://www.stderr.nl/Blog/Blog/MathJaxInMarkdown.html

yihui yihui 2022-12-17 05:39:28

Thanks a lot for sharing your approach! It does look like better than mine!

Originally posted on 2019-12-10 19:05:22

giscus-bot giscus-bot 2022-12-17 05:39:24
Guest *XueSong Ye* @ 2020-04-16 04:10:04 originally posted:

Maybe you can consider switching to https://github.com/yuin/goldmark? It has great math extension goldmark-mathjax which supports inline math using the $ delimiter and block math using the $$ delimiter.

yihui yihui 2022-12-17 05:39:29

Thanks a lot for letting me know! My solution in this post is a general one, and doesn't depend on a specific Markdown rendering engine. If I decide not to use Hugo someday (which is unlikely, I think), I can still use this solution.

Originally posted on 2020-04-16 15:48:17

giscus-bot giscus-bot 2022-12-17 05:39:26
Guest *Scott* @ 2021-11-30 11:58:37 originally posted:

Thanks for all the work you do ! Do you think it will be possible at some point to support color in equations in Rmd documents and presentations? Like this: https://twitter.com/mdekstrand/status/1373400822470504451

yihui yihui 2022-12-17 05:39:31

Whether this is possible is up to MathJax. I don't know if MathJax supports colors. You may do a quick search.

Originally posted on 2021-11-30 17:43:32

Sign in to join the discussion

Sign in with GitHub