4

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)

Diff patch example

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

1 Answers1

5

This may be a start - using `fancyvrb:

enter image description here

\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}
Werner
  • 603,163