valentjn / vscode-ltex

LTeX: Grammar/spell checker :mag::heavy_check_mark: for VS Code using LanguageTool with support for LaTeX :mortar_board:, Markdown :pencil:, and others
https://valentjn.github.io/ltex
Mozilla Public License 2.0
781 stars 26 forks source link

Punctuation symbols at the end of \[ \] LaTeX math environment produce errors #507

Open grivasgervilla opened 2 years ago

grivasgervilla commented 2 years ago

I have encountered an error when I put a comma inside a [ ] math environment in LaTeX. For example, the following code is correctly parse by LTeX without errors:

\begin{definition}[operadores de derivación de Burusco et al~\cite{burusco_juandeaburre_study_1994}~\label{def:burusco-derivation-operators}]
   \[A^\uparrow(m) =. \bigwedge_{g \in G}(A(g)' \oplus I(g,m))\]
   \[B^\downarrow(g) =, \bigwedge_{m \in M}(B(m)' \oplus I(g,m))a\]
\end{definition}

Here I have used a period and a comma behind the equal symbols. However, if I place these punctuation symbols at the end of the math invoronment

\begin{definition}[operadores de derivación de Burusco et al~\cite{burusco_juandeaburre_study_1994}~\label{def:burusco-derivation-operators}]
   \[A^\uparrow(m) = \bigwedge_{g \in G}(A(g)' \oplus I(g,m)),\]
   \[B^\downarrow(g) = \bigwedge_{m \in M}(B(m)' \oplus I(g,m))a.\]
\end{definition}

then I get the following error trace:

ene. 03, 2022 12:01:53 A. M. org.bsplines.ltexls.server.DocumentChecker logTextToBeChecked
DETALLADO: Checking the following text in language 'es' via LanguageTool: " Dummy0, Dummy1. "
ene. 03, 2022 12:01:53 A. M. org.bsplines.ltexls.server.DocumentChecker checkAnnotatedTextFragment
GRAVE: LanguageTool failed. The following exception occurred:
java.lang.RuntimeException: java.lang.RuntimeException: Could not check sentence (language: Spanish): <sentcontent> Dummy0, Dummy1. </sentcontent>
    at org.languagetool.JLanguageTool.performCheck(JLanguageTool.java:1230)
    at org.languagetool.JLanguageTool.checkInternal(JLanguageTool.java:970)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:900)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:882)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:869)
    at org.bsplines.ltexls.languagetool.LanguageToolJavaInterface.checkInternal(LanguageToolJavaInterface.kt:112)
    at org.bsplines.ltexls.languagetool.LanguageToolInterface.check(LanguageToolInterface.kt:22)
    at org.bsplines.ltexls.server.DocumentChecker.checkAnnotatedTextFragment(DocumentChecker.kt:138)
    at org.bsplines.ltexls.server.DocumentChecker.checkAnnotatedTextFragments(DocumentChecker.kt:91)
    at org.bsplines.ltexls.server.DocumentChecker.check(DocumentChecker.kt:279)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.check(LtexTextDocumentItem.kt:413)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndGetDiagnostics(LtexTextDocumentItem.kt:295)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnostics(LtexTextDocumentItem.kt:272)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnosticsWithoutCache(LtexTextDocumentItem.kt:267)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnosticsWithoutCache$default(LtexTextDocumentItem.kt:266)
    at org.bsplines.ltexls.server.LtexTextDocumentService.didChange$lambda-3(LtexTextDocumentService.kt:227)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Could not check sentence (language: Spanish): <sentcontent> Dummy0, Dummy1. </sentcontent>
    at org.languagetool.JLanguageTool$TextCheckCallable.getOtherRuleMatches(JLanguageTool.java:1883)
    at org.languagetool.JLanguageTool$TextCheckCallable.call(JLanguageTool.java:1765)
    at org.languagetool.JLanguageTool$TextCheckCallable.call(JLanguageTool.java:1736)
    at org.languagetool.JLanguageTool.performCheck(JLanguageTool.java:1226)
    ... 21 more
Caused by: java.lang.RuntimeException: fromPos (204) must be less than toPos (204) for match: <sentcontent>MORFOLOGIK_RULE_ES:1-7:Se ha encontrado un posible error ortográfico.</sentcontent>
    at org.languagetool.rules.RuleMatch.setOffsetPosition(RuleMatch.java:326)
    at org.languagetool.JLanguageTool.adjustRuleMatchPos(JLanguageTool.java:1345)
    at org.languagetool.JLanguageTool$TextCheckCallable.getOtherRuleMatches(JLanguageTool.java:1856)
    ... 24 more

These are my settings:

"ltex.language": "es",
"ltex.completionEnabled": true,
"ltex.additionalRules.motherTongue": "es",
"ltex.checkFrequency": "edit",
"ltex.diagnosticSeverity": "error",
"ltex.trace.server": "verbose"

Would it be possible to make LTeX ignore the content of \[\] and $$ math environments? Many thanks for your time :smile:.

vic-torr commented 2 years ago

Reproduced the same here, but with pt-BR: Original text:

Quando \(y=f(x)\), o modelo atribui uma entrada descrita pelo por \(x\), que nosso caso constitui uma amostra de entrada, a uma categoria identificada por um código numérico \(y\).

Exception:

Jul 04, 2022 1:57:38 AM org.bsplines.ltexls.server.DocumentChecker checkAnnotatedTextFragment
SEVERE: LanguageTool failed. The following exception occurred:
java.lang.RuntimeException: java.lang.RuntimeException: Could not check sentence (language: Portuguese (Brazil)): <sentcontent>Quando Dummy8, o modelo atribui uma entrada descrita pelo por Ina9, que nosso caso constitui uma amostra de entrada, a uma categoria identificada por um código numérico Dummy10. </sentcontent>
    at org.languagetool.JLanguageTool.performCheck(JLanguageTool.java:1230)
    at org.languagetool.JLanguageTool.checkInternal(JLanguageTool.java:970)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:900)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:882)
    at org.languagetool.JLanguageTool.check(JLanguageTool.java:869)
    at org.bsplines.ltexls.languagetool.LanguageToolJavaInterface.checkInternal(LanguageToolJavaInterface.kt:112)
    at org.bsplines.ltexls.languagetool.LanguageToolInterface.check(LanguageToolInterface.kt:22)
    at org.bsplines.ltexls.server.DocumentChecker.checkAnnotatedTextFragment(DocumentChecker.kt:138)
    at org.bsplines.ltexls.server.DocumentChecker.checkAnnotatedTextFragments(DocumentChecker.kt:91)
    at org.bsplines.ltexls.server.DocumentChecker.check(DocumentChecker.kt:279)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.check(LtexTextDocumentItem.kt:413)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndGetDiagnostics(LtexTextDocumentItem.kt:295)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnostics(LtexTextDocumentItem.kt:272)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnosticsWithoutCache(LtexTextDocumentItem.kt:267)
    at org.bsplines.ltexls.server.LtexTextDocumentItem.checkAndPublishDiagnosticsWithoutCache$default(LtexTextDocumentItem.kt:266)
    at org.bsplines.ltexls.server.LtexTextDocumentService.didSave$lambda-2(LtexTextDocumentService.kt:197)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Could not check sentence (language: Portuguese (Brazil)): <sentcontent>Quando Dummy8, o modelo atribui uma entrada descrita pelo por Ina9, que nosso caso constitui uma amostra de entrada, a uma categoria identificada por um código numérico Dummy10. </sentcontent>
    at org.languagetool.JLanguageTool$TextCheckCallable.getOtherRuleMatches(JLanguageTool.java:1883)
    at org.languagetool.JLanguageTool$TextCheckCallable.call(JLanguageTool.java:1765)
    at org.languagetool.JLanguageTool$TextCheckCallable.call(JLanguageTool.java:1736)
    at org.languagetool.JLanguageTool.performCheck(JLanguageTool.java:1226)
    ... 21 more
Caused by: java.lang.RuntimeException: fromPos (4147) must be less than toPos (4147) for match: <sentcontent>HUNSPELL_RULE:169-174:Encontrado possível erro de ortografia.</sentcontent>
    at org.languagetool.rules.RuleMatch.setOffsetPosition(RuleMatch.java:326)
    at org.languagetool.JLanguageTool.adjustRuleMatchPos(JLanguageTool.java:1345)
    at org.languagetool.JLanguageTool$TextCheckCallable.getOtherRuleMatches(JLanguageTool.java:1856)
    ... 24 more
lrnv commented 1 year ago

I am glad this issue exists, as researching "must be less than toPos" in the issue tracker pointed me exactly here and to the root of the problem I was having (exactly this one).

Disabling LTeX around the problematic equation via magic comments allowed me to continue checking the rest of the document.

It is a shame that when the language server errors on some line, the whole documents stays unchecked. A better behavior would be to remove the line from the checking text so that the rest can still be outputted: One missing line made me though that my 10-pages document was clear of language issues, while it clearly wasn't.

The LTeX client did receive zero response and did not even complain about it, while te LTeX server clearly was reporting errors. Maybe the client could report errors when the server does ? The status bar keeps saying "LTeX ready" as everything is OK although it is not, which was confusing.

So I guess the following things could be done to mitigate the trouble this kind of issues can cause to the user:

1° When the server errors on some text, it could report it alongside the rest of the issues as maybe a special rule "SERVER_ERRORED: There is something on this line that LTeX Server did not like and errored on, we are sorry. Try to ignore this line and re-check" ? Even if nothing else is reported on the document, this will greatly ameliorate debugging. 2° The status bar could have a cross instead of a check sign when the server errors, so that we know something's wrong

Of course, I do not know at all if such things are easy to implement or even possible, I'll let you decide what is the best course of actions :)

PierreMarchand20 commented 6 months ago

I encountered the same kind of error due to this line : \titleformat*{\section}{\bfseries}.