@wordpress/latex-to-mathml 是一个 WordPress 包,用于将 LaTeX 数学语法转换为 MathML 格式。它支持块级和行内模式,适用于在 WordPress 环境中处理数学公式。
import latexToMathML from '@wordpress/latex-to-mathml';
// Convert LaTeX to MathML (display mode, for block equations)
const mathML = latexToMathML( 'E = mc^2' );
// Convert LaTeX to MathML (inline mode)
const inlineMathML = latexToMathML( 'x^2', { displayMode: false } );确保 LaTeX 语法正确,否则转换会失败并抛出错误。此包专为 WordPress 和 Gutenberg 项目设计,但也可用于其他软件项目。
Convert LaTeX math syntax to MathML.
Install the module:
npm install @wordpress/latex-to-mathml --save
import latexToMathML from '@wordpress/latex-to-mathml';
// Convert LaTeX to MathML (display mode, for block equations)
const mathML = latexToMathML( 'E = mc^2' );
// Convert LaTeX to MathML (inline mode)
const inlineMathML = latexToMathML( 'x^2', { displayMode: false } );
latexToMathML( latex, options )Converts LaTeX math syntax to MathML.
latex (string): The LaTeX string to convert.options (Object): Optional conversion options.
displayMode (boolean): Whether to render in display mode (block) or inline mode. Default: true.string): The MathML string.This is an individual package that’s part of the Gutenberg project. The project is organized as a monorepo. It’s made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by WordPress as well as other software projects.
To find out more about contributing to this package or Gutenberg as a whole, please read the project’s main contributor guide.