TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.



The document begins.  A bunch of regular Latex code and TikZ pictures here.

%Set domain, range, and scale of picture.

%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);


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 '14 at 23:36

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
@baha-kev: please don't forget to accept the question. – Martin Scharrer Apr 5 '11 at 13:03

Your Answer


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.