12

Plain TeX provides \centerline for centering, well, lines of text, but nothing to center a paragraph. LaTeX has \centering and the \center environment. Looking at the LaTeX code, it appears very similar to what Bechtolsheim proffers in "TeX in Practice":

\rightskip = 1in plus 4em
\leftskip = \rightskip
\spaceskip = .3333em
\xspaceskip = .5em
\parfillskip = 0pt
\noindent
On the other hand there are sometimes cases where you want to have a
sequence of lines, all centered, but you do not want to make the line
breaking decisions all by yourself. So here is a sample where \TeX{}
did all the work.

\bye

Bechtolsheim also gives a begin/end environment-like example using this code.

A previous stackexchange question has similar code: A center environment for plain TeX

My question is why does Bechtolsheim recommend the use of \spaceskip and \xspaceskip and how did he come up with those numbers? Why do LaTeX (I believe) and the solution @egreg provides in the previous question eschew them?

Admittedly I don't fully understand \(x)spaceskip so an explanation of them would be helpful.

p.s. I know the TUGboat and Amazon reviews of Bechtolsheim work (TeX in Practice) were only somewhat favorable, but I think the books are awesome. Yes, there are typographical and editing errors, but the content is great and I am finding the verbose examples extremely helpful and valuable. I would definitely encourage anyone who wants to learn the finer details of TeX to check them out. However, one should do at least a first reading of Knuth's "The TeX Book" first (dangerous bends being initially avoided), because Bechtolsheim does make some assumptions that the reader has a basic familiarity with TeX.

UPDATE: Great answer and comments. I think the ragged2e latex package documentation explains the issue quite well and points out that the Plain TeX version of ragged is in some ways superior to default LaTeX and attempts to fix it as well as the centering and raggedleft environments by essentially setting the fontdim2 value of a font (if available) to \spaceskip which provides optimal spacing while preserving the ability to hyphenate which is unfortunately lost when fil is used. I think a good Plain TeX implementation of centering, then should do something similar. It is also somewhat interesting that Schröder's package uses 2em instead of Bechtolsheim's 4em in the left/right skip registers.

acarlow
  • 1,311
  • 1
    They don't have stretch/shrink components, so the interword spaces keep at a constant "optimal" value. Same thing inside \raggedright. – morbusg Jun 26 '14 at 17:47
  • (and xspaceskip for after end-of-sentence) – morbusg Jun 26 '14 at 17:50
  • @morbusg In the @egreg and LaTeX implementations they use fil for the left/right skip (Bechtolsheim uses 4em). Does the fil make \(x)spaceskip unnecessary then? – acarlow Jun 26 '14 at 17:53
  • Good question! I'm not sure, but sure sounds reasonable. – morbusg Jun 26 '14 at 17:59
  • @acarlow yes.... – David Carlisle Jun 26 '14 at 18:08
  • Of course, the follow-up question would then be, why did Bechtolsheim use \(x)spaceskip and 4em instead of fil... – acarlow Jun 26 '14 at 18:09
  • @acarlow that matches the plain tex definition of \raggedright which similarly uses a finite stretch in the margin and sets spaceskip – David Carlisle Jun 26 '14 at 18:14
  • @DavidCarlisle Thanks for pointing that out. I can understand Knuth's reasoning -- to prevent too much "raggedness" (I think that's the case anyway). Still, seems odd to me that with fil as an option for \leftskip and \rightskip one would use finite glue. It would be fascinating to see an example where the finite glue implementation would be "better". – acarlow Jun 26 '14 at 18:24
  • regarding the reviews of "tex in practice", i think they reflect the fact that there's a lot of repetition -- multiple examples, for instance, that don't necessarily add much to the volume of information conveyed. of course, this is subjective, and depends on what one is looking for. if you need concise explanations, tex by topic is your cup of tea. if you're looking for an example to crib as a starting point for some not-quite-obvious project, then tex in practice is a much better resource. – barbara beeton Jun 26 '14 at 19:20
  • @barbarabeeton Thanks for your thoughts on the reviews. Being new to TeX, I think the repetition and verbosity helps reinforce things nicely. I can see how more experienced TeX people might be put off. To me, they are perhaps the best resource for "advanced beginners" that I've come across and thought a review from that perspective would give better balance to their overall value. – acarlow Jun 26 '14 at 19:29
  • @acarlow using fil allows a line just to have a on it and all white space if the following word is long and gets taken over, only allowing finite stretch in the margin forces Tex to consider hyphenation as a possibility – David Carlisle Jun 26 '14 at 19:53
  • @acarlow -- you might be interested in the list of tex-related publications i put together for ams. (haven't checked the links for several months, so some of them may have gone south. it could also use some reorganization; i thought it was in reverse chronological order, but parts of it are not.) some items are out of print, but might possibly be found in used book lists. and suggestions for additions are welcome too. – barbara beeton Jun 26 '14 at 19:56
  • @barbarabeeton Great list of books! Thanks for putting forth the effort to compile it. I've already found some that look interesting. – acarlow Jun 27 '14 at 04:14

1 Answers1

10

The settings there use a finite amount of stretch so the text isn't too ragged (like ragged2e package \RaggedRight). But left on its own that would mean that any line stretching would be shared between the margins and the inter word space, so the spaceskip settings freeze those at fixed values.

The latex version uses infinite glue stretch in the margins so this naturally forces all the interword glue to its natural length as all the stretch is taken up at the margin.

David Carlisle
  • 757,742
  • Any conceivable reason why a finite stretch would be warranted (in the context of centering lines)? – acarlow Jun 26 '14 at 18:15
  • 1
    The finite stretch is used in order to force TeX to enter to the second pass in paragraph beaking algorithm when there is very "ragged" margins. The second pass invokes the word hyphenation. – wipet Jun 26 '14 at 18:26
  • @wipet Ok, so the infinite glue implementation would allow for more raggedness because it doesn't get to the second pass for hyphenation? – acarlow Jun 26 '14 at 18:29
  • @acarlow Yes. If there is infinite stretch then the lines have zero badness and the second pass (and hyphenated words) never occurs. – wipet Jun 26 '14 at 19:01
  • @acarlow as wipet said. al,so see more discussion and side by side examples try texdoc ragged2e to see the ragged2e version of raggedright which is like the plain tex version with finite stretch – David Carlisle Jun 26 '14 at 19:57
  • @DavidCarlisle Thanks for the tip. I've updated the question and cited M. Schröder's package and documentation. – acarlow Jun 26 '14 at 20:17