From 058af4445a221e5a5a8b84599a27c93f78f1e95d Mon Sep 17 00:00:00 2001 From: James Yu Date: Sat, 6 Jan 2024 10:33:54 +0000 Subject: [PATCH] Fix #4127 Remove macro star when rendering MathJax --- src/preview/math/mathpreviewlib/newcommandfinder.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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') {