5

What does \hskip 60pt plus 100pt minus 100pt mean? I used to think of this as a mechanical spring with natural width and some string constant k. But, I know that it is not exactly so, since the plus and minus need not be exact, and, also, the text box has maximal and minimal width, whereas a Hookean spring has infinite elasticity.

Now, the nice thing about Hookean strings is that they can be connected in series and in parallel. Here are some questions:

  • Does TeX inner engine rely on this property to model several adjacent boxes as one?
  • Does the physics of spring carry through to TeX? Did Knuth develop the math and physics of glue?
  • Are there any instances in which \hboxes are connected in parallel?
  • If TeX glues are likened to physical springs, what are TeX springs in the physical world?

If you do not like the springs analogy, the questions are then restricted to creatures created by \hbox and glues. Is it the case that the serial concatenation of two of these, cannot be represented with a single box with different glue?

More abstractly, what are the elasticity functions of compound creatures? Is it a Tropical Geometry of some kind?

Yossi Gil
  • 15,951
  • 2
    I think any reference to physical springs would just be confusing. I'm sure we have an answer somewhere explaining glue specification, I'll see if I can find. – David Carlisle May 21 '17 at 19:34
  • You should not push analogies to the limit. If a line has to be stretched, the amount of stretching is proportionally divided among the glue stretchabilities. – egreg May 21 '17 at 19:36
  • But, that's exactly what physical springs do, stretch proportionally. – Yossi Gil May 21 '17 at 19:39
  • 1
    You can read the Knuth–Plass paper Breaking Paragraphs Into Lines for a definitive description of this. (The latest version is the one reprinted in the 2012 printing of Digital Typography.) The box-glue-penalty "algebra" that you seem to be interested in is in the section “An Algebraic Approach” (on page 1146 in the original paper, on page 102 in DT). Incidentally Knuth–Plass wrote a further paper Choosing Better Line Breaks, introducing notions (such as that of “kerf” that are not even present in TeX). – ShreevatsaR May 21 '17 at 20:10
  • 1
    See also Knuth's short note TeX's infinite glue is projective in TUGboat (2007). – ShreevatsaR May 21 '17 at 20:12
  • Sorry, but this question just seems designed to confuse and intimidate users. I would have thought that the concept of glue was already sufficiently confusing and intimidating, without needing to make matters worse by needlessly multiplying the conceptual complications. – cfr May 21 '17 at 23:01
  • @cfr it's a natural analogy from the point of view of someone immersed in physics. If it was correct it might be enlightening, but as it's wrong, it does indeed lead to confusion. – Chris H May 22 '17 at 10:12

2 Answers2

6

So, here is my analysis of the topic. The springs that TeX use are not physical springs that obey Hooke's law. They are springs that obey a different law not found in our real world physics.

In the Knuthian physics, a spring is specified by three values: min, natural-length, max. We tend to think of a spring in physics as specified by two values: natural length and string elasticity constant k. In truth, physical strings have three values, since elasticity may be different for shrinking and for elongation.

Knuth springs have these properties in common with Hookean springs:

  1. Both springs are specified by three parameters: Hookean springs have a natural length, and two elasticity constants, one for compression, and another one for elongation. They can be written as a triplet of three real (typically) non-negative numbers (c,n,e) representing compression elasticity constant (1/k), natural length, and elongation elasticity constant (also 1/k, except that it does not have to be the same k).
  2. Connecting Knuthean spring <min1,n1,max1> to spring <min2,n2,max2> in series, gives <min1+min2,len1+len2,max1+max2>. This is just the same as Hookean springs connected in series, you get <c1+c2, n1+n2, e1+e2>.
  3. The badness of Knuthean spring is |\Delta x^3|$, where \Delta X is the relative deviation from n. Badness is similar to energy, but if one thinks of energy, as a global additive property that is minimized in equilibrium, then the static energy of a Knuthean spring is $(\Delta x)^5 +(\Detla x)^3$. Recall that the energy of a Hookean spring is (dx)^2(actually, \frac12k(dx)^2 but we ignore constants), where dx is the absolute change in dimension.
  4. Hooke's law also models 2D (and 3D) objects. Not sure whether in Knuthean 2D boxes can be thought of like 2D springs.

Differences include:

  1. Connecting spring <min1,len1,max1> to spring <min2,len2,max2> in parallel, gives <max(min1,min2),?,min(max1,max2)>, where the question mark needs to be defined. Is there a natural length of putting two glues in parallel? Should it depend on the min and max values, or just on the base lengths? Furthermore, note that the parallel attachment of Knuthean springs may create an undefined spring, i.e., one whose minimal length is greater than its max length.

  2. Knuthean springs have a theory of breakdown: underfull and overfull boxes. Nothing like this in Hookean springs.

  3. Knuthean springs interact with breakpoints and penalties, the potential locations in a paragraph in which lines might be broken. Penalties have dyadic semantics, not typically found in physics, and certainly not in spring mechanics.

  4. Energy is "minimized" in Knuthean springs by a dynamic programming algorithm; rules of physics do not apply here.

