3

I am trying to quote (not compile!) LaTeX code (including TikZ code) within a LaTeX document. The verbatim package works, but it doesn't wrap text and doesn't look very nice. So I am trying to use the package listings, but am having problems:

It is giving me issues on the quoted code when I try to compile, when it should just be treating it like text! I imagine this is because it is trying to color the syntax or something, but at this point that would be a bonus — I just want the code to look nice and wrap (and not compile within \begin{lstlisting}).

Also, it seems that the TikZ code that I use within a LaTeX document is also giving listings trouble.

\usepackage{listings}

\lstset{
language=TeX,                       
defaultdialect=empty,
basicstyle=\footnotesize,           
numbers=left,                           
numberstyle=\footnotesize,          
stepnumber=5,                           
numbersep=5pt,                      
backgroundcolor=\color{white},  
showspaces=false,                   
showstringspaces=false,             
showtabs=false,                     
frame=single,                   
tabsize=2,                  
captionpos=b,               
breaklines=true,                
breakatwhitespace=false,        
escapeinside={\%}{)}            
}


\begin{document}
The document begins.  A bunch of regular Latex code and TikZ pictures here.
\begin{lstlisting}

%Set domain, range, and scale of picture.
\begin{tikzpicture}[domain=0:100,range=0:200,scale=0.7,thick]
\usetikzlibrary{calc}

%Define linear parameters 
\def\inc{10}            %Total freight.
\def\pa{1}              %Price of x1.
\def\pb{1}              %Price of x2.
\def\panew{0.5}     %New price for x1.

% Define coordinates.
\coordinate (x2) at  (0,{\inc/\pb});
\coordinate (x1) at  ({\inc/\pa},0);
\coordinate (x1') at  ({\inc/\panew},0);

\end{lstlisting}
\end{document}

Note: I do not want the TikZ picture to render within \begin{lstlisting}, I just want to be able to show the code. Same with the the LaTeX code within it.

Is there a better way to tackle this?

migrated from stackoverflow.com Apr 5 '11 at 9:19

This question came from our site for professional and enthusiast programmers.

10

You are explicitly requesting that everything from a % to the next ) be executed as LaTeX code, removing the line escapeinside={\%}{)} fixes this.

  • 1
    @baha-kev: please don't forget to accept the question. – Martin Scharrer Apr 5 '11 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.