Archive for April, 2008

LaTeX Language definition for Patch Files (generated by diff)

April 27th, 2008 | Category: Informatics

As there is no lstlisting class for patches in LaTeX today I’ve had the problem to define a working definition to highlight diff files. If anyone else is having that problem, here are those 11 Lines of Code.

\definecolor{darkgreen}{cmyk}{0.7, 0, 1, 0.5}

\lstdefinelanguage{diff}
{
    morekeywords={+, -},
    sensitive=false,
    morecomment=[l]{//},
    morecomment=[s]{/*}{*/},
    morecomment=[l][\color{darkgreen}]{+},
    morecomment=[l][\color{red}]{-},
    morestring=[b]",
}

After defining the diff format you can add the content by using the following code.

\lstset{language={diff}}
\begin{lstlisting}[captionpos=b, caption=text, label=src:patch]
- your content here -
\end{lstlisting}


Screenshot of the PDF file

3 comments