在博客中使用MathJax写数学公式

2023-03-07,,

前言

总结一些在博客园使用MathJax数学公式的经验。

博客园

设置使用数学公式

进入你的博客:管理 > 选项

里面有个启用数学公式支持,选上后保存。

这时,你就可以在你的博客里写数学公式了。

美化数学公式

本文中数学公式的显示风格和默认的不同。

数学公式的背景色为浅灰;

行间数学公式有个灰色框;

行间数学公式设定为居左;

行间数学公式带编号。

下面是对应的配置。

进入你的博客管理 > 配置

页首脚tml代码中输入一下内容:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
},
displayAlign : "left",
TeX: {
equationNumbers: {
autoNumber: "all",
useLabelIds: true
}
},
"HTML-CSS": {
linebreaks: {
automatic: true
},
scale: 100,
styles: {
".MathJax_Display": {
"text-align": "left",
"width" : "auto",
"margin": "10px 0px 10px 0px !important",
"background-color": "#f5f5f5 !important",
"border-radius": "3px !important",
border: "1px solid #ccc !important",
padding: "5px 5px 5px 5px !important"
},
".MathJax": {
"background-color": "#f5f5f5 !important",
padding: "2px 2px 2px 2px !important"
}
}
},
SVG: {
linebreaks: {
automatic: true
}
}
});
</script>
<!--
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
-->

注意:如果你发现保存后,输入的内容丢失了。这是因为默认情况下不能在页脚Html代码使用JS.

配置页面上有个申请使用JS的按钮(具体的按钮标签记不清了),

点击这个按钮,输入申请理由,比如:“需要使用MathJax写数学公式”, 然后等管理员批准之后,就可以输入了。

参照

如果你想配置你的特有风格,可以参照这里:

Loading and Configuring MathJax
The TeX input processor
CSS Style Objects

LaTex 语法

行内

一个行内$f(x)$函数.

一个行内\(f(x)\)函数
行间

一个行间

$$f(x)$$

函数

一个行间

\[f(x)
\]

函数

一些例子

LaTex Syntax Sample Description
a \qquad b \(a \qquad b\) double quad space
a \quad b \(a \quad b\) quad space
a\ b$ \(x_i\) subscript
\text{subject to} \(\text{subject to}\) text
e^{i\pi} \(e^{i\pi}\) upperscript
x_i^2 \(x_i^2\) subscript and upperscript
\sqrt{2} \(\sqrt{2}\) square root
\frac{1}{2} \(\frac{1}{2}\) fraction
\textstyle \sum_{i=1}^n w_ix_i \(\textstyle \sum_{i=1}^n w_ix_i\) sum
\displaystyle \sum_{i=1}^n w_ix_i \(\displaystyle \sum_{i=1}^n w_ix_i\) sum
\because \(\because\) because
\therefore \(\therefore\) therefore
= \(=\) equal to
> \(>\) great than
< \(<\) great than
\geqslant \(\geqslant\) great than and equal to
\leqslant \(\leqslant\) less than and equal to
\geq \(\geq\) great than and equal to
\leq \(\leq\) less than and equal to
\neq \(\neq\) not equal to
\lVert w \rVert \(\lVert w \rVert\) vertical
\langle x, y \rangle \(\langle x, y \rangle\) angle
\underset{a}{max} \(\underset{a}{max}\) under set
\bar{\gamma} \(\bar{\gamma}\) bar

multiple lines

b =
\begin{cases}
b_1, & \text{if}\ b_1 > 0 \\
b_2, & \text{if}\ b_2 > 0 \\
\frac{b_1 + b_2}{2} & \text{otherwise}
\end{cases}

\[b =
\begin{cases}
b_1, & \text{if}\ b_1 > 0 \\
b_2, & \text{if}\ b_2 > 0 \\
\frac{b_1 + b_2}{2} & \text{otherwise}
\end{cases}
\]

LaTex资源

Help:Displaying a formula
LaTeX Wiki
List of LaTeX symbols
LaTeX/数学公式
LaTeX documentation

在博客中使用MathJax写数学公式的相关教程结束。

《在博客中使用MathJax写数学公式.doc》

下载本文的Word格式文档,以方便收藏与打印。