area/language-latex

Syntax highlighting in lstlisting

Closed this issue · 7 comments

I'm having some issues using language-latex in combination with lstlistings.

When there are ticks in a lstlisting like

gh

the syntax highlighting gets broken and all text after the last " is highlighted as text in ticks.

Using a verbatim doesn't show this behaviour. Would it be possible to handle lstlistings like a verbatim environment in regards to syntax-highlighting?

Possibly related #87 ?

I am having some trouble too with lstlisting and language-latex. For example:
capture d ecran 2016-11-08 a 23 07 42

The syntax highlighting gets broken after the last $. I agree with moospit, a behavior like verbatim would be really great.

Same when using minted 👍

I manage this case by using a $ sign behind the initial statement which then does not appear in my output:

\begin{lstlisting}[caption=test]$
  bla with $ sign
\end{lstlisting}

Found your problem: this package does not support the lstlistings package at all properly.

To begin a lstlistings environment, it needs to satisfy this (atom grammar package version) regex
(?:\\s*)(\\\\begin)(\\{)(lstlisting)(\\})(\\[)(?:.*\\blanguage\\s*=\\s*Python\\b.*)(\\])
In normal regex it would be
(?:\s*)\\begin\{lstlisting\}\[(?:.*\blanguage\s*=\s*Python\b.*\])
Try the normal regex on https://regex101.com/r/u4HCqg/1

This means it will look for \begin{lstlisting} AND, immediately following this, a pair of square brackets containing the words language=Python at the end. The only other supported language is Java.

As you do not provide the square brackets, it is not detecting the lstlisting environment. Hence, it detects the combination of "> as some kind of French quotation mark (check the scope), starts highlighting everything inside the quote green, and continues until it finds an end quote (experimenting shows this is "<). As it never finds one, the rest of the file is green. Similar thing is happening with the $ signs: they are being picked up as mathmode entries/exits because the scope is still regular latex.

A fix would involve changing the regex to properly detect lstlisting and minted environments. But I don't feel like fixing this can't edit this repo.

This should be fixed in v1.1.0. Feel free to reopen if you still see some problems.

I have just installed the last version (1.1.0) and my example is still broken:
capture d ecran 2017-08-16 a 17 19 38

@PierreMarchand20 should be fixed in v1.1.1. sorry for inconvenience.