Does anyone know how to remove the whitespace which is created by TeX everytime I use my own created environment? I tried the tricks with \ignorespaces and \ignorespacesafterend but that doesn't seem to work. I want to make use of labels to cross-reference to included code parts later on, and I have a feeling that this labeling issue might be responsible for the white-space I'm generating? Thanks in advance.
\document{book}
\usepackage{listings}
\newcounter{codeexcerptcounter}
\newcommand{\CEN}{Code excerpt~\thecodeexcerptcounter}
\newenvironment{codeexcerpt}[1][]{
\refstepcounter{codeexcerptcounter}%
}{%
}
\newcommand{\addcodeexcerpt}[1][]%
{\begin{center}
\begin{codeexcerpt}
#1
\end{codeexcerpt}
\end{center}}%
\begin{document}
\chapter{First Chapter}
Here goes some explanation.
\addcodeexcerpt[\label{codeex:first}]
\lstinputlisting[title=\CEN: Mirror.java]{code/Mirror.java}
\end{document}
center
environment?\begin{center}
and\end{center}
, use\begingroup\centering
and\endgroup
respectively.