mathpix-markdown is a superset of Markdown that adds helpful syntax for the STEM community, such as advanced equation, table, and chemistry support. Wherever possible, we borrow syntax from LaTeX. In other cases (such as chemistry) we invent new syntax that is backward compatible with Markdown.
Here are the key benefits over plain Markdown:
Click here for the full syntax reference.
Mathpix Markdown is an open format with multiple implementations:
mathpix-markdown-it
npm library to render STEM content on your websiteMathpix Markdown addresses these limitations by adding support for the following standard Latex syntax elements which are already familiar to the scientific community:
\( <latex math> \)
\[ <latex math> \]
or $$ <math> $$
\begin{tabular} ... \end{tabular}
\begin{figure} \caption{...} ... \end{figure}
\begin{itemize} ... \end{itemize}
and ordered lists via \begin{enumerate} ... \end{enumerate}
\begin{elem} ... \end{elem}
and \begin{elem*} ... \end{elem*}
where elem=equation|align|split|gather
\label
, \ref
, \eqref
, \tag
\title{...}
, \author{...}
, \begin{abstract}...\end{abstract}
, \section{Section Title}
, \subsection{Section Title}
, \subsubsection{Section Title}
, \textit{italicized text}
, \textbf{bold text}
, \url{link}
<smiles>OC(=O)c1cc(Cl)cs1</smiles>
or```smiles
OC(=O)c1cc(Cl)cs1
```
{ width=50% }
{ width="36px" }
{width="20px",height="20px"}
{width="20px",height="20px",right}
{width="20px",height="20px", align="left"}
\newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \begin{theorem} Let \(f\) be a function whose derivative exists in every point, then \(f\) is a continuous function. \end{theorem} \begin{lemma} Given two line segments whose lengths are \(a\) and \(b\) respectively there is a real number \(r\) such that \(b=ra\). \end{lemma} \begin{proof} To prove it by contradiction try and assume that the statement is false, proceed from there and at some point you will arrive to a contradiction. \end{proof}
Footnote marker without text. Auto increment counter to 1 \footnotemark{} should be 1. Footnote marker with text. Auto increment counter to 2 \footnotemark{} be 2. \footnotetext{text should be 2} Auto increment counter to 3 \footnote{text should be 3} Auto increment counter to 4 \footnote{text should be 4} Footnote marker without text. Auto increment counter to 5 \footnotemark{} should be 5. Footnote marker with text. Auto increment counter to 6 \footnotemark{} should be 6. \footnotetext{text should be 6} Auto increment counter to 7 \footnote{text should be 7} Auto increment counter to 8 \footnote{text should be 8}
Underline text: \underline{Underlined text!} Underline text: \uline{Underlined text!} Double underline text: \underline{\underline{Double underlined text!}} Double underline text: \uuline{Double underlined text!} Wavy underlined text: \uwave{This text is underlined with a wavy line!} Dashed underline text: \dashuline{Dashed Underline} Dotted underline text: \dotuline{Dotted Underline} Strikethrough text: \sout{Text with a horizontal line through its center!} Struck with Hatching text: \xout{Text with hatching pattern!}
mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript.
It relies on the following open source libraries:
npm usage:
$ npm install mathpix-markdown-it
yarn usage:
$ yarn add mathpix-markdown-it
We provide React components which make rendering of mathpix-markdown-it easy for React applications: Full example
import {MathpixMarkdown, MathpixLoader} from 'mathpix-markdown-it'; class App extends Component { render() { return ( <MathpixLoader> <MathpixMarkdown text="\\(ax^2 + bx + c = 0\\)"/> <MathpixMarkdown text="$x = \frac { - b \pm \sqrt { b ^ { 2 } - 4 a c } } { 2 a }$"/> ... </MathpixLoader> ); } }
import * as React from 'react'; import { MathpixMarkdownModel as MM } from 'mathpix-markdown-it'; class App extends React.Component { componentDidMount() { const elStyle = document.getElementById('Mathpix-styles'); if (!elStyle) { const style = document.createElement("style"); style.setAttribute("id", "Mathpix-styles"); style.innerHTML = MM.getMathpixFontsStyle() + MM.getMathpixStyle(true); document.head.appendChild(style); } } render() { const html = MM.render('$x = \\frac { - b \\pm \\sqrt { b ^ { 2 } - 4 a c } } { 2 a }$'); return ( <div className="App"> <div className="content" dangerouslySetInnerHTML={{__html: html}}></div> </div> ) } } export default App;
class ConvertForm extends React.Component { constructor(props) { super(props); this.state = { value: '\\[\n' + 'y = \\frac { \\sum _ { i } w _ { i } y _ { i } } { \\sum _ { i } w _ { i } } , i = 1,2 \\ldots k\n' + '\\]', result: '' }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleChange(event) { this.setState({value: event.target.value}); } handleSubmit(event) { event.preventDefault(); this.setState({result: MM.markdownToHTML(this.state.value)}) } render() { return ( <div> <form onSubmit={this.handleSubmit}> <h1>Input Text with Latex:</h1> <textarea value={this.state.value} onChange={this.handleChange} /> <input type="submit" value="Convert" /> </form> <div id='preview-content' dangerouslySetInnerHTML={{__html: this.state.result}}/> </div> ); } }
Rendering methods have the ability to convert Latex
representation to such formats as: mathml
, asciimath
, tsv
const options = { outMath: { //You can set which formats should be included into html result include_mathml: true, include_asciimath: true, include_latex: true, include_svg: true, // sets in default include_tsv: true, include_table_html: true, // sets in default } }; const html = MathpixMarkdownModel.markdownToHTML(`$x^x$`, options);
markdownToHTML()
returns an HTML string that will contain the formats specified in the options.
For Latex
formulas, the result will be:
<span class="math-inline"> <mathml style="display: none">...</mathml> <asciimath style="display: none">...</asciimath> <latex style="display: none">...</latex> <mjx-comtainer class="MathJax" jax="SVG">..</mjx-comtainer> </span>
For tabular
, the result will be:
<div class="table_ tabular"> <table id="tabular">...</table> <tsv style="display: none">...</tsv> </div>
Then calling the parseMarkdownByHTML(html)
method will return all formats as a list from the incoming html string.
For Latex
formulas:
[ { "type": "mathml", "value": "<math>...</math>" }, { "type": "asciimath", "value": "x^(x)" }, { "type": "latex", "value": "x^x" }, { "type": "svg", "value": "<sgv>...</svg>" } ]
For tabular
:
[ { "type": "html", "value": "<table>...</table>" }, { "type": "tsv", "value": "<tsv>...</tsv>" } ]
For Latex
formulas:
const options = { outMath: { include_mathml: false, include_asciimath: true, include_latex: false, } }; const latex = `$x^x$`; const html = MathpixMarkdownModel.markdownToHTML(latex, options); const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html, false);
html
:
<div> <span class="math-inline"> <asciimath style="display: none;">x^(x)</asciimath> <mjx-comtainer class="MathJax" jax="SVG"><svg>...</svg></mjx-comtainer> </span> </div>
parsed
:
[ { "type": "asciimath", "value": "x^(x)" }, { "type": "svg", "value": "<sgv>...</svg>" } ]
For tabular
:
const options = { outMath: { include_table_html: false, include_tsv: true, } }; const latex = `\\begin{tabular}{ l c r } 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \\\\ \\end{tabular}`; const html = MathpixMarkdownModel.markdownToHTML(latex, options); const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html, false);
<div class="table_tabular " style="text-align: center"> <tsv style="display: none">1 2 3 4 5 6 7 8 9</tsv> </div>
parsed
:
[ { type: 'tsv', value: '1\t2\t3\n4\t5\t6\n7\t8\t9' } ]
const options = { outMath: { include_asciimath: true, include_mathml: true, include_latex: true, include_svg: true, include_tsv: true, include_table_html: true } }; const latex = `\\begin{tabular}{ l c r } 1 & {$x^1$} & 3 \\\\ 4 & {$y^1$} & 6 \\\\ 7 & {$z^1$} & 9 \\\\ \\end{tabular}`; const html = MathpixMarkdownModel.markdownToHTML(latex, options); const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html);
parsed
:
[ { type: 'html', value: '<table>..</table>' }, { type: 'tsv', value: '1\tx^(1)\t3\n4\ty^(1)\t6\n7\tz^(1)\t9' }, { type: 'mathml', value: '<math xmlns="http://www.w3.org/1998/Math/MathML">\n <msup>\n <mi>x</mi>\n <mn>1</mn>\n </msup>\n</math>' }, { type: 'asciimath', value: 'x^(1)' }, { type: 'latex', value: 'x^1' }, { type: 'svg', value: '<svg >..</svg>' }, { type: 'mathml', value: '<math xmlns="http://www.w3.org/1998/Math/MathML">\n <msup>\n <mi>y</mi>\n <mn>1</mn>\n </msup>\n</math>' }, { type: 'asciimath', value: 'y^(1)' }, { type: 'latex', value: 'y^1' }, { type: 'svg', value: '<svg ></svg>' }, { type: 'mathml', value: '<math xmlns="http://www.w3.org/1998/Math/MathML">\n <msup>\n <mi>z</mi>\n <mn>1</mn>\n </msup>\n</math>' }, { type: 'asciimath', value: 'z^(1)' }, { type: 'latex', value: 'z^1' }, { type: 'svg', value: '<svg
AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作
AI办公助手,复杂任务高效处理
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!
AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规 划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号