@@ -81,7 +81,8 @@ npm install mathup --save
81
81
82
82
### In a browser
83
83
84
- Use an [ importmap] [ importmap ] . Change ` /path/to/modules ` to the location of your modules.
84
+ Use an [ importmap] [ importmap ] . Change ` /path/to/modules ` to the
85
+ location of your modules.
85
86
86
87
``` html
87
88
<!-- mathup is optional -->
@@ -107,10 +108,8 @@ import markdownItMath from "markdown-it-math";
107
108
108
109
// Optional (with defaults)
109
110
const options = {
110
- inlineOpen: " $" ,
111
- inlineClose: " $" ,
112
- blockOpen: " $$" ,
113
- blockClose: " $$" ,
111
+ inlineDelimiters: [" $" , [" $`" , " `$" ]]
112
+ blockDelimiters: " $$" ,
114
113
defaultRendererOptions,
115
114
inlineCustomElement, // see below
116
115
inlineRenderer, // see below
137
136
138
137
### Options
139
138
140
- - ` inlineOpen ` : The delimiter to start an inline math expression. Default ` $ `
141
- - ` inlineClose ` : The delimiter to close an inline math expression. Default ` $ `
142
- - ` blockOpen ` : The delimiter to start a block math expression. Default ` $$ `
143
- - ` blockClose ` : The delimiter to close a block math expression. Default ` $$ `
144
- - ` defaultRendererOptions ` :
145
- The options passed into the default renderer. Ignored if you use a custom renderer. Default ` {} `
139
+ - ` inlineDelimiters ` : A string, or an array of strings (or pairs of
140
+ strings) specifying delimiters for inline math expressions. If a
141
+ string, the same delimiter is used for open and close. If a pair of
142
+ strings, the first string opens and the second one closes. Empty
143
+ strings or pairs containing empty strings are ignored. If no valid
144
+ strings or pairs are provided, it will turn off the rule.
145
+ Default `` ["$", ["$`", "`$"]] `` .
146
+ - ` blockDelimiters ` : Same as above, but for block expressions. Default ` "$$" ` .
147
+ - ` defaultRendererOptions ` : The options passed into the default
148
+ renderer. Ignored if you use a custom renderer. Default ` {} `
146
149
- ` inlineCustomElement ` :
147
150
Specify ` "tag-name" ` or ` ["tag-name", { some: "attrs" }] ` if you want to
148
151
render inline expressions to a custom element. Ignored if you provide a
@@ -226,34 +229,52 @@ md.render("$\\sin(2\\pi)$");
226
229
// <p><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mn>2</mn><mi>π</mi><mo stretchy="false">)</mo></mrow><annotation encoding="TeX">\sin(2\pi)</annotation></semantics></math></p>
227
230
```
228
231
232
+ Turning off inline math:
233
+
234
+ ``` js
235
+ import markdownIt from " markdown-it" ;
236
+ import markdownItMath from " markdown-it-math" ;
237
+
238
+ const md = markdownIt ().use (markdownItMath, {
239
+ inlineDelimiters: " " ,
240
+ });
241
+ ```
242
+
243
+ ``` md
244
+ Only block math is allowed. $a^2$ will not render into inline math.
245
+
246
+ But this will render into block math:
247
+
248
+ $$
249
+ a^2
250
+ $$
251
+ ```
252
+
229
253
Using LaTeX style delimiters:
230
254
231
255
``` js
232
256
import markdownIt from " markdown-it" ;
233
257
import markdownItMath from " markdown-it-math" ;
234
258
235
259
const md = markdownIt ().use (markdownItMath, {
236
- inlineOpen: " \\ (" ,
237
- inlineClose: " \\ )" ,
238
- blockOpen: " \\ [" ,
239
- blockClose: " \\ ]" ,
260
+ inlineDelimiters: [[" \\ (" , " \\ )" ]],
261
+ blockDelimiters: [[" \\ [" , " \\ ]" ]],
240
262
});
241
263
```
242
264
243
265
Note there are restrictions on what inline delimiters you can use,
244
266
based on optimization for the markdown-it parser [ see here for
245
- details] [ why-my-inline-rule-is-not-executed ] . And block level math
246
- must be on its own lines with newlines separating the math from the
247
- delimiters .
267
+ details] [ why-my-inline-rule-is-not-executed ] .
268
+
269
+ Block level math must be on its own lines .
248
270
249
271
``` markdown
250
272
Some text with inline math \(a^2 + b^2 = c^2\)
251
273
252
- And block math
274
+ And block math:
275
+ \[e = sum\_(n=0)^oo 1/n!\]
253
276
254
- \[
255
- e = sum\_(n=0)^oo 1/n!
256
- \]
277
+ This expression \[P(x \in X) = 0\] will not render.
257
278
```
258
279
259
280
[ importmap ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
@@ -270,15 +291,26 @@ e = sum\_(n=0)^oo 1/n!
270
291
271
292
Version 5 introduced some breaking changes, along with dropping legacy platforms.
272
293
294
+ - The ` inlineOpen ` , ` inlineClose ` , ` blockOpen ` , and ` blockClose ` options have
295
+ been depricated in favor of ` inlineDelimiters ` and ` blockDelimiters `
296
+ respectively.
297
+ ``` diff
298
+ markdownIt().use(markdownItMath, {
299
+ - inlineOpen: "$",
300
+ - inlineClose: "$",
301
+ - blockOpen: "$$",
302
+ - blockClose: "$$",
303
+ + inlineDelimiters: "$",
304
+ + blockDelimiters: "$$",
305
+ });
306
+ ```
273
307
- The default delimiters changed from ` $$ ` and ` $$$ ` for inline and
274
308
block math respectively to ` $ ` and ` $$ ` . If you want to keep the
275
309
thicker variants, you must set the relevant options:
276
310
``` js
277
311
markdownIt ().use (markdownItMath, {
278
- inlineOpen: " $$" ,
279
- inlineClose: " $$" ,
280
- blockOpen: " $$$" ,
281
- blockClose: " $$$" ,
312
+ inlineDelimiters: " $$" ,
313
+ blockDelimiters: " $$$" ,
282
314
});
283
315
```
284
316
- The options passed into the default mathup renderer has been renamed
0 commit comments