Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math equations do not work when imported from another file #9901

Open
6 of 7 tasks
ArthurFlag opened this issue Feb 29, 2024 · 3 comments
Open
6 of 7 tasks

Math equations do not work when imported from another file #9901

ArthurFlag opened this issue Feb 29, 2024 · 3 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax

Comments

@ArthurFlag
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • 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

Self-service

  • I'd be willing to fix this bug myself.
@ArthurFlag ArthurFlag added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Feb 29, 2024
@ArthurFlag ArthurFlag changed the title Math equation do not work when imported from another file Math equations do not work when imported from another file Feb 29, 2024
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Feb 29, 2024
@slorber
Copy link
Collaborator

slorber commented Feb 29, 2024

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

@LuudJanssen
Copy link

LuudJanssen commented Mar 1, 2024

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.

@Josh-Cena Josh-Cena added the domain: markdown Related to Markdown parsing or syntax label Mar 3, 2024
@ArthurFlag
Copy link
Contributor Author

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax
Projects
None yet
Development

No branches or pull requests

5 participants
@slorber @LuudJanssen @ArthurFlag @Josh-Cena and others