This question is about the semantics of glues like 0pt plus -1fill, where the coefficient in front of the fill is negative. The following minimal example shows my attempt to figure this out empirically:

\framebox[80pt]{\hskip 0pt plus 1fill    2        \hskip 0pt plus    2fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    1        \hskip 0pt plus    1fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    0.1      \hskip 0pt plus  0.1fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    $-0.5$   \hskip 0pt plus -0.5fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    $-1$     \hskip 0pt plus   -1fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    $-2$     \hskip 0pt plus   -2fill} \\
\framebox[80pt]{\hskip 0pt plus 1fill    $m2$     \hskip 0pt minus  2fill}

Here's the output:

output of example

Comparing the -2 and m2 lines, we see that plus -2fill really is different from minus 2fill. The -0.5 line makes sense to me. I said I wanted the ratio of the two spaces to be -0.5, and it looks like tex made it so. The space on the left-hand side is positive, while the space on the right-hand side is negative and about half as big.

What I don't understand is the results for -1 and -2. They don't seem to extrapolate logically from the preceding examples. Is this just some kind of artifact of the internal implementation of the data structure, like an integer overflow or something?

-------------- material added later -------------

After playing with this some more, I think I understand it at least a little better. This code produces the following output.

  \framebox[20pt]{\hskip 0pt plus 1fill{}.\hskip 0pt plus #1fill}%

more test output

This makes sense because it's trying to place an amount of whitespace L on the left and R on the right such that L+R=w and R/L=x, where w=20 pt and x is the number such as -0.5 in the above code. The solution of these equations is L=w/(1+x), which is what we see graphed. What is still a little odd to me is how it handles x=-1, for which there is no solution.

related: Mathematical description of TeX's infinite numbers?

  • Perhaps -1 is too big and it is leaving the page on the right hand side? For example with -0.85 it is quite near the right margin. – samcarter_is_at_topanswers.xyz Jun 23 '14 at 15:33
  • 2
    plus refers to the stretching component, minus to the shrinking component; the shrinking component is disregarded if the text has to be stretched and conversely. So plus -2fill and minus 2fill have nothing to do with each other. – egreg Jun 23 '14 at 15:42
  • In the -1 case the sum of the stretchable parts is zero. so they don't count and the normal fil of the makebox command center the argument. The -2 case is the same as the -0.5 case only to the other side. – Ulrike Fischer Jun 23 '14 at 15:58
  • Re the addition: try \framebox[20pt][s]{...} so the implicit centering glue (of fil order) is not inserted at either end of the box (see fifth example in my answer, where I added some words). – egreg Jun 23 '14 at 18:27

Let's examine the examples from the fourth on, as the first three pose no problem. I'll denote by t the natural width of the text and by w the requested width.

Fourth and sixth example

Since t < w, the glue must stretch in order to fill wt. The available stretching is infinite (fill units), subdivided into 1fill and -0.5fill. Thus the stretching ratio is 0.5, which means that ((wt)/0.5)*1 will go in the first glue and ((wt)/0.5)*(–0.5) will go in the second glue. This of course means that the text will go outside the frame.

Similarly for the sixth example, but the negative glue will be wider than the positive glue, so the text will stick on the left of the frame.

Fifth example

Here we have a different situation. In the linked question I described the \advance operation on glue registers. When TeX is building a box, it sums the available glues using the operation in Z7 and then applies the function γ. Thus the two fill infinities cancel each other and the normal glue added in a \framebox[80pt]{...} resurrects, so you get the same result as with \framebox[80pt]{$-1$}.

When you say \makebox[80pt]{<text>} (the frame is irrelevant), LaTeX basically translates this into \hbox to 80pt{\hfil<text>\hfil}. If the stretch component of the glue in <text> cancel out, as is the case here, the two \hfil commands will act, because there's no higher order infinite glue that supersedes them. You'd get an Underfull \hbox message with

\framebox[80pt][s]{\hskip 0pt plus 1fill $-1$\hskip 0pt plus -1fill}

because the [s] option will make LaTeX not to insert \hfil at either end.

Seventh example

Since the glue must stretch, the minus component is disregarded. So the result is the same as if you did \framebox[80pt]{\hfill m2} (as \hfill is equivalent to \hskip0pt plus 1fill).

| improve this answer | |
  • Thanks! I think this all makes sense to me now, as explained in my edit to the question, except that I don't really follow the part where you analyze the fifth example and there is "normal glue" that "resurrects." – Ben Crowell Jun 23 '14 at 18:25
  • @BenCrowell In examples with nonzero total fill, the fil parts (added by the \framebox macro) are ignored: only the highest level infinite stretch is used. But in the 5th example, fill + -fill = 0fill, so there is zero total fill glue and positive total fil glue, so only the fil has any effect. – Dan Jun 23 '14 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.