collab/mermaid/docs/config/math.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/math.md](../../packages/mermaid/src/docs/config/math.md).
6dd74de6
6dd74de7# Math Configuration (v10.9.0+)
6dd74de8
6dd74de9Mermaid supports rendering mathematical expressions through the [KaTeX](https://katex.org/) typesetter.
6dd74de10
6dd74de11## Usage
6dd74de12
6dd74de13To render math within a diagram, surround the mathematical expression with the `$$` delimiter.
6dd74de14
6dd74de15Note that at the moment, the only supported diagrams are below:
6dd74de16
6dd74de17### Flowcharts
6dd74de18
6dd74de19```mermaid-example
6dd74de20 graph LR
6dd74de21 A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
6dd74de22 A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
6dd74de23 B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
6dd74de24 C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
6dd74de25```
6dd74de26
6dd74de27```mermaid
6dd74de28 graph LR
6dd74de29 A["$$x^2$$"] -->|"$$\sqrt{x+3}$$"| B("$$\frac{1}{2}$$")
6dd74de30 A -->|"$$\overbrace{a+b+c}^{\text{note}}$$"| C("$$\pi r^2$$")
6dd74de31 B --> D("$$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$$")
6dd74de32 C --> E("$$x(t)=c_1\begin{bmatrix}-\cos{t}+\sin{t}\\ 2\cos{t} \end{bmatrix}e^{2t}$$")
6dd74de33```
6dd74de34
6dd74de35### Sequence
6dd74de36
6dd74de37```mermaid-example
6dd74de38sequenceDiagram
6dd74de39 autonumber
6dd74de40 participant 1 as $$\alpha$$
6dd74de41 participant 2 as $$\beta$$
6dd74de42 1->>2: Solve: $$\sqrt{2+2}$$
6dd74de43 2-->>1: Answer: $$2$$
6dd74de44 Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
6dd74de45```
6dd74de46
6dd74de47```mermaid
6dd74de48sequenceDiagram
6dd74de49 autonumber
6dd74de50 participant 1 as $$\alpha$$
6dd74de51 participant 2 as $$\beta$$
6dd74de52 1->>2: Solve: $$\sqrt{2+2}$$
6dd74de53 2-->>1: Answer: $$2$$
6dd74de54 Note right of 2: $$\sqrt{2+2}=\sqrt{4}=2$$
6dd74de55```
6dd74de56
6dd74de57## Legacy Support
6dd74de58
6dd74de59By 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.
6dd74de60
6dd74de61Example with legacy mode enabled (the latest version of KaTeX's stylesheet can be found on their [docs](https://katex.org/docs/browser.html)):
6dd74de62
6dd74de63```html
6dd74de64<!doctype html>
6dd74de65<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
6dd74de66<html lang="en">
6dd74de67 <head>
6dd74de68 <!-- Please ensure the stylesheet's version matches with the KaTeX version in your package-lock -->
6dd74de69 <link
6dd74de70 rel="stylesheet"
6dd74de71 href="https://cdn.jsdelivr.net/npm/katex@{version_number}/dist/katex.min.css"
6dd74de72 integrity="sha384-{hash}"
6dd74de73 crossorigin="anonymous"
6dd74de74 />
6dd74de75 </head>
6dd74de76
6dd74de77 <body>
6dd74de78 <script type="module">
6dd74de79 import mermaid from './mermaid.esm.mjs';
6dd74de80 mermaid.initialize({
6dd74de81 legacyMathML: true,
6dd74de82 });
6dd74de83 </script>
6dd74de84 </body>
6dd74de85</html>
6dd74de86```
6dd74de87
6dd74de88## Handling Rendering Differences
6dd74de89
6dd74de90Due 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.
6dd74de91
6dd74de92This 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.
6dd74de93
6dd74de94If 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).
6dd74de95
6dd74de96![Image showing differences between Browsers](img/mathMLDifferences.png)