1.1.3 • Published 3 months ago

@tats-u/docusaurus-plugin-copy-katex-assets v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

docusaurus-plugin-copy-katex-assets plugin

Version NPM Downloads NPM Last Update

This plugin copies KaTeX assets to the build directory. This makes it unnecessary to load KaTeX assets from the CDN.

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:

NameDescription
copyKaTeXAssetsPluginDocusaurus plugin to copy KaTeX assets
CopyKaTeXAssetsPluginOptionsConfiguration options for the plugin
defaultKaTeXStyleSheetDefault KaTeX style sheet entry for config.stylesheets array
getKaTeXStyleSheetDitto, but with custom base URL
defaultKaTeXCssPathDefault KaTeX CSS path
getKaTeXCssPathDitto, but with custom base URL

Then add the plugin to docusaurus.config.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:

import { type CopyKaTeXAssetsPluginOptions, copyKatexAssetsPlugin, defaultKaTeXStyleSheet } from '@tats-u/docusaurus-plugin-copy-katex-assets';

Compatibility with Docusaurus Faster

This plugin is compatible with Docusaurus Faster.

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:

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:

const baseUrl = '/your-repo-name/';

const config = {
  // ...
  baseUrl,
  // ...
  stylesheets: [
    // ...
    getKaTeXStyleSheet(baseUrl),
  ],
  plugins: [
    // ...
    [
      copyKatexAssetsPlugin,
      /** @satisfies {CopyKaTeXAssetsPluginOptions} */({ baseUrl }),
    ],
  ],
}
1.1.3

3 months ago

1.1.2

3 months ago

1.1.1

3 months ago

1.1.0

3 months ago

1.0.0

3 months ago

1.0.0-beta.1

3 months ago