Below you'll find my MWE, which has a stripped down version of the internal macro I'm writing. As you can see, there is extra space between the two lines of the material in the box when I use it (one example at normal text size, and another with [cmd]\scriptsize[/cmd] text because that introduces even more space).
In my attempts to work out what's going wrong, I tried stripping things down even further to produce the last two examples. These work, but I'm not sure what the difference between them and the macro is. As best I can tell, I've reproduced all of the boxing steps just with fixed values for the parameters and without recursive function calling. They clearly show that what I want to do is possible. How do I get my macro to produce what these later examples are showing is possible (though without the customizable parameters).
Note: While I don't believe it makes a difference here, the package which this macro appears in is targeted for LuaLaTeX and LuaTeX (it is compatible with both).
Code: Select all
% !TEX program = LuaLaTeX+se
\documentclass{report}
\makeatletter
\newbox\gre@box@temp@width%
\newdimen\gre@dimen@temp@three
\newdimen\gre@dimen@annotationseparation
\gre@dimen@annotationseparation = 0pt
\def\gre@widthof#1{%
\setbox\gre@box@temp@width=\hbox{#1}%
\global\gre@dimen@temp@three=\wd\gre@box@temp@width%
\relax%
}%
\newbox \gre@box@annotation@old
\newbox \gre@box@annotation@add
\newbox \gre@box@annotation
\def\gre@annotation[#1]#2{%
\ifx l#1\relax%
\let\gre@rightfill\hfil%
\let\gre@leftfill\relax%
\else\ifx r#1\relax%
\let\gre@rightfill\relax%
\let\gre@leftfill\hfil%
\else\ifx c#1\relax%
\let\gre@rightfill\hfil%
\let\gre@leftfill\hfil%
\else%
\gre@error{Unrecognzied alignment option for \protect\greannotation}%
\fi\fi\fi%
% first we determine the widest box
\gre@widthof{#2}%
\ifdim\gre@dimen@temp@three < \wd\gre@box@annotation\relax%
\gre@dimen@temp@three = \wd\gre@box@annotation\relax%
\fi%
\setbox\gre@box@annotation@old = \hbox to \gre@dimen@temp@three{\gre@leftfill\copy\gre@box@annotation\gre@rightfill}%
\setbox\gre@box@annotation@add = \hbox to \gre@dimen@temp@three{\gre@leftfill#2\gre@rightfill}%
\ifvoid\gre@box@annotation%
\setbox\gre@box@annotation = \hbox to \gre@dimen@temp@three{\vtop{{\offinterlineskip\vss\noindent\box\gre@box@annotation@add}}}%
\else%
\setbox\gre@box@annotation = \hbox to \gre@dimen@temp@three{\vtop spread \gre@dimen@annotationseparation\relax{{\offinterlineskip\noindent\box\gre@box@annotation@old\vss\noindent\box\gre@box@annotation@add}}}%
\fi%
}%
\begin{document}
\gre@annotation[c]{Test}
\gre@annotation[c]{Also Test}
|\box\gre@box@annotation|
\bigskip
\noindent\rule{\textwidth}{0.4pt}
\bigskip
\gre@annotation[c]{\scriptsize Test}
\gre@annotation[c]{\scriptsize Also Test}
|\box\gre@box@annotation|
\bigskip
\noindent\rule{\textwidth}{0.4pt}
\bigskip
\newbox\original
\newbox\old
\newbox\intermediate
\newbox\new
\newbox\combine
\setbox\original = \hbox to 1in{\hfil Test\hfil}
\setbox\intermediate = \hbox to 1in{\vtop{{\offinterlineskip\vss\noindent\box\original}}}
\setbox\old = \hbox to 1in {\hfil\copy\intermediate\hfil}
\setbox\new = \hbox to 1in {\hfil Also Test\hfil}
\setbox\combine = \hbox to 1in {\vtop spread 0pt {\offinterlineskip\noindent\box\old\vss\noindent\box\new}}
|\box\combine|
\bigskip
\noindent\rule{\textwidth}{0.4pt}
\bigskip
\setbox\original = \hbox to 1in{\hfil\scriptsize Test\hfil}
\setbox\intermediate = \hbox to 1in{\vtop{{\offinterlineskip\vss\noindent\box\original}}}
\setbox\old = \hbox to 1in {\hfil\copy\intermediate\hfil}
\setbox\new = \hbox to 1in {\hfil \scriptsize Also Test\hfil}
\setbox\combine = \hbox to 1in {\vtop spread 0pt {\offinterlineskip\noindent\box\old\vss\noindent\box\new}}
|\box\combine|
\end{document}