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

Integrated Katex typesetting into flowcharts #2885

Merged
merged 69 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1e53c12
chore: added katex as a dependency
NicolasNewman Feb 26, 2022
b746747
chore: added css-loader, sass, sass-loader, style-loader
NicolasNewman Feb 28, 2022
c2e8cb7
chore: added katex rendering to flowcharts v1 & 2
NicolasNewman Feb 28, 2022
275f200
chore: added katex demo
NicolasNewman Feb 28, 2022
4736e59
fix(katex): enforce html output for consistency
NicolasNewman Mar 29, 2022
1db4230
feat(katex): fixed node sizing issues, caused by KaTeX fonts not bein…
NicolasNewman Mar 29, 2022
825f502
feat(katex): improved handling of KaTeX errors
NicolasNewman Mar 31, 2022
cc2c828
feat(katex): added cypress testing
NicolasNewman Apr 2, 2022
f67254c
Merge branch 'develop' of https://github.com/mermaid-js/mermaid into …
NicolasNewman Apr 2, 2022
f346056
chore(katex): removed unused debugging code
NicolasNewman Apr 2, 2022
b243609
chore(katex): merged with branch develop
NicolasNewman Feb 13, 2023
58bc6c7
Merge branch 'mermaid-js:develop' into feature/2776_katex_math
NicolasNewman Feb 13, 2023
483722f
fix(katex): fixed rendering of KaTeX errors
NicolasNewman Feb 13, 2023
21479b2
fix(katex): fixed rendering of KaTeX errors
NicolasNewman Feb 13, 2023
4da9c71
fix(katex): fixed rendering of KaTeX errors
NicolasNewman Feb 13, 2023
2740edf
chore(katex): added katex to cSpell.json
NicolasNewman Feb 13, 2023
fb5d80a
fix(katex): removed extra body tag from merge
NicolasNewman Feb 13, 2023
bbc6eb6
chore(katex): lint:fix
NicolasNewman Feb 13, 2023
ebef1c4
chore: merged with develop
NicolasNewman Feb 23, 2023
fdd9000
chore(katex): lint:fix
NicolasNewman Feb 23, 2023
7dd21d8
fix(katex): disabled 4th katex cypress test due to recent changes to …
NicolasNewman Feb 23, 2023
12e1af4
Merge branch 'mermaid-js:develop' into feature/2776_katex_math
NicolasNewman Mar 4, 2023
f3b939e
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Apr 13, 2023
f4cb6a1
chore(katex): fixed issues from merge
NicolasNewman Apr 14, 2023
e0e038d
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid to…
NicolasNewman Apr 14, 2023
f8a4488
feat(katex): added common functions for aiding in KaTeX rendering
NicolasNewman May 6, 2023
4202488
feat(katex): added KaTeX support to sequence diagrams
NicolasNewman May 6, 2023
e7a1d83
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman May 6, 2023
cf54ddc
chore(katex): lint:fix
NicolasNewman May 6, 2023
077cc65
chore(katex): included uncommited files
NicolasNewman May 31, 2023
0605b85
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman May 31, 2023
619ae2f
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman May 31, 2023
a3930eb
fix(katex): resolved broken lockfile
NicolasNewman May 31, 2023
b193013
fix(katex): resolved removed class from demo during merging
NicolasNewman May 31, 2023
9ee4576
Update docs
NicolasNewman May 31, 2023
5c69e5f
feat(katex): optimized importing of katex
NicolasNewman Jun 23, 2023
bee2b69
Merge branch 'feature/2776_katex_math' of https://github.com/NicolasN…
NicolasNewman Jun 23, 2023
8b42302
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Jun 23, 2023
fe8474f
fix(katex): updated specs
NicolasNewman Jun 23, 2023
f979ced
refactor(katex): revision changes
NicolasNewman Jun 24, 2023
40e75fe
docs(katex): added documentation
NicolasNewman Jun 24, 2023
a23f0da
docs(katex): specified minimum version
NicolasNewman Jul 7, 2023
f15e8c9
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Jul 8, 2023
3d5616c
docs(katex): version set to MERMAID_RELEASE_VERSION
NicolasNewman Jul 8, 2023
2cce8ee
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Jul 8, 2023
67cbdb4
fix(katex): resolved legacyMathML config issues from previous merge
NicolasNewman Jul 8, 2023
22a7234
chore(katex): generated types
NicolasNewman Jul 8, 2023
6518e13
Update sequence.html
NicolasNewman Jul 8, 2023
c2f6056
chore(katex): lint-fix
NicolasNewman Jul 8, 2023
6fa8a51
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Oct 11, 2023
2dce7f0
Merge branch 'develop' of https://github.com/NicolasNewman/mermaid in…
NicolasNewman Oct 11, 2023
e690656
refactor(katex): resolved linting errors
NicolasNewman Oct 11, 2023
8d90815
Merge branch 'develop' into pr/NicolasNewman/2885
sidharthv96 Dec 6, 2023
0d98e6c
refactor: Revert type change for renderer
sidharthv96 Dec 6, 2023
70b948f
refactor: Optimize renderKatex
sidharthv96 Dec 6, 2023
1d86cf0
refactor: Cleanup error renderer
sidharthv96 Dec 6, 2023
886eda9
chore: await drawActors
sidharthv96 Dec 6, 2023
85774b7
chore: Fix configAPI
sidharthv96 Dec 6, 2023
a9818b4
chore: Remove special case error handling
sidharthv96 Dec 6, 2023
22f83f1
fix: Sequence actor rendering
sidharthv96 Dec 7, 2023
d91934b
comment out skipped test
sidharthv96 Dec 10, 2023
413de28
Merge branch 'develop' into pr/NicolasNewman/2885
sidharthv96 Jan 19, 2024
d1178c4
Merge branch 'develop' into pr/NicolasNewman/2885
sidharthv96 Jan 27, 2024
52d276b
chore: Update katex
sidharthv96 Jan 27, 2024
3b0c5c3
fix: Message width
sidharthv96 Jan 27, 2024
bc332e3
Fix boundMessage type
sidharthv96 Jan 27, 2024
0b087b7
Merge branch 'develop' into feature/2776_katex_math
sidharthv96 Jan 30, 2024
ebc59d8
Merge branch 'develop' into feature/2776_katex_math
sidharthv96 Jan 31, 2024
4a4e96c
Merge branch 'develop' into feature/2776_katex_math
sidharthv96 Feb 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"jgreywolf",
"jison",
"jiti",
"katex",
"kaufmann",
"khroma",
"klemm",
Expand All @@ -81,6 +82,7 @@
"logmsg",
"lucida",
"markdownish",
"mathml",
"matthieu",
"matthieumorel",
"mdast",
Expand Down
36 changes: 36 additions & 0 deletions cypress/integration/rendering/katex.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { imgSnapshotTest } from '../../helpers/util';

