# How is glue calculated?

Consider the following example:

\tracingonline=1
\hfuzz=10000pt
\showbox0
\setbox0=\hbox{a.b}
\showthe\wd0
\end


The output is:

> \box0=
\hbox(6.94444+0.0)x16.77782, glue set - 1.0
.\tenrm a
.\tenrm .
.\glue 4.44444 plus 4.99997 minus 0.37036
.\tenrm b


and

> 13.33337pt.


Now let's try to manually calculate the glue according to p.77 of TeXbook:

Here shrink component of the glue must be used (as spread is negative). It is equal to 0.37036 (according to rule on top of p.76, i.e., normal shrink 1.11111pt multiplied by 1000/f, where f is 3000 because of the dot). So, z0 is 0.37036. We go to case (b). "Glue set order" is 0. "Glue set ratio" is 1.0 because x-w, which is 1pt (argument of spread) is greater than 0.37036. (The ratio is also shown in \showbox output: glue set - 1.0.) Then the glue takes the new width 4.44444-0.37036. The total width thus must be 13.33337+4.44444-0.37036=17.40745. But \showbox shows 16.77782. Why?

You are doing the calculations in the wrong order, the box width is calculated first.

\tracingonline=1
\hfuzz=10000pt
\setbox2=\hbox{a. b}
\showbox2
\showbox0
\setbox0=\hbox{a.b}
\showthe\wd0
\end


Shows that the natural width is 17.77782pt

> \box2=
\hbox(6.94444+0.0)x17.77782


So the box with spread -1pt is 1pt less:

> \box0=
\hbox(6.94444+0.0)x16.77782, glue set - 1.0


The amount glue stretches or shrinks to achieve that is (by design) an internal calculation that is not accessible from the tex macro layer.

In this case the glue can not shrink enough so the content overflows the box, you would have been warned

Overfull \hbox (0.62964pt too wide) detected at line 5


except that you set \hfuzz to suppress the warning, but that only suppresses the warning it does not change the fact that the box is smaller than its contents.

• So, to sum it up: 17.40745-16.77782=0.62964. – Igor Liferenko May 31 at 8:21
• @IgorLiferenko within a sp or two, yes:-) – David Carlisle May 31 at 8:23
• Here is another way to “see” the 0.62964pt (or 0.62963pt) overfull amount. We ask the only glue in the box to shrink by 1pt, however because the normal shrink component of this glue is multiplied by 1000/f = 1/3 and the glue shrink order of the \hbox is zero, the glue and therefore the box can't shrink more than (normal shrink)×1/3 = 0.37036pt, as Igor computed. This results in an overfull of 1pt - 0.37036pt = 0.62963pt. – frougon May 31 at 9:59

Consider these five boxes:

\setbox1=\hbox{ab}
\setbox2=\hbox{a.b}
\setbox3=\hbox{a b}
\setbox4=\hbox{a. b}


By looking at their widths (in pt with \showbox1 etc. or in sp with \count1=\wd1 \showthe\count1 etc.), we can see that:

In the first case \hbox{ab}, the width is 691771 sp (= 691771/65536 pt ≈ 10.55559pt). This comes from adding up the widths of the a and the b in the \tenrm font.

In the second case \hbox{a.b}, the width is 873816 sp (= 873816/65536 pt ≈ 13.33337pt). This comes from adding up the widths of the a , the ., and the b in the \tenrm font.

In the third case \hbox{a b}, the width is 910224 sp (≈ 13.88892pt). The glue in this case is the normal interword glue, calculated from the font. This glue has:

• natural width \fontdimen2\font = 218453 (≈ 3.33333pt).

• Stretch \fontdimen3\font = 109226 (≈ 1.66666pt).

• Shrink \fontdimen4\font = 72818 (≈ 1.11111pt).

So we take the width of \hbox{ab} and add the natural width of the glue above, to get 691771 + 218453 = 910224.

In the fourth case \hbox{a. b}, the width is 1165087 sp (= 17.77782pt). Here the glue is larger because of the . which has space factor 3000. The natural width, stretch, and shrink are transformed from the previous case as:

• natural width: add \fontdimen7\font = 72818 (≈ 1.11111pt), to get 218453+72818=291271 (≈ 4.44444pt).

• Stretch: multiply by f/1000=3, so 109226*3 = 327678 (≈ 4.99997pt).

• Shrink: multiply by 1000/f=1/3, so 72818/3 = 24272 (≈ 0.37036pt).

So we take the width of the \hbox{a.b}, and add the natural width above, to get 873816 + 291271 = 1165087.

In the fifth case \hbox spread -1pt{a. b}, the width is 1099551 (≈ 16.77782pt). This we get by simply decreasing the previous width by 65536 (=1pt) as requested, so 1165087 - 65536 = 1099551.

Compared to the natural width 1165087 decreased by the shrink 24272 (so 1165087 - 24272 = 1140815 ≈ 17.40745pt), this is further less by 41264 (≈0.62964pt) so you get an overfull warning mentioning that length. Or as @frougon pointed out, we can see that there was an available shrink of 24272 and we asked for a shrink of 65536, so we asked for 65536 - 24272 = 41264 more shrink than was available.