https://github.com/tats-u/docusaurus-plugin-copy-katex-assets
Docusaurus plugin to copy KaTeX assets
https://github.com/tats-u/docusaurus-plugin-copy-katex-assets
docusaurus docusaurus-plugin katex
Last synced: about 1 month ago
JSON representation
Docusaurus plugin to copy KaTeX assets
- Host: GitHub
- URL: https://github.com/tats-u/docusaurus-plugin-copy-katex-assets
- Owner: tats-u
- License: other
- Created: 2025-04-13T12:56:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-05-23T01:38:17.000Z (about 2 months ago)
- Last Synced: 2026-05-23T03:26:14.531Z (about 2 months ago)
- Topics: docusaurus, docusaurus-plugin, katex
- Language: TypeScript
- Homepage: https://tats-u.github.io/docusaurus-plugin-copy-katex-assets/
- Size: 611 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docusaurus-plugin-copy-katex-assets plugin
[](https://npmjs.com/package/@tats-u/docusaurus-plugin-copy-katex-assets) [](https://npmjs.com/package/@tats-u/docusaurus-plugin-copy-katex-assets) [](https://npmjs.com/package/@tats-u/docusaurus-plugin-copy-katex-assets)
This plugin copies KaTeX assets to the build directory. This makes it unnecessary to [load KaTeX assets from the CDN](https://docusaurus.io/docs/markdown-features/math-equations).
Demo: https://tats-u.github.io/docusaurus-plugin-copy-katex-assets
## How to Use
Install the plugin:
```
npm install @tats-u/docusaurus-plugin-copy-katex-assets
```
This package exports the following plugin and companion types and variables:
| Name | Description |
| --- | --- |
| `copyKaTeXAssetsPlugin` | Docusaurus plugin to copy KaTeX assets |
| `CopyKaTeXAssetsPluginOptions` | Configuration options for the plugin |
| `defaultKaTeXStyleSheet` | Default KaTeX style sheet entry for `config.stylesheets` array |
| `getKaTeXStyleSheet` | Ditto, but with custom base URL |
| `defaultKaTeXCssPath` | Default KaTeX CSS path |
| `getKaTeXCssPath` | Ditto, but with custom base URL |
Then add the plugin to `docusaurus.config.js`:
```js
import { copyKatexAssetsPlugin, defaultKaTeXStyleSheet } from '@tats-u/docusaurus-plugin-copy-katex-assets';
/**
* @import { CopyKaTeXAssetsPluginOptions } from '@tats-u/docusaurus-plugin-copy-katex-assets';
*/
const config = {
// ...
stylesheets: [
// ...
defaultKaTeXStyleSheet,
],
plugins: [
// ...
copyKatexAssetsPlugin,
],
}
```
> [!NOTE]
> For TypeScript, use the following instead:
>
> ```ts
> import { type CopyKaTeXAssetsPluginOptions, copyKatexAssetsPlugin, defaultKaTeXStyleSheet } from '@tats-u/docusaurus-plugin-copy-katex-assets';
> ```
### Compatibility with Docusaurus Faster
This plugin is compatible with [Docusaurus Faster](https://github.com/facebook/docusaurus/issues/10556).
### Configuration
The default deployed path is `/assets/katex-{KaTeX version}/katex.min.css`. If you want to change the path, pass `assetsRoot` to the plugin:
```js
const config = {
// ...
plugins: [
// ...
[
copyKatexAssetsPlugin,
// Important: Path shall not start with `/`.
/** @satisfies {CopyKaTeXAssetsPluginOptions} */({ assetsRoot: 'assets/katex' }),
],
],
}
```
> [!NOTE]
> For TypeScript, use `{ ... } satisfies CopyKaTeXAssetsPluginOptions` instead.
If you want to use a custom base URL, pass `baseUrl` to the plugin, and use `getKaTeXStyleSheet` instead of `defaultKaTeXStyleSheet`:
```js
const baseUrl = '/your-repo-name/';
const config = {
// ...
baseUrl,
// ...
stylesheets: [
// ...
getKaTeXStyleSheet(baseUrl),
],
plugins: [
// ...
[
copyKatexAssetsPlugin,
/** @satisfies {CopyKaTeXAssetsPluginOptions} */({ baseUrl }),
],
],
}
```
## Acknowledgement
This plugin is derived from [docusaurus-copy-plugin](https://github.com/rlamana/docusaurus-plugin-copy). Thanks to [Ramón Lamana (@rlamana)](https://github.com/rlamana) for the original work.
## Demo Website
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
### Installation
```
$ pnpm i
```
### Local Development
```
$ node --run start
```
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
### Build
```
$ node --run build
```
This command generates static content into the `build` directory and can be served using any static contents hosting service.