前言
總結一些在博客園使用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寫數學公式”, 然后等管理員批准之后,就可以輸入了。
- 參照
如果你想配置你的特有風格,可以參照這里:
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} \]