Vscode-spell-checker: LaTeX: No spell check for user-defined commands

Created on 11 Feb 2019  路  4Comments  路  Source: streetsidesoftware/vscode-spell-checker

This issue is similar to #179, and I'm not sure if someone else has mentioned this before. I attached a figure as an example for the problem. Line 191, 198, 199 are checked as expected, line 201, 202 are not checked as expected. However, I want the line 196 also be checked.

image

Sometimes, downloaded LaTeX templates may define commands to wrap text with font styles, like the "abc" I defined here on line 193. However, the code spell checker fully ignores the arguments of these user-defined commands on line 196.

As opposed to a blacklist solution that does check against "chapter, section, ...", I propose a whitelist solution that does not check "label, ref, (maybe) newcommand...". Then, all user-defined commands and "chapter, section, ..." will be spell-checked.

If this can not be fixed universally for all users, is there a way that I can turn on the spell checking for user-defined commands only for myself? Thank you so much for the help.

Most helpful comment

@society765
Thank you for providing a work around.

There is no need to change the default settings. You can override them locally.

In your user settings create your own pattern called LaTexMacrosMultiLine

To add todo, it would look like the following:

    "cSpell.languageSettings": [
        {
            "languageId": "latex",
            "patterns": [
                {
                    "name": "LaTexMacrosMultiLine",
                    "pattern": "\\\\(?!(?:title|color|section|subsection|footnote|chapter|part|caption|emph|text|todo))\\w+(?:\\[[^]*?\\]|\\{[^]*?\\})*",
                    "description": "Match against all LaTex Macros"
                }
            ]
        }
    ]

To check everything:

    "cSpell.languageSettings": [
        {
            "languageId": "latex",
            "patterns": [
                {
                    "name": "LaTexMacrosMultiLine",
                    "pattern": "",
                    "description": "Match against all LaTex Macros"
                }
            ]
        }
    ]

All 4 comments

Is this feature supported? Can't seem to find any information.

I have various custom commands, and would like spell checking to be applied.

Example:

\todo{This text should be spell checked.}

Hi @vallentin ,

I solved this problem in a local way. On MacOS, the extension has a configuration file at, for example, ~/.vscode/extensions/streetsidesoftware.code-spell-checker-1.7.20/server/node_modules/cspell-dict-latex/cspell-ext.json, which I guess is the backend of the spell checker.

In the json file, you may find something like

    // Language Rules to apply to matching files.
    // Files are matched on `languageId` and `local`
    "languageSettings": [
        {
            // VSCode languageId. i.e. typescript, java, go, cpp, javascript, markdown, latex
            // * will match against any file type.
            "languageId": "latex",
            // Language local. i.e. en-US, de-AT, or ru. * will match all locals.
            // Multiple locals can be specified like: "en, en-US" to match both English and English US.
            "local": "*",
            // By default the whole text of a file is included for spell checking
            // Adding patterns to the "includeRegExpList" to only include matching patterns
            "includeRegExpList": [],
            // regex patterns than can be used with ignoreRegExpList or includeRegExpList
            // Example: "pattern": [{ "name": "mdash", "pattern": "—" }]
            // This could be included in "ignoreRegExpList": ["mdash"]
            "patterns": [
                {
                    "name": "LaTexMacros",
                    "pattern": "\\\\\\w*(\\[.*?\\])?(\\{.*?\\})?",
                    "description": "Match against all LaTex Macros"
                },
                {
                    "name": "LaTexMacrosMultiLine",
                    "pattern": "\\\\(?!(?:title|color|section|subsection|footnote|chapter|part|caption|emph|text))\\w+(?:\\[[^]*?\\]|\\{[^]*?\\})*",
                    "description": "Match against all LaTex Macros"
                },
                {
                    "name": "LaTexMath",
                    "pattern": "\\$.+?\\$",
                    "description": "Match against all LaTex Macros"
                }
            ],
            // To exclude patterns, add them to "ignoreRegExpList"
            "ignoreRegExpList": ["LaTexMacrosMultiLine", "LaTexMath"],
            // List of dictionaries to enable by name in `dictionaryDefinitions`
            "dictionaries": ["latex"],
            // Dictionary definitions can also be supplied here. They are only used iff "languageId" and "local" match.
            "dictionaryDefinitions": []
        }
    ]

I only did a small change by removing LaTexMacrosMultiLine from the ignoreRegExpList, and that solved the problem. Don't forget to reload the VSCode. There could be an issue if the backend is updated as the configuration file will be changed to default.

Hope that helps.

@society765
Thank you for providing a work around.

There is no need to change the default settings. You can override them locally.

In your user settings create your own pattern called LaTexMacrosMultiLine

To add todo, it would look like the following:

    "cSpell.languageSettings": [
        {
            "languageId": "latex",
            "patterns": [
                {
                    "name": "LaTexMacrosMultiLine",
                    "pattern": "\\\\(?!(?:title|color|section|subsection|footnote|chapter|part|caption|emph|text|todo))\\w+(?:\\[[^]*?\\]|\\{[^]*?\\})*",
                    "description": "Match against all LaTex Macros"
                }
            ]
        }
    ]

To check everything:

    "cSpell.languageSettings": [
        {
            "languageId": "latex",
            "patterns": [
                {
                    "name": "LaTexMacrosMultiLine",
                    "pattern": "",
                    "description": "Match against all LaTex Macros"
                }
            ]
        }
    ]

Hi @Jason3S. Thanks for the solution. That looks more elegant and neat.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gandalfsaxe picture gandalfsaxe  路  3Comments

Deilan picture Deilan  路  3Comments

floatingpurr picture floatingpurr  路  5Comments

eamodio picture eamodio  路  6Comments

fgarcia picture fgarcia  路  3Comments