summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/ontarget/ontarget-makesnosense.tex
blob: 3a9e45e5e14d43816e63b6ff0f72f9dc7aabf0d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
% language=us runpath=texruns:manuals/ontarget

\startcomponent ontarget-makesnosense

\environment ontarget-style

\startchapter[title={Not all makes sense}]

The development of \CONTEXT\ is to a large extend driven by users with a wide
variety of background and usage. I can safely say that much time spent on
\CONTEXT\ qualifies as hobby (or maybe even more by curiosity). Of course I do
use it myself but personally I never make advanced documents. I'm not a writer,
nor an artist, nor a typesetter. I do like challenges so that's why we get
mechanisms that can do tricky things and some stay sort of hidden because the
practical usage is limited, although you will be surprised to see what users find
in the source and use anyway. My colleague uses \CONTEXT\ for large scale, mostly
complex and demanding \XML\ documents where one source is rendered in different
ways with different parts used. Many features in \CONTEXT\ relate to workflows.

I like to visualize things so that's part of the development cycle. I never start
from some \quote {typographical} point of view, if only because in my experience
much design is arbitrary and personal. The output should look okay on the
average, and on reasonable simple documents there should be no need for manual
intervention. I am quite willing to accept an occasional less optimal looking
page and don't loose sleep over it. A next time, when a sentence gets added, it
might be better and the problem can be moved further down the pages. Also, given
what one runs into nowadays the average job that \TEX\ does is pretty good (but
users can of course mess up). It is boundary conditions that determine in what
direction a style or solution goes. The more abstract one argues about
typesetting and possible solutions, the less interested I often become simply
because there are no perfect solutions for every case. There are always those
last few \percent\ points that need manual intervention or some trickery and most
users get that. It is also what makes using \TEX\ fun.

As mentioned, the \TEX\ engine does a pretty good job on average but that didn't
prevent me from extending it: the mix of \TEX, \METAPOST\ and \LUA\ is even more
fun. But what is the development agenda there? Again, it is very much driven by
what users want me to solve, but there's also the curiosity element. A recent
example of extending is the math sub system. It was already made more
configurable and some features where added but now it is really flexible. This
was doable because the heuristics in the engine are clear. It was could be done
because I had a dedicated partner in this journey. \footnote {In another chapter
I summarize what Mikael Sundqvist and I did in this context.} Other parts are
more difficult but have nevertheless been extended, to mention a few: alignments,
par building and page building. However the last two use some heuristics that are
hard to make more flexible. For instance the badness calculation combined with
the loop that tries to find breakpoints is already quite good and the somewhat
special values involved in the calculations have been optimized stepwise by Don
Knuth during the development of \TEX.

Does that mean that one cannot add some options to influence that tuning? For sure
one can. The source has this comment:

\startquotation
    When looking for optimal line breaks, \TEX\ creates a \quote {break node} for
    each break that is {\em feasible}, in the sense that there is a way to end a line
    at the given place without requiring any line to stretch more than a given
    tolerance. A break node is characterized by three things: the position of the
    break (which is a pointer to a \type {glue_node}, \type {math_node}, \type
    {penalty_node}, or \type {disc_node}); the ordinal number of the line that will
    follow this breakpoint; and the fitness classification of the line that has just
    ended, i.e., \type {tight_fit}, \type {decent_fit}, \type {loose_fit}, or \type
    {very_loose_fit}.
\stopquotation

The book {\TEX\ by Topic} (by Eijkhout) gives a good explanation of the way lines
are broken so there is no need to go into detail here. The code involved is not
that trivial anyway. The criteria for deciding what is bad are as follows:

\starttabulate[|c|c|c|]
\FL
\BC verdict    \BC effect  \BC badness \NC \NR
\ML
\NC very loose \NC stretch \NC >= 100  \NC \NR
\NC loose      \NC stretch \NC >= 13   \NC \NR
\NC decent     \NC         \NC <= 12   \NC \NR
\NC tight      \NC shrink  \NC >= 13   \NC \NR
\LL
\stoptabulate

When the difference between two lines is more than one, they are considered to be
visually incompatible. Then, if the badness of any line exceeds \type
{pretolerance} a second pass is triggered, When \type {pretolerance} is negative
the first pass is skipped. When the badness of any line exceeds \type {tolerance}
a third pass is triggered and \type {emergencystretch} is used to make things fit.

Where in traditional \TEX\ a lot of parsing, hyphenation, font handling and par
building is combined, in \LUAMETATEX\ we always work with completely hyphenated
and font readied lists. In traditional \TEX\ the first pass works on
the original non|-|hyphenated lists.

In the source there is an old note that one day I will play with a plugged in
badness calculation but it also says that there might be a performance impact as
well as all kind of unforeseen side effects because \TEX\ makes sure that the
heuristics lead to values that don't result in overflow and such.

Another note concerns more fitness values. Doing that will increase the runtime a
little but on a modern machine that is not really an issue. Shortly after I
upgraded my laptop to a somewhat newer one I decided to play with this and
therefore any performance hit would go unnoticed anyway. The following snippet
from the source shows the idea:

\starttyping
typedef enum fitness_value {
    very_loose_fit, /*tex lines stretching more than their stretchability */
    loose_fit,      /*tex lines stretching 0.5 to 1.0 of their stretchability */
    semi_loose_fit,
    decent_fit,     /*tex for all other lines */
    semi_tight_fit,
    tight_fit,      /*tex lines shrinking 0.5 to 1.0 of their shrinkability */
    n_of_finess_values
} fitness_value;
\stoptyping

