问题描述
我正在尝试在 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 时,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>
上面的例子和引用源自here。
这是一种让数学居中的非常快速的方法,因为不需要额外的配置。