diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c80c558..897395a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ## 9.0.1 (upcoming) - Ignore `\pgfmathsetmacro`, `\setmainfont`, and `\theoremstyle` +- Fix accent commands such as `\O` in math mode resulting in diagnostics (fixes [vscode-ltex#216](https://github.com/valentjn/vscode-ltex/issues/216)) ## 9.0.0 (January 3, 2021) diff --git a/ltexls-core/src/main/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilder.java b/ltexls-core/src/main/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilder.java index d6e190f5..db1b9931 100644 --- a/ltexls-core/src/main/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilder.java +++ b/ltexls-core/src/main/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilder.java @@ -561,21 +561,21 @@ public LatexAnnotatedTextBuilder addCode(String code) { popMode(); addMarkup(command, generateDummy()); } else if (command.equals("\\AA")) { - addMarkup(command, "\u00c5"); + addMarkup(command, (isMathMode(this.curMode) ? "" : "\u00c5")); } else if (command.equals("\\O")) { - addMarkup(command, "\u00d8"); + addMarkup(command, (isMathMode(this.curMode) ? "" : "\u00d8")); } else if (command.equals("\\aa")) { - addMarkup(command, "\u00e5"); + addMarkup(command, (isMathMode(this.curMode) ? "" : "\u00e5")); } else if (command.equals("\\ss")) { - addMarkup(command, "\u00df"); + addMarkup(command, (isMathMode(this.curMode) ? "" : "\u00df")); } else if (command.equals("\\o")) { - addMarkup(command, "\u00f8"); + addMarkup(command, (isMathMode(this.curMode) ? "" : "\u00f8")); } else if (command.equals("\\`") || command.equals("\\'") || command.equals("\\^") || command.equals("\\~") || command.equals("\\\"") || command.equals("\\=") || command.equals("\\.")) { Matcher matcher = accentPattern1.matcher(code.substring(this.pos)); - if (matcher.find()) { + if (!isMathMode(this.curMode) && matcher.find()) { @Nullable String accentCommand = matcher.group(1); @Nullable String letter = ((matcher.group(3) != null) ? matcher.group(3) : matcher.group(5)); @@ -588,7 +588,7 @@ public LatexAnnotatedTextBuilder addCode(String code) { } else if (command.equals("\\c") || command.equals("\\r")) { Matcher matcher = accentPattern2.matcher(code.substring(this.pos)); - if (matcher.find()) { + if (!isMathMode(this.curMode) && matcher.find()) { @Nullable String accentCommand = matcher.group(1); @Nullable String letter = ((matcher.group(3) != null) ? matcher.group(3) : matcher.group(4)); diff --git a/ltexls-core/src/test/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilderTest.java b/ltexls-core/src/test/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilderTest.java index 1b465932..f5aea00a 100644 --- a/ltexls-core/src/test/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilderTest.java +++ b/ltexls-core/src/test/java/org/bsplines/ltexls/parsing/latex/LatexAnnotatedTextBuilderTest.java @@ -223,6 +223,13 @@ public void testMathMode() { + " a \\text{,~and} b.\n" + "\\end{equation*}\n", "This is a test: Dummy0,\u00a0and Dummy1. "); + assertPlainText( + "This is a test:\n" + + "\\begin{equation}\n" + + " Gau\\ss{}: \\O(n^2).\n" + + "\\end{equation}\n" + + "This is another test: $Gau\\ss{}: \\O(n^2)$.\n", + "This is a test: Dummy0. This is another test: Dummy1. "); assertPlainText( "This is a test:\n" + "\\[\n"