Skip to content

Add support for multiple minted and lstlistings languages in LaTeX documents

I use kile to edit my latex slides with massive use of minted env. I appreciated that \begin{minted}{cpp}... was making syntax highlighting, however when custom env with \newminted{cpp}{...} was created, the \begin{cppcode}.. block was missing syntax highlighting. So I made it working, but then I realised I can do more, and I can put support to much larger range of languages. Oryginally only C++ and Python was supported.

I wrote for this purpose a script which generates syntax rules for LaTeX. I am mainly focused on minted (pygments) based lexers, and I try to match them with language definitions in Kde. At the moment I addedd around 180 new entries. Some of them are duplicated like py and python so effectively less languages are covered but the number is fairly large.

The script still has some issues with matching, like pygments's ocaml is not yet properly matched with KDE's Objective Caml.

I have some thoughts that:

  1. the names in language definitions could be change, like Objective Caml -> Ocaml or
  2. new attribute which is called e.g. lexer to correlate them with pygmentize -L lexer could be introduced to schema.

The solution no. 1 is fairly easy but I am not sure whether it will not break other parts. Maybe some expert can tell me whether this change would be fine, e.g. in `ocaml.xml'

<language name="Objective Caml"

to

<language name="OCaml"

Screenshots below show three cases:

  1. before introducing new rules
  2. after change, the code folding also works here
  3. in case of unknown language (artificial ccppcode) the code is coloured in orange which makes a such block easily distinguishable from a plain text. Verbatim has similar thing with colouring in red.

minted_before minted_after minted_unknown

Theoretically this should also work with lstlistings but the language definitions are sometimes slightly different so there might be some issues of missing language support: the syntax highlighting may work for requested language which is not supported by lstlisting and should be marked as error which is not done yet. I am working on that, but it is tricky as minted and lstlistings share the same set of rules.

Other issue I also still see is leak of syntax highlighting for some languages. I see this problem with lua. Perhaps other have the same but I am not able to tests all of them. Your help is appreciated.

Anyway, I am eager to hear your opinion about my changes and your suggestions and recommendations. I also encourage you to test it and report which languages which are still missing, you would like to have included. I can think about more manual way to introducing them if script fails.

As a last, a few more examples of new syntax highlighting in LaTeX (please note that lua does not work). minted_more_examples

Merge request reports