File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 */
1011const 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
4748const _render = ( options : KatexOptions ) => ( raw : string ) => {
You can’t perform that action at this time.
0 commit comments