Hugo Cosmos support LaTeX \LaTeX L A T E X using KaTeX \KaTeX K A T E X , you can include complex mathematical formulae into your web page, either inline or centred on its own line. Since KaTeX \KaTeX K A T E X relies on server side rendering, it produces the same output regardless of your browser or your environment. Formulae can be shown either inline or in display mode.
The following code sample produces a text line with three inline formulae:
1
When $ a \ne 0 $ , there are two solutions to $ ax^2 + bx + c= 0 $ and they are $ x = {- b \pm \sqrt{b^2 - 4 ac} \over 2 a}$ .
When a ≠ 0 a \ne 0 a = 0 , there are two solutions to a x 2 + b x + c = 0 ax^2 + bx + c= 0 a x 2 + b x + c = 0 and they are x = − b ± b 2 − 4 a c 2 a x = {-b \pm \sqrt{b^2-4ac} \over 2a} x = 2 a − b ± b 2 − 4 a c .
The following code sample produces an introductory text line followed by a formula numbered as (1) residing on its own line:
1
2
3
4
The probability of getting $k$ heads when flipping $n$ coins is:
```math
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
```
The formula itself is written inside a GLFM math block . The above code fragment renders to:
The probability of getting k k k heads when flipping n n n coins is:
P ( E ) = ( n k ) p k ( 1 − p ) n − k (1) \tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k} P ( E ) = ( k n ) p k ( 1 − p ) n − k (1)
Warning
math code blocks are only supported as of hugo version 0.93.
In case of hugo version 0.92 or lower, use this code snippet with $$ delimiter to display the formula:
1
2
3
$$
\tag* {( 1 ) } P( E) = {n \choose k} p^k ( 1 - p) ^{n- k}
$$
P ( E ) = ( n k ) p k ( 1 − p ) n − k (1)
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
P ( E ) = ( k n ) p k ( 1 − p ) n − k (1)
Tip
This wiki page provides in-depth information about typesetting mathematical formulae using the LaTeX \LaTeX L A T E X typesetting system.
Hugo enable KaTeX \KaTeX K A T E X automatically by default. If you want to use math formulae in your page, you need to manually activate KaTeX \KaTeX K A T E X support. The easiest way to do so is to add a math attribute to the frontmatter of your page and set it to true:
Additionally, you can disable KaTeX \KaTeX K A T E X support inside config.toml, if needed:
1
2
3
[params .katex ]
# enable/disable KaTeX support, default true
enable = false
Here is the default delimiter option for KaTeX \KaTeX K A T E X in hugo cosmos:
1
2
3
4
5
6
7
8
renderMathInElement (document.querySelector (`.post-content` ), {
delimiters : [
{ left : "$$" , right : "$$" , display : true },
{ left : "$" , right : "$" , display : false },
{ left : "\\(" , right : "\\)" , display : false },
{ left : "\\[" , right : "\\]" , display : true }
]
});
For a complete list of options and their detailed description, have a look at the documentation of KaTeX’ s {\KaTeX}’s K A T E X ’ s Rendering API options and of KaTeX’ s {\KaTeX}’s K A T E X ’ s configuration options .
1
f(x) = \int _{-\infty }^\infty\hat f(\xi )\, e^{2 \pi i \xi x}\, d\xi
f ( x ) = ∫ − ∞ ∞ f ^ ( ξ ) e 2 π i ξ x d ξ f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi f ( x ) = ∫ − ∞ ∞ f ^ ( ξ ) e 2 πi ξ x d ξ
1
2
3
4
\begin {matrix}
a & b \\
c & d
\end {matrix}
a b c d \begin{matrix}
a & b \\
c & d
\end{matrix} a c b d
1
2
3
4
\begin {array}{cc}
a & b \\
c & d
\end {array}
a b c d \begin{array}{cc}
a & b \\
c & d
\end{array} a c b d
1
2
3
4
\begin {pmatrix}
a & b \\
c & d
\end {pmatrix}
( a b c d ) \begin{pmatrix}
a & b \\
c & d
\end{pmatrix} ( a c b d )
1
2
3
4
\begin {bmatrix}
a & b \\
c & d
\end {bmatrix}
[ a b c d ] \begin{bmatrix}
a & b \\
c & d
\end{bmatrix} [ a c b d ]
1
2
3
4
\begin {vmatrix}
a & b \\
c & d
\end {vmatrix}
∣ a b c d ∣ \begin{vmatrix}
a & b \\
c & d
\end{vmatrix} a c b d
1
2
3
4
\begin {Vmatrix}
a & b \\
c & d
\end {Vmatrix}
∥ a b c d ∥ \begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix} a c b d
1
2
3
4
\begin {Bmatrix}
a & b \\
c & d
\end {Bmatrix}
{ a b c d } \begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix} { a c b d }
1
2
3
4
5
6
7
\def\arraystretch {1.5}
\begin {array}{c:c:c}
a & b & c \\ \hline
d & e & f \\
\hdashline
g & h & i
\end {array}
a b c d e f g h i \def\arraystretch{1.5}
\begin{array}{c:c:c}
a & b & c \\ \hline
d & e & f \\
\hdashline
g & h & i
\end{array} a d g b e h c f i
1
2
3
4
x = \begin {cases}
a &\text {if } b \\
c &\text {if } d
\end {cases}
x = { a if b c if d x = \begin{cases}
a &\text{if } b \\
c &\text{if } d
\end{cases} x = { a c if b if d
1
2
3
4
\begin {rcases}
a &\text {if } b \\
c &\text {if } d
\end {rcases}=>...
a if b c if d } = > . . . \begin{rcases}
a &\text{if } b \\
c &\text{if } d
\end{rcases}=>... a c if b if d } => ...
1
2
3
4
5
\begin {equation}
\begin {split} a &=b+c\\
&=e+f
\end {split}
\end {equation}
a = b + c = e + f \begin{equation}
\begin{split} a &=b+c\\
&=e+f
\end{split}
\end{equation} a = b + c = e + f
1
2
3
4
\begin {align}
a&=b+c \\
d+e&=f
\end {align}
a = b + c d + e = f \begin{align}
a&=b+c \\
d+e&=f
\end{align} a d + e = b + c = f
1
2
3
4
\begin {gather}
a=b \\
e=b+c
\end {gather}
a = b e = b + c \begin{gather}
a=b \\
e=b+c
\end{gather} a = b e = b + c
1
2
3
4
\begin {alignat}{2}
10&x+&3&y=2\\
3&x+&13&y=4
\end {alignat}
10 x + 3 y = 2 3 x + 13 y = 4 \begin{alignat}{2}
10&x+&3&y=2\\
3&x+&13&y=4
\end{alignat} 10 3 x + x + 3 13 y = 2 y = 4
Author
Houmin Wei
Publish
January 5, 2023
LastMod
July 11, 2023
(8d68658)
License
本作品采用 CC BY-NC-ND 4.0 许可协议进行许可,转载时请注明原文链接
如果你在浏览博客的过程中发现了任何问题,欢迎在对应文章下评论。如果你有其他事情想要咨询,可以通过邮件联系我。