10
10
AsciiMath dialect. If you want to use LaTeX, follow the instructions
11
11
below.
12
12
13
+ ** Note** [ mathup] [ mathup ] or [ temml] [ temml ] are optional peer
14
+ dependencies, you must explicitly install either of them if you plan
15
+ to use the default renderer (see [ installation] [ #Installation ] below).
16
+
13
17
``` md
14
18
Pythagorean theorem is $a^2 + b^2 = c^2$.
15
19
@@ -53,9 +57,9 @@ location of your modules.
53
57
</script >
54
58
```
55
59
56
- ** Note** Importing [ mathup] [ mathup ] or [ temml] [ temml ] are
57
- optional. Only import mathup if you want to use it as the default
58
- AsciiMath renderer. Import Temml if you want to use it as the LaTeX
60
+ ** Note** Adding [ mathup] [ mathup ] or [ temml] [ temml ] to your import map
61
+ is optional. Only add mathup if you want to use it as the default
62
+ AsciiMath renderer. Add Temml if you want to use it as the LaTeX
59
63
renderer.
60
64
61
65
## Usage
@@ -71,7 +75,7 @@ const options = {
71
75
inlineDelimiters: [" $" , [" $`" , " `$" ]],
72
76
inlineAllowWhiteSpacePadding: false ,
73
77
blockDelimiters: " $$" ,
74
- defaultRendererOptions ,
78
+ mathupOptions ,
75
79
inlineCustomElement, // see below
76
80
inlineRenderer, // see below
77
81
blockCustomElement, // see below
@@ -101,26 +105,28 @@ default renderer.
101
105
### LaTeX (Temml)
102
106
103
107
``` bash
108
+ # install temml as a peer dependency
104
109
npm install --save temml
105
110
```
106
111
107
112
``` js
108
113
import markdownIt from " markdown-it" ;
109
- import markdownItMath from " markdown-it-math" ;
110
- import temml from " temml" ;
114
+ import markdownItMathTemml from " markdown-it-math/temml" ;
111
115
112
116
// Optional, if you want macros to persit across equations.
113
117
const macros = {};
114
118
115
- const md = markdownIt ().use (markdownItMath, {
116
- inlineRenderer : (src ) => temml .renderToString (src, { macros }),
117
- blockRenderer : (src ) =>
118
- temml .renderToString (src, { displayStyle: true , macros }),
119
+ const md = markdownIt ().use (markdownItMathTemml, {
120
+ temmlOptions: { macros },
119
121
});
120
122
```
121
123
124
+ Note that the ` markdown-it-math/temml ` export supports the same
125
+ options as above, except ` mathupOptions ` , you can use ` temmlOptions `
126
+ instead.
127
+
122
128
``` js
123
- md .render (`
129
+ md .render (String . raw `
124
130
A text $1+1=2$ with math.
125
131
126
132
$$
@@ -138,6 +144,26 @@ You may also want to include the stylesheets and fonts from Temml. See
138
144
[ Temml] [ temml ] for reference and usage instructions about the
139
145
default renderer.
140
146
147
+ ### No Default Renderer
148
+
149
+ ** ` markdown-it-math/no-default-renderer ` ** is the minimal export. Use
150
+ this if you want to provide your own renderer.
151
+
152
+ ** Note:** The other two exports use top-level await to dynamically
153
+ import the respective peer dependency. If your environment does not
154
+ support that, this export is recommended, in which case you should
155
+ manually supply the renderers.
156
+
157
+ ``` js
158
+ import markdownIt from " markdown-it" ;
159
+ import markdownItMath from " markdown-it-math/no-default-renderer" ;
160
+
161
+ const md = markdownIt ().use (markdownItMath, {
162
+ inlineRenderer: customInlineMathRenderer,
163
+ blockRenderer: customBlockMathRenderer,
164
+ });
165
+ ```
166
+
141
167
### Options
142
168
143
169
- ` inlineDelimiters ` : A string, or an array of strings (or pairs of
@@ -153,8 +179,11 @@ default renderer.
153
179
` \(...\) ` as delimiters where the risk of non-intended math
154
180
expression is low.
155
181
- ` blockDelimiters ` : Same as above, but for block expressions. Default ` "$$" ` .
156
- - ` defaultRendererOptions ` : The options passed into the default
157
- renderer. Ignored if you use a custom renderer. Default ` {} `
182
+ - ` mathupOptions ` : The options passed to the default mathup renderer. Ignored
183
+ if you use a custom renderer. Default ` {} ` .
184
+ - ` temmlOptions ` : The options passed to the temml renderer. Only available if
185
+ you import from ` markdown-it-math/temml ` Ignored if you use a custom renderer.
186
+ Default ` {} ` .
158
187
- ` inlineCustomElement ` :
159
188
Specify ` "tag-name" ` or ` ["tag-name", { some: "attrs" }] ` if you want to
160
189
render inline expressions to a custom element. Ignored if you provide a
@@ -167,7 +196,7 @@ default renderer.
167
196
import mathup from " mathup" ;
168
197
169
198
function defaultInlineRenderer (src , token , md ) {
170
- return mathup (src, defaultRendererOptions ).toString ();
199
+ return mathup (src, mathupOptions ).toString ();
171
200
}
172
201
```
173
202
@@ -184,7 +213,7 @@ default renderer.
184
213
185
214
function defaultBlockRenderer (src , token , md ) {
186
215
return mathup (src, {
187
- ... defaultRendererOptions ,
216
+ ... mathupOptions ,
188
217
display: " block" ,
189
218
}).toString ();
190
219
}
@@ -207,7 +236,7 @@ import markdownIt from "markdown-it";
207
236
import markdownItMath from " markdown-it-math" ;
208
237
209
238
const md = markdownIt ().use (markdownItMath, {
210
- defaultRendererOptions : { decimalMark: " ," },
239
+ mathupOptions : { decimalMark: " ," },
211
240
});
212
241
213
242
md .render (" $40,2$" );
@@ -338,14 +367,14 @@ e = \sum_{n=0}^{\infty} \frac{1}{n!}
338
367
339
368
``` js
340
369
import markdownIt from " markdown-it" ;
341
- import markdownItMath from " markdown-it-math" ;
370
+ import markdownItMathTemml from " markdown-it-math/temml " ;
342
371
import temml from " temml" ;
343
372
344
373
// An object to keep all the global macros.
345
374
const macros = {};
346
375
347
- const md = markdownIt ().use (markdownItMath , {
348
- inlineRenderer : ( src ) => temml . renderToString (src, { macros }) ,
376
+ const md = markdownIt ().use (markdownItMathTemml , {
377
+ temmlOptions : { macros },
349
378
350
379
blockDelimiters: [" $$" , [" $$ preample" , " $$" ]],
351
380
blockRenderer (src , token ) {
@@ -384,23 +413,39 @@ delimiter can be customized to look like an info string (see
384
413
below). Consider [ markdown-it-mathblock] [ markdown-it-mathblock ] if you
385
414
need commonmark compliant info strings.
386
415
387
- ## Upgrading From v4
388
-
389
- Version 5 introduced some breaking changes, along with dropping legacy platforms.
416
+ ## Deprecated Options
390
417
391
- - The ` inlineOpen ` , ` inlineClose ` , ` blockOpen ` , and ` blockClose ` options have
392
- been depricated in favor of ` inlineDelimiters ` and ` blockDelimiters `
393
- respectively.
418
+ - ** ` inlineOpen ` ** and ** ` inlineClose ` ** (since v5.0.0): Deprecated in favor
419
+ of ` inlineDelimiters ` :
394
420
``` diff
395
421
markdownIt().use(markdownItMath, {
396
422
- inlineOpen: "$",
397
423
- inlineClose: "$",
424
+ + inlineDelimiters: "$",
425
+ });
426
+ ```
427
+ - ** ` blockOpen ` ** and ** ` blockClose ` ** (since v5.0.0): Deprecated in favor
428
+ of ` blockDelimiters ` :
429
+ ``` diff
430
+ markdownIt().use(markdownItMath, {
398
431
- blockOpen: "$$",
399
432
- blockClose: "$$",
400
- + inlineDelimiters: "$",
401
433
+ blockDelimiters: "$$",
402
434
});
403
435
```
436
+ - ** ` defaultRendererOptions ` ** (since v5.2.0): Deprecated in favor of
437
+ ` mathupOptions ` :
438
+ ``` diff
439
+ markdownIt().use(markdownItMath, {
440
+ - defaultRendererOptions: { decimalMark: "," },
441
+ + mathupOptions: { decimalMark: "," },
442
+ });
443
+ ```
444
+
445
+ ## Upgrading From v4
446
+
447
+ Version 5 introduced some breaking changes, along with dropping legacy platforms.
448
+
404
449
- The default delimiters changed from ` $$ ` and ` $$$ ` for inline and
405
450
block math respectively to ` $ ` and ` $$ ` . If you want to keep the
406
451
thicker variants, you must set the relevant options:
@@ -411,11 +456,11 @@ Version 5 introduced some breaking changes, along with dropping legacy platforms
411
456
});
412
457
```
413
458
- The options passed into the default mathup renderer has been renamed
414
- from ` renderingOptions ` to ` defaultRendererOptions ` :
459
+ from ` renderingOptions ` to ` mathupOptions ` :
415
460
``` diff
416
461
markdownIt().use(markdownItMath, {
417
462
- renderingOptions: { decimalMark: ",", },
418
- + defaultRendererOptions : { decimalMark: ",", },
463
+ + mathupOptions : { decimalMark: ",", },
419
464
});
420
465
```
421
466
- The default math renderer has been changed from Ascii2MathML to it’s
@@ -441,7 +486,6 @@ Version 5 introduced some breaking changes, along with dropping legacy platforms
441
486
442
487
[ @mdit/plugin-katex ] : https://mdit-plugins.github.io/katex.html
443
488
[ importmap ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
444
- [ jsdelivr ] : https://www.jsdelivr.com/
445
489
[ markdown-it ] : https://github.com/markdown-it/markdown-it
446
490
[ markdown-it-mathblock ] : https://github.com/runarberg/markdown-it-mathblock
447
491
[ markdown-it-mathspan ] : https://github.com/runarberg/markdown-it-mathspan
0 commit comments