Math Equations
CodeHarborHub documentation supports mathematical equations using KaTeX. KaTeX allows you to write LaTeX-style math directly inside Markdown files for clean, professional rendering.
See configuration to enable this feature.
Usageβ
Please read the KaTeX documentation for detailed syntax. Below are the most common use-cases.
Inline Equationsβ
For inline math, wrap the LaTeX expression in single dollar signs:
Let $f\colon[a,b]\to\R$ be Riemann integrable.
Let $F\colon[a,b]\to\R$ be $F(x)=\int_{a}^{x} f(t)\,dt$.
Then $F$ is continuous, and where $f$ is continuous, $F'(x)=f(x)$.
Let be Riemann integrable.
Let be .
Then is continuous, and where is continuous, .
Block Equationsβ
For display-mode equations, use double dollar signs on separate lines:
$$
I = \int_0^{2\pi} \sin(x)\,dx
$$
Enabling Math Equationsβ
To render equations, install and configure the required plugins.
1. Install Pluginsβ
Use the latest KaTeX-compatible versions:
npm install --save remark-math@6 rehype-katex@7
For Docusaurus v3 (MDX v3), use remark-math@6
and rehype-katex@7
. Other versions may not work properly.
2. Configure docusaurus.config.js
β
These plugins are ES Modules only, so we recommend using an ESM config file:
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
export default {
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
path: 'docs',
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
},
},
],
],
};
Using CommonJS?
You can dynamically import ES modules with an async config:
module.exports = async function createConfigAsync() {
return {
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
path: 'docs',
remarkPlugins: [(await import('remark-math')).default],
rehypePlugins: [(await import('rehype-katex')).default],
},
},
],
],
};
};
3. Add KaTeX Stylesheetβ
Include the KaTeX CSS for proper rendering:
export default {
// ...
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/katex@0.13.24/dist/katex.min.css',
type: 'text/css',
integrity:
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
crossorigin: 'anonymous',
},
],
};
Complete Example
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
export default {
title: 'CodeHarborHub',
tagline: 'Empowering Developers to Learn & Build',
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
path: 'docs',
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
},
},
],
],
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/katex@0.13.24/dist/katex.min.css',
type: 'text/css',
integrity:
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
crossorigin: 'anonymous',
},
],
};
Self-Hosting KaTeX Assetsβ
For maximum control or offline support, you can self-host KaTeX:
- Download the latest KaTeX release.
- Copy
katex.min.css
and the requiredfonts
(usually.woff2
is sufficient) into your siteβsstatic
directory. - Update the stylesheet path in
docusaurus.config.js
:
export default {
stylesheets: [
{
href: '/katex/katex.min.css',
type: 'text/css',
},
],
};