# Ignore first parskip inside a save box

I have the following definition (MWE below) of a lrbox. If I use the normal setting parskip=off the interaction \mdf@restoreparams works as expected. Inside the lrbox I can use parskip and parindent. But if I use the option parskip=half I get an extra skip at the beginning of the save box. How can I avoid this.

Picture

MWE:

\documentclass[parskip=half]{scrreprt}
\usepackage{kantlipsum}

\catcode\@11\relax

\def\mdf@lrbox#1{%
\edef\mdf@restoreparams{%
\parindent=\the\parindent \parskip=\the\parskip}%
\setbox#1\vbox\bgroup%
\color@begingroup%
%     \mdf@horizontalmargin@equation%
\columnwidth=\hsize%
\textwidth=\hsize%
\let\if@nobreak\iffalse%
\let\if@noskipsec\iffalse%
\let\par\@@par%
\let\-\@dischyph%
\let\'\@acci\let\\@accii\let\=\@acciii%
\parindent\z@ \parskip\z@skip%
\linewidth\hsize%
\@totalleftmargin\z@%
\leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip%
\parfillskip\@flushglue \lineskip\normallineskip%
\baselineskip\normalbaselineskip%
%%  \sloppy%
\let\\\@normalcr%
\hrule \@height\z@ \@width\hsize\relax
\mdf@restoreparams\relax
\@afterindentfalse%
}

\def\endmdf@lrbox{\color@endgroup\egroup}

\newbox\MyTestBox

\begin{document}

\mdf@lrbox\MyTestBox
\kant[1]

\kant[1]
\endmdf@lrbox

\fbox{\box\MyTestBox}
\end{document}


I didn't tag this question with KOMA because the same result is reached by the header with a standard class

\documentclass[]{report}
\usepackage{parskip}


or with memoir

\documentclass[]{memoir}
\setlength{\parindent}{0pt}
\nonzeroparskip

-
If you have any improvements I won't be disappointed ;-) – Marco Daniel May 18 '12 at 10:13

Well....

If you don't do

     \hrule \@height\z@ \@width\hsize\relax


Then you don't get the parskip at the top.

Then in your end code, if the width of the box is not what you expect (because no paragraph material has been added) do

\vbox{
hrule \@height\z@ \@width\hsize\relax
}


\documentclass[parskip=half]{scrreprt}
\usepackage{kantlipsum}

\catcode\@11\relax

\def\mdf@lrbox#1{%
\edef\mdf@restoreparams{%
\parindent=\the\parindent \parskip=\the\parskip}%
\def\tmp{#1}%
\setbox#1\vbox\bgroup%
\color@begingroup%
%     \mdf@horizontalmargin@equation%
\columnwidth=\hsize%
\textwidth=\hsize%
\let\if@nobreak\iffalse%
\let\if@noskipsec\iffalse%
\let\par\@@par%
\let\-\@dischyph%
\let\'\@acci\let\\@accii\let\=\@acciii%
\parindent\z@ \parskip\z@skip%
\linewidth\hsize%
\@totalleftmargin\z@%
\leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip%
\parfillskip\@flushglue \lineskip\normallineskip%
\baselineskip\normalbaselineskip%
%%  \sloppy%
\let\\\@normalcr%
%     \hrule \@height\z@ \@width\hsize\relax
\mdf@restoreparams\relax
\@afterindentfalse%

}

\def\endmdf@lrbox{\color@endgroup\egroup
\ifdim\wd\tmp<\hsize
\typeout{making box fill width}
\setbox\tmp\vbox{%
\hrule \@height\z@ \@width\hsize\relax
\unvbox\tmp}%
\fi
}

\newbox\MyTestBox

\begin{document}

\mdf@lrbox\MyTestBox
\kant[1]

\kant[1]
\endmdf@lrbox

\fbox{\box\MyTestBox}

\mdf@lrbox\MyTestBox
\begin{tabbing}aaa\end{tabbing}
\endmdf@lrbox

\fbox{\box\MyTestBox}

\end{document}

-
The aim of the rule is to get the correct with of the vbox ;-) -- I tried \setbox\MyTestBox=\vbox{\unvbox\MyTestBox} but it didn't remains the first skip. – Marco Daniel May 18 '12 at 10:46
If a paragraph is started (ie you get the parskip) the box will have the correct width without that rule (as the paragraph lines will be hboxes of that width) you only need the rule when there is no paragraph, I'll fill out a patched MWE. – David Carlisle May 18 '12 at 10:50
Exactly what I searched – Marco Daniel May 18 '12 at 11:02

You can add \vskip-\parskip just at the end of the definition of \mdf@lrbox, that is between \@afterheading and the closing brace.

This will cancel out the \parskip glue automatically inserted when the first paragraph is about to be started.

-
So long as the paragraph does get started. the reason why the rule is there in Marco's code is to catch the cases where no paragraph is started, to ensure the final box has full width. – David Carlisle May 18 '12 at 10:48