describe('Katex', () => {
it('1: should render a complex Katex flowchart no htmlLabels', () => {
imgSnapshotTest(
`graph LR
A["$$f(\\relax{x}) = \\int_{-\\infty}^\\infty \\hat{f}(\\xi)\\,e^{2 \\pi i \\xi x}\\,d\\xi$$"] -->|"$$\\Bigg(\\bigg(\\Big(\\big((\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a})\\big)\\Big)\\bigg)\\Bigg)$$"| B("$$1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}} {1+\\frac{e^{-8\\pi}} {1+\\cdots}}}}$$")
A -->|"$$\\overbrace{a+b+c}^{\\text{note}}$$"| C("$$\\phase{-78^\\circ}$$")
B --> D("$$x = \\begin{cases} a &\\text{if } b \\\\ c &\\text{if } d \\end{cases}$$")
C --> E("$$x(t)=c_1\\begin{bmatrix}-\\cos{t}+\\sin{t}\\\\ 2\\cos{t} \\end{bmatrix}e^{2t}$$")`,
{ fontFamily: 'courier' }
);
});
it('2: should render a Katex flowchart containing the Greek alphabet', () => {
imgSnapshotTest(
`graph LR
A["$$\\alpha\\beta\\gamma\\delta\\epsilon\\zeta\\eta\\theta\\iota\\kappa\\lambda\\mu\\nu\\xi\\omicron\\pi\\rho\\sigma\\tau\\upsilon\\phi\\chi\\psi\\omega$$"] --> B["$$\\Alpha\\Beta\\Gamma\\Delta\\Epsilon\\Zeta\\Eta\\Theta\\Iota\\Kappa\\Lambda\\Mu\\Nu\\Xi\\Omicron\\Pi\\Rho\\Sigma\\Tau\\Upsilon\\Phi\\Chi\\Psi\\Omega$$"]`,
{ fontFamily: 'courier' }
);
});
it('3: should render a Katex flowchart containing set theory symbols', () => {
imgSnapshotTest(
`graph LR
A["$$\\forall\\complement\\therefore\\emptyset\\exists\\subset\\because\\empty\\exist\\supset\\mapsto\\varnothing\\nexists\\mid\\to\\implies\\in\\land\\gets\\impliedby\\isin\\lor\\leftrightarrow\\iff\\notin\\ni\\notni\\lnot$$"] --> B["$$\\nabla\\Im\\Reals\\jmath\\partial\\image\\wp\\aleph\\Game\\weierp\\alef\\Finv\\N\\Z\\alefsym\\cnums\\natnums\\beth\\Complex\\R\\gimel\\ell\\Re\\daleth\\hbar\\real\\eth\\hslash\\reals$$"]`,
{ fontFamily: 'courier' }
);
});
// TODO: changes made to develop between Feb 13 - Feb 23 cause this test to no longer function
// it.skip('4: should render an error box originating from Katex', () => {
// imgSnapshotTest(
// `graph LR
// A["$$\\shouldBeError$$"]`,
// { fontFamily: 'courier' }
// );
// });
});
55 changes: 53 additions & 2 deletions demos/flowchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,57 @@ <h3>flowchart</h3>
</pre>
<hr />

