1

In VS Code I can define keyboard shortcuts to only work in certain conditions:

https://code.visualstudio.com/api/references/when-clause-contexts

So i can add different variables, e.g. this keyboard shortcut would only work when writing latex documents and the text is focused:

{
        "key": "alt+.",
        "command": "editor.action.insertSnippet",
        "when": "editorLangId == latex && editorTextFocus",
        "args": {
            "snippet": "\\cdot $0"
        }
    },
}

Is there any clause context (like "editorTextFocus") that would tell me whether I'm in LaTeX math mode or not that comes with any extension or something (I use the LaTeX Workshop extension)? I haven't found anything online. Or can I define something like this myself? If yes, does anyone know a good resource to find out how to do so?

Hebol
  • 51
  • 7
  • Sadly even the LaTeX Workshop extension doesn't set any context when in math mode, as its only call to the related API is https://github.com/James-Yu/LaTeX-Workshop/blob/e85585e2bc0dd767e8e0887c452ec0a53ec23bad/src/main.ts#L154. So you have to define the math mode context yourself, and set/reset it in your own extension. – Lex Li May 21 '22 at 16:28

1 Answers1

0

It is possible to use the extension HyperSnips to create more advanced snippets that only trigger in math-mode (also using regex etc.). Tutorial can be found on their Github. So one could theoretically bind a keyboard shortcut to typing some key or something which then gets auto-expanded by the extension.

Hebol
  • 51
  • 7