# Prevent parskip after special at beginning of vbox

If I understand correctly, when entering unrestricted horizontal mode, TeX inserts a parskip if the containing vertical list is non-empty. That applies even when the only item on the list is not actually a paragraph, but e.g. a special:

\vbox{\special{}x}


Is there a way to prevent the parskip in this case?

More specifically, how would I write a macro \foo that involves \special and should work in both of these cases:

\vbox{\foo x}
\vbox{\foo\hbox{x}}


i.e. whether or not horizontal mode will be entered after the macro. The first case could be solved by adding \leavevmode to the macro, but for the second case, that is not an option.

But I can't detect during expansion of \foo if \leavevmode will be needed.

• this is why \color sometimes affects spacing, it's bascally not soluable in classic tex Aug 1, 2022 at 20:58

This is why \color sometimes affects spacing, it's basically not soluable in classic tex.

Using e-tex you can catch some cases


\tracingoutput1
\tracingonline1
\showboxdepth=6

\def\foo{%
\ifnum\currentgrouptype=4
\ifnum\lastnodetype=-1
\vbox\bgroup\aftergroup\foox
\else
\special{}%
\fi
\else
\special{}%
\fi}

\def\foox{\setbox0\lastbox\special{}\unvbox0\egroup}

\vbox{\foo x}

\bye


produces a box

..\vbox(4.30554+0.0)x469.75499
...\special{}
...\hbox(4.30554+0.0)x469.75499, glue set 444.47719fil
....\hbox(0.0+0.0)x20.0
....\tenrm x
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0


where the special is immediately before the hbox with x.

This basically detects if it is at the start of a vbox and if so makes a vbox without the \special then re-boxes it after adding the \special But using such code without breaking something is hard in real documents