# Is there a way to format a diff patch block? [duplicate]

I'm trying to inline a few snippets of diff patches, and manually formatting them is a droll - is there a way to do it automatically?

In general I want it to look like the following example, but obviously the finer details of font and colour are less important (as long as they're internally consistent)

## marked as duplicate by egreg, Peter Jansson, ChrisS, Werner, SperavirFeb 6 '14 at 21:39

• By automatic formatting, are you referring to the colour, the layout, or something else altogether? – Werner Feb 6 '14 at 20:11
• Colours, mostly - but also that it be in monospace font, a self contained block, etc. – Daniel Feb 6 '14 at 20:12

This may be a start - using fancyvrb:

\documentclass{article}
\usepackage{fancyvrb,xcolor}% http://ctan.org/pkg/{fancyvrb,xcolor}
%\newcommand{\defaultformat}{\color{black}}
\newcommand{\typeA}{\color{green!50!black}}
\newcommand{\typeB}{\color{red!60!black}}
\newcommand{\typeC}{\color{blue!70!yellow}}
\newcommand{\typeD}{\color{green!60!blue}}
\begin{document}

\begin{Verbatim}[commandchars=\~\{\}]
~typeA--- <unnamed>
~typeA+++ <unnamed>
~typeB@@ -47,13 +47,14 @@

;; t \in Term
;; t ::= '(true) | '(false) | '(z) | (if-then-else ,t ,t ,t)
~typeC-;;     | (succ ,t) | (pred ,t) | (zero? ,t)
~typeD+;;     | (succ ,t) | (pred ,t) | (zero? ,t) | (pr ,t ,t)
~typeD+;;     | (first ,t) | (second ,t)

;; nv \in Num
\end{Verbatim}

\end{document}
`