# Typesetting curiosity: word change on one line does not affect how that line is set, but affects how the next line is set

The following two paragraphs differ only in that the first one uses "his" on the first line and the second one uses "her".

\documentclass[12pt]{book}

\textwidth5.5in

\begin{document}

Each producer $$j$$, when choosing the output of his production unit (an element in $$T(j)$$)
takes as given the price system $$(p_1,p_2)$$ prevailing in the market and maximizes the value
of this output (the unit's profit).

Each producer $$j$$, when choosing the output of her production unit (an element in $$T(j)$$)
takes as given the price system $$(p_1,p_2)$$ prevailing in the market and maximizes the value
of this output (the unit's profit).
\end{document}


TeX sets the paragraphs like this: The linebreak for the first line is the same in both paragraphs, but the linebreak for the second line differs between the paragraphs. Thus the difference in the first lines doesn't affect the way the first line is set, but affects the way the second line is set. Why does TeX's paragraph-setting mechanism do that?

• Interesting... What TeX engine (pdftex, xetex, luatex,...) and distribution/version are you using? I couldn't reproduce that with neither engine in TeXLive 15, 18, 19, and 20. Mar 14 '20 at 2:43
• Ah, BaKoMa is WYSIWYG (What You See Is What You Get). I'd change that acronym to WYSMBWYWG,BNN (What You See Might Be What You Will Get, But Not Necessarily). There is a lot of things going on under the hood of a program like that, which is not done by TeX, and since the program is not open source, you can't tell what it does. If you compile that using a TeX engine, both lines will probably look the same. Mar 14 '20 at 3:34
• I'm not sure this is the case (very likely it's not), but TeX attempts to create lines with a similar spacing. If spaces in the first line are shrinked, it can think the second line is best typeset with less spacing. Mar 14 '20 at 6:22
• This is not at all impossible as tex tries to avoid having one tight line next to another loose line, but to check please add \tracingparagraphs=2 and show the log that you get. Mar 14 '20 at 8:41
• @PhelypeOleinik The sense in which BaKoMa is "WYSIWYG" is pretty much the same as the sense in which every other TeX processor with a preview capability is WYSIWYG. It's just that when you edit the TeX code in BaKoMa, the preview instantly recompiles, whereas in other systems you have to press a special key to induce the recompilation. (In BaKoMa you can also edit the TeX code by typing in the Preview window, which is often extremely convenient.) Mar 14 '20 at 14:08

I could not reproduce the output that you show, however by exaggerating width of her I can produce the effect,

\documentclass[12pt]{book}

\textwidth5.5in

\lefthyphenmin=3
\tracingparagraphs2

\begin{document}

Each producer $$j$$, when choosing the output of his production unit (an element in $$T(j)$$)
takes as given the price system $$(p_1,p_2)$$ prevailing in the market and maximizes the value
of this output (the unit's profit).

Each producer $$j$$, when choosing the output of he\vrule width7.01pt r production unit (an element in $$T(j)$$)
takes as given the price system $$(p_1,p_2)$$ prevailing in the market and maximizes the value
of this output (the unit's profit).
\end{document}


TeX tries to avoid having a very loose line next to a very tight one. In order to get and on to the second line the white space has to be very compressed and that isn't allowed in the first paragraph but with the wider her in the second form, the white space in the first line is compressed enough to allow the tight second line.

The log shows

First paragraph:

@firstpass
@secondpass
[]\T1/mdput/m/n/12 Each pro-ducer $\OML/mdput/m/it/12 j$\T1/mdput/m/n/12 , when
choos-ing the out-put of his pro-duc-tion unit (an ele-
@\discretionary via @@0 b=0 p=50 d=2600
@@1: line 1.2- t=2600 -> @@0
ment in $\OML/mdput/m/it/12 T\OT1/mdput/m/n/12 (\OML/mdput/m/it/12 j\OT1/mdput/ m/n/12 )$\T1/mdput/m/n/12 ) takes as given the price sys-tem $\OT1/mdput/m/n/12 (\OML/mdput/m/it/12 p[]; p[]\OT1/mdput/m/n/12 )$ \T1/mdput/m/n/12 pre-vail-ing
in the mar-ket
@ via @@1 b=28 p=0 d=1444
@@2: line 2.1 t=4044 -> @@1
and
@ via @@1 b=86 p=0 d=9216
@@3: line 2.3 t=11816 -> @@1
max-i-mizes the value of this out-put (the unit's profit).
@\par via @@2 b=0 p=-10000 d=100
@\par via @@3 b=0 p=-10000 d=100
@@4: line 3.2- t=4144 -> @@2


second paragraph

@firstpass
@secondpass
[]\T1/mdput/m/n/12 Each pro-ducer $\OML/mdput/m/it/12 j$\T1/mdput/m/n/12 , when
choos-ing the out-put of he|r pro-duc-tion unit (an
@ via @@0 b=102 p=0 d=22544
@@1: line 1.0 t=22544 -> @@0
ele-
@\discretionary via @@0 b=38 p=50 d=4804
@@2: line 1.3- t=4804 -> @@0
ment in $\OML/mdput/m/it/12 T\OT1/mdput/m/n/12 (\OML/mdput/m/it/12 j\OT1/mdput/ m/n/12 )$\T1/mdput/m/n/12 ) takes as given the price sys-tem $\OT1/mdput/m/n/12 (\OML/mdput/m/it/12 p[]; p[]\OT1/mdput/m/n/12 )$ \T1/mdput/m/n/12 pre-vail-ing
in the mar-
@\discretionary via @@1 b=9 p=50 d=12861
@@3: line 2.2- t=35405 -> @@1
ket
@ via @@1 b=4 p=0 d=10196
@ via @@2 b=28 p=0 d=11444
@@4: line 2.1 t=16248 -> @@2
and
@ via @@2 b=86 p=0 d=9216
@@5: line 2.3 t=14020 -> @@2
max-i-mizes the value of this out-put (the unit's profit).
@\par via @@3 b=0 p=-10000 d=5100
@\par via @@4 b=0 p=-10000 d=100
@\par via @@5 b=0 p=-10000 d=100
@@6: line 3.2- t=14120 -> @@5


Martin sent me a full \tracingall log of the document in the question, run through Bakoma TeX, so that I could investigate why I needed to add the rule to make her wider.....

Comparing a \tracingall log of the original version, the LaTeX in the bakoma tex run advertises itself as

LaTeX2e <2017-04-15>


I actually got the fewest differences using texlive 2016, but there the main difference appears to be slight differences in the mathdesign package setup

In particular the diff of the logs shows

tl2016

Package: mathdesign 2013/08/29 v2.31 Math Design Project
...
{select font mdputr8t at 11.28003pt}
...
OT1/mdput/m/n -><->s*[0.94]mdputr7t


bakoma

Package: mathdesign 2006/01/29 v1.55 Math Design Project
...
{select font mdputr8t at 11.03998pt}
...
OT1/mdput/m/n -><->s*[0.92]mdputr7t


so a .02 difference in scale factors used in the fonts. After that of course it is not surprising that in a particularly sensitive paragraph like this where two possible linebreaking options have similar badness and just the width difference between his and her tips the balance that a small difference in font size meant that I had to adjust the word widths to see the same effect.

TeX classifies lines in a paragraph as

1. tight
2. decent
3. loose
4. very loose
5. overfull/underfull

according to their badness, which is computed by looking at how much interword spaces have to be stretched or shrinked for obtaining justification; the names should be self-explanatory.

The algorithm for dividing paragraphs into lines takes the badness of each possible line into account because it works on the whole paragraph. The final result will be so that consecutive lines don't differ by more than one degree according to the table above. So there will be no loose line next to a tight one, nor a very loose one next to a decent one.

If there is no way to obtain the result, you'll get a warning of underfull box or, in some cases, overfull box: this happens if there is no way to break the paragraph respecting the stated tolerance.

The result is that changing a word in the first line of a paragraph might even influence the last one: if the first line changes from decent to tight, say, this may propagate.

• It's not possible that a change only in line 1 can leave the linebreak between lines 1 and 2 at the same place and also leave line 2 unchanged, but change the setting of line 3, is it? If TeX looks only at adjacent lines, then the fact that line 2 is the same in both cases means that line 3 has to be set the same, too, doesn't it? Mar 14 '20 at 14:30
• @MartinJ.Osborne Right, I'll change the wording. Mar 14 '20 at 14:33