Add TeX math equations to your Markdown documents rendered by markdown-it parser. KaTeX is used as a fast math renderer.
-
markdown-it-texmathreached 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.
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.
- Macro support
- Simple formula numbering
- Inline math with tables, lists and blockquote.
- User setting delimiters:
'dollars'(default)- inline:
$...$or$$...$$ - display:
$$...$$ - display + equation number:
$$...$$ (1)
- inline:
'brackets'- inline:
\(...\) - display:
\[...\] - display + equation number:
\[...\] (1)
- inline:
'doxygen'- inline:
\f$...$\f - display:
\f[...\f] - display + equation number:
\f[...\f] (1)
- inline:
'gitlab'- inline:
$`...`$ - display:
```math ... ``` - display + equation number:
```math ... ``` (1)
- inline:
'julia'- inline:
$...$or``...`` - display:
```math ... ``` - display + equation number:
```math ... ``` (1)
- inline:
'kramdown'- inline:
$$...$$ - display:
$$...$$ - display + equation number:
$$...$$ (1)
- inline:
'beg_end'(display math only)- inline: N/A
- display:
begin{...}...end{...} - display + equation number: N/A
View a test table.
Install the extension. Verify having markdown-it and katex already installed .
npm install markdown-it-texmath
Use it with JavaScript.
const tm = require('markdown-it-texmath');
const md = require('markdown-it')({html:true})
.use(tm, { engine: require('katex'),
delimiters: 'dollars',
katexOptions: { macros: {"\\RR": "\\mathbb{R}"} } });
const str = "Euler\'s identity $e^{i\\pi}+1=0$ is a beautiful formula in $\\RR^2$.";
md.render(str);<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css">
<link rel="stylesheet" href="../css/texmath.css">
<script src="https://cdn.jsdelivr.net/npm/markdown-it/dist/markdown-it.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js"></script>
<script src="../texmath.js"></script>
<title>test</title>
</head>
<body>
<div id="out"></div>
<script>
const str = `"Euler\'s identity $e^{i\\pi}+1=0$ is a beautiful formula in $\\RR^2$."`
document.addEventListener("DOMContentLoaded", () => {
const md = markdownit({html:true})
.use(texmath, { engine: katex,
delimiters: 'dollars',
katexOptions: { macros: {"\\RR": "\\mathbb{R}"} } } );
out.innerHTML = md.render(str);
})
</script>
</body>
</html>Use following links for texmath.js and texmath.css
https://cdn.jsdelivr.net/npm/markdown-it-texmath/texmath.min.jshttps://cdn.jsdelivr.net/npm/markdown-it-texmath/css/texmath.min.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.
nothing yet
-
Support of inline syntax of display math ?
- Inline syntax of display math with
dollarsmode 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.
- Inline syntax of display math with
-
Multiline diplay math in
blockquoteblock possible ?- Display math inside of
blockquoteblocks is able to span multiple lines with version "0.7.3".
- Display math inside of
-
markdown-it-texmathwith React Native does not work, why ?markdown-it-texmathis using regular expressions withy(sticky) property and cannot avoid this. The use of theyflag in regular expressions means the plugin is not compatible with React Native (which as of now doesn't support it and throws an errorInvalid flags supplied to RegExp constructor).
-
Why doesn't
markdown-it-texmathwork with other engines ?markdown-it-texmathis 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.
- Update to KaTeX version
0.15.6. - Update to
markdown-it13.0.1. - Bug fixed in level handling with
markdown-it. Thanks to williamstein. - Bug fixed in mapping with
markdown-it. Thanks to williamstein. - Supporting native
begin{..}/end{...}environments as delimiters itself. Thanks to williamstein for proposing. - Merging different delimiters for simultaneous use via
delimiters:[<delims1>, <delims2>]. Thanks to tlylt for proposing.
- Redundant
</math>end-tag with display-mode equations removed. All modes were affected ... invisible effect though. Thanks to yuanbug for reporting.
- Small bug in 'dollars' inline-display-mode regex fixed.
- More Optimization done with the 'dollars' regexes.
- Optimizing the 'dollars' regexes. Thanks to Erik Demaine.
- Adding 'doxygen' delimiters support. (#31). Thanks to arwedus.
- Fixing newline bug in 'dollars' regexes. (#32).
- Fixing disability to include escaped dollar when using dollars delimiters (#32).
- potential XSS vulnerability with equation numbers fixed (#29).
- KaTeX options
{katexOptions:...}within markdown-it-texmath options are directly handed over to katex. See KaTeX options. Thanks to Kirill for pull request. - Potential error message XSS vulnerability fixed. Thanks to CatNose.
- Using new boolean markdown-it-texmath
outerSpaceoption, inline rulesdollarsexplicitly require surrounding spaces when set totrue(default isfalsefor backwards compatibility). This is primarily a guard against misinterpreting single$'s in normal markdown text. - Update to KaTeX version 0.13.11.
- Infinite loop bug with
gitlabmode and display math insideblockquotesection removed. - Fundamental redesign of display math implementation.
- Update to KaTeX version 0.12.0.
- Regex bug with
gitlabmode removed.
- Experimental
pandocmode removed. Enhanceddollarsmode now does, whatpandocmode was requiring. - With
dollarsmode 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
blockquoteblocks removed.
- Now display math inside of
blockquoteblocks can span multiple lines, provided that every line starts with a>character. - Possible cause of [blockquote bug(goessner/mdmath#50)] presumably eliminated.
- Update to
markdown-itversion 11.0.0
- Now supporting katex options. Thanks goto Kirill.
- Removed a small bug in activation method.
- Hand instance of
katexover tomarkdown-it-texmathusingoptions.engineobject. Works withnode.jsand browsers. Withnode.jsoptions.engineentry{ engine:'katex' }as a string also works. - As a consequence of the topic before, the
usemethod ofmarkdown-it-texmathis deprecated now. - Add beta support for Pandoc syntax on request. Here waiting for test results.
- Using jsdelivr as cdn from now on.
- Add support for Julia Markdown on request.
- Remove pathological bug within blockquotes.
- Add support for Tex macros (https://katex.org/docs/supported.html#macros) .
- Bug with brackets delimiters .
- Add support for Kramdown .
- Fatal blockquote bug investigated. Implemented workaround to vscode bug, which has finally gone with vscode 1.26.0 .
- Escaped underscore bug removed.
- Backslash bug removed.
- Modifying the
blockmode regular expression withgitlabdelimiters, so removing thenewlinebug.
markdown-it-texmath is licensed under the MIT License