-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
MDX v3 LaTeX: Escaping Curly Braces #9538
Comments
Hi, please upgrade your remark-math and rehype-katex to the latest versions. Docusaurus website itself displays math with absolutely no problems: https://github.com/facebook/docusaurus/blob/main/website/docs/guides/markdown-features/markdown-features-math-equations.mdx |
Can anyone tell me is this correct way to add equation? What am I missing? Thanks diff --git a/blog/2021-08-01-mdx-blog-post.mdx b/blog/2021-08-01-mdx-blog-post.mdx
index c04ebe3..331cd90 100644
--- a/blog/2021-08-01-mdx-blog-post.mdx
+++ b/blog/2021-08-01-mdx-blog-post.mdx
@@ -5,8 +5,17 @@ authors: [slorber]
tags: [docusaurus]
---
+import MathText from '@site/src/components/MathText'
+
Blog posts support [Docusaurus Markdown features](https://docusaurus.io/docs/markdown-features), such as [MDX](https://mdxjs.com/).
+<MathText>
+
+Let $f\colon[a,b] \to \R$ be Riemann integrable. Let $F\colon[a,b]\to\R$ be $F(x)=
+\int_{a}^{x} f(t)\,dt$. Then $F$ is continuous, and at all $x$ such that $f$ is continuous at $x$, $F$ is differentiable at $x$ with $F'(x)=f(x)$.
+
+</MathText>
+
:::tip
Use the power of React to create interactive blog posts.
diff --git a/docusaurus.config.ts b/docusaurus.config.ts
index 4058eac..795618e 100644
--- a/docusaurus.config.ts
+++ b/docusaurus.config.ts
@@ -2,6 +2,9 @@ import {themes as prismThemes} from 'prism-react-renderer';
import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
+import remarkMath from 'remark-math';
+import rehypeKatex from 'rehype-katex';
+
const config: Config = {
title: 'My Site',
tagline: 'Dinosaurs are cool',
@@ -29,11 +32,23 @@ const config: Config = {
locales: ['en'],
},
+ stylesheets: [
+ {
+ href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
+ type: 'text/css',
+ integrity:
+ 'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
+ crossorigin: 'anonymous',
+ },
+ ],
+
presets: [
[
'classic',
{
docs: {
+ remarkPlugins: [remarkMath],
+ rehypePlugins: [rehypeKatex],
sidebarPath: './sidebars.ts',
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
diff --git a/package.json b/package.json
index 9bca92d..10c2e27 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,9 @@
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
- "react-dom": "^18.0.0"
+ "react-dom": "^18.0.0",
+ "rehype-katex": "^7.0.0",
+ "remark-math": "^6.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.0.1",
|
You have to escape {a} with / Your content is not valid MDX, try to run it on the MDX playground and see. It's not a Docusaurus issue, it's how MDX works. V3 blog post presents an option to turn on a common mark mode if you don't like this behavior |
@slorber The same code on our docs works without escaping, and that page doesn't seem to be in commonmark mode. I wonder how it works |
It is not working.
How it is working? I tried to explore the code but it seems it is same. |
Okay, it seems that, it only works in docs not in blog, here diff for working in docs.
diff --git a/blog/2021-08-01-mdx-blog-post.mdx b/blog/2021-08-01-mdx-blog-post.mdx
index c04ebe3..afb9dd7 100644
--- a/blog/2021-08-01-mdx-blog-post.mdx
+++ b/blog/2021-08-01-mdx-blog-post.mdx
@@ -5,8 +5,18 @@ authors: [slorber]
tags: [docusaurus]
---
+import BrowserWindow from '@site/src/components/BrowserWindow';
+
Blog posts support [Docusaurus Markdown features](https://docusaurus.io/docs/markdown-features), such as [MDX](https://mdxjs.com/).
+
+<BrowserWindow>
+
+$$\int_{a}^{b}$$
+
+</BrowserWindow>
+
+
:::tip
Use the power of React to create interactive blog posts.
diff --git a/docs/intro.md b/docs/intro.md
index 45e8604..51cbd0e 100644
--- a/docs/intro.md
+++ b/docs/intro.md
@@ -2,6 +2,8 @@
sidebar_position: 1
---
+
+
# Tutorial Intro
Let's discover **Docusaurus in less than 5 minutes**.
diff --git a/docs/tutorial-basics/markdown-features.mdx b/docs/tutorial-basics/markdown-features.mdx
index 0337f34..77361d5 100644
--- a/docs/tutorial-basics/markdown-features.mdx
+++ b/docs/tutorial-basics/markdown-features.mdx
@@ -4,6 +4,16 @@ sidebar_position: 4
# Markdown Features
+import BrowserWindow from '@site/src/components/BrowserWindow';
+
+<BrowserWindow>
+
+
+$$\int_{a}^{b}$$
+
+</BrowserWindow>
+
+
Docusaurus supports **[Markdown](https://daringfireball.net/projects/markdown/syntax)** and a few **additional features**.
## Front Matter
diff --git a/docusaurus.config.ts b/docusaurus.config.ts
index 4058eac..a362da8 100644
--- a/docusaurus.config.ts
+++ b/docusaurus.config.ts
@@ -2,6 +2,9 @@ import {themes as prismThemes} from 'prism-react-renderer';
import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
+const math = require('remark-math');
+const katex = require('rehype-katex');
+
const config: Config = {
title: 'My Site',
tagline: 'Dinosaurs are cool',
@@ -29,6 +32,16 @@ const config: Config = {
locales: ['en'],
},
+ stylesheets: [
+ {
+ href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
+ type: 'text/css',
+ integrity:
+ 'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
+ crossorigin: 'anonymous',
+ },
+ ],
+
presets: [
[
'classic',
@@ -39,6 +52,8 @@ const config: Config = {
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
+ remarkPlugins: [math],
+ rehypePlugins: [katex],
},
blog: {
showReadingTime: true,
@@ -46,6 +61,8 @@ const config: Config = {
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
+ remarkPlugins: [math],
+ rehypePlugins: [katex],
},
theme: {
customCss: './src/css/custom.css',
diff --git a/package.json b/package.json
index 9bca92d..10c2e27 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,9 @@
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
- "react-dom": "^18.0.0"
+ "react-dom": "^18.0.0",
+ "rehype-katex": "^7.0.0",
+ "remark-math": "^6.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.0.1", |
Please share a docusaurus.new runnable repro showing the problem |
Problem - Math equations
Solution: again, escape
\{
?Originally posted by @slorber in #8288 (comment)
Is there no way to disable this behavior? Using { } is very slow and breaks a lot of documents.
The text was updated successfully, but these errors were encountered: