3.5 KB97 lines
Blame
1> **Warning**
2>
3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
4>
5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/math.md](../../packages/mermaid/src/docs/config/math.md).
6
7# Math Configuration (v10.9.0+)
8
9Mermaid supports rendering mathematical expressions through the [KaTeX](https://katex.org/) typesetter.
10
11## Usage
12
13To render math within a diagram, surround the mathematical expression with the `$$` delimiter.
14
15Note that at the moment, the only supported diagrams are below:
16
17### Flowcharts
18
19```mermaid-example
20 graph LR
21 A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
22 A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
23 B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
24 C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
25```
26
27```mermaid
28 graph LR
29 A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
30 A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
31 B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
32 C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
33```
34
35### Sequence
36
37```mermaid-example
38sequenceDiagram
39 autonumber
40 participant 1 as $$\alpha$$
41 participant 2 as $$\beta$$
42 1->>2: Solve: $$\sqrt{2+2}$$
43 2-->>1: Answer: $$2$$
44 Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
45```
46
47```mermaid
48sequenceDiagram
49 autonumber
50 participant 1 as $$\alpha$$
51 participant 2 as $$\beta$$
52 1->>2: Solve: $$\sqrt{2+2}$$
53 2-->>1: Answer: $$2$$
54 Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
55```
56
57## Legacy Support
58
59By 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.
60
61Example with legacy mode enabled (the latest version of KaTeX's stylesheet can be found on their [docs](https://katex.org/docs/browser.html)):
62
63```html
64<!doctype html>
65<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
66<html lang="en">
67 <head>
68 <!-- Please ensure the stylesheet's version matches with the KaTeX version in your package-lock -->
69 <link
70 rel="stylesheet"
71 href="https://cdn.jsdelivr.net/npm/katex@{version_number}/dist/katex.min.css"
72 integrity="sha384-{hash}"
73 crossorigin="anonymous"
74 />
75 </head>
76
77 <body>
78 <script type="module">
79 import mermaid from './mermaid.esm.mjs';
80 mermaid.initialize({
81 legacyMathML: true,
82 });
83 </script>
84 </body>
85</html>
86```
87
88## Handling Rendering Differences
89
90Due to differences between default fonts across operating systems and browser's MathML implementations, inconsistent results can be seen across platforms. If having consistent results are important, or the most optimal rendered results are desired, `forceLegacyMathML` can be enabled in the config.
91
92This option will always use KaTeX's stylesheet instead of only when MathML is not supported (as with `legacyMathML`). Note that only `forceLegacyMathML` needs to be set.
93
94If including KaTeX's stylesheet is not a concern, enabling this option is recommended to avoid scenarios where no MathML implementation within a browser provides the desired output (as seen below).
95
96![Image showing differences between Browsers](img/mathMLDifferences.png)
97