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.

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

How do I fix this haunting message?

"text dropped after beginning of listing"

In my preamble I use:



Then within the document I use the package this way:

\begin{lstlisting} http://www.victim.com/cms/login.php?..\end{lstlisting}

Also this way:

// connect to the database
$conn = mysql_connect("localhost","username","password");

Is that because the text in a listing environment shouldn't be on one line only?

share|improve this question
For single-line listings, you could use \lstinline rather than the environment form. – Werner Jan 23 '13 at 18:16
Should I define \lstinline in the preamble as well? \def\inline{\lstinline[basicstyle=\ttfamily]} And whenever I need I only call it? Can you please show me a practical example? – user1990170 Jan 23 '13 at 18:21
up vote 6 down vote accepted

For lengthy listings, leave the environment \begin and \end on their own lines. For short, in-line listings, use \lstinline (already defined). Here's an example of their usages:

enter image description here

\usepackage{listings}% http://ctan.org/pkg/listings
Some text and \lstinline!http://www.victim.com/cms/login.php?..! and some more text.

The listings documentation uses the following terminology (section 4.2 Typesetting listings, p 25-26):

  • Code snippets: \lstinline
  • Displayed code: lstlisting environment
  • Stand alone files: \lstinputlisting

Regarding the use of the displayed code lstlisting environment, it also states (p 26):

In contrast to the environment of the verbatim package, LaTeX code on the same line and after the end of environment is typeset respectively executed.

This allows you to use


but not


Regardless, I don't see the need to keep code listings and their enclosed environment definitions on the same line, so even the allowed use above could benefit from putting \end{lstlisting} on its own line.

share|improve this answer

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.