Debian Codegraph @

texmf-dist/doc/hitex/base/hitexman.tex

raw
1 % This file is part of HINT
2 % Copyright 2017-2025 Martin Ruckert, Hochschule Muenchen, Lothstrasse 64, 80336 Muenchen
3 %
4 % Permission is hereby granted, free of charge, to any person obtaining a copy
5 % of this software and associated documentation files (the "Software"), to deal
6 % in the Software without restriction, including without limitation the rights
7 % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 % copies of the Software, and to permit persons to whom the Software is
9 % furnished to do so, subject to the following conditions:
10 %
11 % The above copyright notice and this permission notice shall be
12 % included in all copies or substantial portions of the Software.
13 %
14 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 % COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 % WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
19 % OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 % THE SOFTWARE.
21 %
22 % Except as contained in this notice, the name of the copyright holders shall
23 % not be used in advertising or otherwise to promote the sale, use or other
24 % dealings in this Software without prior written authorization from the
25 % copyright holders.
26
27 \input cwebmac
28 \input btxmac.tex
29 \input hintmac.tex
30
31 \hyphenation{HINT-ver-sion}
32 \hyphenation{HINT-mi-nor-ver-sion}
33 \hyphenation{HINT-image}
34 \hyphenation{HINT-global-color}
35 \hyphenation{HINT-color}
36 \hyphenation{HINT-end-color}
37 \hyphenation{HINT-start-link}
38 \hyphenation{HINT-end-link}
39 \hyphenation{HINT-global-link-color}
40 \hyphenation{HINT-link-color}
41 \hyphenation{HINT-dest}
42 \hyphenation{HINT-out-line}
43 \hyphenation{HINT-set-page}
44 \hyphenation{HINT-stream}
45 \hyphenation{HINT-set-stream}
46 \hyphenation{HINT-before}
47 \hyphenation{HINT-after}
48
49
50 \makeindex
51
52 \maketoc
53
54
55 \titletrue
56
57 \null
58
59 %fonts
60 %\font\largetitlefont=cmssbx10 scaled\magstep4
61 %\font\largetitlefont=lmsans10-bold.otf scaled\magstep4
62 %\font\smalltitlefont=cmssbx10 scaled\magstep3
63 %\font\smalltitlefont=lmsans10-bold.otf scaled\magstep3
64 %\font\tenrm=lmroman10-regular.otf
65 %\font\tenit=lmroman10-italic.otf
66 %\font\tenbf=lmroman10-bold.otf
67 %\font\tt=lmmono10-regular.otf
68 %\font\figrm=cmr9 scaled\magstep0
69 %\font\figrm=lmroman9-regular.otf
70 %\font\largebf=cmbx12 scaled\magstep1
71 %\font\largebf=lmroman12-bold.otf scaled\magstep1
72
73
74 \font\utf={[/usr/share/fonts/truetype/dejavu/DejaVuSansMono]} at 9pt
75
76
77 \hbox{}
78 \vskip 0pt plus 1fill
79 {
80 \baselineskip=1cm\parindent=0pt
81 \largetitlefont\raggedright Hi\TeX\par
82 \vskip 10pt plus 0.1fill
83 \leftline{\smalltitlefont User Manual}
84 \vskip-3pt
85 \vskip 10pt plus 0.5fill
86 \hskip 0pt plus 2fill {\it F\"ur Beatriz}\hskip 0pt plus 0.5fill\hbox{}
87 \vskip 10pt plus 3fill
88 \leftline{\smalltitlefont Version 1.1 (Draft)}
89 \bigskip
90 \raggedright\baselineskip=12pt
91 {\bf MARTIN RUCKERT}\ {\it Munich University of Applied Sciences}\par
92 \bigskip
93 }
94 \eject
95
96 \titletrue
97
98 \begingroup
99 \figrm
100 \parindent=0pt
101
102 {\raggedright\advance\rightskip 3.5pc
103 The author has taken care in the preparation of this document,
104 but makes no expressed or implied warranty of any kind and assumes no
105 responsibility for errors or omissions. No liability is assumed for
106 incidental or consequential damages in connection with or arising out
107 of the use of the information or programs contained herein.
108 \bigskip
109 {\def\:{\discretionary{}{}{}}
110 Internet page {\tt http:\://hint.\:userweb.\:mwn.\:de/\:hint/hitex.html}
111 may contain current information, downloadable software,
112 and news.}
113
114 \vfill
115 Copyright $\copyright$ 2022 by Martin Ruckert
116 \smallskip
117 All rights reserved.
118 \smallskip
119 This publication is protected by copyright, and permission must be
120 obtained prior to any prohibited reproduction, storage in
121 a~retrieval system, or transmission in any form or by any means, electronic,
122 mechanical, photocopying, recording, or likewise.
123 To obtain permission to use material from this work, please submit a written
124 request to Martin Ruckert,
125 Hochschule M\"unchen,
126 Fakult\"at f\"ur Informatik und Mathematik,
127 Lothstrasse 64,
128 80335 M\"unchen,
129 Germany.
130 \medskip
131 {\tt ruckert\:@cs.hm.edu}
132 \medskip
133 Last commit: Sun Feb 1 14:57:55 2026
134 \par
135 }
136 \eject
137 \endgroup
138 \rm
139
140 \frontmatter
141 \pageno=3%
142
143
144 \tableofcontent
145
146 \mainmatter
147 \parindent 2em\parskip 3pt plus 3pt
148
149
150 %\def\rs{\penalty100\hskip 2pt plus 3pt minus 2pt\penalty100\relax}
151 %\def\rs{\kern 2pt}
152 \def\rule#1:#2.{\par{\parskip 0pt\hangindent32pt\hangafter1\parindent0pt\rightskip 0pt plus 60pt#1 $\longrightarrow$ %
153 \hskip 0pt plus 60pt\penalty-300\hskip 0pt plus -60pt#2\par}}
154 \def\prim#1.{\par{\hangindent32pt\hangafter1\parindent0pt\rightskip 0pt plus 60pt#1\par}}
155 \def\sym#1{$\langle\hbox{\it #1\/}\rangle$}
156 \def\OR{${\,}\vert{\,}$}
157 \def\opt#1{$\left[\right.$#1$\left.\right]$}
158 \def\ctl#1{{\tt\BS #1}}
159
160 \section{Introduction}
161 When I started the \HINT\ project in 2017,
162 I tried to keep the project as small as possible to increase the
163 chances that I would be able to complete it. So one design decision
164 was to keep things simple---or to quote an aphorism attributed to
165 Albert Einstein: ``Make things as simple as possible, but not simpler''.
166 The other imperative was:
167 keep things out of the viewer if possible because I do not know
168 how much processing power or battery power is available.
169
170 As a consequence, I focused on Donald Knuth' original \TeX,
171 disregarding all later developments like \eTeX\ or \LaTeX, and I
172 decided that the \TeX\ interpreter would not need to run in the
173 viewer.
174 Of course \TeX's line breaking routine will run in the viewer
175 and modifications of \TeX's page breaking routine.
176 But the decision to keep the \TeX\ interpreter
177 out of the \HINT\ viewer implies that \HINT\ files do
178 not contain token lists and that there are
179 neither output routines nor marks.
180 To replace them, the \HINT\ file format includes
181 page templates. I have described the technical
182 means to specify page templates below and try to explain
183 the rationale behind it, but \HINT's page templates
184 are at the time of this writing a largely untested area.
185
186 By now, the state of the \HINT\ project is far beyond of what
187 I had expected then, and the processing power of even low-cost
188 mobile devices is far better than expected especially when programming the
189 graphics card directly using OpenEGL.
190
191 The following sections will describe all the primitive control sequences
192 that are special for Hi\TeX. I tried to be as close to similar primitives
193 that have proven to be useful in other engines, notably pdf\TeX, to make
194 it easy for package writers to support the Hi\TeX\ engine.
195
196 While currently Hi\TeX\ is the only \TeX\ engine that supports output in the \HINT\ file
197 format, this might not be so forever. To avoid unnecessary complications for
198 package writers, it is strongly suggested that all such \TeX\ engines implement
199 the same primitives according to the same specification. The following is the first
200 draft of this specification. All the primitives use {\tt HINT} as a prefix to
201 avoid name conflicts. The prefix {\tt HINT}, as opposed to e.g. {\tt HiTeX},
202 was chosen to stress the idea that these primitives are specific for the
203 output format---not for the \TeX\ engine.
204
205 It is common practice in other \TeX\ engines to support the \ctl{special}
206 primitive to insert raw code snippets in the output. Using this primitive,
207 it is possible to insert PostScript code into a PS file, or PDF code in a
208 PDF output file. It is currently not planed to support this mechanism for
209 \HINT\ output files for two reasons:
210 First, the development of Hi\TeX\ is closely related to the development of
211 the \HINT\ file format and therefore features that are part of the \HINT\
212 file format will enjoy support in Hi\TeX\ by corresponding primitives.
213 Everything that is not available through primitives in Hi\TeX\ should
214 be considered ``internal'' and might change in the future.
215 Second, Hi\TeX\ is not considered a replacement for but
216 a supplement to other engines. If your aim is the production of a printed
217 book, your will target one of the engines that produce PDF output.
218 But if, on occasion, you want to read what you wrote on a computer screen,
219 you might just use Hi\TeX\ to process your source file. At this point you
220 do not want to write \ctl{special} commands for the new target; you want
221 Hi\TeX\ as a plug-in replacement for your main target engine, even if it
222 is not completely faithful to your final printed book.
223
224 \section{Hi\TeX\ primitives}
225
226 Because this is the first specification that will reach a wider user base,
227 it is reasonable to expect changes to occur in the future. Therefore it is
228 recommended that these primitives should not be used directly in a
229 \TeX\ document; instead they should be encapsulated in suitable
230 macros so that the consequences of any change to the primitives will
231 be local to these macros.
232
233 \subsection{Syntax Description}
234 In the following, we describe the syntax of primitive control sequences which were
235 added to \TeX.
236
237 \itemize
238 \item We use a {\tt typewriter font}\index{typewriter font}
239 for text that occurs \index{verbatim}verbatim in the \TeX\ document.
240 \item We use \sym{italics} enclosed in pointed brackets to denote symbols\index{symbol+\sym{symbol}}.
241 \item We use rules\index{rule} to define the meaning of symbols.
242 A rule starts with the symbol
243 to be explained, followed by a colon ``{\bf :}'', and then the text that this symbol
244 stands for. A rule ends with a period ``{\bf .}''.
245 \item Optional\index{optional+\opt{optional}} parts of the rule's text
246 are enclosed in \opt{square brackets}.
247 \item Alternatives\index{alternative} are separated by a vertical bar ``\OR''\index{\OR}.
248 \item Some symbols refer to text that is defined as part of standard \TeX. These are explained here by an example:
249
250 \medskip
251 \rule\sym{integer}:
252 an integer as in \ctl{penalty}\sym{integer}.\index{integer+\sym{integer}}
253 \rule\sym{number}:
254 a general number as in \ctl{kern}\sym{number}\.{pt}.\index{number+\sym{number}}
255 \rule\sym{normal\ dimension}:
256 a dimension as in \ctl{hrule} \.{width} \sym{normal\ dimension}.\index{normal dimension+\sym{normal\ dimension}}
257 \rule\sym{dimension}:
258 a dimension as in \ctl{vskip} \.{0pt} \.{plus} \sym{dimension}.\index{dimension+\sym{dimension}}
259 \rule\sym{name}:
260 a name as in \ctl{input} \sym{name}.\index{name+\sym{name}}
261 \rule\sym{vertical\ list}:
262 a token list with matching braces as in
263 \ctl{vbox}\.{\{}\sym{vertical\ list}\.{\}}.\index{vertical list+\sym{vertical\ list}}
264 \rule\sym{horizontal list}:
265 a token list with matching braces as in
266 \ctl{hbox}\.{\{}\sym{horizontal\ list}\.{\}}.\index{horizontal list+\sym{horizontal\ list}}
267 \rule\sym{general text}:
268 a token list with matching braces as in
269 \ctl{write}\.{\{}\sym{general\ text}\.{\}}.\index{general text+\sym{general\ text}}
270 \medskip
271 \enditemize
272
273 \subsection{Version and Revision}
274 The control sequences \ctl{HINTversion}\index{HINTversion+\ctl{HINTversion}}
275 and \ctl{HINTminorversion}\index{HINTminorversion+\ctl{HINTminorversion}} are
276 used to determine the major and minor version numbers of the \HINT\ output format
277 that is generated by Hi\TeX. It can be used as part of the output as
278 in \verbatim|\the\HINTversion|.
279 The most important use, however, is testing whether the current \TeX\ engine
280 will in fact produce \HINT\ output.
281 As an example the file {\tt ifhint.tex}\index{ifhint.tex+{\tt ifhint.tex}}
282 contains the following code:
283
284
285 \verbatim/
286 \newif\ifhint
287 \expandafter
288 \ifx\csname HINTversion\endcsname\relax
289 \hintfalse\else\hinttrue\fi/
290
291
292 \subsection{UTF8 Input}
293 Starting with \HiTeX\ version 2.0, published with \TeX\ Live 2026,
294 the one and only input encoding supported by \HiTeX\ is \UTF8.
295 While other input encodings may be supported by loading special
296 packages, it is recomended not to use such packages but instead
297 use one of the commonly available tools, like {\tt iconv} or {\tt Notepad++}
298 to convert the input files before processing them with \HiTeX.
299
300 On the technical level, \HiTeX\ converts any (multibyte) \UTF8 codepoint from an input file
301 into a single character token with a character value in the range 0 to \.{"10FFFF}.
302 On output, a character token with a value within the ASCII range 0 to \.{"7F}
303 is conveted using the ``classic'' output routines of \TeX\ that attempt to
304 present even non-printable characters in a readable form,
305 while a character token with a value greater than \.{"7F} is converted to
306 its multibyte \UTF8 encoding.
307
308 Following the example of \LuaTeX\ and \XeTeX, a number of primitives were
309 extended and others were added to cope with the larger range of character codes.
310 The syntax and semantics of these primitives are described in the following.
311
312 \subsubsection{Working with character codes}
313 A character code in \HiTeX\ is no longer
314 an \sym{\hbox{8-bit}\ number} but an \sym{utf\ character\ code}:
315 \medskip
316 \rule\sym{utf\ character\ code}:
317 a \sym{number} in the range \.{0} to \.{"10FFFF}. \index{utf character code+\sym{utf\ character\ code}}
318 \medskip
319
320 Some traditional primitives are simply extended to handle these larger
321 character codes. To get access to any character whatsoever, you can type
322 \ctl{char}\sym{utf\ character\ code}. Similarly, you can write
323 \ctl{chardef}\sym{control sequence}\.{=}\sym{utf\ character\ code}.
324
325 New are the primitives \ctl{Uchar} and \ctl{Ucharcat} as defined by the
326 \XeTeX\ manual. \ctl{Uchar}\sym{utf\ character\ code} expands to a
327 character token with the specified \sym{utf\ character\ code} with
328 category code 12. While it looks superficially like the \TeX\ primitive
329 \ctl{char}, \ctl{Uchar} is an expandable operation.
330 \ctl{Ucharcat}\sym{utf\ character\ code} \sym{catcode} expands to a
331 character token with the specified \sym{utf\ character\ code}
332 and the given \sym{catcode}. The values allowed
333 for \sym{catcode} are: 1--4, 6--8 and 10--13.
334
335 With a small exception, \ctl{if}, \ctl{ifcat}, and \ctl{ifx}
336 work for unicode characters exactly as described in the \TeX\ book:
337 If the argument of \ctl{if} is a control sequence,
338 \TeX\ considers it to have category code 16
339 and character code 256 which is 1 bigger than \TeX's largest character code;
340 \HiTeX\ will consider it to have category code 16 as well, but the
341 character code will be \.{"110000} which is 1 bigger than the largest
342 unicode character code.
343
344 \HiTeX\ makes it possible to use any unicode character as an active character or
345 define a single character control sequence using such a character.
346
347 \TeX\ keeps multibyte character control sequences in a hash table and
348 single byte control sequences in a separate table with 256 entries.
349 Since the range of single byte UTF8 codes is only 0 to \.{"7F},
350 \HiTeX\ needs only a smaller table with 127 entries for these controll sequences.
351 Characters outside this range are coded with multiple bytes and go
352 into \TeX's hash table. The same schema is used for active characters.
353 It is, however, necessary to use a separate hash table for characters
354 that have a multibyte UTF8 coding, because, the control sequence associated
355 with an active character is not the same thing as the single character
356 control sequence for the same character.
357
358 \TeX\ allows the use of the {\tt `} (left quote) character as a prefix to
359 any character to specify its numeric value. For example {\tt\ctl{count}1=98}
360 is equivalent to {\tt\ctl{count}1=`b}. \HiTeX\ allows this for all unicode characters.
361 For example {\tt\ctl{count}1=8491} is equivalent to {\tt\ctl{count}1=`}{\utf Å}
362 using the Angstr\"om symbol.
363
364
365
366
367 \subsubsection{Setting and retrieving character information}
368 To typeset characters correctly, \TeX\ relies on a number of properties
369 associated with a character: its
370 \ctl{catcode}, \ctl{sfcode}, \ctl{uccode}, \ctl{lccode},
371 %\ctl{Umathcode}, \ctl{Umathcodenum},
372 \ctl{mathcode}, and \ctl{delcode}.
373
374 While \TeX\ traditionaly stores this information in arrays indexed
375 by the character code, this approach is no longer appropriate if
376 character codes span a range from 0 to 1114111 as is the case for
377 \UTF\ coded characters. For this reason, \HiTeX\ uses a compressed
378 tree representation that is compact (about 40kByte) and allows very fast access.
379 Modifying the data stored this way is less convenient and will run out of
380 table space if more than a few dozend character codes need to be changed.
381 Since traditionaly character data is changed only for
382 code vales less than 256, \HiTeX\ assumes that most changes of
383 \ctl{catcode}, \ctl{sfcode},
384 \ctl{mathcode}, % family, class, slot
385 and \ctl{delcode} occur in this range and keeps this data in \TeX's
386 traditional arrays where changes will not affect the compressed tables.
387
388 It is to bee seen if this approach will work in practice or
389 some other data structure will deliver similar performance while
390 allowing large scale across the whole range of unicode characters.
391
392 Because the compression is a complicated operation, it is not done at run time,
393 but a separate program computes the compressed tables which are loaded into
394 the \HiTeX\ engine at compiletime. Therefore \HiTeX\ is different from other
395 unicode \TeX\ engines: With \HiTeX, it is not a good idea
396 to load the unicode character data at runtime. The loading would destroy the
397 compression and would sooner or later produce and overflow error.
398 Instead the character data is already part of the \HiTeX\ engine when it starts
399 with exactly the same values it would and should have after the runtime initialization.
400
401 Now let's consider the details.
402
403 \subsubsection{\ctl{catcode} and \ctl{sfcode}}
404 These primitives work pretty much as usual, except that their argument
405 is no longer an \sym{\hbox{8-bit}\ number} but \sym{utf\ character\ code}:
406
407 The values---category codes are in the range from 1 to 15 and
408 space factor codes are in the range from 0 to 32767---can be retrieved like this:
409 \medskip
410 \rule\sym{internal\ integer}:
411 \ctl{catcode}\sym{utf\ character\ code}.
412 \rule\sym{internal\ integer}:
413 \ctl{sfcode}\sym{utf\ character\ code}.
414 \medskip
415 Setting new values is equaly simple. The assigned \sym{number} must be in the
416 propper range.
417 \medskip
418 \rule\sym{code\ assignment}:
419 \ctl{catcode}\sym{utf\ character\ code} \opt{\.{=}} \sym{number}.
420 \rule\sym{code\ assignment}:
421 \ctl{sfcode}\sym{utf\ character\ code} \opt{\.{=}} \sym{number}.
422 \medskip
423
424 \subsubsection{\ctl{uccode} and \ctl{lccode}}
425 These primitives are again extended to work with the full range of unicode
426 characters. It is expected that the assignment of new lower case or upper case
427 values is relatively rare. Sometimes it is used in certain coding tricks.
428 So \TeX's traditional tables are not retained and all information is stored
429 in the new compressed format. Take this into accound before attempting to
430 large scale rearangements of these assignments. Information about ``title case''
431 is currently not implemented.
432 \medskip
433 \rule\sym{internal\ integer}:
434 \ctl{lccode}\sym{utf\ character\ code}.
435 \rule\sym{internal\ integer}:
436 \ctl{uccode}\sym{utf\ character\ code}.
437 \rule\sym{code\ assignment}:
438 \ctl{lccode}\sym{utf\ character\ code} \opt{\.{=}} \sym{utf\ character\ code}.
439 \rule\sym{code\ assignment}:
440 \ctl{uccode}\sym{utf\ character\ code} \opt{\.{=}} \sym{utf\ character\ code}.
441 \medskip
442
443
444 \subsubsection{\ctl{mathcode}, \ctl{delcode} and friends}
445 Before diving deeper into this section, there is a confession due:
446 using \HiTeX\ with unicode fonts in math mode is a largely untested area.
447 But the basics are implemented in the \HiTeX\ engine.
448
449 Making the \ctl{mathcode} primitive work nicely with unicode values
450 requires some extra work because \TeX\ packs three different values,
451 the class, the family, and the character code into one integer.
452 In hexadecimal notation a mathcode contains four hexadecimal digits:
453 the leading hex-digit specifies the class,
454 the next hex-digit specifies the familiy and the lowest two digits
455 a one byte character code.
456 \medskip
457 \rule\sym{class}: \sym{hexdigit}.
458 \rule\sym{family}: \sym{hexdigit}.
459 \rule\sym{byte}: \sym{hexdigit}\sym{hexdigit}.
460 \rule\sym{math\ code}:\sym{class}\sym{familiy}\sym{byte}.
461 \medskip
462 It is not strictly necessary to give the number in hexadecimal;
463 it is possible to convert the hexadecimal number into a decimal
464 number and write it down in decimal; or in any other format that
465 \TeX\ provides for the representation of numbers.
466
467 To be compatible with existing \TeX\ code this format is retained when
468 using \ctl{mathcode}, only the argument of \ctl{mathcode} now can be
469 any unicode character.
470 \medskip
471 \rule\sym{math\ code}:
472 \ctl{mathcode}\sym{utf\ character\ code}.
473 \rule\sym{code\ assignment}:
474 \ctl{mathcode}\sym{utf\ character\ code} \opt{\.{=}} \sym{math\ code}.
475 \medskip
476 So you can say \ctl{mathcode}\.{96} as well as \ctl{mathcode}\.{9600}
477 and in both cases, you will get a math code in the range 0 to \.{"FFFF}.
478 If however the class stored for the character in question is not
479 in the range 0 to \.{"F}, or the family is not in the range \.{"F},
480 or the character code does not fit into one byte, \ctl{mathcode} will
481 return zero. You can also use \ctl{mathcode}\.{9600} to give a new math code
482 value to the unicode character 9600, but the new value is limited to a
483 one byte character code.
484 Note also that you can continue to use the special math code value \.{"8000}
485 to make an ``active'' math character.
486
487
488 To set or retrieve math codes with arbitrary unicode characters,
489 \HiTeX\ follows the example of \LuaTeX\ and \XeTeX\ and
490 packs a 3-bit class number, a 8-bit family number and a 21-bit unicode character
491 into a 32-bit value: the 8 most siginficant bits contain the family, the
492 next 3 bits contain the class, and the 21 least significant bits contain
493 the unicode character.
494 \medskip
495 \rule\sym{Uclass}: \sym{\hbox{3-bit}}.
496 \rule\sym{Ufamily}: \sym{\hbox{8-bit}}.
497 \rule\sym{Ucode}: \sym{\hbox{21-bit}}.
498 \rule\sym{Umath\ code}:\sym{Ufamily}\sym{Uclass}\sym{Ucode}.
499 \medskip
500
501 Because the three values are not nicely aligned
502 on the four bit boundaries of an hexadecimal notation
503 two new primitives \ctl{Umathcode} and \ctl{Umathcodenum} are provided.
504 \ctl{Umathcodenum} is a simple extension of \ctl{mathcode}. It returns
505 a single number in the bit-packed format as just described and when
506 a new value is set it must already be in the correct bit-packed format.
507 \medskip
508 \rule\sym{Umath\ code}:
509 \ctl{Umathcodenum}\sym{utf\ character\ code}.
510 \rule\sym{code\ assignment}:
511 \ctl{Umathcodenum}\sym{utf\ character\ code} \opt{\.{=}} \sym{Umath\ code}.
512 \medskip
513 \ctl{Umathcode} is a little easier to use because it does not require
514 the user to do the bit packing. Instead a new math code can be set by
515 giving three separate numbers: one for the class, one for the family and
516 one for the character code.
517 \medskip
518 \rule\sym{class\ number}: a \sym{number} in the range 0 to 7.
519 \rule\sym{family\ number}: a \sym{number} in the range 0 to 255.
520 \rule\sym{Umath\ code}:
521 \ctl{Umathcode}\sym{utf\ character\ code}.
522 \rule\sym{code\ assignment}:
523 \ctl{Umathcode}\sym{utf\ character\ code} \opt{\.{=}}
524 \sym{class\ number} \sym{family\ number} \sym{utf\ character\ code}.
525 \medskip
526
527 \HiTeX's \ctl{delcode} primitive offers no surprise. For any unicode
528 character, you can use \ctl{delcode} to set or retrieve its delimiter code.
529 The traditional delimiter code is in the range -1 to \.{"FFFFFF}.
530
531 \medskip
532 \rule\sym{internal\ integer}: \ctl{delcode}\sym{utf\ character\ code}.
533 \rule\sym{code\ assignment}:
534 \ctl{delcode}\sym{utf\ character\ code} \opt{\.{=}} \sym{number}.
535 \medskip
536
537 The primitives \ctl{Udelcode} and \ctl{Udelcodenum}, as known from \XeTeX\ or
538 \LuaTeX, are not yet implemented.
539
540 \subsection{OpenType fonts}
541 When \TeX\ was invented, digital fonts, especially fonts suitable to typeset
542 mathematics, were a scarce commodity. But \TeX\ came with a companion, \MF, to
543 create digital fonts. These fonts had their own glyph encoding
544 and their own file format for glyphs (\.{.pk} files)
545 and for font metrics (\.{.tfm} files).
546 Soon after that, the American Mathematical Society commissioned
547 a collection of \TeX\ font files in the PostScript Type 1 format, which allowed
548 the creation of PostScript (and much later \PDF) output files with \TeX.
549 The PostScript Type 1 fonts largely replaced the original \.{.pk} files.
550 A replacement for the font metric files was not necessary and so the \.{.tfm} files
551 are still in use today.
552
553 In the meantime, the number of high quality, freely available, digital fonts has
554 exploded. And ``high quality'' is no longer equivalent to ``PostScript Type 1''.
555 Today, the most popular file format for fonts is the OpenType format, an extension
556 of the slightly simpler TrueType format. So it seems natural to extend the
557 capabilities of \TeX\ to work with these types of font files.
558 OpenType font files not only contain the glyphs, but they also contain the
559 necessary font metrics. So an OpenType font file can replace both the \.{.pk} file
560 and the \.{.tfm} file.
561
562 To define fonts, \HiTeX\ extents the syntax and semantics of \TeX's \ctl{font}
563 primitive. It tries to be simple and as much as possible compatible with
564 the implementation of the \ctl{font} primitive in \LuaTeX\ and \XeTeX.
565
566 The syntax is:
567 \medskip
568 \rule\sym{font\ assignment}: \ctl{font}\sym{control\ sequence} \opt{\.{=}}
569 \sym{input\ file} \opt{\sym{at\ clause}}.
570 \rule\sym{input\ file}: \.{"}\sym{font\ specifier}\.{"}.
571 \rule\sym{input\ file}: \.{\{}\sym{font\ specifier}\.{\}}.
572 \rule\sym{input\ file}: \sym{font\ specifier}.
573 \rule\sym{font\ specifier}: \sym{pathname}.
574 \rule\sym{at\ clause}: \.{at} \sym{dimen} \OR\ \.{scaled} \sym{number}.
575 \medskip
576 The \sym{at\ clause} to adjust the font size is described in the \TeX\ book
577 and has not changed.
578
579 In modern \TeX\ engines, an \sym{input\ file} can be more than just a sequence of characters
580 terminated by a space token or a \ctl{relax}.
581 If the name of the \sym{input\ file} contains spaces, it is possible to enclose it
582 in \.{"} (double quote) characters. In fact, if a file name contains
583 double quote characters they switch quoting alternatingly on and off and are
584 otherwise ignored as parts of the file name. Inside the quoted parts, space characters
585 are part of the file name; the first space character outside of a quoted part
586 terminates the file name.
587 A more convenient way to define an arbitrary \sym{input\ file} is enclosing it
588 in curly braces \.{\{}\dots\.{\}}.
589 In this case the general text inside the braces---with spaces, special symbols,
590 expanded macros, and all double quotes removed---is considered the \sym{input\ file}.
591
592 After \HiTeX\ has done all this preprocessing of the \sym{input\ file},
593 the result is a \sym{font\ specifier}
594 Before we look at the more complex forms of a \sym{font\ specifier}
595 we look at the simple case of a \sym{pathname}.
596 In this case, \HiTeX\ passes it to the \.{kpathsearch} library to find a matching \.{.tfm} file.
597 If the \.{.tfm} file is found, \HiTeX\ will assume that
598 the font is one of the traditional \TeX\ fonts, using \TeX's traditional encoding.
599 Later, \HiTeX\ will then use again the \.{kpathsearch} library to
600 find and open the matching PostScript Type 1 font and if that is not possible
601 a matching \.{.pk} file. Thats all.
602
603 If the \.{kpathsearch} library can not find a suitable \.{.tfm} file,
604 \HiTeX\ assumes that an OpenType or TrueType file should be loaded.
605 In this case, a \sym{font\ specifier} is not just simply the name of a file,
606 but it has a very sophisticated syntax---mostly due to the attempt to be
607 compatibel with existing implementations.
608
609 \medskip
610 \rule\sym{font\ specifier}: \sym{font\ file\ name} \opt{\.{:} \sym{font\ features}}.
611 \rule\sym{font\ file\ name}: \.{file:}\sym{pathname} \opt{\sym{font\ selector}}.
612 \rule\sym{font\ file\ name}: \.{[}\sym{pathname}\.{]}\opt{\sym{font\ selector}}.
613 \rule\sym{font\ selector}: \.{(}\sym{number}\.{)}.
614 \rule\sym{font\ specifier}: \.{name:}\sym{font\ name} \opt{\.{:} \sym{font\ features}}.
615 \smallskip
616 $\bullet$ Note that the use of \sym{font\ features} is currently not yet implemented.
617 Any \sym{font\ features} given will be silently ignored.
618
619 $\bullet$ Note that font lookup using the \.{name:} prefix to indicate the use
620 of ``font names'' as opposed to ``file names'' is currently not yet implemented.
621 Currently only file name lookup is implemented.
622
623 $\bullet$ Note that a \sym{font\ selector} must be an index number.
624 Using the PostScript name to select a font is not yet implemented.
625
626 $\bullet$ Note that \HiTeX\ in an attempt to maintain compatibility with other engines
627 will not give up on a font specifier that neither leads to a matching \.{.tfm} file
628 nor has a \.{file:} or \.{name:} prefix and is not bracketed either.
629 Instead \HiTeX\ will issue a warning and tries to resolve the problem.
630 First, it tries to assume that the \.{file} prefix is missing, and if
631 that does not help, it tries to assume that the \.{name:} prefix is missing.
632 Only if none of this leads to a usable font file, \HiTeX\ succumbs.
633
634 \medskip
635
636 The extended font specifiers used for OpenType fonts
637 assign special meaning to the colon ``\.{:}'', the slash ``\.{/}'',
638 and the opening parenthesis ``\.{(}''.
639 If these characters occur in the \sym{pathname} of a font file, it is possible to use
640 a bracketed notation of the \sym{pathname} as a alternative to using the \.{file:} prefix.
641 If the pathname is enclosed in square brackets, it may
642 contain any character except the closing square bracket; otherwise it must not contain
643 the colon ``\.{:}'', the slash ``\.{/}'', nor the opening parenthesis ``\.{(}''.
644 Since the colon can be necessary after a drive letter in Windows and the slash serves as
645 a directory separator in Linux, the bracketed verions is quite common. The paraenthesis
646 is excluded from the unbracketed version because is start the optional \sym{font\ selector}.
647
648 Once \HiTeX\ has determined the \sym{pathname}, it uses the \.{kpathsearch} library to
649 find a matching OpenType font and if this does not succeed, it tries to find a matching
650 TrueType font. Once the file is found, the Harfbuzz library is used to open the font file.
651
652 $\bullet$ Note that it is possible to open PostScript Type 1 font files without a \.{.tfm} file
653 using Harfbuzz. The use of Type 1 fonts with Harfbuzz, however,
654 requires the use of \.{.afm} files, and this does not work well and is deprecated.
655 Therefore \HiTeX\ does not support it.
656 For Type 1 fonts, one should use \.{afm2tfm} to convert the \.{.afm} files to \.{tfm}
657 files and put the new \.{tfm} files in a place where the \.{kpathsearch} library
658 can find them. Then run \.{mktexls}.
659
660 \subsubsection{Embedding subsets of fonts}
661
662
663
664 \subsection{Images}
665 The primitive \ctl{HINTimage}\index{HINTimage+\ctl{HINTimage}}
666 includes an image\index{image} in a document.
667 The syntax is as follows:
668
669 \medskip
670 \prim\ctl{HINTimage} \opt{\.{=}} \sym{name}
671 \opt{\sym{width}} \opt{\sym{height}}.
672 \medskip
673
674 The optional equal sign can be added to make the code look nicer.
675 The \sym{name} specifies the image file.
676 The width specification determines the width of the image. If omitted,
677 Hi\TeX\ tries to determine the image's width from the image file.
678 The same holds for the height specification.
679
680 \medskip
681 \rule \sym{width}:\.{width} \sym{normal\ dimension}.\index{width+\sym{width}}
682 \rule \sym{height}:\.{height} \sym{normal\ dimension}.\index{height+\sym{height}}
683 \medskip
684
685 Note that a \sym{normal\ dimension} that is computed from \ctl{hsize}
686 or \ctl{vsize} retains this dependency when processed by Hi\TeX.
687 This allows an image to adapt to the size of the viewing area.
688 Scaling in the \HINT\ viewer will, however, never change the
689 aspect ratio of an image. So it may become smaller or larger,
690 but it will never be distorted.
691 For this reason, Hi\TeX\ will inspect the image file to determine the
692 aspect ratio\index{aspect ratio} of the stored image.
693 The width and height values as given in the \TeX\ file serve
694 as the maximum values for the actual width and height. When rendering,
695 the image will become as large as possible within the given bounds.
696 If \TeX\ does not specify neither width nor height, the image file
697 must specify the absolute width and height of the image.
698 It is considered an error if valid settings for the image's width and height
699 can not be obtained.
700
701 \subsection{Colors}
702 Since the \HINT\ file format is designed for on-screen viewing,
703 the only color model supported is the RGBA model, where a color is
704 specified by four values: the red, the green, the blue, and the alpha
705 value. The first three determine the light intensity of the red,
706 green, and blue component of a pixel; the alpha value determines
707 the relative share of a color when displaying
708 one color on top of another color.
709 Because in practice most display devices use one byte for
710 each of the four values that define a color, the \HINT file
711 format stores the four color
712 components using integer values in the range 0 to 255.
713 Independent of the input format, Hi\TeX\ will convert all
714 colors to this format when storing them in the output file.
715
716 \subsubsection{Foreground Color}
717 The most common color specification is the specification of a
718 foreground color. (We will consider background colors below.)
719 A foreground color can be specified using
720 the following syntax:
721
722 \medskip
723 \rule\sym{foreground}:
724 \.{FG\{} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
725 \index{foreground+\sym{foreground}}
726 \medskip
727
728 Note that for convenience, the alpha value
729 is optional; if no alpha value is given, the value 255 will be used
730 and the color is completely opaque.
731
732 Here are some examples:
733 \.{FG\{255 0 0\}}, \.{FG\{255 0 0 255\}},
734 both specify the same plain opaque red;
735 \.{FG\{0 0 255\}} is plain blue;
736 \.{FG\{255 255 0 127\}} is a transparent yellow.
737 Because each value fits in a single byte, the values are often given in
738 hexadecimal notation. In \TeX, hexadecimal values are written with
739 a \.{"}~prefix. The same colors as before are then written
740 \.{FG\{"FF 0 0\}}, \.{FG\{"FF 0 0 "FF\}},
741 \.{FG\{0 0 "FF\}} and \.{FG\{"FF "FF 0 "7F\}}.
742 Values greater than 255 or less than 0 are not allowed.
743
744 A common alternative to the color representation just described
745 is the device independent notation where each
746 value is a real number in the interval from 0 to 1.
747 To keep both representations apart, the device independent
748 representation (with the smaller numbers) uses the lowercase
749 keyword \.{fg} instead of \.{FG}. Here is the syntax:
750
751 \medskip
752 \index{foreground+\sym{foreground}}
753 \rule\sym{foreground}:
754 \.{fg\{} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
755 \medskip
756
757 Using the new syntax, the colors above are written
758 \.{fg\{1 0 0\}}, \.{fg\{1 0 0 1\}},
759 \.{fg\{0 0 1\}} and \.{fg\{1 1 0 0.5\}}.
760 Values greater than 1 and less than 0 are not allowed.
761 Note that \.{fg\{1 1 1\}} is pure white while \.{FG\{1 1 1\}} is
762 the darkest possible gray, which on most devices is indistinguishable
763 from pure black.
764
765 When specifying colors for computer screen, using red, green, and blue
766 components is natural. For printing on paper, the specification using
767 cyan, magenta, yellow, and black is the default.
768 Since collections of named colors using the latter format
769 are common, Hi\TeX\ allows the use of this format by prefixing the numbers with
770 the keyword \.{cmyk}. Specifying the keyword \.{rgb} is also possible and has the
771 same effect as giving no keyword. Using the new syntax the transparent yellow
772 can be written \.{fg\{cmyk 0 0 1 0 0.5\}}, \.{FG\{cmyk 0 0 "FF 0 "7F\}},
773 \.{fg\{rgb 1 1 0 0.5\}}, or \.{FG\{rgb "FF "FF 0 "7F\}}.
774
775 The additional syntax rules are:
776
777 \medskip
778 \index{foreground+\sym{foreground}}
779 \rule\sym{foreground}:
780 \.{fg\{ rgb \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \}}.
781 \rule\sym{foreground}:
782 \.{fg\{ cmyk \sym{number} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \}}.
783 \rule\sym{foreground}:
784 \.{FG\{ rgb \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \}}.
785 \rule\sym{foreground}:
786 \.{FG\{ cmyk \sym{integer} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \}}.
787 \medskip
788
789 \subsubsection{Defining and Using Colors}
790 As we will see, colors come in whole sets of colors.
791 To define such a set of colors, Hi\TeX\ provides
792 the primitive \ctl{HINTcolor}. Its syntax is
793 \medskip
794 \prim\ctl{HINTcolor} \.{\{} \sym{color\ specification} \.{\}}.
795 \medskip
796 Before we give the complete definition of a \sym{color\ specification},
797 we start with some examples.
798 In its simplest form this primitive just specifies a single color.
799 For example \ctl{HINTcolor}\.{\{fg\{0 0 0\}\}} specifies
800 the foreground color black which is then used for rules and glyphs.
801 In addition to the foreground color, you can specify a background color.
802 For example, black text on white background is specified by
803 \ctl{HINTcolor}\.{\{fg\{0 0 0\}} \.{bg\{1 1 1\}\}} or
804 \ctl{HINTcolor}\.{\{fg\{0 0 0\}} \.{BG\{"FF "FF "FF\}\}}.
805
806 The viewer for \HINT\ files may provide a ``dark'' mode, and as a document
807 author, you can specify the colors also for dark mode.
808 If you like white letters on dark blue background you can write
809 \ctl{HINTcolor}\.{\{fg\{0 0 0\}} \.{bg\{1 1 1\}}
810 \.{dark} \.{fg\{1 1 1\}} \.{bg\{0 0 0.3\}\}}.
811
812 There are two more colors that an author might care about: When searching
813 for a text, all occurrences of the search phrase are highlighted by
814 using a different color. And while the user iterates over the occurrences
815 on the page, one occurrence has the ``focus'' and is rendered again in a
816 different color. You can specify the highlight color right after
817 the normal text color and the focus color right after the highlight color.
818 The same can be done for the colors in ``dark'' mode.
819
820 Here are the remaining rules that complete the \sym{color\ specification}:
821
822 \medskip
823 \index{color\ specification+\sym{color\ specification}}
824 \rule\sym{color\ specification}: \sym{color\ set} \opt{\.{dark} \sym{color\ set}}.
825 \index{color set+\sym{color\ set}}
826 \rule\sym{color set}:
827 \sym{color} \opt{\sym{color} \opt{\sym{color}}}.
828 \index{color+\sym{color}}
829 \rule\sym{color}:
830 \sym{foreground} \opt{\sym{background}}.
831 \index{background+\sym{background}}
832 \rule\sym{background}:
833 \.{FG\{ \opt{\.{rgb}} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \}}.
834 \rule\sym{background}:
835 \.{fg\{ \opt{\.{rgb}} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \}}.
836 \rule\sym{background}:
837 \.{FG\{ cmyk \sym{integer} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \}}.
838 \rule\sym{background}:
839 \.{fg\{ cmyk \sym{number} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \}}.
840 \medskip
841 If some of the optional parts in the \sym{color\ specification} are missing,
842 the corresponding colors from the set of default colors, as described below,
843 are used.
844
845 Note that the background colors for highlighted text and focus text
846 can be given, but current viewers ignore these background specifications.
847 Further note that the current specification of the \HINT\ file format
848 limits the total number of different color specifications in a document to 255.
849
850
851 The colors given in \ctl{HINTcolor} will have an immediate effect
852 on all following rules and glyphs and the background of the enclosing box.
853 The effect will persist until the next change of colors or until
854 the end of the box---whatever occurs first.
855
856 The line breaking algorithm of Hi\TeX\
857 tracks changes in color within a paragraph and reinsert an appropriate
858 color change at the start of every \ctl{hbox} that contains a new line.
859 In this way local color changes inside a paragraph can span multiple lines
860 but do not affect the inter line glue or material that is inserted with
861 \ctl{vadjust}. Similarly, spliting off the initial part of a vertical
862 box with \ctl{vsplit} will insert a color node in the remaining part
863 if necessary to keep the color consistent accross the split.
864
865 Special care is needed if background colors are used.
866 Unless the background color is completely transparent
867 with an alpha value equal to zero,
868 the background color will fill a vertical box from left to right
869 and a horizontal box from top to bottom. Since height, depth, and width of
870 boxes often depend on the text that is inside, which in turn
871 might depend on the outcome of line breaking, it is strongly recommended
872 to use background colors with caution, and use \ctl{strut}s to enforce
873 a fixed height and depth of horizontal boxes.
874
875
876 \subsubsection{Default Colors}
877 The \HINT\ file format specifies default values for all colors.
878 Hi\TeX\ provides the primitive \ctl{HINTdefaultcolor} to overwrite these
879 default colors. This primitive must not be used after defining any custom
880 colors using \ctl{HINTcolor}. Its syntax is
881 \medskip
882 \prim\ctl{HINTdefaultcolor} \.{\{} \sym{color\ specification} \.{\}}.
883 \medskip
884 The \HINT\ format specifies the following default colors:
885 Normal text is black \.{FG\{0 0 0\}},
886 highlight text is a slightly dark red \.{FG\{"EE 0 0\}},
887 and focus text is slighty dark green \.{FG\{0 "EE 0\}}.
888 The background is transparent white \.{BG\{"FF "FF "FF 0\}}.
889 In dark mode the background is transparent black \.{BG\{0 0 0 0\}},
890 normal text is white \.{FG\{"FF "FF "FF\}},
891 and a slightly lighter red \.{FG\{"FF "11 "11\}},
892 and green \.{FG\{"11 "FF "11\}}, are used for highlighted and focus text.
893
894 \subsubsection{Nesting Colors}
895 A color change is limited to the enclosing box. Hence the
896 nesting of boxes leads to a nesting of color definitions.
897 So for example a transparent background color in the inner box
898 will not completely replace the background color of the enclosing
899 box but will only modify this color like seeing it through colored glas.
900
901 A color change ends not only at the end of the enclosing box,
902 it will also end at the next use of the \ctl{HINTcolor}
903 or \ctl{HINTendcolor} primitive:
904 The \ctl{HINTcolor} primitive will replace the current colors by
905 a new set of colors; the \ctl{HINTendcolor} primitive will resume
906 the color specification that was valid just before the matching use
907 of \ctl{HINTcolor}. Hi\TeX\ maintains a color stack tracking
908 local color changes within a box or paragraph, and uses it to
909 insert appropriate color changes so that the \ctl{HINTendcolor} primitive
910 will simply cancel the color change by the matching \ctl{HINTcolor} primitive.
911 If there is no matching \ctl{HINTcolor} primitive,
912 the \ctl{HINTendcolor} primitive is silently ignored.
913 Note that within a single box, there is at any point only a single
914 background color: The color stack will switch from one background
915 color to an other background color but will not overlay an ``inner''
916 background color over an ``outer'' background color.
917 This is only the case when multiple boxes are nested as described above.
918
919 Here is an example:
920 Suppose we want the \TeX\ logo to be rendered in light red,
921 and notes in dark green. You can write
922 \medskip
923 {\tt\parindent 0pt\rightskip=0pt plus 160pt
924 \verbatim/\def\redTeX{\HINTcolor{fg{1 0.3 0.3}}\TeX\HINTendcolor}
925 \def\beginnote{\HINTcolor{fg{0 0.5 0}}}% dark green
926 \def\endnote{\HINTendcolor}/
927 \medskip
928 This is an example showing the \ctl{redTeX}\BS\ logo in red color.
929 \ctl{beginnote}\ Note how the \ctl{redTeX}\BS\ logo is still red inside
930 this note.\ctl{endnote}\par}
931 \medskip
932
933 After the first occurrence of the red \TeX\ logo, the color will be switched
934 back to normal black, while after the second occurrence the color will
935 be switched back to dark green. The color switching will work as intended
936 even if the paragraph is spread over several lines by the line breaking routine.
937
938 \subsubsection{Colors for Pages}
939 When a page get rendered in the \HINT\ file viewer,
940 the renderer starts with the default colors and the page is initially
941 cleared using the default background color. If a different page
942 color is desired, color changes can be added to the page templates.
943
944 In a vertical box, the color stack of Hi\TeX\ has a similar effect as in
945 a horizontal box. Similar to the precautions in the line breaking routine,
946 Hi\TeX\ will insert color changes when splitting a vertical box with \ctl{vsplit}.
947 Complications arise from color changes in the top level vertical list
948 which is split into pages in the \HINT\ viewer at runtime.
949 Because the page builder in the viewer has no global information and
950 should not need global information, Hi\TeX\ will insert copies of the
951 local color information after every possible breakpoint in the top
952 level vertical list. This will ensure that page breaks will not
953 affect the colors of the displayed material.
954 Note, however, that \TeX\ considers glue (and kerns) as discardable
955 and will remove these items from the top of a new page. Because glues and kerns
956 are colored using the current background color, these items might be visible
957 on a page but disappear when they follow immediately after a page break.
958 So if you want the effect of a colored glue or kern that is not affected by
959 a page break, you should include it inside a box or use a colored rule instead.
960
961 \subsubsection{Colors for Links}
962 The most common change in color is caused by the use of links.
963 To support this changing of colors, the primitives
964 \ctl{HINTstartlink}\index{HINTstartlink+\ctl{HINTstartlink}}
965 and \ctl{HINTendlink}\index{HINTendlink+\ctl{HINTendlink}}
966 (see section~\secref{llo})
967 cause an automatic change of the color specification.
968 A document author can set the default colors used for links
969 with the primitive \ctl{HINTdefaultlinkcolor} and change
970 the current link color with the primitive \ctl{HINTlinkcolor}.
971 The syntax is:
972 \medskip
973 \prim\ctl{HINTdefaultlinkcolor} \.{\{} \sym{color\ specification} \.{\}}.
974 \prim\ctl{HINTlinkcolor} \.{\{} \sym{color\ specification} \.{\}}.
975 \medskip
976
977 For convenience, the \HINT\ file format specifies default colors
978 for links as well: links use dark blue \.{FG\{0 0 "EE\}} and in dark mode
979 light blue \.{FG\{"11 "11 "FF\}}.
980 The primitive \ctl{HINTdefaultlinkcolor} is used
981 to partly or completely redefine these defaults.
982
983 Later uses of \ctl{HINTlinkcolor} will set new current link colors.
984 Colors that are missing in the new link color specification are taken
985 from the corresponding default colors for links.
986
987 Whenever the \ctl{HINTstartlink} primitive is used, its effect on the
988 colors is equivalent to the \ctl{HINTcolor} primitive using the current
989 link color. This implies that the color change caused by \ctl{HINTstartlink}
990 is local to the enclosing box.
991
992 Whenever the \ctl{HINTendlink} primitive is used, it will restore
993 the color stack of Hi\TeX\ to its state before the matching \ctl{HINTstartlink}.
994 It is the responsibility of the \TeX\ source code (or package) to keep the
995 sequence of \ctl{HINTstartlink}, \ctl{HINTendlink},
996 \ctl{HINTcolor}, and \ctl{HINTendcolor} properly nested.
997 A sequence like ``\ctl{HINTstartlink} \dots\ \ctl{HINTcolor}
998 \dots\ \ctl{HINTendlink} \dots\ \ctl{HINTendcolor}'' is possible,
999 but it will cause \ctl{HINTendlink} to restore the colors to those
1000 in effect before the \ctl{HINTstartlink}.
1001 The following \ctl{HINTendcolor} will then either restore
1002 a color of a matching \ctl{HINTcolor} preceeding
1003 the link in the same box or it will restore the
1004 color in the outer box, or it will be ignored.
1005 In effect, the color changes inside a link stay local to the link.
1006
1007 \subsubsection{\LaTeX\ Support}
1008 Starting with \TeX\ Live 2025, there is a limited support for the \.{xcolor}
1009 package.
1010
1011 After \ctl{usepackage}\.{\{xcolor\}} you can use the predefined standard colors;
1012 for example \ctl{color}\.{\{red\}}.
1013 If you add one (or several) of the named color
1014 options \.{x11names}, \.{svgnames}, or \.{dvipsnames} to the package,
1015 you can also use commands like
1016 \ctl{color}\.{\{Tomato4\}} (x11),
1017 \ctl{color}\.{\{BlanchedAlmond\}} (svg), or
1018 \ctl{color}\.{\{Plum\}} (dvips).
1019
1020
1021 To define your own colors you can use for example
1022
1023 \ctl{definecolor}\.{\{mypink1\}\{rgb\}\{0.858, 0.188, 0.478\}},
1024
1025 \ctl{definecolor}\.{\{mypink2\}\{RGB\}\{219, "30, 122\}},
1026
1027 \ctl{definecolor}\.{\{mypink3\}\{cmyk\}\{0, 0.7808, 0.4429, 0.1412\}}, or
1028
1029 \ctl{definecolor}\.{\{mygray\}\{gray\}\{0.2\}}.
1030
1031 The mixing of colors is supported as well. For example a
1032 mixture of 40\% green and 60\% yellow look is produced by
1033 \ctl{color}\.{\{green!40!yellow\}}.
1034
1035 The colors for links and other references can be given as options
1036 to the \.{hyperref} package. For example as in
1037
1038 \ctl{usepackage}\.{[linkcolor=green,urlcolor=red]\{hyperref\}}
1039
1040 \subsubsection{Differences between \LaTeX\ and Hi\LaTeX}
1041
1042 \noindent{\bf Colors and Groups}\par\smallskip\noindent
1043 In \LaTeX, colors are local to the group. So by writing
1044 ``\.{text 1} \.{\{}\ctl{color}\.{\{blue\}} \.{text 2} \.{\}} \.{text 3}''
1045 after \.{text~1} the color of \.{text~2} will change to blue and after \.{\}}
1046 marking the end of the group, the color of \.{text~3} will revert to the
1047 color of \.{text~1}. Hi\LaTeX\ emulates this behaviour by inserting
1048 \ctl{HINTendcolor} at the end of the group.
1049
1050 When it comes to paragraphs,
1051 the scoping rules of colors in Hi\LaTeX\ are however slightly
1052 different from the \LaTeX\ scoping rules.
1053 In \TeX\ and \LaTeX, boxes and references all have there own group,
1054 but this is not true for paragraphs.
1055 So \TeX\ or \LaTeX\ will allow you to start a new group in one paragraph and
1056 end the group in the next paragraph, while it is not possible to start a
1057 group in one box and end the group in another box. As a consequence,
1058 you can switch to blue text color in the middle of a paragraph and end the blue
1059 color in the middle of the next paragraph.
1060 In Hi\TeX, on the other hand, when it comes to colors,
1061 paragraphs behave pretty much like boxes: The effect of a color change inside
1062 a paragraph will not extend past the end of the paragraph. The closing of the
1063 group in the next paragraph will then have no effect.
1064
1065 \bigskip\noindent{\bf Colors in vertical Lists}\par\smallskip\noindent
1066 The \HINT\ file format allows color specifications in horizontal boxes
1067 and---unlike the \PDF\ file format---in vertical boxes as well.
1068 Together with the mode switching of \TeX, which goes into horizontal mode
1069 when it sees the beginning of a paragraph and back into vertical mode at
1070 the end of the paragraph, this can cause unexpected color effects.
1071
1072 There is for example a big difference between
1073
1074 \medskip
1075 \verbatim/\color{blue}
1076 The first paragraph ...
1077
1078 The second paragraph ...
1079 /
1080 \medskip
1081 and
1082 \medskip
1083 \verbatim/\indent
1084 \color{blue}
1085 The first paragraph ...
1086
1087 The second paragraph ...
1088 /
1089 \medskip
1090
1091 In the first case, the color change is part of the vertical list
1092 and the letter ``\.T'' starts the paragraph.
1093 As a consequence, the color change is still in effect when the second
1094 paragraph starts.
1095 In the second case, the \ctl{indent} command puts \TeX\ into horizontal mode
1096 and the color change becomes part of the first paragraph.
1097 As a consequence, the color change will end with the first paragraph, as explained
1098 in the previous section.
1099
1100 Even more surprising is this:
1101 \medskip
1102 \verbatim/{\color{blue} Blue} The first paragraph ...
1103
1104 The second paragraph ...
1105 /
1106 \medskip
1107
1108
1109 \TeX\ finds the begining of the group \.{\{} and the color change in vertical mode
1110 and it puts the color change into the vertical list. Then it finds the letter
1111 ``\.B'' and starts the paragraph. When \TeX\ encounters the end of the group,
1112 there is no local color change {\it inside} the paragraph and the text
1113 continues to be blue. Even the second paragraph and all following paragraphs
1114 will continue in blue until the end of the vertical list.
1115
1116 The confusion that such behaviour might create has its root in \TeX's
1117 mode switching which is not synchronized with \TeX's grouping.
1118 While grouping is typically visible in the source text, the mode
1119 switching remains largely invisible.
1120
1121
1122 \bigskip\noindent{\bf Future Changes}\par\smallskip\noindent
1123 While it may be questionable whether all the color changes shown above
1124 makes sense, it is definitely undesirable if Hi\LaTeX\ and \LaTeX\
1125 behave differently.
1126 As a consequence, Hi\LaTeX\ might very well change in this respect in a
1127 later version, so that Hi\TeX\ will no longer treat the begining
1128 and ending of paragraphs as the beginning and ending of a group.
1129 It is an open question how Hi\TeX\ should handle the end of a group
1130 in the middle of a paragraph ending a color change that started in
1131 the enclosing vertical list. Currently a \ctl{HINTendcolor} at that
1132 position would be silently ignored because it can only undo local
1133 changes {\it inside} the paragraph. Should Hi\TeX\ instead change the color
1134 of the enclosing vertical box immediately? What does
1135 it mean to do this change immediately? At the baseline?
1136 Before the next interline glue? What are the implications for the
1137 rendering engine? How complicated can it be to look ahead
1138 for color changes that occur depply nested inside a vertical list?
1139 Would it not be better to demand the use of \ctl{vadjust} for such an effect?
1140 Should Hi\TeX\ postpone the color change in the enclosing vertical
1141 box until the end of the paragraph?
1142
1143 \bigskip\noindent{\bf Default Colors}\par\smallskip\noindent
1144 Because complete color specifications are pretty long. It is important
1145 to provide usefull defaults. Currently missing elements of a color specification
1146 are taken from a single default color specification. It might be convenient
1147 to be able to provide a way to define color specifications using the
1148 current color as a basis for missing elements.
1149
1150 \bigskip\noindent{\bf Color Numbers}\par\smallskip\noindent
1151 The \HINT\ file format references a color set by a number in the range
1152 0 to 254.
1153 So Hi\TeX\ assigns each color specification a number, using the same
1154 number for two identical color specifications.
1155 One extension to the above specification of Hi\TeX's color primitives
1156 could be to make these numbers accessible to document authors or
1157 package programmers. For example \ctl{the}\ctl{HINTcolor} could
1158 expand to the number $n$ of the current color set and
1159 \ctl{HINTcolor}$n$ would be equivalent to a use of \ctl{HINTcolor}
1160 with a full color specification that is equivalent to the color specification
1161 belonging to $n$.
1162 This would be quite efficient; it would not be necessary
1163 to scan the color specification and search the existing color specifications
1164 for the matching specification with number $n$.
1165
1166 The \LaTeX\ named colors are stored as macros, which has the advantage that
1167 loading a whole package of color names does not use any of Hi\TeX's
1168 color numbers. Only colors that actually get used (probably only a few)
1169 will get a color number. This works well in practice.
1170 So currently, there are no plans to implement this extension.
1171
1172 \subsection{Links, Labels, and Outlines}\label{llo}
1173 A link\index{link} in a \HINT\ document refers to another location in the same document.
1174 It can be used to navigate to that location.
1175 A link is defined using the primitives
1176 \ctl{HINTstartlink}\index{HINTstartlink+\ctl{HINTstartlink}}
1177 and \ctl{HINTendlink}\index{HINTendlink+\ctl{HINTendlink}}.
1178 Neither of them can be used in vertical mode.
1179 The text between the start and the end of the link
1180 constitutes the visible part of the link. Depending on the user interface, clicking
1181 or tapping or otherwise activating the link (e.g. pronouncing)
1182 will navigate to the destination of the link.
1183 The user interface might provide a visual clue to make the user aware of the
1184 available links for example using a special cursor when hovering over a link.
1185 But it also may choose to leave the visual clues completely to the author
1186 of the document (e.g. using a special colors, images, or fonts).
1187
1188 The syntax is
1189 \ctl{HINTstartlink} \sym{destination}
1190 and
1191 \ctl{HINTendlink}
1192 with
1193
1194 \medskip
1195 \index{destination+\sym{destination}}
1196 \rule \sym{destination}:\.{goto} \sym{label}.
1197 \index{label+\sym{label}}
1198 \rule \sym{label}:
1199 \.{name} \.{\{}\sym{general\ text}\.{\}} \OR\ \.{num} \sym{integer}.
1200 \medskip
1201
1202 As you can see, the link refers to its destination using a label
1203 which is either a name or a number.
1204 The destination can be defined by using the
1205 \ctl{HINTdest}\index{HINTdest+\ctl{HINTdest}} primitive.
1206 Forward and backward links are allowed; the definition of a label can either
1207 precede or follow the use of the label. If at the end of the document a label
1208 is undefined, a warning is given, and the label will reference the beginning of the
1209 document.
1210
1211 The syntax is
1212 \medskip
1213 \prim\ctl{HINTdest} \sym{label} \opt{\sym{placement}}.
1214 \medskip
1215 with
1216 \medskip
1217 \index{placement+\sym{placement}}\index{top+{\tt top}}\index{bot+{\tt bot}}
1218 \rule\sym{placement}:
1219 \.{top} \OR\ \.{bot}.
1220 \medskip
1221
1222 The optional placement argument specifies how to build the page
1223 containing the destination location. \.{top} demands
1224 a page starting with the destination location. This is useful
1225 if the destination is for example the start of a section or chapter heading.
1226 Similarly \.{bot} asks for a page that ends with the destination location.
1227 The most common case is to omit the placement argument. In this case, the
1228 viewer will build a ``good'' page that includes the given destination.
1229 In case of a section heading, for example, it will most probably start the
1230 page with the section heading because section headings are usually preceded
1231 by a negative penalty that will convince the page builder that this is a good
1232 place to break the page. But if the section heading is immediately preceded
1233 by a chapter heading, the negative penalty found there will probably
1234 persuade the page builder to start with the chapter heading instead.
1235
1236 There is a special label that has the form
1237 \.{name} \.{\{}\.{HINT.home}\.{\}}\index{HINT.home+{\tt HINT.home}}.
1238 It is used to mark the ``home page''\index{home page} of the document. User interfaces
1239 are encouraged to offer a button or keyboard shortcut to navigate to the
1240 document location labeled this way. The page should be a convenient
1241 starting point to explore the document. The typical place for this label
1242 would be the documents table of content.
1243
1244 The labels that identify destinations in a document can also be used
1245 to define document outlines. A document outline\index{outline} is a document summary
1246 given as a hierarchical list of headings where each of them
1247 refers to a specific location in the document.
1248
1249 The syntax is
1250 \medskip
1251 \prim\ctl{HINToutline}\index{HINToutline+\ctl{HINToutline}}
1252 \sym{destination} \opt{\sym{depth}} \.{\{}\sym{horizontal\ list}\.{\}}.
1253 \medskip
1254 \index{depth+\sym{depth}}
1255 \rule \sym{depth}: \.{depth} \sym{integer}.
1256 \medskip
1257
1258 The user interface can format the \sym{horizontal\ list} much like
1259 a \ctl{hbox} would do and display it to the user. When the user selects
1260 this text, the document will be repositioned to show the destination location
1261 in the same way as with a link. In order to support also simpler
1262 user interfaces, the current \HINT\ backend also extracts the characters
1263 (and spaces) from the horizontal list (in top-left to bottom-right order)
1264 and makes this character string available to the user interface.
1265
1266
1267 The order in which outline items are defined is important because
1268 this is the order in which they will be presented to the reader of the
1269 document. The optional depth argument allows to structure
1270 the list of outline items as a hierarchy. Outline items with a higher depth value are considered to be sub-items of items earlier in the list with lower
1271 depth values. If no depth value is given, the depth value is set to zero.
1272 It is not necessary to define depth values strictly consecutive.
1273
1274
1275 \subsection{Page Templates and Streams}\index{page template}\index{stream}
1276
1277 To produce the final page, \TeX\ uses a special piece of program
1278 called the output routine\index{output routine}. Because a \HINT\
1279 file is pure data, it can not contain output routines. Instead it
1280 uses page templates to assemble pages from the main text, footnotes,
1281 floating illustrations, and other material. I start here by
1282 describing how \HINT's page templates work and the special syntax used
1283 to specify them in a \TeX\ file that is about to be processed with
1284 Hi\TeX. For those interested in how the design decision was made and
1285 how page templates relate to \TeX's page building mechanism, a
1286 separate section follows at the end.
1287
1288 The syntax of a page template specification is:
1289 \medskip
1290 \prim\ctl{HINTsetpage}\index{HINTsetpage+\ctl{HINTsetpage}}
1291 \sym{integer} \opt{\.{=}} \sym{name}
1292 \opt{\sym{priority}} \opt{\sym{width}} \opt{\sym{height}}
1293 \.{\{}\sym{vertical\ list} \sym{stream\ definition list}\.{\}}.
1294 \medskip
1295
1296 The \sym{integer} specifies the page templates number in the range 1
1297 to 255. The number 0 is reserved for the build in page template of
1298 the \HINT\ file format, which is used if no other page template has
1299 been defined. The page template 0 can not be redefined.
1300 The \sym{name} associates a name with the page template. The name can
1301 be displayed by the \HINT\ viewer to help the user selecting a
1302 suitable page template.
1303
1304 After the name follows an optional priority; it is used to select the
1305 ``best page template'' if multiple templates are available. The
1306 default value is~1. The build-in template has priority~0.
1307
1308 \medskip
1309 \index{priority+\sym{priority}}
1310 \rule\sym{priority}: {\tt priority} \sym{integer}.
1311 \medskip
1312
1313
1314 After that follows an optional width and height of the full page
1315 including the margins. After subtracting \ctl{hsize} from the width
1316 and \ctl{vsize} from the height, the remainder is used for the margins
1317 around the displayed text. For example giving the width as
1318 1.2\ctl{hsize} will leave 0.1\ctl{hsize} for the margins on both sides.
1319 In this case the margins will grow together with the available width
1320 of the display. If the width is computed by adding 20pt
1321 to \ctl{hsize}, the margin will be 10pt on both sides. In this case
1322 the margin will not grow with the size of the display, but it will
1323 grow with the magnification factor. Of course both methods can be
1324 used together. The default is \ctl{hsize} for the width and \ctl{vsize}
1325 for the height so there are no margins.
1326
1327 The following \sym{vertical\ list} defines the page itself. It should assign suitable values
1328 to \ctl{topskip} and \ctl{maxdepth} because the values valid at the end of the vertical list
1329 are stored in the page template and are used in the page building process.
1330 The vertical list usually also specifies the insertion of content streams
1331 using a \sym{stream\ insert point}.
1332
1333 \medskip
1334 \index{stream insert point+\sym{stream\ insert\ point}}
1335 \rule\sym{stream\ insert\ point}:
1336 \ctl{HINTstream} \sym{integer}.
1337 \medskip
1338
1339 Here the \sym{integer} must be in the range 0 to 254. The value 255 is invalid;
1340 the value 0 indicates the main body of text (what \TeX's page builder would normally put into
1341 box 255 before calling the output routine).
1342 Otherwise, the \sym{integer} is \TeX's insertion number, that is the number of \TeX's box
1343 containing the insertions. As usual, this box is filled using \TeX's \ctl{insert} primitive.
1344 So after plain \TeX\ has defined \ctl{footins},
1345 the footnotes for the current page can be inserted after the main body of text in the \sym{vertical\ list}
1346 by saying \ctl{HINTstream}\.0 followed by \ctl{HINTstream}\ctl{footins}.
1347 Of course you might want to have a footnote rule and a small skip to separate the
1348 footnotes ---if there are any---from the main text. This can be achieved by a suitable
1349 \sym{stream\ definition} in the \sym{stream\ definition\ list}.
1350
1351 \medskip
1352 \index{stream definition list+\sym{stream\ definition\ list}}
1353 \rule\sym{stream\ definition\ list}:
1354 \OR\ \sym{stream\ definition\ list} \sym{stream\ definition}.
1355 \index{stream definition+\sym{stream\ definition}}
1356 \rule\sym{stream\ definition}:
1357 \ctl{HINTsetstream} \sym{integer} \opt{\.{=}}
1358 \opt{{\tt preferred} \sym{integer}}
1359 \opt{\.{next} \sym{integer}}
1360 \opt{\.{ratio} \sym{integer}} \.{\{}\sym{vertical\ list}\.{\}}.
1361 \medskip
1362
1363
1364 The first \sym{integer} is the streams insertion number $i$,
1365 and it must match the \sym{integer}
1366 previously used in the \sym{stream\ insert\ point}.
1367 Then follows the optional specification of a preferred stream with insertion number $p$,
1368 a next stream with insertion number $n$, and a split ratio $r$.
1369 If $r>0$, the contributions to stream $i$ are split between
1370 stream $p$ and $n$ in the ratio $r/1000$ for $p$ and $1-r/1000$ for $n$
1371 before contributing streams $p$ and $r$ to the page.
1372 Else if $p\ge0$ any insertion to stream $i$ is moved to stream $p$ as long as possible,
1373 and if $n\ge0$ we move an insert to stream $n$ if there is ``no room left'' in $p$ nor in $i$.
1374 How much ``room'' is available for the insertions is specified inside the vertical list
1375 that follows.
1376 Here \ctl{dimen}$i$ should be set to the maximum total height of the insertions in class $i$ per page.
1377 \ctl{count}$i$ should be set to the magnification factor $f$,
1378 such that inserting a box of height $h$ will contribute $h*f/1000$ to the main page;
1379 and \ctl{skip}$i$ should be set to the extra space needed if an insertion in class $i$ is present.
1380
1381 This extra space is usually taken up by material that is inserted before and after the insertions,
1382 such as for example the footnote rule. This material can be defined by a
1383 \sym{before\ list} and an \sym{after\ list}.
1384
1385 \medskip\index{HINTbefore+\ctl{HINTbefore}}\index{HINTafter+\ctl{HINTafter}}
1386 \index{before list+\sym{before\ list}}
1387 \rule \sym{before\ list}:
1388 \ctl{HINTbefore} \opt{\.{=}} \.{\{}\sym{vertical\ list}\.{\}}.
1389 \index{after list+\sym{after\ list}}
1390 \rule \sym{after\ list}:
1391 \ctl{HINTafter} \opt{\.{=}} \.{\{}\sym{vertical\ list}\.{\}}.
1392 \medskip
1393
1394 If you are interested in the design decision that motivate the definitions that have
1395 be given in this section, you should read section~\secref{build}.
1396
1397 \section{Other Primitives}
1398
1399 Since I consider the support for \LaTeX\ to be crucial for
1400 the success of the \HINT\ project, quite a few primitives
1401 have been added to Hi\TeX\ that go beyond \TeX's original
1402 specification.
1403
1404 \subsection{\eTeX}
1405 First, the primitives of \eTeX\ have been
1406 added with the exception of those primitives that deal with
1407 line breaking, with right to left reading, and with marks.
1408 Here is a list of \eTeX\ primitives that are missing in Hi\TeX:
1409 \itemize
1410 \item\ctl{TeXXeTstate} (current reading direction)
1411 \item\ctl{beginL}, \ctl{endL} (switching reading direction)
1412 \item\ctl{beginR}, \ctl{endR} (switching reading direction)
1413 \item\ctl{predisplaydirection} (reading direction)
1414 \item\ctl{lastlinefit} (line breaking)
1415 \item\ctl{marks} (multiple marks)
1416 \item\ctl{botmarks}, \ctl{splitbotmarks} (multiple marks)
1417 \item\ctl{firstmarks}, \ctl{splitfirstmarks} (multiple marks)
1418 \item\ctl{topmarks} (multiple marks)
1419 \enditemize
1420
1421 \subsection{\LaTeX\ and \Prote}
1422 Second, the primitives required to support
1423 \LaTeX\ were added using Thierry Larondes implementation of \Prote.
1424
1425 \itemize
1426 \item\ctl{Proteversion}, \ctl{Proterevision} (version information)
1427 \item\ctl{resettimer}, \ctl{elapsedtime} (timing information)
1428 \item\ctl{creationdate}, \ctl{filemoddate}, \ctl{filesize},
1429 \ctl{filedump}, \ctl{mdfivesum} (file information)
1430 \item\ctl{shellescape} (Currently only a dummy implementation.)
1431 \item\ctl{setrandomseed}, \ctl{randomseed},
1432 \ctl{normaldeviate}, \ctl{uniformdeviate} (random numbers)
1433 \item\ctl{expanddepth}, \ctl{expanded} (programming)
1434 \item\ctl{ifincsname}, \ctl{ifprimitive} \ctl{primitive} (programming)
1435 \item\ctl{savepos}, \ctl{lastxpos}, \ctl{lastypos}, \ctl{pageheight},
1436 \ctl{pagewidth} (Only dummy implementations since this information
1437 is not available to Hi\TeX\ at runtime.)
1438 \item\ctl{strcmp} (comparing strings)
1439 \enditemize
1440
1441
1442 \subsection{{\tt kpathsearch} and \ctl{input}}
1443 In Don Knuth's implementation of \TeX, the \ctl{input} primitive
1444 will add the extension {\tt .tex} to any filename that does not have an
1445 extension. This implies that a file without extension cannot be opened
1446 as an input file. The usual engines do not add such an extension but
1447 pass the filename as given to \verbatim/kpse_find_file/ function.
1448 Hi\TeX\ does the same. The {\tt kpathsearch} library will find files
1449 in a variety of directories and yes, it will also find files without
1450 extension. Using this library, or equivalent functionality, is just about
1451 mandatory for any engine that wants to process \LaTeX\ input.
1452
1453
1454 \section{Replacing \TeX's Page Builder}\label{build}
1455
1456 \TeX\ uses an output\index{output routine} routine to finalize the page.
1457 The output outline takes the material which the page builder had accumulated in {\tt box255}
1458 and attaches headers, footers, and floating material
1459 like figures, tables, and footnotes. The latter material is specified by insert nodes
1460 while headers and footers are often constructed using mark nodes.
1461 Running an output routine requires the full power of the \TeX\ engine and is not
1462 part of the \HINT\ viewer. Therefore, \HINT\ replaces output routines by page templates\index{template}.
1463 \TeX\ can use different output routines for different parts of a book---for example
1464 the index might use a different output routine than the main body of text.
1465
1466 \TeX\ uses insertions to describe floating content that is not necessarily displayed
1467 where it is specified. Three examples may illustrate this:
1468 \itemize
1469 \item Footnotes\footnote*{Like this one.} are specified in the middle of the text but are displayed at the
1470 bottom of the page. Several
1471 footnotes\index{footnote} on the same page are collected and displayed together. The
1472 page layout may specify a short rule to separate footnotes from the
1473 main text, and if there are many short footnotes, it may use two columns
1474 to display them. In extreme cases, the page layout may demand a long
1475 footnote to be split and continued on the next page.
1476
1477 \item Illustrations\index{illustration} may be displayed exactly where specified if there is enough
1478 room on the page, but may move to the top of the page, the bottom of the page,
1479 the top of next page, or a separate page at the end of the chapter.
1480
1481 \item Margin notes\index{margin note} are displayed in the margin on the same page starting at the top
1482 of the margin.
1483 \enditemize
1484
1485 \HINT\ uses page templates and content streams to achieve similar effects.
1486 But before I describe the page building\index{page building} mechanisms of \HINT,
1487 let me summarize \TeX's page builder.
1488
1489 \subsection{\TeX's page building mechanism}
1490 \TeX's page builder ignores leading glue\index{glue}, kern\index{kern},
1491 and penalty\index{penalty} nodes until the first
1492 box\index{box node} or rule\index{rule node} node is encountered;
1493 whatsit\index{whatsit node} nodes do not really contribute
1494 anything\footnote*{This changes when images are implemented as whatsit nodes.} to
1495 a page; mark\index{mark node} nodes are recorded for later use. Once
1496 the first box, rule, or insert\index{insert node} arrives, \TeX\ makes
1497 copies of all parameters that influence the page building process and
1498 uses these copies. These parameters are the \.{page\_goal} and the
1499 \.{page\_max\_depth}. Further, the variables {\tt page\_total}, {\tt page\_shrink},
1500 {\tt page\_stretch}, {\tt page\_depth}, and {\tt in\-sert\_pe\-nal\-ties} are
1501 initialized to zero. The top skip\index{top skip} adjustment is made
1502 when the first box or rule arrives---possibly after an insert.
1503 Now the page builder accumulates material: normal material goes
1504 into {\tt box255}\index{box 255} and will change {\tt page\_total}, {\tt page\_shrink},
1505 {\tt page\_stretch}, and {\tt page\_depth}. The latter is adjusted so that
1506 is does not exceed {\tt page\_max\_depth}.
1507
1508 The handling of inserts\index{insert node} is more complex.
1509 \TeX\ creates an insert class using {\tt newinsert}. This reserves a number $i$
1510 and four registers: {\tt box\hair$i$} for the inserted material,
1511 {\tt count\hair$i$} for the magnification factor $f$, {\tt dimen\hair$i$}
1512 for the maximum size per page $d$, and {\tt skip\hair$i$} for the
1513 extra space needed on a page if there are any insertions of class $i$.
1514
1515 For example plain \TeX\ allocates $n=254$ for footnotes\index{footnote} and sets
1516 {\tt count254} to~$1000$, {\tt dimen254} to 8in, and {\tt skip254} to
1517 {\tt \BS big\-skip\-amount}.
1518
1519 An insertion node will specify the insertion class $i$, some vertical material,
1520 its natural height plus depth $x$, a {\tt split\-\_top\-\_skip}, a {\tt split\-\_max\_depth},
1521 and a {\tt floa\-ting\-\_pe\-nal\-ty}.
1522
1523
1524 Now assume that an insert node with subtype 254 arrives at the page builder.
1525 If this is the first such insert, \TeX\ will decrease the {\tt page\_goal}
1526 by the width of {\tt skip254} and adds its stretchability and shrinkability
1527 to the total stretchability and shrinkability of the page. Later,
1528 the output routine will add some space and the footnote rule to fill just that
1529 much space and add just that much shrinkability and stretchability to the page.
1530 Then \TeX\ will normally add the vertical material in the insert node to
1531 {\tt box254} and decrease the {\tt page\_goal} by $x\times f/1000$.
1532
1533 Special processing is required if \TeX\ detects that there is not enough space on
1534 the current page to accommodate the complete insertion.
1535 If already a previous insert did not fit on the page, simply the {\tt floating\_penalty}
1536 as given in the insert node is added to the total {\tt insert\_penalties}.
1537 Otherwise \TeX\ will test that the total natural height plus depth of {\tt box254}
1538 including $x$ does not exceed the maximum size $d$ and that the
1539 ${\tt page\_total} + {\tt page\_depth} + x\times f/1000 - {\tt page\_shrink} \le {\tt page\_goal}$.
1540 If one of these tests fails, the current insertion
1541 is split in such a way as to make the size of the remaining insertions just pass the tests
1542 just stated.
1543
1544 Whenever a glue node, or penalty node, or a kern node that is followed by glue arrives
1545 at the page builder, it rates the current position as a possible end of the page based on
1546 the shrinkability of the page and the difference between {\tt page\_total} and {\tt page\_goal}.
1547 As the page fills, the page breaks tend to become better and better until the
1548 page starts to get overfull and the page breaks get worse and worse until
1549 they reach the point where they become {\tt awful\_bad}. At that point,
1550 the page builder returns to the best page break found so far and fires up the
1551 output routine.
1552
1553
1554 \subsection{\HINT\ Page Templates}
1555 Let's look at the problems that show up when implementing a replacement for \TeX's
1556 page building mechanism.
1557
1558 \enumerate
1559 \item
1560 An insertion node can not always specify its height $x$ because insertions may contain paragraphs that need
1561 to be broken in lines and the height of a paragraph depends in some non obvious way on
1562 its width.
1563
1564 \item
1565 Before the viewer can compute the height $x$, it needs to know the width of the insertion. Just imagine
1566 displaying footnotes in two columns or setting notes in the margin. Knowing the width, it
1567 can pack the vertical material and derive its height and depth.
1568
1569 \item
1570 \TeX's plain format provides an insert macro that checks whether there is still space
1571 on the current page, and if so, it creates a contribution to the main text body, otherwise it
1572 creates a {\tt topinsert}. Such a decision needs to be postponed to the \HINT\ viewer.
1573
1574 \item
1575 \HINT\ has no output routines that would specify something like the space and the rule preceding the footnote.
1576
1577 \item
1578 \TeX's output routines have the ability to inspect the content of the boxes,
1579 split them, and distribute the content over the page.
1580 For example, the output routine for an index set in two column format might
1581 expect a box containing index entries up to a height of $2\times\.{vsize}$.
1582 It will split this box in the middle and display the top part in the left
1583 column and the bottom part in the right column. With this approach, the
1584 last page will show two partly filled columns of about equal size.
1585
1586 \item
1587 \HINT\ has no mark nodes that could be used to create page headers or footers.
1588 Marks, like output routines, contain token lists and need the full \TeX\ interpreter
1589 for processing them. Hence, \HINT\ does not support mark nodes.
1590 \endenumerate
1591
1592
1593 Instead of output routines, \HINT\ uses page templates.
1594 Page templates are basically vertical boxes with \sym{stream\ insert\ points} marking the
1595 positions where the content of the box registers, filled by the page builder,
1596 should appear.
1597 To output the page, the viewer traverses the page template,
1598 replaces the placeholders by the appropriate box content, and
1599 sets the glue.
1600
1601 It is only natural to treat the page's main body,
1602 inserts, and marks using the same mechanism. We call this
1603 mechanism a content stream\index{stream}.
1604 Content streams are identified by a stream number in the range 0 to 254;
1605 the number 255 is used to indicate an invalid stream number.
1606 The stream number 0 is reserved for the main content stream; it is always defined.
1607
1608 \medskip
1609 {\small \advance \leftskip by 30pt \advance \rightskip by 30pt
1610 It is planed to implement a replacement for \TeX's mark nodes using
1611 different types of streams:
1612 \itemize
1613 \item normal streams correspond to \TeX's inserts and accumulate content on the page,
1614 \item first\index{first stream} streams correspond to \TeX's first marks and will contain only the first insertion of the page,
1615 \item last\index{last stream} streams correspond to \TeX's bottom marks and will contain only the last insertion of the page, and
1616 \item top\index{top stream} streams correspond to \TeX's top marks. Top streams are not yet implemented.
1617 \enditemize
1618 \medskip
1619 }
1620
1621 Nodes from the content section are considered contributions to stream~0 except
1622 for insert nodes which will specify the stream number explicitly.
1623 If the stream is not defined or is not used in the current page template, its content is simply ignored.
1624
1625 The page builder needs a mechanism to redirect contributions from one content
1626 stream to another content stream based on the availability of space.
1627 Hence a \HINT\ content stream can optionally specify a preferred stream number,
1628 where content should go if there is still space available, a next stream number,
1629 where content should go if the present stream has no more space available, and
1630 a split ratio if the content is to be split between these two streams before
1631 filling in the template.
1632
1633 Various stream parameters govern the treatment of contributions to the stream
1634 and the page building process.
1635
1636 \itemize
1637 \item The magnification factor $f$: Inserting a box of height $h$ to this stream will contribute $h\times f/1000$
1638 to the height of the page under construction. For example, a stream
1639 that uses a two column format will have an $f$ value of 500; a stream
1640 that specifies notes that will be displayed in the page margin will
1641 have an $f$ value of zero.
1642
1643 \item The height $h$: The extended dimension $h$ gives the maximum height this
1644 stream is allowed to occupy on the current page.
1645 To continue the previous example, a stream that will be split into two columns
1646 will have $h=2\cdot\.{vsize}$ , and a stream that specifies
1647 notes that will be displayed in the page margin will have
1648 $h=1\cdot\.{vsize}$. You can restrict the amount of space occupied by
1649 footnotes to the bottom quarter by setting the corresponding $h$ value
1650 to $h=0.25\cdot\.{vsize}$.
1651
1652 \item The depth $d$: The dimension $d$ gives the maximum depth this
1653 stream is allowed to have after formatting.
1654
1655 \item The width $w$: The extended dimension $w$ gives the width of this stream
1656 when formatting its content. For example margin notes
1657 should have the width of the margin less some surrounding space.
1658
1659 \item The ``before'' list $b$: If there are any contributions to this
1660 stream on the current page, the material in list $b$
1661 is inserted {\it before\/} the material from the stream itself. For
1662 example, the short line that separates the footnotes from the main
1663 page will go, together with some surrounding space, into the list~$b$.
1664
1665 \item The top skip glue $g$: This glue is inserted between the material
1666 from list $b$ and the first box of the stream, reduced
1667 by the height of the first box. Hence it specifies the distance between
1668 the material in $b$ and the first baseline of the stream content.
1669
1670 \item The ``after'' list $a$: The list $a$ is treated like list $b$ but
1671 its material is placed {\it after\/} the material from the stream itself.
1672
1673 \item The ``preferred'' stream number $p$: If $p\ne 255$, it is the number of
1674 the {\it preferred\/} stream. If stream $p$ has still
1675 enough room to accommodate the current contribution, move the
1676 contribution to stream $p$, otherwise keep it. For example, you can
1677 move an illustration to the main content stream, provided there is
1678 still enough space for it on the current page, by setting $p=0$.
1679
1680 \item The ``next'' stream number $n$: If $n\ne 255$, it is the number of the
1681 {\it next\/} stream. If a contribution can not be
1682 accommodated in stream $p$ nor in the current stream, treat it as an
1683 insertion to stream $n$. For example, you can move contributions to
1684 the next column after the first column is full, or move illustrations
1685 to a separate page at the end of the chapter.
1686
1687 \item The split ratio\index{split ratio} $r$: If $r$ is positive, both $p$ and $n$ must
1688 be valid stream numbers and contents is not immediately moved to stream $p$ or $n$ as described before.
1689 Instead the content is kept in the stream itself until the current page is complete.
1690 Then, before inserting the streams into the page template, the content of
1691 this stream is formatted as a vertical box, the vertical box is
1692 split into a top fraction and a bottom fraction in the ratio $r/1000$
1693 for the top and $(1000-r)/1000$ for the bottom, and finally the top
1694 fraction is moved to stream $p$ and the bottom fraction to stream
1695 $n$. You can use this feature for example to implement footnotes
1696 arranged in two columns of about equal size. By collecting all the
1697 footnotes in one stream and then splitting the footnotes with $r=500$
1698 before placing them on the page into a right and left column. Even
1699 three or more columns can be implemented by cascades of streams using
1700 this mechanism.
1701 \enditemize
1702
1703 \HINT\ allows multiple page templates but Hi\TeX\ currently does not implement
1704 restricting them to individual page ranges and the viewer selects
1705 the page template with the highest priority. To support different output media, the page
1706 templates are named and a suitable user interface may offer the user a selection
1707 of possible page layouts. In this way, the page layout remains in the hands of the
1708 book designer, and the user has still the opportunity to pick a layout that best fits
1709 the display device.
1710
1711 The build-in page template with number 0 is always defined and has priority 0.
1712 It will display just the main content stream. It puts a small margin
1713 of $\.{hsize}/8 -4.5\hbox{pt}$ all around it.
1714 Given a letter size page, 8.5 inch wide, this formula yields a margin of 1 inch,
1715 matching \TeX's plain format. The margin will be positive as long as
1716 the page is wider than $1/2$ inch. For narrower pages, there will be no
1717 margin at all. In general, the \HINT\ viewer will never set {\tt hsize} larger
1718 than the width of the page and {\tt vsize} larger than its height.
1719
1720 %8.5 in should give 1 inch margin 2/17
1721 %612pt should give 72pt margin
1722 %72pt = 612/8-4.5pt
1723 %This would give a positive margin starting at 36pt or 1/2 inch
1724
1725
1726 %\appendix
1727
1728 %\plainsection{References}
1729
1730 %{\baselineskip=11pt
1731 %\def\bfblrm{\small\rm}%
1732 %\def\bblem{\small\it}%
1733 %\bibliography{../hint}
1734 %\bibliographystyle{plain}
1735 %}
1736
1737
1738
1739 \plainsection{Index}
1740 \begingroup
1741 \def\_{{\tt \UL}} % underline in a string
1742 \catcode`\_=\active \let_=\UL % underline is a letter
1743 \input hitexman.ind\relax
1744 \endgroup
1745
1746 \write\cont{} % ensure that the contents file isn't empty
1747 % \write\cont{\catcode `\noexpand\@=12\relax} % \makeatother
1748 \closeout\cont% the contents information has been fully gathered
1749
1750 \inx
1751 \fin
1752 \end