This means that when we loop over \type {very_loose_fit} upto \type {tight_fit}
we have two more classes to take into account: the semi ones. Playing with that
and associating them with magic numbers quickly learned that we enter the area of
\quote {random improvements}. You can render variants and because some will look
better and others worse one can argue for any case. And as usual, once a user
(unaware of what we are doing) looks at it, things like successive hyphens, wider
spaces, rivers and such are seen as the main difference. Of course spacing is the
direct result of this kind of messing, but because the effects are actually
mostly noticeable on non|-|justified texts it then is the end|-|of|-|line spacing
that influences the verdict. \footnote {When \HZ\ showed up in \PDFTEX\ we did
experiments with random samples of its usage and \TEX ies at user group meetings
and the results were such that one could only draw the conclusion that on the
average a user has no clue if something is good or bad for what reason. The
strong emphasis in the \TEX\ community on hyphenation makes that an eye|-|catching
criterium. So having two in a successive lines even when there is really no
better solution is what draws the attention and users then tend to think that
what a survey is about is \quotation {The quality of hyphenation related to
breaking paragraphs into lines.}}

In the end this kind of extensions make little sense. One can of course play
science and introduce all kind of imaginary cases where it might work but that is
why I started this summary by explaining what drives developments: users and
constraints. Playing science for the sake of it is pseudo science. And, as with
much science related to typesetting (probably with the exception of Don's work)
most has therefore little practical value.

So, do we keep this feature or not? We actually do, if only to be able to
demonstrate the fuzziness of this. We have an undocumented magic parameter:

\starttyping
\linebreakcriterium"0C0C0C63
\stoptyping

Actually the value is zero but when one of the four byte pairs is zero it will
default to \type {"0C} (\number"0C) or \type {"63} (\number"63). The values
concern \type {semitight}, \type {decent}, \type {semiloose}, and \type {loose}.
After some trial and error I got to the examples on the next two pages. You need
to zoom in to see the differences (the black one is the original). In setting used are:

\starttabulate[|c|c|l|]
\BC   \BC \type {\hsize} \BC \type {\setupalign}       \NC \NR
\NC 1 \NC 12em           \NC normal, stretch, tolerant \NC \NR
\NC 2 \NC 18em           \NC flushleft                 \NC \NR
\stoptabulate

As mentioned, one can look at specific expected properties and draw conclusions
but when \TEX\ cannot find a good solution using its default, it is unlikely that
alternative settings help you out, unless you do that on a per|-|paragraph basis.

% run in default font and layout

\startbuffer[lbc]
\def\TestA#1#2#3%
  {\switchtobodyfont[10pt]%
   \ruledvtop
     {\hsize#1\relax
      \begingroup
      \setupalign[#2]%
      \linebreakcriterium"#3\relax
      \samplefile{tufte}\par
      \endgroup
      \hpack to \hsize{\hss\infofont\setstrut\strut\black\string\linebreakcriterium="#3\hss}}}

\def\TestB#1#2%
  {\startTEXpage[offset=4dk]
     \hbox \bgroup
         {\black  \TestA{#1}{#2}{00000000}}\kern1ex
         {\red    \TestA{#1}{#2}{00001C00}}\kern1ex
         {\green  \TestA{#1}{#2}{00002C00}}\kern1ex
         {\blue   \TestA{#1}{#2}{00003C00}}\kern1ex
         {\cyan   \TestA{#1}{#2}{00004C00}}\kern1ex
         {\magenta\TestA{#1}{#2}{00005C00}}
     \egroup
     \vskip1ex
     \hbox \bgroup
         \startoverlay {\TestA{#1}{#2}{00000000}}                                    \stopoverlay \kern1ex
         \startoverlay {\TestA{#1}{#2}{00000000}} {\red    \TestA{#1}{#2}{00001C00}} \stopoverlay \kern1ex
         \startoverlay {\TestA{#1}{#2}{00000000}} {\green  \TestA{#1}{#2}{00002C00}} \stopoverlay \kern1ex
         \startoverlay {\TestA{#1}{#2}{00000000}} {\blue   \TestA{#1}{#2}{00003C00}} \stopoverlay \kern1ex
         \startoverlay {\TestA{#1}{#2}{00000000}} {\cyan   \TestA{#1}{#2}{00004C00}} \stopoverlay \kern1ex
         \startoverlay {\TestA{#1}{#2}{00000000}} {\magenta\TestA{#1}{#2}{00005C00}} \stopoverlay
    \egroup
   \stopTEXpage}

\TestB{12em}{normal,stretch,tolerant}
\TestB{18em}{flushleft}
\stopbuffer

\startpagemakeup[pagestate=start,doublesided=no,page=no]
    \centerbox {\typesetbuffer[lbc][page=1,frame=on,height=\dimexpr\textwidth-2ex\relax,orientation=90]}
\stoppagemakeup
\startpagemakeup[pagestate=start,doublesided=no,page=no]
    \centerbox {\typesetbuffer[lbc][page=2,frame=on,width=\dimexpr\textheight-2ex\relax,orientation=90]}
\stoppagemakeup

\stopchapter

\stopcomponent