The fastest math typesetting library for the web.
KaTeX
How to insert formulas in a webpage? For example, $x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$.
One method is to use images, but it is extremely inconvenient. The best approach is to describe mathematical formulas in text and leave the rendering to the engine. LaTeX
is a commonly used typesetting tool, including but not limited to mathematical formulas, tables, and chemical formulas. However, our primary need is to display mathematical formulas, so we only require a subset of LaTeX
that can render mathematical formulas. KaTeX is a lightweight mathematical formula engine that supports HTML
.
File Configuration
Open the theme configuration file
_config.butterfly.yml
, disableMathJax
, and modifyKaTeX
.1# MathJax 2mathjax: 3 enable: false 4 per_page: false 5 6# KaTeX 7katex: 8 enable: true # false to load when needed, must add katex: true in the Markdown Front-matter 9 per_page: false 10 hide_scrollbar: true
Uninstall the
marked
orkramed
plugin and installhexo-renderer-markdown-it
. You can check this in thepackage.json
file.1npm un hexo-renderer-marked --save # Uninstall the marked plugin 2npm un hexo-renderer-kramed --save # Uninstall the kramed plugin 3npm i hexo-renderer-markdown-it --save # Install the rendering plugin 4npm install katex @renbaoshuo/markdown-it-katex # Install the rendering plugin
Configure in the
_config.yml
file in the root directory ofhexo
.1markdown: 2 plugins: 3 - plugin: 4 name: "@renbaoshuo/markdown-it-katex" 5 enable: true 6 options: 7 strict: false # Disable verbose warning messages from KaTeX on the command line
After successful configuration, add the parameter
katex: true
at the beginning of the article that needs rendering.