Skip to content

Commit

Permalink
Fix accent commands in math mode causing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
valentjn committed Jan 12, 2021
1 parent 314448e commit 1b6d0e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1b6d0e8

Please sign in to comment.