[Tex/LaTex] How to highlight (colorize) the syntax of configuration files (like .ini or .conf)

highlightingsyntax

I need to highlight the syntax of files containing lines with parameters and their values in LaTeX. Let's say I have a following file:

# some comment
parameter1 = value of parameter1
parameter2 = some another value
# and so on ...

Is it possible to colorize it with 3 colors: one for comments, one for parameter names and one for their values?

Best Answer

Here is a ConTeXt solution, in case someone is interested. The vim module uses the vim editor to provide syntax highlighting, which has support for a huge number of languages, so there is no need to create your own parsing style.

\usemodule[vim]

\definevimtyping[INI][syntax=dosini]


\starttext
\startINI
# some comment
parameter1 = value of parameter1
parameter2 = some another value
# and so on ...
\stopINI
\stoptext

which gives

enter image description here

The vim module automatically caches the result, so there is no considerable performance penalty.

Related Question