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 get an emptypage on multi page listings if I use listings with afterpage.

\documentclass{scrartcl}
\usepackage{listings}
\usepackage{afterpage}

\begin{document}
\afterpage{%
%some fancy stuff
}
\begin{lstlisting}
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123
asd 123 asd 123 asd 123 asd 123 asd 123 asd 123

\end{lstlisting}



\end{document}

I think this question is different to \afterpage issue with \lstlisting because there was a recursive macro definition, causing the problem.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Er well it must be a feature of listings because clearly it can't be anything wrong with afterpage.

You can get them to agree on the page break by boxing and unboxing the listing.

\setbox0\vbox{
\begin{lstlisting}

...
\end{lstlisting}
}
\unvbox0
share|improve this answer
    
I don't think this is a "feature". Anyway I was trying the following as workaround: \usepackage{etoolbox} \AtBeginEnvironment{lstlisting}{\setbox0\vbox\bgroup} \AtEndEnvironment{lstlisting}{\egroup\unvbox0} but it isn't working. Any Idea? –  someonr Oct 23 '12 at 16:22
    
does it work on your real example if you use the setbox directly and just fail with AtBeginEnvironment, or does it not work at all? –  David Carlisle Oct 23 '12 at 16:28
    
It works in the real example and just fails with AtBeginEnvironment –  someonr Oct 23 '12 at 16:30
    
someone who knows etoolbox might be able to help (I've never used it) the timing of the end code is a bit tricky in verbatim-like environments. –  David Carlisle Oct 23 '12 at 16:33
    
ok thx, I don't need to use etoolbox, just would like to "patch" lstlisting ;) –  someonr Oct 23 '12 at 16:37
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.