Math equations do not work when imported from another file
Have you read the Contributing Guidelines on issues?
- [X] I have read the Contributing Guidelines on issues.
Prerequisites
- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the
npm run clearoryarn clearcommand. - [X] I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).
Description
Math equations do not get parsed/styled as they should when they are imported from another md file.
Reproducible demo
https://codesandbox.io/p/devbox/crimson-breeze-23sstv?file=%2Fdocs%2Fintro.md%3A10%2C1
Steps to reproduce
- Create a md file in the
staticfolder. - Add a math equation in it.
## some title some text $$ 2 + 4 $$ - Import that file in a docs file.
---
sidebar_position: 1
---
# Tutorial Intro
$$
{MATH} + 4
$$
import Page from "@site/static/math.md"
<Page/>
Expected behavior
I expect to see 2 equations:
- the one from my docs file.
- the one from my imported file.
Actual behavior
Only one equation is shown correctly:
Your environment
- Public source code: https://codesandbox.io/p/devbox/crimson-breeze-23sstv?file=%2Fdocs%2Fintro.md%3A10%2C1
- Public site URL:
- Docusaurus version used: 3.1.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):
Self-service
- [ ] I'd be willing to fix this bug myself.
Your codesandbox is private so I can't access it.
Currently, remark plugins (including the math plugin) are plugin-specific. They only apply to the folder of the plugin you configured them in (./docs for example).
They do not apply to the static folder, for which we do register a "fallback mdx loader" for convenience, but we don't offer a way for now to provide custom remark plugins. So it's not really easy/possible to register remark-math for mdx files outside of ./docs ./versioned_docs, ./blog or ./src/pages
Although technically you could use the plugin configureWebpack lifecycle hook to add a custom mdx-loader for that path and use custom remark plugins. But it's not super straightforward to do so, nor robust or documented.
The solution is likely to have a global siteConfig.markdown.remarkPlugins option
I'm running into this issue as well, where I have a monorepo and I want to reuse all of the README.md files of the packages throughout the repository, but still have them be processed with plugins.
The siteConfig.markdown.remarkPlugins option sounds like a great idea, and a nice addition to the configuration overall.
Sorry for the permission issue, fixed it now.
Thanks for the info about plugins work and are configured. I'll change things around but I also like your idea about a global option 👍
At the moment this is working as intended. The global option is tracked in https://github.com/facebook/docusaurus/issues/5999.