Hi,
I'm making using of the listings package to format code. I frequently use the lstlisting environment to format blocks of inline (i.e. not floating) code:
"
Here is some code:
\begin{lstlisting}
example
example
example
example
example
example
example
\end{lstlisting}
"
This works fine most of the time. Every now and then, a lstlisting block will causes Latex errors after I add some extra text to the top of the document. One lstlisting block will sometimes generate 100 odd errors, all of the form:
"Extra }, or forgotten $. |"
This appears to happen when the lstlisting block starts on one page and ends on the other. Adding text above a block can push it onto the next page, meaning one can give me problems later when Latex was happy with it before.
The only workaround I have to to manually tweak the page so this doesn't happen. Is there anything better I can do?
General ⇒ lstlisting spread between two pages causes errors
-
- Posts: 2
- Joined: Tue Nov 10, 2009 10:05 pm
NEW: TikZ book now 40% off at Amazon.com for a short time.

lstlisting spread between two pages causes errors
Hi,
can you please post a minimal working example (MWE) showing the mentioned problem?
I ask you for this MWE since the following example produces no errors on my system:
Compile the example code as it is; then, uncomment the line \lipsum[1-4] and compile again (this will add some text before the listing and will force it to cross pages).
can you please post a minimal working example (MWE) showing the mentioned problem?
I ask you for this MWE since the following example produces no errors on my system:
Code: Select all
\documentclass{article}
\usepackage{listings}
\usepackage{lipsum}
\begin{document}
%\lipsum[1-4]
\begin{lstlisting}
example
example
example
example
example
example
example
example
example
example
example
\end{lstlisting}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Posts: 2
- Joined: Tue Nov 10, 2009 10:05 pm
Re: lstlisting spread between two pages causes errors
Thanks for the reply. I've tried to make a minimal working example but cannot seem to reproduce this behaviour in smaller documents. I'm making use of a custom thesis package and the document is about 200 pages. I was hoping it would just be some common problem. It seems clear it's a problem when the lstlisting block goes over a page as I can resolve the errors by adding a "\newpage" just before the block. Any idea of things I could try?
lstlisting spread between two pages causes errors
Without a MWE, all I can suggest you is to compile the code that produces the errors and post here, as an attachment, the .log file obtained. Perhaps this will help us to detect the problem (but I don't promise anything).
1,1,2,3,5,8,13,21,34,55,89,144,233,...