# \hbox_overlap_right:n{} vs. \makebox[0pt][l]{}

I stumbled about some, to my understanding, unexpected behaviour of the expl3 command \hbox_overlap_right:n. I was expecting all examples below to produce the same result, that is, the frame box sitting at the same position as the yellow box. But only the \makebox example produces the expected result. The expl3 examples even insert a line break between the yellow and the frame boxes. What is going wrong?

\documentclass{article}
\usepackage{color}
\usepackage{expl3}

\begin{document}
\ExplSyntaxOn
%doesn't work
\hbox_overlap_right:n{\color{yellow}\rule{1in}{0.5in}}\frame{\phantom{\rule{1in}{0.5in}}}
\par
%doesn't work either
\hbox_to_zero:n{\color{yellow}\rule{1in}{0.5in}\hss}\frame{\phantom{\rule{1in}{0.5in}}}
\par
%LaTeX2e working as expected
\makebox[0pt][l]{\color{yellow}\rule{1in}{0.5in}}\frame{\phantom{\rule{1in}{0.5in}}}
\ExplSyntaxOff
\end{document}


-
You're forgetting, at the least, that \hbox doesn't start horizontal mode. –  egreg Mar 21 '14 at 10:58

## 1 Answer

The function \hbox_overlap_right:n is just the same as the Plain TeX \rlap (apart being \protected), while \hbox_to_zero:n is the same as \hbox to 0pt:

> texdef -t latex -p expl3 'hbox_overlap_right:n'

\hbox_overlap_right:n:
\protected\long macro:#1->\hbox_to_zero:n {#1\tex_hss:D }

> texdef -t latex -p expl3 'hbox_to_zero:n'

\hbox_to_zero:n:
\protected\long macro:#1->\tex_hbox:D to\c_zero_dim {#1}

> texdef -t latex frame

\frame:
\long macro:#1->\leavevmode \hbox {\hskip -\@wholewidth \vbox {\vskip -\@wholewidth \hrule \@height \@wholewidth \hbox {\vrule \@width \@wholewidth #1\vrule \@width \@wholewidth }\hrule \@height \@wholewidth \vskip -\@wholewidth }\hskip -\@wholewidth }


Since the primitive \hbox doesn't start horizontal mode, while \frame and \makebox do, the result you get is normal.

Add \leavevmode before \hbox_overlap_right:n.

-
@cgnieder: Thank you both! Good to know. There were blank lines in the package file within macro definitions (for increasing readability). Now I know that I have to avoid them (or use commented blank lines) because they switch back to vertical mode, neutralizing the \leavevmode I put at the start of the user command definition. –  AlexG Mar 21 '14 at 11:23
Also thanks for the example use of the texdef command! –  AlexG Mar 21 '14 at 11:29
@AlexG Blank lines for readability are good in the LaTeX3 programming environment, not in any other situation. –  egreg Mar 21 '14 at 11:30
Within my package I am well in an L3 environment. Something else, not the blank lines, must be the cause for switching back to vertical mode then. –  AlexG Mar 21 '14 at 11:49
We can discuss of course the logic, but my understanding is that thee 'low level' box operations are meant for places where the programmer is in 'full control': for example, they are also not colour-safe. –  Joseph Wright Mar 21 '14 at 13:11