Skip to content

Commit b1dbd0a

Browse files
committed
add mathMacro object to use macro defined in other line.
example: ``` $\gdef\pdv#1#2{\frac{\partial#1}{\partial #2}}$ $$H=\dot q\pdv{L}{\dot q}-L$$ ```
1 parent 513b721 commit b1dbd0a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

browser/lib/markdown.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Markdown {
5858

5959
const updatedOptions = Object.assign(defaultOptions, options)
6060
this.md = markdownit(updatedOptions)
61+
this.mathMacro = {}
6162

6263
if (updatedOptions.sanitize !== 'NONE') {
6364
const allowedTags = ['iframe', 'input', 'b',
@@ -117,19 +118,19 @@ class Markdown {
117118
inlineClose: config.preview.latexInlineClose,
118119
blockOpen: config.preview.latexBlockOpen,
119120
blockClose: config.preview.latexBlockClose,
120-
inlineRenderer: function (str) {
121+
inlineRenderer: (str) => {
121122
let output = ''
122123
try {
123-
output = katex.renderToString(str.trim())
124+
output = katex.renderToString(str.trim(), { macros : this.mathMacro })
124125
} catch (err) {
125126
output = `<span class="katex-error">${err.message}</span>`
126127
}
127128
return output
128129
},
129-
blockRenderer: function (str) {
130+
blockRenderer: (str) => {
130131
let output = ''
131132
try {
132-
output = katex.renderToString(str.trim(), { displayMode: true })
133+
output = katex.renderToString(str.trim(), { displayMode: true, macros : this.mathMacro })
133134
} catch (err) {
134135
output = `<div class="katex-error">${err.message}</div>`
135136
}

0 commit comments

Comments
 (0)