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 have a simple command which takes one argument. Now I want to pass a small listing-environment to the command.

Here is the code:


  \newcommand{\test}[1]{ #1 }



While compiling I get this error:

Package Listings Warning: Text dropped after begin of listing on input line 12.


Any suggestions would be great appreciated.


locked by Joseph Wright Nov 27 '14 at 6:55

This post has been locked due to the high amount of off-topic comments generated. For extended discussions, please use chat.

marked as duplicate by Jubobs, Jesse, Martin Schröder, Sean Allred, Marco Daniel Mar 2 '14 at 17:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 Mar 2 '14 at 13:16

Don't do it. lstlisting is a verbatim-like environment and must do a lot of \catcode magic which will not work if you use it in an argument ( http://www.tex.ac.uk/cgi-bin/texfaq2html?label=verbwithin ). Even if you perhaps can get it to work for some case it will be prone to break in other cases. What you can try is to put your listing in an external file and then use \lstlistinginput{..}.


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