在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Mathpix/mathpix-markdown-it开源软件地址(OpenSource Url):https://github.com/Mathpix/mathpix-markdown-it开源编程语言(OpenSource Language):JavaScript 94.2%开源软件介绍(OpenSource Introduction):mathpix-markdown-itWhat is Mathpix Markdown?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:
Mathpix Markdown Syntax referenceClick here for the full syntax reference. How to edit mmd files?Mathpix Markdown is an open format with multiple implementations:
How is Mathpix Markdown different from regular Markdown?Mathpix Markdown addresses these limitations by adding support for the following standard Latex syntax elements which are already familiar to the scientific community:
What is mathpix-markdown-it?mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries:
QuickstartInstallationnpm usage: $ npm install mathpix-markdown-it yarn usage: $ yarn add mathpix-markdown-it How to useReact usagemathpix-markdown-it components usageWe 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>
);
}
} MathpixMarkdownModel methods usageExample of render() method usageimport * 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; Example of markdownToHTML() method usageclass 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>
);
}
} Latex to mathml/asciimath/tsv conversionExample of Latex to mathml/asciimath/tsv conversionRendering methods have the ability to convert 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);
For <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 <div class="table_ tabular">
<table id="tabular">...</table>
<tsv style="display: none">...</tsv>
</div> Then calling the For [
{
"type": "mathml",
"value": "<math>...</math>"
},
{
"type": "asciimath",
"value": "x^(x)"
},
{
"type": "latex",
"value": "x^x"
},
{
"type": "svg",
"value": "<sgv>...</svg>"
}
] For [
{
"type": "html",
"value": "<table>...</table>"
},
{
"type": "tsv",
"value": "<tsv>...</tsv>"
}
] Example of outMath option usageFor 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);
<div>
<span class="math-inline">
<asciimath style="display: none;">x^(x)</asciimath>
<mjx-comtainer class="MathJax" jax="SVG"><svg>...</svg></mjx-comtainer>
</span>
</div>
[
{
"type": "asciimath",
"value": "x^(x)"
},
{
"type": "svg",
"value": "<sgv>...</svg>"
}
] For 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>
[
{
type: 'tsv',
value: '1\t2\t3\n4\t5\t6\n7\t8\t9'
}
] Example of the include_sub_math option usage for tables containing nested tables and formulasparseMarkdownByHTML(html: string, include_sub_math: boolean = true)By default, the include_sub_math option is enabled, and as a result will contain formats for the nested table and math.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);
[
{
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 ></svg>' }
] If you set the include_sub_math option in the false, then as a result, will not contain formats for all the nested table and math.const options = {
outMath: {
include_asciimath: true,
include_mathml: true,
include_latex: true,
include_svg: true,
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论