I have a little problem where I would like to insert a svn diff of a LaTeX document into another LaTeX document, the goal is to show what has changed since revision XXX. However since the diff contains a lot of LaTeX command I can't include it right into the document since LaTeX will interpit them and not just "print" them.
Today I have this in my Makefile
DIFF_INFO=diff.info.tex
DIFF_REV=167
diffinfo:
$(shell echo "\n" > $(DIFF_INFO) )
$(shell echo "\\section{diff $(DIFF_REV)} \n" >> $(DIFF_INFO) )
$(shell echo \\\\begin{verbatim} >> $(DIFF_INFO) )
$(shell svn diff --revision $(DIFF_REV) $(N).tex >> $(DIFF_INFO) )
$(shell echo \\\\end{verbatim} >> $(DIFF_INFO) )
And at the end of the LaTeX document I have this:
\IfFileExists{diff.info.tex}
{
\newpage
\input{diff.info.tex}
}
But this fails hard!
My next idea is to write a perl script that replaces all invalid chars with something that LaTeX can show, but it feels like I'm risking to reinvent the wheel so I figured that I could ask if someone had a better idea?
How do I include and show LaTeX code in the document?
Thanks Johan
Update: Thanks "unknown (google)" for pointing out verbatim, it did what I wanted it to.
Update: I also looks like I should try that listings that las3rjock told us about since it look kind of nice.
Update: Could not get listings to work in my case, I get some strange utf warnings about invalid chars. But the verbatim is working so I will use that way this time.
I second Boojum's recommendation in a comment to another answer that you use the listings package. For LaTeX code listings, I use settings that I found in André Miede's classicthesis package. Here is a sample document (quine.tex
) and its output:
\documentclass[12pt,letterpaper]{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color}
% listings settings from classicthesis package by
% Andr\'{e} Miede
\lstset{language=[LaTeX]Tex,%C++,
keywordstyle=\color{RoyalBlue},%\bfseries,
basicstyle=\small\ttfamily,
%identifierstyle=\color{NavyBlue},
commentstyle=\color{Green}\ttfamily,
stringstyle=\rmfamily,
numbers=none,%left,%
numberstyle=\scriptsize,%\tiny
stepnumber=5,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
frame=single
%frame=L
}
\begin{document}
\lstinputlisting{quine.tex}
\end{document}
(click to enlarge)
There' a verbatim
package that you can include with \usepackage{verbatim}
and access using \verbatiminput{
filename}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With