<h2>Sample 20</h2>
<h3>graph</h3>
<pre class="mermaid">
graph LR
A["$$f(\relax{x}) = \int_{-\infty}^\infty \hat{f}(\xi)\,e^{2 \pi i \xi x}\,d\xi$$"] -->|"$$\Bigg(\bigg(\Big(\big((\frac{-b\pm\sqrt{b^2-4ac}}{2a})\big)\Big)\bigg)\Bigg)$$"| B("$$1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots}}}}$$")
A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\phase{-78^\circ}$$")
B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
</pre>
<hr />

<h3>flowchart</h3>
<pre class="mermaid">
flowchart LR
A["$$f(\relax{x}) = \int_{-\infty}^\infty \hat{f}(\xi)\,e^{2 \pi i \xi x}\,d\xi$$"] -->|"$$\Bigg(\bigg(\Big(\big((\frac{-b\pm\sqrt{b^2-4ac}}{2a})\big)\Big)\bigg)\Bigg)$$"| B("$$1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots}}}}$$")
A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\phase{-78^\circ}$$")
B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
</pre>
<hr />

<h2>Sample 21</h2>
<h3>graph</h3>
<pre class="mermaid">
graph LR
A["$$\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu\nu\xi\omicron\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega$$"] --> B["$$\Alpha\Beta\Gamma\Delta\Epsilon\Zeta\Eta\Theta\Iota\Kappa\Lambda\Mu\Nu\Xi\Omicron\Pi\Rho\Sigma\Tau\Upsilon\Phi\Chi\Psi\Omega$$"]
</pre>
<hr />

<h3>flowchart</h3>
<pre class="mermaid">
graph LR
A["$$\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu\nu\xi\omicron\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega$$"] --> B["$$\Alpha\Beta\Gamma\Delta\Epsilon\Zeta\Eta\Theta\Iota\Kappa\Lambda\Mu\Nu\Xi\Omicron\Pi\Rho\Sigma\Tau\Upsilon\Phi\Chi\Psi\Omega$$"]
</pre>
<hr />

<h2>Sample 22</h2>
<h3>graph</h3>
<pre class="mermaid">
graph LR
A["$$\forall\complement\therefore\emptyset\exists\subset\because\empty\exist\supset\mapsto\varnothing\nexists\mid\to\implies\in\land\gets\impliedby\isin\lor\leftrightarrow\iff\notin\ni\notni\lnot$$"] --> B["$$\nabla\Im\Reals\jmath\partial\image\wp\aleph\Game\weierp\alef\Finv\N\Z\alefsym\cnums\natnums\beth\Complex\R\gimel\ell\Re\daleth\hbar\real\eth\hslash\reals$$"]
</pre>
<hr />

<h3>flowchart</h3>
<pre class="mermaid">
graph LR
A["$$\forall\complement\therefore\emptyset\exists\subset\because\empty\exist\supset\mapsto\varnothing\nexists\mid\to\implies\in\land\gets\impliedby\isin\lor\leftrightarrow\iff\notin\ni\notni\lnot$$"] --> B["$$\nabla\Im\Reals\jmath\partial\image\wp\aleph\Game\weierp\alef\Finv\N\Z\alefsym\cnums\natnums\beth\Complex\R\gimel\ell\Re\daleth\hbar\real\eth\hslash\reals$$"]
</pre>
<hr />

<hr />

<pre class="mermaid">
Expand Down Expand Up @@ -1524,11 +1575,11 @@ <h3>flowchart</h3>
F{Flow 2} == Choice 2.1 ==> H[Feedback node]
H[Feedback node] ==> B[Step 1]
F{Flow 2} == Choice 2.2 ==> G((Finish))

