LaTeX support with KaTeX
Hugo Cosmos support $\LaTeX$ using $\KaTeX$ , you can include complex mathematical formulae into your web page, either inline or centred on its own line. Since $\KaTeX$ 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.
Inline Mode
The following code sample produces a text line with three inline formulae:
|
|
When $a \ne 0$, there are two solutions to $ax^2 + bx + c= 0$ and they are $x = {-b \pm \sqrt{b^2-4ac} \over 2a}$.
Display Mode
The following code sample produces an introductory text line followed by a formula numbered as (1)
residing on its own line:
|
|
The formula itself is written inside a GLFM math block. The above code fragment renders to:
The probability of getting $k$ heads when flipping $n$ coins is:
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:
|
|
$$ \tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k} $$
This wiki page provides in-depth information about typesetting mathematical formulae using the $\LaTeX$ typesetting system.
Configuration
Hugo enable $\KaTeX$ automatically by default. If you want to use math formulae in your page, you need to manually activate $\KaTeX$ 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$ support inside config.toml
, if needed:
|
|
Here is the default delimiter option for $\KaTeX$ in hugo cosmos:
|
|
For a complete list of options and their detailed description, have a look at the documentation of ${\KaTeX}’s$ Rendering API options1 and of ${\KaTeX}’s$ configuration options2.
Examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reference
alipay
Author Houmin Wei
Publish January 5, 2023
LastMod July 11, 2023 (8d68658)
License 本作品采用 CC BY-NC-ND 4.0 许可协议进行许可,转载时请注明原文链接
如果你在浏览博客的过程中发现了任何问题,欢迎在对应文章下评论。如果你有其他事情想要咨询,可以通过邮件联系我。
-
No backlinks found.