Skip to content

How to use KaTeX extensions (like mhchem and copy-tex) in Docusaurus? #9266

Closed Answered by dbxxx-ac
dbxxx-ac asked this question in Q&A
Discussion options

You must be logged in to vote

Here's the way to add the copy-tex support:

copy katex/dist/contrib/mhchem.mjs to /src folder, with some addition:

  1. add import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; on the top of the file
  2. find the code document.addEventListener('copy', function (event) {, and wrap this function with if (ExecutionEnvironment.canUseDOM) {}.

After that, load it as a client module.

Here's the way to add the mhchem support:

use yarn patch to modify the rehype-katex module(rather than just making a simple copy) to avoid cache warning.

add require('katex/contrib/mhchem') at the top of /lib/index.js

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@dbxxx-ac
Comment options

@dbxxx-ac
Comment options

@Josh-Cena
Comment options

@dbxxx-ac
Comment options

Comment options

You must be logged in to vote
1 reply
@ttheng3810
Comment options

Answer selected by dbxxx-ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants