docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Math equations do not work when imported from another file

Open ArthurFlag opened this issue 1 year ago • 3 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [X] I'm using the latest version of Docusaurus.
  • [X] I have tried the npm run clear or yarn clear command.
  • [X] I have tried rm -rf node_modules yarn.lock package-lock.json and 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

  1. Create a md file in the static folder.
  2. Add a math equation in it.
    ## some title
    
    some text
    
    $$ 
    2 + 4
    $$
    
  3. 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:

Screenshot 2024-02-29 at 08 36 49

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.

ArthurFlag avatar Feb 29 '24 15:02 ArthurFlag

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

slorber avatar Feb 29 '24 16:02 slorber

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.

LuudJanssen avatar Mar 01 '24 22:03 LuudJanssen

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 👍

ArthurFlag avatar Mar 04 '24 15:03 ArthurFlag

At the moment this is working as intended. The global option is tracked in https://github.com/facebook/docusaurus/issues/5999.

Josh-Cena avatar Jul 19 '24 22:07 Josh-Cena