Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

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

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

    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jan 15 at 23:36
add comment

1 Answer

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

share|improve this answer
    
Great; that worked! Thank you- –  baha-kev Apr 4 '11 at 21:48
1  
@baha-kev: please don't forget to accept the question. –  Martin Scharrer Apr 5 '11 at 13:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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