3

In the following example, space factor is 1000 everywhere, so \spaceskip must never be used. But why if we change it to 0pt (after calling \raggedright), the result is different?

\hsize=2in
\raggedright
%\spaceskip0pt

once upon a time in a distant galaxy there lived\end
1
  • See also the “How TeX turns spaces into glue” part of the answer to tex.stackexchange.com/questions/412189/… which answers your question (I think). The normal interword glue (which is \spaceskip if it has been set, else taken from the font) is always used for space factor < 2000. – ShreevatsaR May 30 '19 at 12:43
5

As you probably suspected, the space factor has no role whatsoever here.

When \spaceskip is nonzero it is always used for interword space, unless the space factor is ≥ 2000, where \xspaceskip is used (if nonzero as well).

If you look at the definition of \raggedright

% plain.tex, line 647
\def\raggedright{\rightskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}

So it's obvious that the output may change when you set back \spaceskip to zero. The big difference is that the standard interword space has flexibility, whereas \raggedright sets \spaceskip with no flexibility.

Test file

\hsize=2in
\raggedright
%\spaceskip0pt

\tracingoutput=1 \tracingonline=1
\showboxbreadth=\maxdimen \showboxdepth=\maxdimen

\nopagenumbers

\hrule\bigskip

once upon a time in a distant galaxy there lived\end

Without \spaceskip=0pt

Completed box being shipped out [1]
\vbox(667.20255+0.0)x144.54
.\vbox(0.0+0.0)x144.54, glue set 14.0fil
..\glue -22.5
..\hbox(8.5+0.0)x144.54, glue set 144.54fil
...\vbox(8.5+0.0)x0.0
...\glue 0.0 plus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\vbox(643.20255+0.0)x144.54, glue set 600.31366fill
..\glue(\topskip) 9.6
..\rule(0.4+0.0)x*
..\glue 12.0 plus 4.0 minus 4.0
..\glue(\parskip) 0.0 plus 1.0
..\hbox(6.94444+1.94444)x144.54, glue set 0.4882
...\hbox(0.0+0.0)x20.0
...\tenrm o
...\tenrm n
...\tenrm c
...\tenrm e
...\glue(\spaceskip) 3.33298
...\tenrm u
...\tenrm p
...\kern0.27779
...\tenrm o
...\tenrm n
...\glue(\spaceskip) 3.33298
...\tenrm a
...\glue(\spaceskip) 3.33298
...\tenrm t
...\tenrm i
...\tenrm m
...\tenrm e
...\glue(\spaceskip) 3.33298
...\tenrm i
...\tenrm n
...\glue(\spaceskip) 3.33298
...\tenrm a
...\glue(\spaceskip) 3.33298
...\tenrm d
...\tenrm i
...\tenrm s
...\discretionary
...\tenrm -
...\glue(\rightskip) 0.0 plus 20.00003
..\penalty 400
..\glue(\baselineskip) 3.11111
..\hbox(6.94444+1.94444)x144.54, glue set 45.34639fil
...\tenrm t
...\tenrm a
...\tenrm n
...\kern-0.27779
...\tenrm t
...\glue(\spaceskip) 3.33298
...\tenrm g
...\tenrm a
...\tenrm l
...\tenrm a
...\tenrm x
...\tenrm y
...\glue(\spaceskip) 3.33298
...\tenrm t
...\tenrm h
...\tenrm e
...\tenrm r
...\tenrm e
...\glue(\spaceskip) 3.33298
...\tenrm l
...\tenrm i
...\tenrm v
...\kern-0.27779
...\tenrm e
...\tenrm d
...\penalty 10000
...\glue(\parfillskip) 0.0 plus 1.0fil
...\glue(\rightskip) 0.0 plus 20.00003
..\hbox(0.0+0.0)x144.54
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 24.0
.\hbox(0.0+0.0)x144.54, glue set 144.54fil
..\glue 0.0 plus 1.0fil

With \spaceskip=0pt

Completed box being shipped out [1]
\vbox(667.20255+0.0)x144.54
.\vbox(0.0+0.0)x144.54, glue set 14.0fil
..\glue -22.5
..\hbox(8.5+0.0)x144.54, glue set 144.54fil
...\vbox(8.5+0.0)x0.0
...\glue 0.0 plus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\vbox(643.20255+0.0)x144.54, glue set 600.31366fill
..\glue(\topskip) 9.6
..\rule(0.4+0.0)x*
..\glue 12.0 plus 4.0 minus 4.0
..\glue(\parskip) 0.0 plus 1.0
..\hbox(6.94444+1.94444)x144.54, glue set - 0.74403
...\hbox(0.0+0.0)x20.0
...\tenrm o
...\tenrm n
...\tenrm c
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm u
...\tenrm p
...\kern0.27779
...\tenrm o
...\tenrm n
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm a
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm i
...\tenrm m
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm i
...\tenrm n
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm a
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm d
...\tenrm i
...\tenrm s
...\tenrm t
...\tenrm a
...\tenrm n
...\kern-0.27779
...\tenrm t
...\glue(\rightskip) 0.0 plus 20.00003
..\penalty 300
..\glue(\baselineskip) 3.11111
..\hbox(6.94444+1.94444)x144.54, glue set 66.73427fil
...\tenrm g
...\tenrm a
...\tenrm l
...\tenrm a
...\tenrm x
...\tenrm y
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm h
...\tenrm e
...\tenrm r
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm l
...\tenrm i
...\tenrm v
...\kern-0.27779
...\tenrm e
...\tenrm d
...\penalty 10000
...\glue(\parfillskip) 0.0 plus 1.0fil
...\glue(\rightskip) 0.0 plus 20.00003
..\hbox(0.0+0.0)x144.54
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 24.0
.\hbox(0.0+0.0)x144.54, glue set 144.54fil
..\glue 0.0 plus 1.0fil
2
  • As an aside: \ (and ~) behaves as if space factor is 1000, without changing it (i.e., `\ ' always uses normal space glue for the current font). – Igor Liferenko May 31 '19 at 2:22
  • @IgorLiferenko That's right. In the TeXbook, this is documented on page 285 (Chapter 25: Summary of Horizontal Mode) and on page 290 (Chapter 26: Summary of Math Mode), rather than on page 76 (Chapter 12: Glue) where the rest of the stuff about space factor is documented. In the program, this is in (section 1030) in which you can see the same code for both hmode + spacer : if space_factor = 1000 … and for hmode + ex_space, mmode + ex_space (“ex_space” stands for the \ primitive). – ShreevatsaR Jun 1 '19 at 2:47

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.