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
800 stars 27 forks source link

Inline Math (text between a single dollar sign) causes LTeX to stop working #855

Open attiliocn opened 1 year ago

attiliocn commented 1 year ago

Describe the bug The use of inline math in a .tex document "shuts down" LTeX. This problem seems to occur only when the inline math is not preceded by any character.

Steps to reproduce

This document should be sufficient to demonstrate the problem.

\documentclass[12pt]{report}
\begin{document}

Lorem ipsum$\Delta$ dolor sit amet, consectetur adipiscing elit. 

Lorem ipsum $\Delta$ dolor sit amet, consectetur adipiscing elit. 

\end{document}

If both lines containing Lorem ipsum are kept uncommented, then the following server log is obtained and VSCode does not show any highlighted word.

image

Oct 03, 2023 10:59:28 AM org.bsplines.ltexls.server.DocumentChecker logTextToBeChecked
FINE: Checking the following text in language 'pt-BR' via LanguageTool: " \n\nLorem ipsumDummy0 dolor sit amet, consectetur adipiscing elit.\n\nLorem ipsum Dummy1 dolor sit amet"... (truncated to 100 characters)
Oct 03, 2023 10:59:29 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>Lorem ipsum Dummy1 dolor sit amet, consectetur adipiscing elit.

</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: Portuguese (Brazil)): <sentcontent>Lorem ipsum Dummy1 dolor sit amet, consectetur adipiscing elit.

</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 (134) must be less than toPos (134) for match: <sentcontent>HUNSPELL_RULE:12-17: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

However, if the second Lorem Ipsum is commented, then the following log is obtained and LTeX works as expected.

image

Oct 03, 2023 11:04:38 AM org.bsplines.ltexls.server.DocumentChecker logTextToBeChecked
FINE: Checking the following text in language 'pt-BR' via LanguageTool: " \n\nLorem ipsumDummy0 dolor sit amet, consectetur adipiscing elit.\n\n"
Oct 03, 2023 11:04:38 AM org.bsplines.ltexls.server.DocumentChecker checkAnnotatedTextFragment
FINE: Obtained 8 rule matches

Expected behavior I expect that the Grammar/Spell check does not stops because there is an inline math present in the text.

Sample document

```latex \documentclass[12pt]{report} \begin{document} Lorem ipsum$\Delta$ dolor sit amet, consectetur adipiscing elit. Lorem ipsum $\Delta$ dolor sit amet, consectetur adipiscing elit. \end{document} ```

LTeX configuration

``` { "enabled": [ "latex", "markdown" ], "language": "pt-BR", "dictionary": {}, "disabledRules": {}, "enabledRules": {}, "hiddenFalsePositives": {}, "bibtex": { "fields": {} }, "latex": { "commands": { "\\autocite{}": "ignore" }, "environments": {} }, "markdown": { "nodes": {} }, "configurationTarget": { "dictionary": "workspaceFolderExternalFile", "disabledRules": "workspaceFolderExternalFile", "hiddenFalsePositives": "workspaceFolderExternalFile" }, "additionalRules": { "enablePickyRules": false, "motherTongue": "pt-BR", "languageModel": "", "neuralNetworkModel": "", "word2VecModel": "" }, "languageToolHttpServerUri": "", "languageToolOrg": { "username": "", "apiKey": "" }, "ltex-ls": { "path": "", "logLevel": "fine", "languageToolHttpServerUri": "", "languageToolOrgUsername": "", "languageToolOrgApiKey": "" }, "java": { "path": "", "initialHeapSize": 64, "maximumHeapSize": 1024 }, "sentenceCacheSize": 10000, "completionEnabled": false, "diagnosticSeverity": "information", "checkFrequency": "edit", "clearDiagnosticsWhenClosingFile": true, "statusBarItem": true, "trace": { "server": "off" } } ```

"LTeX Language Server" log file Included in the problem description

"LTeX Language Client" log file First, set the ltex.trace.server setting in your settings.json to "verbose". Then, reload the VS Code window and reproduce the bug. Go to ViewOutput and select LTeX Language Client in the drop-down list. Paste this log here (note: it will contain your checked document):

``` 2023-10-03T14:12:45.513Z Info: Setting LTeX UI language to 'en'. 2023-10-03T14:12:45.513Z Info: Loading i18n messages... 2023-10-03T14:12:45.513Z Info: Loading default i18n messages... 2023-10-03T14:12:45.515Z Info: 2023-10-03T14:12:45.515Z Info: ltex.ltex-ls.path not set. 2023-10-03T14:12:45.515Z Info: Searching for ltex-ls in '/home/attilio/.vscode-server/extensions/valentjn.vscode-ltex-13.1.0/lib'... 2023-10-03T14:12:45.515Z Info: ltex-ls found in '/home/attilio/.vscode-server/extensions/valentjn.vscode-ltex-13.1.0/lib/ltex-ls-15.2.0'. 2023-10-03T14:12:45.515Z Info: 2023-10-03T14:12:45.515Z Info: Using ltex-ls from '/home/attilio/.vscode-server/extensions/valentjn.vscode-ltex-13.1.0/lib/ltex-ls-15.2.0'. 2023-10-03T14:12:45.515Z Info: Using Java bundled with ltex-ls as ltex.java.path is not set. 2023-10-03T14:12:45.517Z Info: Testing ltex-ls... 2023-10-03T14:12:45.517Z Info: Command: "/home/attilio/.vscode-server/extensions/valentjn.vscode-ltex-13.1.0/lib/ltex-ls-15.2.0/bin/ltex-ls" 2023-10-03T14:12:45.517Z Info: Arguments: ["--version"] 2023-10-03T14:12:45.517Z Info: env['JAVA_HOME']: undefined 2023-10-03T14:12:45.517Z Info: env['JAVA_OPTS']: "-Xms64m -Xmx512m" 2023-10-03T14:12:45.808Z Info: Test successful! 2023-10-03T14:12:45.818Z Info: 2023-10-03T14:12:45.823Z Info: Starting ltex-ls... 2023-10-03T14:12:45.823Z Info: Command: "/home/attilio/.vscode-server/extensions/valentjn.vscode-ltex-13.1.0/lib/ltex-ls-15.2.0/bin/ltex-ls" 2023-10-03T14:12:45.823Z Info: Arguments: [] 2023-10-03T14:12:45.823Z Info: env['JAVA_HOME']: undefined 2023-10-03T14:12:45.823Z Info: env['JAVA_OPTS']: "-Xms64m -Xmx512m" 2023-10-03T14:12:45.823Z Info: 2023-10-03T14:14:23.875Z Info: Creating bug report... ```

Version information List here the version information of the relevant software.

Additional context/information

mok33 commented 11 months ago

I also have the same issue unfortunately. Is there a way to tell ltex to ignore some line that he can't parse correctly ?

attiliocn commented 11 months ago

I also have the same issue unfortunately. Is there a way to tell ltex to ignore some line that he can't parse correctly ?

I'm using the inline math environment as a workaround.

\documentclass[12pt]{report}
\begin{document}

Lorem ipsum$\Delta$ dolor sit amet, consectetur adipiscing elit. 

Lorem ipsum \begin{math}\Delta\end{math} dolor sit amet, consectetur adipiscing elit. 

\end{document}

image

caioolivv commented 6 months ago

Also having the same problem here. I can post the logs if needed.