首页 > 解决方案 > Mathjax 配置乳胶到中心

问题描述

我正在尝试在 javascript 中使用 mathjax-node 。

正如你在图片中看到的,我想让 tex 居中而不是离开。

这是渲染的图片

mathjax-node 上是否有任何配置?

我尝试将 text-align 和 displayAlign 居中,但它不起作用。

function convert(tex, options, callback) {
    mathjax.typeset({
        width: options.width,
        ex: 10,
        math: tex,
        format: "TeX",
        // style: "text-align: center;",
        svg: true, // SVG output
        linebreaks: true,
    }, function (data) {
        if (data.errors) return callback(data.errors);
        callback(undefined, data.svg);
    });
}


const mathjax = require('mathjax-node');
mathjax.config({
    TeX: {
        extensions: ["color.js"]
    },
    MathJax: {
        displayAlign: "center",
        // 'text-align': "center"
        extensions: ["TeX/color.js"],
        'fast-preview':{disabled:false}
    },
});
mathjax.start();

这是 mathjax.typeset 和 config 的代码

标签: javascriptmathjax

解决方案


在显示模式下编写 MathJax 时,MathJax 会自动为您将 MathJax 代码居中。

要在显示模式下打印方程,请使用以下分隔符之一:[ ... ]、\begin{displaymath} ... \end{displaymath} 或 \begin{equation} ... \end{equation}。$$ ... $$ 不鼓励使用,因为它可能会给出不一致的间距,并且可能不适用于某些数学包。

<p>
The mass-energy equivalence is described by the famous equation
\[ E=mc^2 \]
discovered in 1905 by Albert Einstein. 
In natural units (\(c = 1 \)), the formula expresses the identity
\begin{equation}
E=m
\end{equation}
</p>

<script type="text/javascript" async  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

上面的例子和引用来自这里

这是一种非常快速的使数学居中的方法,因为不需要额外的配置。


推荐阅读