4

Suppose I type

\hbox to \hsize{abc}

\hbox{abc}

\bye

Now, since the first \hbox is set at \hsize, I am expecting the abc to be glued with maximum stretched glue. In the second \hbox, I expect abc to be glued with normal glue width without any stretching and shrinking. However, when I compare the results in TeX, it seemed that both produce the same results, why?

Henri Menke
  • 109,596
Kun
  • 680

2 Answers2

8

Concerning the line

\hbox to \hsize{abc}

you are actually right in your statement

I am expecting the abc to be glued with maximum stretched glue

Unfortunately, you can't see the glue, because glue is applied between words, not between letters of a word. The space between the letters is given by the font settings, namely kerning which is not allowed to shrink or stretch.

You can easily make the inserted glue visible by simply using two words, where the second one is pushed to far right (due to the glue stretchability).

\hbox to \hsize{abc def}
\bye

enter image description here

Henri Menke
  • 109,596
  • Just a side question, I have seem many times on this site people typeset the output with this yellow pinkish stripe, how can I do that too? – Kun May 02 '16 at 17:33
  • @Kun when in doubt, click "edit" just to have a peek -- that is a quotation box :) – Quentin May 02 '16 at 19:08
5

The term “glue” might be misleading. It is not something that's used to glue letters together, which isn't needed, but rather something that spaces things from one another.

Glue can be rigid or flexible; flexibility can be in the amount of allowed stretch or shrink (or both, of course). When TeX is ordered to fill with text some amount of horizontal space, it takes all available flexible glue into consideration. Before stretching or shrinking, it computes the natural width of the material, in order to decide whether it's wider or narrower than the size to be filled up; then it looks at the flexible glue and divides the stretch or shrink based on the amount of flexibility.

Here's a list of related topics:

Note that shrinking will never be more than the available amount, whereas TeX is allowed to stretch more than is stated as “optimal” (at the expense of badness). Infinite stretchability or shrinkability take the precedence and won't never produce bad boxes (bad to TeX, of course, in the sense of its algorithms; the result might appear awful to a human reader nonetheless).

Spaces in the input are instructions to TeX to insert glue (shrinkable and stretchable). So

\hbox to \hsize{abc def}

will stretch the contents at the space (with an “underfull \hbox” message). If you want to stretch the space between the letters, you have to insert glue manually:

\hbox to\hsize{a\hfil b\hfil c}

will space out the three letters (with no message, because we used infinite glue).

egreg
  • 1,121,712