In addition, Knuthean springs have several infinities. I believe this can be modeled in the physical world.

HTH

Yossi Gil
  • 15,951
  • 2
    I don’t understand what you mean, exactly, by “connecting two ‘Knuthean springs’ ( = glue nodes) in parallel”: glue nodes can only belong to vertical/horizontal/math lists, which are inherently sequential in nature. – GuM May 21 '17 at 21:12
  • 2
    Describing a TeX glue specification in terms of <min1, len1, max1> has no advantages over the standard <width, stretch, shrink> — it makes all the expressions hard to reason about, mistakes harder to spot, and is actively misleading as glues can stretch more than the "max" (overfull box). And I don't know where you get your expression <max(min1,min2),?,min(max1,max2)> from; putting two glues together has their stretch and shrink simply add up. Please delete or fix this answer; inaccurate information on a topic like this is worse than no information. – ShreevatsaR May 21 '17 at 21:16
  • Shouldn't 2 say <min1+min2, len1+len2, max1+max2>? @ShreevatsaR ? – cfr May 21 '17 at 22:56
  • @cfr Yes you're right (if we understand the “min” and “max” to mean “length - shrink” and “length + stretch” respectively: but that's not quite right, because those quantities have no special significance. E.g. we could double each “stretch” and except for the badness computation for line-breaking, if the same breaks are chosen, the result would be the same as before. Also, the stretch and shrink can independently be negative, for achieving certain special effects.) – ShreevatsaR May 21 '17 at 23:05
  • @ShreevatsaR Well, I find the whole analogy confusing. Thanks. – cfr May 21 '17 at 23:08
  • Do the above responses suggest that TeX never needs to optimize Knuthean strings connected in parallel? (In typesetting, this means stretching lines without changing the line breaks?) – Yossi Gil May 22 '17 at 08:58
  • @YossiGil There is no such thing as "connected in parallel". Of course the entire point of glue is to have lines (or other boxes) stretch or shrink to whatever length is necessary (where feasible), so I don't understand the second part of your comment either. – ShreevatsaR May 22 '17 at 09:29
  • It isn't trying to stretch lines without changing line breaks, though, is it? It is trying to find good places to break lines. A paragraph is a list of tokens. It needs to be split up into lines. At least, as I understand it. You make it sound as if it breaks the paragraph into lines first and then worries about justifying them. But that's not how it works. It can't be in horizontal mode and vertical mode simultaneously .... – cfr May 22 '17 at 11:09
  • May I ask why you prefer to describe TeX glue as a triple (min, length, max), rather than (length, stretch, shrink)? Not only is it incorrect because there's no max (see e.g. this question), but even for your comparison with Hooke-law springs described by (length, elasticity), it is the correct triple that makes a closer analogy. So it's puzzling why you prefer the wrong description. (BTW, a TeX glue with length-shrink > length+stretch isn't undefined; it behaves as expected.) – ShreevatsaR May 23 '17 at 17:38
  • Sure. With all due respect, Knuth's work is later and less general than the physical world. So, if I want to equate the two, it makes sense to coerce the TeX terminology to the physical world. In doing so, I discovered something I thought was a bit surprising: Physical springs are allowed two distinct elasticity constants. See my edited answer. – Yossi Gil May 25 '17 at 16:59
  • @YossiGil But the correct (length, stretch, shrink) is closer to the physical world's (length, elongation elasticity constant, compression elasticity constant), than the incorrect (min, length, max) is. So the incorrect (min, length, max) one doesn't even serve your goal of making TeX springs appear closer to the physical world; it's taking it further away. – ShreevatsaR May 25 '17 at 17:10
  • Do you mean the order of the values in the triple? Anyone would do. What do you suggest? – Yossi Gil May 25 '17 at 17:16
  • Yes I mean the triple: what TeX has is a (length, stretch, shrink). It is not the case that length + stretch is a maximum. The stretch and shrink are simply constants used for (computing badness and) allocating stretch/shrink among the different glues in a box. So I would suggest (length, stretch, shrink) or (space, stretch, shrink) (as called in the TeXbook). (Alternative names for the first value: natural length, ideal length. Alternative names for the others: stretchability, shrinkability.) – ShreevatsaR May 25 '17 at 17:37
  • It is one thing, to say \hbox to ... {...}, and another, to break a paragraph into lines. Also, I cannot tell where you derived your (\Delta x)^5 +(\Delta x)^3$ formula from. – GuM May 25 '17 at 18:09
  • 2
    This answer has value. While TeX never combines boxes in parallel, it would make sense to do it. If a displayed equation's natural length exceeds that of a line, TeX shrinks spaces around =, +,… but not within numerator/denominator of fractions. TeX could have computed the fraction's minimal length from those of numerator and denominator (max of the two). (By the way, I agree with other comments concerning the stretch, but describing the shrink by the minimum length makes sense AFAIK.) Why (Δx)^5+(Δx)^3 though? – Bruno Le Floch May 25 '17 at 19:00
  • I think it should be "(Δx)^6+(Δx)^3" but will check again in the minimization function. – Yossi Gil May 26 '17 at 03:57
6

The main things a TeX user needs to know about glue are discussed at What is glue stretching?, but to address the peculiar parts of this question that are not covered there: As @egreg says, it's not accurate to stretch the analogy too far. The “springs” of TeX's line-breaking algorithm are not modelled on real-life springs.

This is all described very clearly in the wonderful paper Breaking Paragraphs into Lines by Knuth and Plass. (Including the “algebra” of putting multiple boxes or glues together.)

To repeat some parts of it: abstractly, for TeX a paragraph is a sequence of

  • boxes: a box has a width wi
  • glue (aka springs, skips): a glue has a width wi, a stretchability yi, and a shrinkability zi. The stretchability and shrinkability may independently be positive, negative, or infinite (in fact there are multiple “orders of infinity”).
  • penalties: has a penalty pi, a width wi and a flag fi which may be 1 or 0 (for the width and flag: think of hyphens).

The stretchability and shrinkability in the glue specification can be specified independently and either of them can be negative.

Some “algebra” of the sort the question asks about:

  • Consecutive boxes are equivalent to a bigger box:

    box(w)box(w') = box(w + w')

  • Consecutive glues are equivalent to a bigger glue:

    glue(w, y, z)glue(w', y', z') = glue(w+w', y+y', z+z')

(Some more stuff about penalties, omitted here.)

All this and more are described in, apart from of course The TeXbook and TeX: The Program (Volumes A and B of Computers and Typesetting), the following papers which are cited thus in the Supplementary Bibliography at the start of Volume B:

  • “Breaking paragraphs into lines” by Michael F. Plass and Donald E. Knuth, Software—Practice and Experience 11 (1981), 1119–1184. *Develops the theory underlying TeX's line-breaking algorithm and applies it to a variety of practical problems; includes an illustrated history of line-breaking techniques in the printing industry. An appendix discusses a simplified algorithm suitable for word processors.

  • “Choosing better line breaks” by Michael F. Plass and Donald E. Knuth, in Document Preparation Systems, Nievergelt et al., eds. (Amsterdam: North-Holland, 1982), 221–242. A shorter version of the preceding paper. Introduces the notion of a “kerf,” which unifies and generalizes TeX's primitive operations of glue, penalties, and discretionary breaks.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • 1
    I think that to omit to mention glue stretching orders is an over-simplification that should be avoided. On the contrary, describing discretionaries as penalties-with-width is an interesting pedagogical apporach… :-) – GuM May 21 '17 at 23:10
  • @GustavoMezzetti Just following the paper :-) And good point, I've edited the answer to mention the orders of infinity though without much explanation—the linked question and answer should be regarded as the reference IMO. – ShreevatsaR May 21 '17 at 23:17
  • Not sure you really got the question, oh well... – Yossi Gil May 22 '17 at 13:08
  • @YossiGil To be more clear: the main point of my answer is “Please take a few minutes and read the paper; it will tell you everything you need to know and you won't ask such questions.” :-) (To elaborate on why the question is meaningless would lead to even more confusion I thought: e.g. there is no such thing as “connecting” skips; they can only be laid out in sequence. There is definitely no such thing as “connecting them in parallel”.) I answered the parts of the question that could be meaningfully answered: is there a mathematics of how multiple glue get put together? (Yes, in sequence.) – ShreevatsaR May 22 '17 at 15:34
  • NP, all is good. I am pretty familiar with the nitty gritty of the layout algorithm, but I was trying to take a different perspective on it. Not sure though that I have an answer to the potentially trivial question: is there a mechanism in TeX that would allow the equivalent of parallel Knuthean springs? If not, can we coerce it to do so? – Yossi Gil May 22 '17 at 23:00
  • @YossiGil There isn't. TeX just deals with plain simple lists; it's simpler than the real world (and even physicists' simplification of it). :-) – ShreevatsaR May 22 '17 at 23:17
  • 1
    @GustavoMezzetti Just occurred to me: A potential reason the "orders of infinity" weren't mentioned by Knuth in the paper: although they are heavily used in TeX in practice, from a mathematical point of view they are not very important as a detail: in the abstract TeX-like line-breaking system, instead of fil and fill, one could simply specify (say) 10^5 and 10^10, and the output would be practically the same. (In fact, TeX78 manual introduces \hfill as equivalent to \hskip 0pt plus 10000000000pt and in "Recent extensions to TeX", \hfil as short for \hskip 0pt plus 100000pt.) – ShreevatsaR May 23 '17 at 08:08