linkStyle 0,1,4,6,7,8,9 stroke:gold, stroke-width:4px

classDef active_node fill:#0CF,stroke:#09F,stroke-width:6px
classDef unactive_node fill:#e0e0e0,stroke:#bdbdbd,stroke-width:3px
classDef unactive_node fill:#e0e0e0,stroke:#bdbdbd,stroke-width:3px
classDef bugged_node fill:#F88,stroke:#F22,stroke-width:3px
classDef start_node,finish_node fill:#3B1,stroke:#391,stroke-width:8px

Expand Down
133 changes: 88 additions & 45 deletions demos/sequence.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<body>
<h1>Sequence diagram demos</h1>
<pre class="mermaid">
sequenceDiagram
accTitle: test the accTitle
accDescr: Test a description
sequenceDiagram
accTitle: test the accTitle
accDescr: Test a description

participant Alice
participant Bob
Expand All @@ -31,39 +31,39 @@ <h1>Sequence diagram demos</h1>
rect rgb(200, 220, 100)
rect rgb(200, 255, 200)

Alice ->> Bob: Hello Bob, how are you?
Bob-->>John: How about you John?
end
Alice ->> Bob: Hello Bob, how are you?
Bob-->>John: How about you John?
end

Bob--x Alice: I am good thanks!
Bob-x John: I am good thanks!
Note right of John: John thinks a long<br />long time, so long<br />that the text does<br />not fit on a row.
Bob--x Alice: I am good thanks!
Bob-x John: I am good thanks!
Note right of John: John thinks a long<br />long time, so long<br />that the text does<br />not fit on a row.

Bob-->Alice: Checking with John...
Note over John:wrap: John looks like he's still thinking, so Bob prods him a bit.
Bob-x John: Hey John - we're still waiting to know<br />how you're doing
Note over John:nowrap: John's trying hard not to break his train of thought.
Bob-x John:wrap: John! Are you still debating about how you're doing? How long does it take??
Note over John: After a few more moments, John<br />finally snaps out of it.
end
Bob-->Alice: Checking with John...
Note over John:wrap: John looks like he's still thinking, so Bob prods him a bit.
Bob-x John: Hey John - we're still waiting to know<br />how you're doing
Note over John:nowrap: John's trying hard not to break his train of thought.
Bob-x John:wrap: John! Are you still debating about how you're doing? How long does it take??
Note over John: After a few more moments, John<br />finally snaps out of it.
end

autonumber off
alt either this
Alice->>+John: Yes
John-->>-Alice: OK
else or this
autonumber
Alice->>John: No
else or this will happen
Alice->John: Maybe
end
autonumber 200
par this happens in parallel
Alice -->> Bob: Parallel message 1
and
Alice -->> John: Parallel message 2
end
</pre>
autonumber off
alt either this
Alice->>+John: Yes
John-->>-Alice: OK
else or this
autonumber
Alice->>John: No
else or this will happen
Alice->John: Maybe
end
autonumber 200
par this happens in parallel
Alice -->> Bob: Parallel message 1
and
Alice -->> John: Parallel message 2
end
</pre>
<hr />
<pre class="mermaid">
---
Expand Down Expand Up @@ -153,18 +153,18 @@ <h1>Sequence diagram demos</h1>
<hr />

<pre class="mermaid">
sequenceDiagram
box lightgreen Alice & John
participant A
participant J
end
box Another Group very very long description not wrapped
participant B
end
A->>J: Hello John, how are you?
J->>A: Great!
A->>B: Hello Bob, how are you ?
</pre
sequenceDiagram
box lightgreen Alice & John
participant A
participant J
end
box Another Group very very long description not wrapped
participant B
end
A->>J: Hello John, how are you?
J->>A: Great!
A->>B: Hello Bob, how are you ?
</pre
>
<hr />

Expand All @@ -188,6 +188,49 @@ <h1>Sequence diagram demos</h1>
end
</pre>

<hr />

