# Is there an analog of \unskip for vertical mode?

I'm gluing together a bunch of code fragments using \verbatiminput, and I want to eliminate the vertical space (glue) that would normally come between the fragments. But I cannot use \unskip because that is for horizontal mode only.

Is there an analog of \unskip (remove the last item on the current list if it is glue) for vertical mode?

For those who requested an example:

\usepackage{verbatim}

...

\verbatiminput{one}
\verbatiminput{two}
\verbatiminput{three}


I'd like to remove the extra spacing inserted between successive calls to \verbatiminput.

-
Well, \unskip works in internal vertical mode. So maybe putting stuff into a \vbox, unskipping to your heart's content, and then \unvboxing would be an alternative? –  Stephan Lehmke Jun 11 '12 at 13:35
Further possibility: \vskip-\lastskip. LaTeX offers a command \removelastskip to that effect. –  Stephan Lehmke Jun 11 '12 at 13:36
Could you please make an example? –  egreg Jun 11 '12 at 14:06

As noted in the comments \unskip works in vertical mode if you are in a box. Or you can \vskip-\lastskip but better really is just not to add the space in the first place.

LaTeX's \addvspace tries to avoid adding space necessarily, it works like \vspace or vskip unless space was recently added. (This is so two consecutive display environments do not get double space in the middle.) Perhaps you want \nointerlineskip or offinterlineskip so TeX does not automatically add skip before the vertical material that you are adding,

-

You can try checking whether a \verbatiminput follows and, in this case, remove the skips that are inserted (twice \topsep):

\documentclass{article}
\usepackage{verbatim}

\makeatletter
\def\verbatim@input#1#2{%
\IfFileExists {#2}{\@verbatim #1\relax
{\typeout {No file #2.}\endgroup}%
\@ifnextchar\verbatiminput{\vspace{-2\topskip}}{}%
}
\makeatother

\begin{document}
\verbatiminput{beer}
\verbatiminput{beer}
This is no beer.
\verbatiminput{beer}
This is no beer.
\end{document}


Here is beer.tex:

\let~\catcode~x13~q~x~z~q~H~q~B~H~j0~jA009
jlet~jlet~Hjpar ~Bjmscount~~jdef~x{q bottlez of beer}
~jw{x on the wall}~jt{jadvanceAB-1ATake one down Aand
pass it around,H}B99~ji{jifnumB}~q{ji=0Nojelsejnumber
Bjfi}~z{ji>1sjfiA }jloop jifnumB>0 jw, x,Hjtjw.jvskip
8ptplus1ptjrepeat Time to buy some more beerjdotsjend


Perhaps, a better solution is to use a different command, let's call it \multiverbatiminput that accepts a list of file names:

\documentclass{article}
\usepackage{verbatim}
\makeatletter
\def\multiverbatiminput{\begingroup
\@ifstar{\multiverbatim@input\relax}%
{\multiverbatim@input{\frenchspacing\@vobeyspaces}}}
\def\multiverbatim@input#1#2{%
\@verbatim #1\relax
\@for\next:=#2\do{%
`