-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX syntax highlighting broken with minted and escapeinside #58
Comments
Also moving this comment over as it hopefully provides additional context: The "Inspect editor tokens and scopes" feature reveals that VS Code still assumes Python inside the escape: and then gets stuck in that even past the Personally I wouldn't mind much if the syntax highlighting for LaTeX inside the |
This issue arises because the Python grammar finds some invalid syntax and gets stuck inside a function call rule. To manually get out of the trap add
I am afraid we cannot do much to solve the root cause of the issue. It would basically require to duplicate all possibly embedded grammars to add a bail out rule. See the discussion in James-Yu/LaTeX-Workshop#1689 for the C++ grammar. This is of course far beyond the scope of this basic vscode built-in extension to provide bailed out grammars and language definitions for over a dozen external languages. @alexr00 A smart solution would be that VS Code implements a bail out rule when embedding a language inside an other grammar. |
@jlelong that makes sense, I didn't think that this issue would be solvable from the latex grammar. However, I don't think we would know when to do the bail out. Sometimes users do write code that should be scoped as |
@alexr00 What I had in mind is the ability to define a bail out pattern when embedding a language. When this pattern is encountered, we leave the embedded grammar and we go back to the calling one. |
@jlelong would this be something that you would define in your textmate grammar at the point that you embed the grammar? |
@jlelong Thanks for that manual escape, that's a life-saver for me! ✨ Here was a particularly spicy one: \begin{minted}[autogobble,escapeinside=||]{python}
@pytest.mark.parametrize("a, b, op, expected", [
pytest.param(1, 2, '+', 3, |\highlightbox{id=}|"add"),
pytest.param(3, 1, '-', 5, |\highlightbox{id=}|"sub"),
# ... some more lines ...
])
def test_calc(a, b, op, expected):
assert calc(a, b, op) == expected
\end{minted}
% VS Code workaround
\if 0
)))))])
\end{minted}\fi |
@alexr00 yes exactly. For instance, embedding the Python language typically looks like
It would be nice if the top level grammar could escape from the Python one when the end pattern is reached. I originally thought a new pattern was needed to trigger the bail out but I believe it will always be the same as the end pattern. Currently, we provide a modified C++ grammar which includes the bail out pattern. This approach would make it useless. Embedding a grammar would much more robust. |
@jlelong I have opened microsoft/vscode-textmate#207 for this. Feel free to close and we can continue discussion there. |
When using minted with LaTeX with its
escapeinside
feature (see pages 22/23 in the docs), this breaks VS Code's syntax highlighting, and the rest of the file is (mostly) rendered in red.A minimal example to reproduce the issue
Outcome on stock config without extensions:
Originally from @The-Compiler in microsoft/vscode#180692
The text was updated successfully, but these errors were encountered: