Skip to content

Commit cc729f2

Browse files
committed
fix: macro conversion error
1 parent 5d27533 commit cc729f2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/assets/ts/latex.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { KatexOptions } from "katex";
66
*
77
* Example:
88
* \newcommand{\foo}[2]{#1 + #2} --> \gdef\foo#1#2{#1 + #2}
9+
* \newcommand{\NN}{\mathbb{N}} --> \gdef\NN{\mathbb{N}}
910
*/
1011
const replaceNewcommandWithGdef = (raw: string): string => {
1112
let result = '';
@@ -15,8 +16,8 @@ const replaceNewcommandWithGdef = (raw: string): string => {
1516

1617
for (const match of raw.matchAll(newcmd_head)) {
1718
const [, cmd, argc] = match;
19+
const braceStart = match.index! + match[0].length - 1;
1820

19-
const braceStart = raw.indexOf('{', match.index + match[0].length);
2021
let depth = 0;
2122
let i = braceStart;
2223

@@ -41,7 +42,7 @@ const replaceNewcommandWithGdef = (raw: string): string => {
4142

4243
result += raw.slice(lastIndex);
4344
return result;
44-
}
45+
};
4546

4647

4748
const _render = (options: KatexOptions) => (raw: string) => {

0 commit comments

Comments
 (0)