<pre class="mermaid">
sequenceDiagram
participant 1 as $$\frac{\lim_{x\rightarrow0}{\frac{1}{x}}}{\frac{-b\pm\sqrt{b^2-4ac}}{2a}}$$
participant 2 as $$\beta$$
participant 3 as $$\delta$$
participant 4 as $$\frac{\frac{\lim_{x\rightarrow0}{\frac{1}{x}}}{\frac{-b\pm\sqrt{b^2-4ac}}{2a}}}{\frac{\text{d}}{\text{d}x}{x^2}}$$
1->>2: $$\sqrt{2}$$
note right of 2: $$\frac{1+\frac{1+\frac{1+\frac{1}{2}}{2}}{2}}{2}+\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$
2->>3: $$\frac{\lim_{x\rightarrow0}{\frac{1}{x}}}{\frac{-b\pm\sqrt{b^2-4ac}}{2a}}$$
note right of 3: $$\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$
3->>4: $$\lim_{x\rightarrow0}{\frac{1}{x}}$$;
note right of 4: multiline
4->>1: multiline<br />using #lt;br /#gt;
note right of 1: multiline<br />$$\frac{1}{2}$$<br />3rd line
</pre>
<hr />
<pre class="mermaid">
sequenceDiagram
autonumber
participant 1 as $$\alpha$$lex
participant 2 as $$\beta$$ob
participant 3 as $$\theta$$iffany
1->>2: Hello John, does&nbsp; $$\frac{1}{2}+1=2$$?
loop $$\frac{1}{2}+1=2$$
2->>2: $$\frac{1}{2}+1=\frac{3}{2}$$
end
Note right of 2: $$x = \begin{cases} 1 &\text{if } \frac{1}{2}+1=2 \\ 0 &\text{if } \frac{1}{2}+1\ne2 \end{cases}$$
2-->>1: $$\frac{1}{2}+1\ne2\implies 1$$
2->>3: $$\frac{\text{d}}{\text{d}x}{3x^2+2x+1}$$
3-->>2: $$6x+2$$
</pre>

<hr />

<pre class="mermaid">
sequenceDiagram
actor Alice
actor John
Alice-xJohn: Hello John, how are you?
John--xAlice: Great!
</pre>
<script type="module">
import mermaid from './mermaid.esm.mjs';
mermaid.initialize({
Expand Down
86 changes: 86 additions & 0 deletions docs/config/math.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
> **Warning**
>
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
>
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/math.md](../../packages/mermaid/src/docs/config/math.md).

# Math Configuration (v\<MERMAID_RELEASE_VERSION>+)

Mermaid supports rendering mathematical expressions through the [KaTeX](https://katex.org/) typesetter.

## Usage

To render math within a diagram, surround the mathematical expression with the `$$` delimiter.

Note that at the moment, the only supported diagrams are below:

### Flowcharts

```mermaid-example
graph LR
A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
```

```mermaid
graph LR
A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
```

### Sequence

```mermaid-example
sequenceDiagram
autonumber
participant 1 as $$\alpha$$
participant 2 as $$\beta$$
1->>2: Solve: $$\sqrt{2+2}$$
2-->>1: Answer: $$2$$
Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
```

```mermaid
sequenceDiagram
autonumber
participant 1 as $$\alpha$$
participant 2 as $$\beta$$
1->>2: Solve: $$\sqrt{2+2}$$
2-->>1: Answer: $$2$$
Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
```

## Legacy Support

By default, MathML is used for rendering mathematical expressions. If you have users on [unsupported browsers](https://caniuse.com/?search=mathml), `legacyMathML` can be set in the config to fall back to CSS rendering. Note that **you must provide KaTeX's stylesheets on your own** as they do not come bundled with Mermaid.

Example with legacy mode enabled (the latest version of KaTeX's stylesheet can be found on their [docs](https://katex.org/docs/browser.html)):

```html
<!DOCTYPE html>
<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<html lang="en">
<head>
<!-- Please ensure the stylesheet's version matches with the KaTeX version in your package-lock -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@{version_number}/dist/katex.min.css"
integrity="sha384-{hash}"
crossorigin="anonymous"
/>
</head>

<body>
<script type="module">
import mermaid from './mermaid.esm.mjs';
mermaid.initialize({
legacyMathML: true,
});
</script>
</body>
</html>
```
2 changes: 2 additions & 0 deletions packages/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"dayjs": "^1.11.7",
"dompurify": "^3.0.5",
"elkjs": "^0.9.0",
"katex": "^0.16.9",
"khroma": "^2.0.0",
"lodash-es": "^4.17.21",
"mdast-util-from-markdown": "^1.3.0",
Expand All @@ -89,6 +90,7 @@
"@types/d3-shape": "^3.1.1",
"@types/dompurify": "^3.0.2",
"@types/jsdom": "^21.1.1",
"@types/katex": "^0.16.7",
"@types/lodash-es": "^4.17.7",
"@types/micromatch": "^4.0.2",
"@types/prettier": "^2.7.2",
Expand Down
Loading
Loading