# Does TeX use Hookean physical springs to represent positive and negative glue? [duplicate]

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?

## marked as duplicate by David Carlisle, CarLaTeX, ShreevatsaR, Moriambar, Martin SchröderMay 21 '17 at 23:53

• 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
• 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
• See also Knuth's short note TeX's infinite glue is projective in TUGboat (2007). – ShreevatsaR May 21 '17 at 20:12

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.

• 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.

• 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
• @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 8:08

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

• 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
• 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
• 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