Is there a ready solution to typeset a diff file?
Using the verbatim
package you can easily apply formatting to each line, so this just extracts the first character and uses it as part of a colour name to use for the highlighting.
\documentclass{article}
\usepackage{verbatim,color}
\makeatletter
\long\def\diffcolor#1#2\@nil{color\string#1diff}
\def\verbatim@processline{%
\nointerlineskip\noindent\rlap{%
\colorbox{\expandafter\diffcolor\next..\@nil}{%
\the\verbatim@line}}\par}
\makeatother
\definecolor{color diff}{rgb}{1,1,1}
\definecolor{color-diff}{rgb}{1,.5,.5}
\definecolor{color+diff}{rgb}{.5,1,.5}
\begin{document}
\verbatiminput{diffex.diff}
\end{document}
You can also use listings
. You must define an own language with own colour settings. The lines with special characters are defined as comment lines here:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\definecolor{diffstart}{named}{Grey}
\definecolor{diffincl}{named}{Green}
\definecolor{diffrem}{named}{OrangeRed}
\usepackage{listings}
\lstdefinelanguage{diff}{
basicstyle=\ttfamily\small,
morecomment=[f][\color{diffstart}]{@@},
morecomment=[f][\color{diffincl}]{+\ },
morecomment=[f][\color{diffrem}]{-\ },
}
\begin{document}
\begin{lstlisting}[language=diff]
@@ -85,8 +85,8 @@
\newcommand{\doctitleifsub}[2]{%
\thispagestyle{empty}
\begin{center}
- \sffamily This document is part of the documentation of \openlilylib%
- \footnote{\url{https://github.com/openlilylib/openLilyLib}},\\
+ \sffamily This document is part of \textbf{\openlilylib}%
+ \footnote{\url{http://www.openlilylib.org}},\\
a collection of resources for the LilyPond notation software%
\footnote{\url{http://www.lilypond.org}}\\
and the \LaTeX{} typesetting system.
\end{lstlisting}
\end{document}
The vim module for ConTeXt uses the VIM editor to do the syntax highlighting of files. As such it supports all syntax highlighting for all filetypes supported by VIM (which is a lot). For example, to highlight diff files, you may use:
\usemodule[vim]
\definevimtyping[DIFFtyping][syntax=diff]
\starttext
\startDIFFtyping
@@ -85,8 +85,8 @@
\newcommand{\doctitleifsub}[2]{%
\thispagestyle{empty}
\begin{center}
- \sffamily This document is part of the documentation of \openlilylib%
- \footnote{\url{https://github.com/openlilylib/openLilyLib}},\\
+ \sffamily This document is part of \textbf{\openlilylib}%
+ \footnote{\url{http://www.openlilylib.org}},\\
a collection of resources for the LilyPond notation software%
\footnote{\url{http://www.lilypond.org}}\\
and the \LaTeX{} typesetting system.
\stopDIFFtyping
\stoptext
which gives
Full disclosure: I am author of the vim module.