# Why does an empty \textwidth coffin lose width when joined with another?

I'm trying to understand coffins. Well, actually, I'm trying to use them. Trying to understand them is a purely instrumental goal.

I wanted to create one coffin of width \textwidth and one of a bit less than .5\textwidth. I then wanted to join the coffins using the anchors given by T and r.

I then wanted to typeset the joined result using the anchor at T and l, so that the text would be pushed to the right of the page. (As if I'd filled the space to the left of a half-width minipage, roughly.)

However, the \textwidth of the first coffin appears to be forgotten when I join the second, so that the text is typeset to the left of the page rather than the right.

In contrast, if the first coffin contains an x, for example, then the width of the coffin is preserved and the text is pushed to the right.

Now, obviously, there are many other ways to achieve this effect. I am not asking for another method. I want to know instead if this is expected and, if so, why, since I did not expect it given my brief excursion into coffin territory.

\documentclass{article}
\usepackage{expl3,showframe}
\begin{document}
\ExplSyntaxOn
\vcoffin_set:Nnn \l_tmpa_coffin { \textwidth }
{
}
\vcoffin_set:Nnn \l_tmpb_coffin { .5\textwidth - .5\columnsep }
{
Some~long~stuff~here~of~some~description~typeset~somehow~or~other~but~maybe~not~so~tediously.
}
\coffin_join:NnnNnnnn \l_tmpa_coffin { T } { r } \l_tmpb_coffin { T } { r } { 0pt } { 0pt }
\noindent
\coffin_typeset:Nnnnn \l_tmpa_coffin { T } { l } { 0pt } { 0pt }
\bigskip
\par
\vcoffin_set:Nnn \l_tmpa_coffin { \textwidth }
{
x
}
\vcoffin_set:Nnn \l_tmpb_coffin { .5\textwidth - .5\columnsep }
{
Some~long~stuff~here~of~some~description~typeset~somehow~or~other~but~maybe~not~so~tediously.
}
\coffin_join:NnnNnnnn \l_tmpa_coffin { T } { r } \l_tmpb_coffin { T } { r } { 0pt } { 0pt }
\noindent
\coffin_typeset:Nnnnn \l_tmpa_coffin { T } { l } { 0pt } { 0pt }
\ExplSyntaxOff
\end{document}


Note, too, that I am aware that xcoffins provides a more appropriate interface for coffins in documents. I'm taking this from a class file and transplanted it just to create the MWE. Since this is the syntax whose territory I've been taking an excursion into, this seemed the most useful way (for me!) to ask the question.

• You can see that the coffin has no width before any joining: \coffin_show_structure:N \l_tmpa_coffin. – Joseph Wright May 10 '16 at 8:53
• @JosephWright Thanks. Is there an expl3 equivalent of adding an \mbox{}? And is this expected? I understand Ulrike's point, I think, but that still doesn't make sense to me in terms of how coffins are explained. – cfr May 10 '16 at 12:30
• @JosephWright In the case of \vbox etc., you can't join/attach them afterwards in the way you can with coffins, can you? Or am I wrong about this? (Very likely I am....) In terms of the function of coffins, it made sense to me to want to do this, I guess. – cfr May 10 '16 at 12:35

Imho it is to be expected. It works similar to the classic \vbox: Setting \hsize doesn't create a large box. You need some material, e.g. a \leavevmode:

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\fbox{\vbox  {\hsize=5cm   }}\par

\fbox{\vbox  {\hsize=5cm x }}\par

\vcoffin_set:Nnn \l_tmpa_coffin { 5cm }
{
}

\vcoffin_set:Nnn \l_tmpb_coffin { 5cm }
{
x
}

\fbox{\coffin_typeset:Nnnnn \l_tmpa_coffin { T } { l } { 0pt } { 0pt }}
\par
\fbox{\coffin_typeset:Nnnnn \l_tmpb_coffin { T } { l } { 0pt } { 0pt }}

\ExplSyntaxOff
\end{document}


• Thanks! I think I understand this, but I don't understand it in terms of the way coffins are explained. In the case of \vbox etc., I don't think you expect to be able to join/attach them afterwards in the way you can with coffins, do you? Or am I wrong about this? (Very likely I am....) – cfr May 10 '16 at 12:33
• @cfr: You are already "joining" boxes if you print them side by side or one below the other. But your main problem is imho that you think that the width of vcoffin describes its "outside" width. This is not the case. If you e.g. put \hbox to 2cm {x} in it, it will have a width of 2cm. The width describes the "inside" width needed for linebreaking. – Ulrike Fischer May 10 '16 at 12:56
• I wouldn't expect it to work in any particular way if I mix in things like \hbox to  etc. because I wouldn't know, from the documentation, how that was meant to behave. And, no, I don't really understand the difference between 'inside' and 'outside' width in the case of coffins as opposed to, say a \parbox or something. But you are not joining \vboxes in the relevant sense when you just print them side-by-side. The bouding box of the first doesn't alter to accommodate the second, for example. – cfr May 10 '16 at 13:17
• Joining is the second step. The first is that your coffin simply doesn't have the width you are expecting. It doesn't "forget" it width: as you didn't put something in the coffin the width is zero -- and this is not different to \parbox: Try out \fbox{\parbox{5cm}{}}. – Ulrike Fischer May 10 '16 at 13:27