1010AsciiMath dialect. If you want to use LaTeX, follow the instructions
1111below.
1212
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+
1317``` md
1418Pythagorean theorem is $a^2 + b^2 = c^2$.
1519
@@ -53,9 +57,9 @@ location of your modules.
5357 </script >
5458```
5559
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
5963renderer.
6064
6165## Usage
@@ -71,7 +75,7 @@ const options = {
7175 inlineDelimiters: [" $" , [" $`" , " `$" ]],
7276 inlineAllowWhiteSpacePadding: false ,
7377 blockDelimiters: " $$" ,
74- defaultRendererOptions ,
78+ mathupOptions ,
7579 inlineCustomElement, // see below
7680 inlineRenderer, // see below
7781 blockCustomElement, // see below
@@ -101,26 +105,28 @@ default renderer.
101105### LaTeX (Temml)
102106
103107``` bash
108+ # install temml as a peer dependency
104109npm install --save temml
105110```
106111
107112``` js
108113import markdownIt from " markdown-it" ;
109- import markdownItMath from " markdown-it-math" ;
110- import temml from " temml" ;
114+ import markdownItMathTemml from " markdown-it-math/temml" ;
111115
112116// Optional, if you want macros to persit across equations.
113117const macros = {};
114118
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 },
119121});
120122```
121123
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+
122128``` js
123- md .render (`
129+ md .render (String . raw `
124130A text $1+1=2$ with math.
125131
126132$$
@@ -138,6 +144,26 @@ You may also want to include the stylesheets and fonts from Temml. See
138144[ Temml] [ temml ] for reference and usage instructions about the
139145default renderer.
140146
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+
141167### Options
142168
143169- ` inlineDelimiters ` : A string, or an array of strings (or pairs of
@@ -153,8 +179,11 @@ default renderer.
153179 ` \(...\) ` as delimiters where the risk of non-intended math
154180 expression is low.
155181- ` 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 ` {} ` .
158187- ` inlineCustomElement ` :
159188 Specify ` "tag-name" ` or ` ["tag-name", { some: "attrs" }] ` if you want to
160189 render inline expressions to a custom element. Ignored if you provide a
@@ -167,7 +196,7 @@ default renderer.
167196 import mathup from " mathup" ;
168197
169198 function defaultInlineRenderer (src , token , md ) {
170- return mathup (src, defaultRendererOptions ).toString ();
199+ return mathup (src, mathupOptions ).toString ();
171200 }
172201 ```
173202
@@ -184,7 +213,7 @@ default renderer.
184213
185214 function defaultBlockRenderer (src , token , md ) {
186215 return mathup (src, {
187- ... defaultRendererOptions ,
216+ ... mathupOptions ,
188217 display: " block" ,
189218 }).toString ();
190219 }
@@ -207,7 +236,7 @@ import markdownIt from "markdown-it";
207236import markdownItMath from " markdown-it-math" ;
208237
209238const md = markdownIt ().use (markdownItMath, {
210- defaultRendererOptions : { decimalMark: " ," },
239+ mathupOptions : { decimalMark: " ," },
211240});
212241
213242md .render (" $40,2$" );
@@ -338,14 +367,14 @@ e = \sum_{n=0}^{\infty} \frac{1}{n!}
338367
339368``` js
340369import markdownIt from " markdown-it" ;
341- import markdownItMath from " markdown-it-math" ;
370+ import markdownItMathTemml from " markdown-it-math/temml " ;
342371import temml from " temml" ;
343372
344373// An object to keep all the global macros.
345374const macros = {};
346375
347- const md = markdownIt ().use (markdownItMath , {
348- inlineRenderer : ( src ) => temml . renderToString (src, { macros }) ,
376+ const md = markdownIt ().use (markdownItMathTemml , {
377+ temmlOptions : { macros },
349378
350379 blockDelimiters: [" $$" , [" $$ preample" , " $$" ]],
351380 blockRenderer (src , token ) {
@@ -384,23 +413,39 @@ delimiter can be customized to look like an info string (see
384413below). Consider [ markdown-it-mathblock] [ markdown-it-mathblock ] if you
385414need commonmark compliant info strings.
386415
387- ## Upgrading From v4
388-
389- Version 5 introduced some breaking changes, along with dropping legacy platforms.
416+ ## Deprecated Options
390417
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 ` :
394420 ``` diff
395421 markdownIt().use(markdownItMath, {
396422 - inlineOpen: "$",
397423 - 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, {
398431 - blockOpen: "$$",
399432 - blockClose: "$$",
400- + inlineDelimiters: "$",
401433 + blockDelimiters: "$$",
402434 });
403435 ```
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+
404449- The default delimiters changed from ` $$ ` and ` $$$ ` for inline and
405450 block math respectively to ` $ ` and ` $$ ` . If you want to keep the
406451 thicker variants, you must set the relevant options:
@@ -411,11 +456,11 @@ Version 5 introduced some breaking changes, along with dropping legacy platforms
411456 });
412457 ```
413458- The options passed into the default mathup renderer has been renamed
414- from ` renderingOptions ` to ` defaultRendererOptions ` :
459+ from ` renderingOptions ` to ` mathupOptions ` :
415460 ``` diff
416461 markdownIt().use(markdownItMath, {
417462 - renderingOptions: { decimalMark: ",", },
418- + defaultRendererOptions : { decimalMark: ",", },
463+ + mathupOptions : { decimalMark: ",", },
419464 });
420465 ```
421466- 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
441486
442487[ @mdit/plugin-katex ] : https://mdit-plugins.github.io/katex.html
443488[ importmap ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
444- [ jsdelivr ] : https://www.jsdelivr.com/
445489[ markdown-it ] : https://github.com/markdown-it/markdown-it
446490[ markdown-it-mathblock ] : https://github.com/runarberg/markdown-it-mathblock
447491[ markdown-it-mathspan ] : https://github.com/runarberg/markdown-it-mathspan
0 commit comments