diff --git a/src/preview/math/mathpreviewlib/newcommandfinder.ts b/src/preview/math/mathpreviewlib/newcommandfinder.ts index 7114a27f8..1d5040760 100644 --- a/src/preview/math/mathpreviewlib/newcommandfinder.ts +++ b/src/preview/math/mathpreviewlib/newcommandfinder.ts @@ -64,7 +64,13 @@ function parseAst(content: string, node: Ast.Node): string[] { lastContent = lastArg.content[lastArg.content.length - 1] } const end = (lastArg.content[lastArg.content.length - 1].position?.end.offset ?? -1 - closeBraceOffset) + closeBraceOffset - macros.push(content.slice(start, end + 1).replaceAll(/\\providecommand([^a-zA-Z])/g, '\\newcommand$1')) + macros.push( + content.slice(start, end + 1) + // Change providecommand to newcommand + .replaceAll(/^\\providecommand([^a-zA-Z])/g, '\\newcommand$1') + // Remove the star as MathJax does not support #4127 + .replaceAll(/^\\([a-zA-Z]+)\*/g, '\\$1') + ) } if ('content' in node && typeof node.content !== 'string') {