@@ -3,7 +3,7 @@ title: "@mdit/plugin-katex"
3
3
icon : square-root-variable
4
4
---
5
5
6
- Plugins to render math expressions with KaTeX, you should install ` katex ` as peer dependency .
6
+ Plugins to render math expressions with KaTeX.
7
7
8
8
::: note
9
9
@@ -41,7 +41,7 @@ mdIt.render("$E=mc^2$");
41
41
42
42
:::
43
43
44
- We also have a package called ` @mdit/plugin-katex-slim ` which ` katex ` is an optional dep .
44
+ We also have a package called ` @mdit/plugin-katex-slim ` which ` katex ` is an optional peer .
45
45
46
46
## Syntax
47
47
80
80
81
81
:::
82
82
83
- ## Options
83
+ ## mhchem extension
84
+
85
+ If you want to load the ` mhchem ` extension, you should import ` loadMhchem ` from ` @mdit/plugin-katex ` :
84
86
85
87
``` ts
86
- interface KatexCatcodes {
87
- [key : string ]: number ;
88
- }
88
+ import { loadMhchem } from " @mdit/plugin-katex" ;
89
89
90
- interface KatexLexerInterFace {
91
- input: string ;
92
- tokenRegex: RegExp ;
93
- settings: Required <KatexOptions >;
94
- catcodes: KatexCatcodes ;
95
- }
90
+ await loadMhchem ();
91
+ ```
96
92
97
- interface KatexSourceLocation {
98
- start: number ;
99
- end: number ;
100
- lexer: KatexLexerInterFace ;
101
- }
93
+ Since it's async, you should call it in prepare stage as markdown-it rendering is sync.
102
94
103
- interface KatexToken {
104
- text: string ;
105
- loc: KatexSourceLocation ;
106
- noexpand: boolean | undefined ;
107
- treatAsRelax: boolean | undefined ;
108
- }
95
+ ## Options
109
96
97
+ ``` ts
110
98
type KatexLogger <MarkdownItEnv = unknown > = (
111
99
errorCode :
112
100
| " unknownSymbol"
@@ -116,9 +104,11 @@ type KatexLogger<MarkdownItEnv = unknown> = (
116
104
| " htmlExtension"
117
105
| " newLineInDisplayMode" ,
118
106
errorMsg : string ,
119
- token : KatexToken ,
107
+ token : Token ,
120
108
env : MarkdownItEnv ,
121
- ) => " error" | " warn" | " ignore" | void ;
109
+ ) => " error" | " warn" | " ignore" | boolean | undefined | void ;
110
+
111
+ type TeXTransformer = (content : string , displayMode : boolean ) => string ;
122
112
123
113
interface MarkdownItKatexOptions <MarkdownItEnv = unknown > extends KatexOptions {
124
114
/**
@@ -138,16 +128,14 @@ interface MarkdownItKatexOptions<MarkdownItEnv = unknown> extends KatexOptions {
138
128
mathFence? : boolean ;
139
129
140
130
/**
141
- * Whether enable mhchem extension
142
- *
143
- * @default false
131
+ * Error logger
144
132
*/
145
- mhchem ? : boolean ;
133
+ logger ? : KatexLogger < MarkdownItEnv > ;
146
134
147
135
/**
148
- * Error logger
136
+ * transformer on output content
149
137
*/
150
- logger ? : KatexLogger < MarkdownItEnv > ;
138
+ transformer ? : TeXTransformer ;
151
139
}
152
140
```
153
141
0 commit comments