Add TeX math equations to your Markdown documents rendered by markdown-it parser. KaTeX is used as a fast math renderer.
What's New?
markdown-it-texmath reached quite a stable state with version 1.0 .
Native begin{...} / end{...} environments are supported as delimiters itself ... thanks to William Stein for proposing.
\begin{equation}
a^2+b^2=c^2
\end{equation}
They can even be nested.
\begin{equation}
\begin{pmatrix}
A & B \\ B & C
\end{pmatrix}
\end{equation}
Different delimiters can be merged. Delimiters options property supports array notation for that. Example: delimiters: ['dollars','beg_end']. Thanks to Liu YongLiang for proposing.
Features
Simplify the process of authoring markdown documents containing math formulas.
This extension is a comfortable tool for scientists, engineers and students with markdown as their first choice document format.
Install the extension. Verify having markdown-it and katex already installed .
npm install markdown-it-texmath
Use it with JavaScript.
consttm=require('markdown-it-texmath');constmd=require('markdown-it')({html:true}).use(tm,{engine: require('katex'),delimiters: 'dollars',katexOptions: {macros: {"\\RR": "\\mathbb{R}"}}});conststr="Euler\'s identity $e^{i\\pi}+1=0$ is a beautiful formula in $\\RR^2$.";md.render(str);
Use in Browser
<!doctype html><html><head><metacharset='utf-8'><linkrel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css"><linkrel="stylesheet" href="../css/texmath.css"><scriptsrc="https://cdn.jsdelivr.net/npm/markdown-it/dist/markdown-it.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js"></script><scriptsrc="../texmath.js"></script><title>test</title></head><body><divid="out"></div><script>conststr=`"Euler\'s identity $e^{i\\pi}+1=0$ is a beautiful formula in $\\RR^2$."`document.addEventListener("DOMContentLoaded",()=>{constmd=markdownit({html:true}).use(texmath,{engine: katex,delimiters: 'dollars',katexOptions: {macros: {"\\RR": "\\mathbb{R}"}}});out.innerHTML=md.render(str);})</script></body></html>
CDN
Use following links for texmath.js and texmath.css
markdown-it: Markdown parser done right. Fast and easy to extend.
katex: This is where credits for fast rendering TeX math in HTML go to.
ToDo
nothing yet
FAQ
Support of inline syntax of display math ?
Inline syntax of display math with dollars mode is supported starting from version "0.7.0". So 'This formula $$a+b=c$$ will result in display math presentation', i.e. gets displayed on a separate line. For true inline math use $..$ mode like before.
Multiline diplay math in blockquote block possible ?
Display math inside of blockquote blocks is able to span multiple lines with version "0.7.3".
markdown-it-texmath with React Native does not work, why ?
markdown-it-texmath is using regular expressions with y(sticky) property and cannot avoid this. The use of the y flag in regular expressions means the plugin is not compatible with React Native (which as of now doesn't support it and throws an error Invalid flags supplied to RegExp constructor).
Why doesn't markdown-it-texmath work with other engines ?
markdown-it-texmath is a personal project of mine. As it does very well with KaTeX what I want it to do, I offer it to the public as an open source plugin. I do not have time or interest to integrate other math engines.
But if someone wants to help here out, pull requests are always welcome.
Fixing disability to include escaped dollar when using dollars delimiters (#32).
[0.9.1] on July 02, 2021
potential XSS vulnerability with equation numbers fixed (#29).
[0.9.0] on May 26, 2021
KaTeX options {katexOptions:...} within markdown-it-texmath options are directly handed over to katex. See KaTeX options. Thanks to Kirill for pull request.
Using new boolean markdown-it-texmath outerSpace option, inline rules dollars explicitly require surrounding spaces when set to true (default is false for backwards compatibility). This is primarily a guard against misinterpreting single $'s in normal markdown text.
Update to KaTeX version 0.13.11.
[0.8.0] on July 10, 2020
Infinite loop bug with gitlab mode and display math inside blockquote section removed.
Fundamental redesign of display math implementation.
Update to KaTeX version 0.12.0.
[0.7.2] on June 22, 2020
Regex bug with gitlab mode removed.
[0.7.0] on June 14, 2020
Experimental pandoc mode removed. Enhanced dollars mode now does, what pandoc mode was requiring.
With dollars mode inline math expression $$..$$ will result in display math presentation now. Adding equation numbers $$..$$(1) is not supported in inline syntax.
Significant code redesign and regular expression optimization results in more compact code and performance gain ... not measured though.
Bug with display math inside of blockquote blocks removed.
[0.6.9] on June 11, 2020
Now display math inside of blockquote blocks can span multiple lines, provided that every line starts with a > character.
Possible cause of [blockquote bug(goessner/mdmath#50)] presumably eliminated.
Hand instance of katex over to markdown-it-texmath using options.engine object. Works with node.js and browsers. With node.jsoptions.engine entry { engine:'katex' } as a string also works.
As a consequence of the topic before, the use method of markdown-it-texmath is deprecated now.
Add beta support for Pandoc syntax on request. Here waiting for test results.
请发表评论