jlelong / vscode-latex-basics

LaTeX grammars for Visual Studio Code
MIT License
19 stars 10 forks source link

Update tokenization of source code listings #57

Closed nilsjor closed 1 year ago

nilsjor commented 1 year ago

Re-connecting from #55. I apologize for that one, I didn't read the README... I think I got it right this time!

This PR will update the tokenization of source code listings using general-purpose packages, such as listings. In particular, it will improve the grammars for detecting the particular language of the listing.

Previously, three environments were supported:

The grammars were defined so that the only way it would detect the language is when it was provided (lower-case only) as the second argument in braces, e.g:

\begin{lstlisting}{python}

However, this does not conform with the actual usage of these packages. In the case of listings, for example, the correct syntax is

\begin{lstlisting}[language=Python]

Additionally, in cases where the language was not specified, all code inside the listing would be tokenized and syntax-highlighted as LaTeX text.

Contribution

In b2bc75ae740cb5f60410c77c9998385ed775580f, build\generate-grammar-blocks.js is updated to:

Further, syntaxes\data\LaTeX.tmLanguage.json is updated to:

An example of the resulting regex-string for the new rule can be seen in Debuggex here.

Additionally, 697409d850f8d0945aed28e56a4a212d826ee4f6 adds support for a few more one-line commands for including external files. The path name is tokenized as a string. This covers the same ground as #52

Finally, 1803dfa91657329f064236517323a9142254645a adds a few lines to the README.

Known issues

nilsjor commented 1 year ago

Here is a small working example: Syntax highlighting