Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

verbatim newenv with extra vertical space

1 view
Skip to first unread message

Tim Arnold

unread,
Nov 23, 2009, 12:12:31 PM11/23/09
to
Hi,
At the end of this message is a minimal document that shows the
problems. Here's the description:
I'm creating a new environment called Mycode which takes an optional
argument and sets its content as an indented block of verbatim text
with no vertical space around the block. I set the vertical space at
the beginning with this command:
\newcommand{\@zeroseps}{%
\setlength{\topsep}{\z@}%
\setlength{\partopsep}{\z@}%
\setlength{\parskip}{\z@}%
}

However, I have two problems -- a blank line appears above and below
the block.
(1)
The blank line that appears before the code block is apparently
related to this code, using xkeyval. The setup:
\define@boolkeys{code}[code@]{show}[true]{}
\presetkeys{code}{show = true,}{}

and in the newenvironment code:
\setkeys{code}{#1}\ifcode@show\verbatim\fi%

(2) The blank line that appears after the code block is apparently
related to this code. The setup:
\newlength{\gparindent}
\setlength{\gparindent}{3ex}%
and in the newenvironment code:

\renewcommand{\verbatim@startline}{\verbatim@line{\hskip\gparindent}}
%

Here is the commented minimal doc.
------------------------------------------------------
\documentclass{book}
\usepackage{verbatim,xkeyval,lipsum}

\makeatletter
\define@boolkeys{code}[code@]{show}[true]{}
\presetkeys{code}{show = true,}{}

\newcommand{\@zeroseps}{%
\setlength{\topsep}{\z@}%
\setlength{\partopsep}{\z@}%
\setlength{\parskip}{\z@}%
}
\newlength{\gparindent}
\setlength{\gparindent}{3ex}%
\newenvironment{Mycode}[1][]{%
\@zeroseps%
% comment this line to remove blank line before verbatim
\setkeys{code}{#1}\ifcode@show\verbatim\fi%
% comment this line to remove blank line after verbatim
\renewcommand{\verbatim@startline}{\verbatim@line{\hskip\gparindent}}
%
% comment or uncomment as needed depending on the setkeys line:
%\verbatim
}%
{\endverbatim}

\makeatother

\begin{document}
\lipsum[1]
\begin{Mycode}[show]
This should be indented by 3ex.
another line, further indented.
\end{Mycode}
\lipsum[1]

\end{document}

------------------------------------------------------
Why or how these two lines interact with the other code I cannot see.
Any suggestions, comments, very welcome!
thanks,
--Tim Arnold

0 new messages