How to show LaTeX code in LaTeX document?

I have a little problem when I would like to insert the svn diff of a LaTeX document into another LaTeX document, the goal is to show what has changed since the XXX revision. However, since diff contains many LaTeX commands, I cannot include it directly in the document, since LaTeX will interpret them, and not just "print" them.

Today I have it 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 the following:

 \IfFileExists{diff.info.tex} { \newpage \input{diff.info.tex} } 

But it fails!

My next idea is to write a perl script that replaces all invalid characters with what LaTeX can show, but it seems to me that I risk reinventing the wheel, so I decided I could ask if anyone has a better idea?

How to enable and show LaTeX code in a document?

Thanks Johan


Update : Thanks to "unknown (google)" for pointing verbatim, he did what I wanted.

Update : It also seems to me that I should try the lists that las3rjock told us about, as they look nice.

Update : Failed to get lists to work in my case, I get some weird utf warnings about invalid characters. But verbatim works, so I will use this path this time.

+7
latex
source share
2 answers

There is a verbatim package that can be enabled with \usepackage{verbatim} and accessed with \verbatiminput{ filename } .

+7
source share

I second recommendation of Boojum in the comment on another answer that you are using the listings package. For LaTeX code lists, I use the settings that I found in the AndrΓ© Miede classicthesis package . Here is an example 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} 

LaTeX document displaying its own source code
(click to enlarge)

+12
source share

All Articles