-
Notifications
You must be signed in to change notification settings - Fork 18
/
chapter07.tex
1030 lines (942 loc) · 40.1 KB
/
chapter07.tex
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{6}
\begin{document}
%\chapter{Numbers}\label{number}
\chapter{Numbers}\label{number}
%In this chapter integers and their
%denotations will be treated,
%the conversions that are possible either way,
%allocation and use of \cs{count} registers, and
%arithmetic with integers.
In this chapter integers and their
denotations will be treated,
the conversions that are possible either way,
allocation and use of \cs{count} registers, and
arithmetic with integers.
%\label{cschap:number}\label{cschap:romannumeral}\label{cschap:count}\label{cschap:countdef}\label{cschap:newcount}\label{cschap:advance}\label{cschap:multiply}\label{cschap:divide}
%\begin{inventory}
%\item [\cs{number}]
% Convert a \gr{number} to decimal representation.
\label{cschap:number}\label{cschap:romannumeral}\label{cschap:count}\label{cschap:countdef}\label{cschap:newcount}\label{cschap:advance}\label{cschap:multiply}\label{cschap:divide}
\begin{inventory}
\item [\cs{number}]
Convert a \gr{number} to decimal representation.
%\item [\cs{romannumeral}]
% Convert a positive \gr{number} to lowercase roman representation.
\item [\cs{romannumeral}]
Convert a positive \gr{number} to lowercase roman representation.
%\item [\cs{ifnum}]
% Test relations between numbers.
\item [\cs{ifnum}]
Test relations between numbers.
%\item [\cs{ifodd}]
% Test whether a number is odd.
\item [\cs{ifodd}]
Test whether a number is odd.
%\item [\cs{ifcase}]
% Enumerated case statement.
\item [\cs{ifcase}]
Enumerated case statement.
%\item [\cs{count}]
% Prefix for count registers.
\item [\cs{count}]
Prefix for count registers.
%\item [\cs{countdef}]
% Define a control sequence to be a synonym for
% a~\cs{count} register.
\item [\cs{countdef}]
Define a control sequence to be a synonym for
a~\cs{count} register.
%\item [\cs{newcount}]
% Allocate an unused \cs{count} register.
\item [\cs{newcount}]
Allocate an unused \cs{count} register.
%\item [\cs{advance}]
% Arithmetic command to add to or subtract from
% a~\gr{numeric variable}.
\item [\cs{advance}]
Arithmetic command to add to or subtract from
a~\gr{numeric variable}.
%\item [\cs{multiply}]
% Arithmetic command to multiply a \gr{numeric variable}.
\item [\cs{multiply}]
Arithmetic command to multiply a \gr{numeric variable}.
%\item [\cs{divide}]
% Arithmetic command to divide a \gr{numeric variable}.
\item [\cs{divide}]
Arithmetic command to divide a \gr{numeric variable}.
%\end{inventory}
\end{inventory}
%\section{Numbers and \gr{number}s}
\section{Numbers and \gr{number}s}
%An important part of the grammar of \TeX\ is the rigorous definition
%of a \gr{number}\index{numbers}, the syntactic entity that
%\TeX\ expects when semantically an \indexterm{integer} is
%expected. This definition will take the largest part of this
%chapter. Towards the end, \cs{count} registers, arithmetic, and tests
%for numbers are discussed.
An important part of the grammar of \TeX\ is the rigorous definition
of a \gr{number}\index{numbers}, the syntactic entity that
\TeX\ expects when semantically an \indexterm{integer} is
expected. This definition will take the largest part of this
chapter. Towards the end, \cs{count} registers, arithmetic, and tests
for numbers are discussed.
%For clarity of discussion a distinction will be made
%here between integers and numbers,
%but note that a \gr{number} can be both
%an `integer' and a `number'.
%`Integer' will be taken to denote a mathematical number:
%a~quantity that can be added or multiplied.
%`Number' will be taken to refer to the printed representation
%of an integer: a string of digits, in other words.
For clarity of discussion a distinction will be made
here between integers and numbers,
but note that a \gr{number} can be both
an `integer' and a `number'.
`Integer' will be taken to denote a mathematical number:
a~quantity that can be added or multiplied.
`Number' will be taken to refer to the printed representation
of an integer: a string of digits, in other words.
%\section{Integers}
\section{Integers}
%Quite a few different sorts of objects can function
%as integers in \TeX. In this section they will all
%be treated, accompanied by the relevant lines from
%the grammar of \TeX.
Quite a few different sorts of objects can function
as integers in \TeX. In this section they will all
be treated, accompanied by the relevant lines from
the grammar of \TeX.
%First of all, an integer can be positive or negative:
%\begin{disp}\gr{number} $\longrightarrow$
%\gr{optional signs}\gr{unsigned number}\nl
%\gr{optional signs} $\longrightarrow$ \gr{optional spaces}\nl
%\indent $|$ \gr{optional signs}\gr{plus or minus}\gr{optional spaces}
%\end{disp}
First of all, an integer can be positive or negative:
\begin{disp}\gr{number} $\longrightarrow$
\gr{optional signs}\gr{unsigned number}\nl
\gr{optional signs} $\longrightarrow$ \gr{optional spaces}\nl
\indent $|$ \gr{optional signs}\gr{plus or minus}\gr{optional spaces}
\end{disp}
%A first possibility for an unsigned integer is a string of digits
%in decimal, octal, or hexadecimal notation.
%Together with the alphabetic constants these will be named
%here \gr{integer denotation}.
%Another possibility for an integer is an
%internal integer quantity, an \gr{internal integer};
%together with the denotations these form the
%\gr{normal integer}s.
%Lastly an integer can be a \gr{coerced integer}:
%an internal \gr{dimen} or \gr{glue}
%quantity that is converted to an integer value.
%\begin{disp}\gr{unsigned number} $\longrightarrow$ \gr{normal integer}
%$|$ \gr{coerced integer}\nl
%\gr{normal integer} $\longrightarrow$ \gr{integer denotation}
%$|$ \gr{internal integer}\nl
%\gr{coerced integer} $\longrightarrow$ \gr{internal dimen}
%$|$ \gr{internal glue}\end{disp}
%All of these possibilities will be treated in sequence.
A first possibility for an unsigned integer is a string of digits
in decimal, octal, or hexadecimal notation.
Together with the alphabetic constants these will be named
here \gr{integer denotation}.
Another possibility for an integer is an
internal integer quantity, an \gr{internal integer};
together with the denotations these form the
\gr{normal integer}s.
Lastly an integer can be a \gr{coerced integer}:
an internal \gr{dimen} or \gr{glue}
quantity that is converted to an integer value.
\begin{disp}\gr{unsigned number} $\longrightarrow$ \gr{normal integer}
$|$ \gr{coerced integer}\nl
\gr{normal integer} $\longrightarrow$ \gr{integer denotation}
$|$ \gr{internal integer}\nl
\gr{coerced integer} $\longrightarrow$ \gr{internal dimen}
$|$ \gr{internal glue}\end{disp}
All of these possibilities will be treated in sequence.
%%\spoint[int:denotation] Denotations: integers
%\subsection{Denotations: integers}
%\label{int:denotation}
%\spoint[int:denotation] Denotations: integers
\subsection{Denotations: integers}
\label{int:denotation}
%Anything that looks like a number
%can be used as a \gr{number}: thus \verb-42- is a number.
%However, bases other than decimal can also be used:
%\begin{verbatim}
%'123
%\end{verbatim}
%is the octal notation for $1\times8^2+2\times8^1+3\times8^0=83$,
%and
%\begin{verbatim}
%"123
%\end{verbatim}
%is the hexadecimal notation
%for $1\times16^2+2\times16^1+3\times16^0=291$.
%\begin{disp}\gr{integer denotation} $\longrightarrow$
%\gr{integer constant}\gr{one optional space} \nl
%\indent $|$ \n{\char`\'}\gr{octal constant}\gr{one optional space}\nl
%\indent $|$ \n{\char`\"}\gr{hexadecimal constant}\gr{one optional space}
%\end{disp}
%The octal digits are \n0--\n7; a~digit \n8 or~\n9 following an
%octal denotation is not part of the number:
%after
%\begin{verbatim}
%\count0='078
%\end{verbatim}
%the \cs{count0} will have the value~7, and the
%digit~\n8 is typeset.
Anything that looks like a number
can be used as a \gr{number}: thus \verb-42- is a number.
However, bases other than decimal can also be used:
\begin{verbatim}
'123
\end{verbatim}
is the octal notation for $1\times8^2+2\times8^1+3\times8^0=83$,
and
\begin{verbatim}
"123
\end{verbatim}
is the hexadecimal notation
for $1\times16^2+2\times16^1+3\times16^0=291$.
\begin{disp}\gr{integer denotation} $\longrightarrow$
\gr{integer constant}\gr{one optional space} \nl
\indent $|$ \n{\char`\'}\gr{octal constant}\gr{one optional space}\nl
\indent $|$ \n{\char`\"}\gr{hexadecimal constant}\gr{one optional space}
\end{disp}
The octal digits are \n0--\n7; a~digit \n8 or~\n9 following an
octal denotation is not part of the number:
after
\begin{verbatim}
\count0='078
\end{verbatim}
the \cs{count0} will have the value~7, and the
digit~\n8 is typeset.
%The hexadecimal digits are \n0--\n9, \n A--\n F, where the \n A--\n F
%can have category code 11\index{category!11}
%or~12\index{category!12}. The latter has a somewhat far-fetched
%justification: the characters resulting from a \cs{string} operation
%have category code~12. Lowercase \n a--\n f are not hexadecimal
%digits, although (in \TeX3) they are used for hexadecimal notation in
%the `circumflex method' for accessing all character codes (see
%Chapter~\ref{char}).
The hexadecimal digits are \n0--\n9, \n A--\n F, where the \n A--\n F
can have category code 11\index{category!11}
or~12\index{category!12}. The latter has a somewhat far-fetched
justification: the characters resulting from a \cs{string} operation
have category code~12. Lowercase \n a--\n f are not hexadecimal
digits, although (in \TeX3) they are used for hexadecimal notation in
the `circumflex method' for accessing all character codes (see
Chapter~\ref{char}).
%%\spoint Denotations: characters
%\subsection{Denotations: characters}
%\spoint Denotations: characters
\subsection{Denotations: characters}
%A character token is a pair consisting of a character code,
%which is a~number in the range 0--255,
%and a category code. Both of these codes are accessible,
%and can be used as a \gr{number}.
A character token is a pair consisting of a character code,
which is a~number in the range 0--255,
and a category code. Both of these codes are accessible,
and can be used as a \gr{number}.
%The character code of a character token, or of a single letter
%control sequence, is accessible through the left quote command:
%both \verb-`a- and~\verb-`\a- denote the character code of~{\tt a},
%which can be used as an integer.
%\begin{disp}\gr{integer denotation} $\longrightarrow$
%\n{\char`\`}\gr{character token}\gr{one optional space}\end{disp}
The character code of a character token, or of a single letter
control sequence, is accessible through the left quote command:
both \verb-`a- and~\verb-`\a- denote the character code of~{\tt a},
which can be used as an integer.
\begin{disp}\gr{integer denotation} $\longrightarrow$
\n{\char`\`}\gr{character token}\gr{one optional space}\end{disp}
%In order to emphasize that accessing the character code is
%in a sense using a denotation, the syntax of \TeX\ allows
%an optional space after such a `character constant'.
%The left quote must have category~12\index{category!12}.
In order to emphasize that accessing the character code is
in a sense using a denotation, the syntax of \TeX\ allows
an optional space after such a `character constant'.
The left quote must have category~12\index{category!12}.
%%\spoint Internal integers
%\subsection{Internal integers}
%\spoint Internal integers
\subsection{Internal integers}
%The class of \gr{internal integers} can
%be split into five parts.
%The \gr{codename}s and \gr{special integer}s
%will be treated separately below; furthermore, there are the following.
The class of \gr{internal integers} can
be split into five parts.
The \gr{codename}s and \gr{special integer}s
will be treated separately below; furthermore, there are the following.
%\begin{itemize} \item The contents of \cs{count} registers;
%either explicitly used by writing for instance \cs{count23},
%or by referring to such a register by means of a
%control sequence
%that was defined by \cs{countdef}:
%after
%\begin{verbatim}
%\countdef\MyCount=23
%\end{verbatim}
%\cs{MyCount} is called a
%\gr{countdef token}, and it is fully equivalent to \cs{count23}.
\begin{itemize} \item The contents of \cs{count} registers;
either explicitly used by writing for instance \cs{count23},
or by referring to such a register by means of a
control sequence
that was defined by \cs{countdef}:
after
\begin{verbatim}
\countdef\MyCount=23
\end{verbatim}
\cs{MyCount} is called a
\gr{countdef token}, and it is fully equivalent to \cs{count23}.
%\item All parameters of \TeX\ that hold integer values;
%this includes obvious ones such as \cs{linepenalty}, but
%also parameters such as
%\cs{hyphenchar}\gr{font} and \cs{parshape}
%(if a paragraph shape has been defined for $n$ lines,
%using \cs{parshape} in the context of a \gr{number}
%will yield this value of~$n$).
\item All parameters of \TeX\ that hold integer values;
this includes obvious ones such as \cs{linepenalty}, but
also parameters such as
\cs{hyphenchar}\gr{font} and \cs{parshape}
(if a paragraph shape has been defined for $n$ lines,
using \cs{parshape} in the context of a \gr{number}
will yield this value of~$n$).
%\item\label{num:chardef} Tokens defined by \cs{chardef} or \cs{mathchardef}.
%After
%\begin{verbatim}
%\chardef\foo=74
%\end{verbatim}
%the control sequence \cs{foo}
%can be used on its own to mean \cs{char74}, but in a context
%where a \gr{number} is wanted it can be used to denote~74:
%\begin{verbatim}
%\count\foo
%\end{verbatim}
%is equivalent to \verb=\count74=.
%This fact is
%exploited in the allocation routines for registers (see
%Chapter~\ref{alloc}).
\item\label{num:chardef} Tokens defined by \cs{chardef} or \cs{mathchardef}.
After
\begin{verbatim}
\chardef\foo=74
\end{verbatim}
the control sequence \cs{foo}
can be used on its own to mean \cs{char74}, but in a context
where a \gr{number} is wanted it can be used to denote~74:
\begin{verbatim}
\count\foo
\end{verbatim}
is equivalent to \verb=\count74=.
This fact is
exploited in the allocation routines for registers (see
Chapter~\ref{alloc}).
%A control sequence thus defined by \cs{chardef} is called a
%\gr{chardef token}; if it is defined by \cs{mathchardef} it
%is called a \gr{mathchardef token}.
A control sequence thus defined by \cs{chardef} is called a
\gr{chardef token}; if it is defined by \cs{mathchardef} it
is called a \gr{mathchardef token}.
%\end{itemize}
\end{itemize}
%Here is the full list:
%\begin{disp}\gr{internal integer} $\longrightarrow$
%\gr{integer parameter} \nl
%\indent $|$ \gr{special integer} $|$ \cs{lastpenalty}\nl
%\indent $|$ \gr{countdef token} $|$ \cs{count}\gr{8-bit number}\nl
%\indent $|$ \gr{chardef token} $|$ \gr{mathchardef token}\nl
%\indent $|$ \gr{codename}\gr{8-bit number}\nl
%\indent $|$ \cs{hyphenchar}\gr{font} $|$ \cs{skewchar}\gr{font}
%$|$ \cs{parshape}\nl
%\indent $|$ \cs{inputlineno} $|$ \cs{badness}\nl
%\gr{integer parameter} $\longrightarrow$\vadjust{\nobreak}
%$|$ \cs{adjdemerits} $|$ \cs{binoppenalty}\nl
%\indent $|$ \cs{brokenpenalty} $|$ \cs{clubpenalty} $|$ \cs{day}%
%\nl
%\indent $|$ \cs{defaulthyphenchar} $|$ \cs{defaultskewchar} \nl
%\indent $|$ \cs{delimiterfactor} $|$ \cs{displaywidowpenalty} \nl
%\indent $|$ \cs{doublehyphendemerits} $|$ \cs{endlinechar}
% $|$ \cs{escapechar}\nl
%\indent $|$ \cs{exhypenpenalty} $|$ \cs{fam} $|$ \cs{finalhyphendemerits}\nl
%\indent $|$ \cs{floatingpenalty} $|$ \cs{globaldefs} $|$ \cs{hangafter}\nl
%\indent $|$ \cs{hbadness} $|$ \cs{hyphenpenalty}
% $|$ \cs{interlinepenalty}\nl
%\indent $|$ \cs{linepenalty} $|$ \cs{looseness} $|$ \cs{mag}\nl
%\indent $|$ \cs{maxdeadcycles} $|$ \cs{month} \nl
%\indent $|$ \cs{newlinechar} $|$ \cs{outputpenalty} $|$ \cs{pausing}\nl
%\indent $|$ \cs{postdisplaypenalty} $|$ \cs{predisplaypenalty}\nl
%\indent $|$ \cs{pretolerance} $|$ \cs{relpenalty} $|$ \cs{showboxbreadth}\nl
%\indent $|$ \cs{showboxdepth} $|$ \cs{time} $|$ \cs{tolerance}\nl
%\indent $|$ \cs{tracingcommands} $|$ \cs{tracinglostchars}
% $|$ \cs{tracingmacros}\nl
%\indent $|$ \cs{tracingonline} $|$ \cs{tracingoutput}
% $|$ \cs{tracingpages}\nl
%\indent $|$ \cs{tracingparagraphs} $|$ \cs{tracingrestores}
% $|$ \cs{tracingstats}\nl
%\indent $|$ \cs{uchyph} $|$ \cs{vbadness} $|$ \cs{widowpenalty}
% $|$ \cs{year}
%\end{disp}
Here is the full list:
\begin{disp}\gr{internal integer} $\longrightarrow$
\gr{integer parameter} \nl
\indent $|$ \gr{special integer} $|$ \cs{lastpenalty}\nl
\indent $|$ \gr{countdef token} $|$ \cs{count}\gr{8-bit number}\nl
\indent $|$ \gr{chardef token} $|$ \gr{mathchardef token}\nl
\indent $|$ \gr{codename}\gr{8-bit number}\nl
\indent $|$ \cs{hyphenchar}\gr{font} $|$ \cs{skewchar}\gr{font}
$|$ \cs{parshape}\nl
\indent $|$ \cs{inputlineno} $|$ \cs{badness}\nl
\gr{integer parameter} $\longrightarrow$\vadjust{\nobreak}
$|$ \cs{adjdemerits} $|$ \cs{binoppenalty}\nl
\indent $|$ \cs{brokenpenalty} $|$ \cs{clubpenalty} $|$ \cs{day}%
\nl
\indent $|$ \cs{defaulthyphenchar} $|$ \cs{defaultskewchar} \nl
\indent $|$ \cs{delimiterfactor} $|$ \cs{displaywidowpenalty} \nl
\indent $|$ \cs{doublehyphendemerits} $|$ \cs{endlinechar}
$|$ \cs{escapechar}\nl
\indent $|$ \cs{exhypenpenalty} $|$ \cs{fam} $|$ \cs{finalhyphendemerits}\nl
\indent $|$ \cs{floatingpenalty} $|$ \cs{globaldefs} $|$ \cs{hangafter}\nl
\indent $|$ \cs{hbadness} $|$ \cs{hyphenpenalty}
$|$ \cs{interlinepenalty}\nl
\indent $|$ \cs{linepenalty} $|$ \cs{looseness} $|$ \cs{mag}\nl
\indent $|$ \cs{maxdeadcycles} $|$ \cs{month} \nl
\indent $|$ \cs{newlinechar} $|$ \cs{outputpenalty} $|$ \cs{pausing}\nl
\indent $|$ \cs{postdisplaypenalty} $|$ \cs{predisplaypenalty}\nl
\indent $|$ \cs{pretolerance} $|$ \cs{relpenalty} $|$ \cs{showboxbreadth}\nl
\indent $|$ \cs{showboxdepth} $|$ \cs{time} $|$ \cs{tolerance}\nl
\indent $|$ \cs{tracingcommands} $|$ \cs{tracinglostchars}
$|$ \cs{tracingmacros}\nl
\indent $|$ \cs{tracingonline} $|$ \cs{tracingoutput}
$|$ \cs{tracingpages}\nl
\indent $|$ \cs{tracingparagraphs} $|$ \cs{tracingrestores}
$|$ \cs{tracingstats}\nl
\indent $|$ \cs{uchyph} $|$ \cs{vbadness} $|$ \cs{widowpenalty}
$|$ \cs{year}
\end{disp}
%Any internal integer can function as an \gr{internal unit},
%which \ldash preceded by \gr{optional spaces} \rdash
%can serve as a \gr{unit of measure}.
%Examples of this are given in Chapter~\ref{glue}.
Any internal integer can function as an \gr{internal unit},
which \ldash preceded by \gr{optional spaces} \rdash
can serve as a \gr{unit of measure}.
Examples of this are given in Chapter~\ref{glue}.
%%\spoint Internal integers: other codes of a character
%\subsection{Internal integers: other codes of a character}
%\spoint Internal integers: other codes of a character
\subsection{Internal integers: other codes of a character}
%The \cs{catcode} command
%(which was described in Chapter~\ref{mouth})
%is a \gr{codename}, and like the other code names
%it can be used as an integer.
%\begin{disp}\gr{codename} $\longrightarrow$ \cs{catcode} $|$ \cs{mathcode}
%$|$ \cs{uccode} $|$ \cs{lccode}\nl \indent $|$ \cs{sfcode} $|$ \cs{delcode}
%\end{disp}
%A~\gr{codename} has to be followed by an \gr{8-bit number}.
The \cs{catcode} command
(which was described in Chapter~\ref{mouth})
is a \gr{codename}, and like the other code names
it can be used as an integer.
\begin{disp}\gr{codename} $\longrightarrow$ \cs{catcode} $|$ \cs{mathcode}
$|$ \cs{uccode} $|$ \cs{lccode}\nl \indent $|$ \cs{sfcode} $|$ \cs{delcode}
\end{disp}
A~\gr{codename} has to be followed by an \gr{8-bit number}.
%Uppercase and lowercase codes were treated in Chapter~\ref{char};
%the \cs{sfcode} is treated
%in Chapter~\ref{space};
%the \cs{mathcode} and~\cs{delcode} are treated in
%Chapter~\ref{mathchar}.
Uppercase and lowercase codes were treated in Chapter~\ref{char};
the \cs{sfcode} is treated
in Chapter~\ref{space};
the \cs{mathcode} and~\cs{delcode} are treated in
Chapter~\ref{mathchar}.
%%\spoint[special:int:list] \gr{special integer}
%\subsection{\gr{special integer}}
%\label{special:int:list}
%\spoint[special:int:list] \gr{special integer}
\subsection{\gr{special integer}}
\label{special:int:list}
%One of the subclasses of the internal integers is
%that of the special integers.
%\begin{disp}\gr{special integer} $\longrightarrow$
%\cs{spacefactor} $|$ \cs{prevgraf}\nl
%\indent $|$ \cs{deadcycles} $|$ \cs{insertpenalties}
%\end{disp}
%An assignment to any of these is called an \gr{intimate
%assignment}, and is automatically global
%(see Chapter~\ref{group}).
One of the subclasses of the internal integers is
that of the special integers.
\begin{disp}\gr{special integer} $\longrightarrow$
\cs{spacefactor} $|$ \cs{prevgraf}\nl
\indent $|$ \cs{deadcycles} $|$ \cs{insertpenalties}
\end{disp}
An assignment to any of these is called an \gr{intimate
assignment}, and is automatically global
(see Chapter~\ref{group}).
%%\spoint Other internal quantities: coersion to integer
%\subsection{Other internal quantities: coersion to integer}
%\spoint Other internal quantities: coersion to integer
\subsection{Other internal quantities: coersion to integer}
%\TeX\ provides a conversion between dimensions and integers:
%if an integer is expected, a \gr{dimen} or \gr{glue} used
%in that context is converted by taking its
%(natural) size
%in scaled points\index{point!scaled}.
%However, only \gr{internal dimen}s and \gr{internal glue}
%can be used this way: no dimension or glue denotations
%can be coerced to integers.
\TeX\ provides a conversion between dimensions and integers:
if an integer is expected, a \gr{dimen} or \gr{glue} used
in that context is converted by taking its
(natural) size
in scaled points\index{point!scaled}.
However, only \gr{internal dimen}s and \gr{internal glue}
can be used this way: no dimension or glue denotations
can be coerced to integers.
%%\spoint Trailing spaces
%\subsection{Trailing spaces}
%\spoint Trailing spaces
\subsection{Trailing spaces}
%The syntax of \TeX\ defines integer denotations (decimal,
%octal, and hexadecimal) and `back-quoted' character tokens
%to be followed by \gr{one optional space}. This means that
%\TeX\ reads the token after the number, absorbing it
%if it was a space token, and backing up if it was not.
The syntax of \TeX\ defines integer denotations (decimal,
octal, and hexadecimal) and `back-quoted' character tokens
to be followed by \gr{one optional space}. This means that
\TeX\ reads the token after the number, absorbing it
if it was a space token, and backing up if it was not.
%Because \TeX's input processor goes into the state `skipping spaces'
%after it has seen one space token, this
%scanning behaviour implies that
%integer denotations can be followed by
%arbitrarily many space characters in the input.
%Also, a line end is admissible.
%However, only one space token is allowed.
Because \TeX's input processor goes into the state `skipping spaces'
after it has seen one space token, this
scanning behaviour implies that
integer denotations can be followed by
arbitrarily many space characters in the input.
Also, a line end is admissible.
However, only one space token is allowed.
%%\point Numbers
%\section{Numbers}
%\point Numbers
\section{Numbers}
%\TeX\ can perform an implicit \indextermsub{number}{conversion} from a string
%\cstoidx number\par\cstoidx romannumeral\par
%of digits to an integer. Conversion from a representation
%in decimal, octal, or hexadecimal notation was
%treated above. The conversion the other way,
%from an \gr{internal integer} to a printed representation,
%has to be performed explicitly.
%\TeX\ provides two conversion routines,
%\cs{number}, to decimal, and \cs{romannumeral} to
%\indexterm{roman numerals}.
%The command \cs{number} is equivalent to \cs{the}
%when followed by an internal integer.
%These commands are performed in the expansion processor of \TeX, that is,
%they are expanded whenever expansion has not been inhibited.
\TeX\ can perform an implicit \indextermsub{number}{conversion} from a string
\cstoidx number\par\cstoidx romannumeral\par
of digits to an integer. Conversion from a representation
in decimal, octal, or hexadecimal notation was
treated above. The conversion the other way,
from an \gr{internal integer} to a printed representation,
has to be performed explicitly.
\TeX\ provides two conversion routines,
\cs{number}, to decimal, and \cs{romannumeral} to
\indexterm{roman numerals}.
The command \cs{number} is equivalent to \cs{the}
when followed by an internal integer.
These commands are performed in the expansion processor of \TeX, that is,
they are expanded whenever expansion has not been inhibited.
%Both commands
%yield a string of tokens with category code~12\index{category!12};
%their argument is a~\gr{number}.
%Thus \verb-\romannumeral51-, \verb-\romannumeral\year-,
%and~\verb-\number\linepenalty- are valid, and so is \verb-\number13-.
%Applying \cs{number} to a denotation has some uses:
%it removes leading zeros and superfluous plus and minus signs.
Both commands
yield a string of tokens with category code~12\index{category!12};
their argument is a~\gr{number}.
Thus \verb-\romannumeral51-, \verb-\romannumeral\year-,
and~\verb-\number\linepenalty- are valid, and so is \verb-\number13-.
Applying \cs{number} to a denotation has some uses:
it removes leading zeros and superfluous plus and minus signs.
%A roman numeral is a string of lowercase `roman digits',
%which are characters of category code~12.
%The sequence\howto Uppercase roman numberals\par
%\begin{verbatim}
%\uppercase\expandafter{\romannumeral ...}
%\end{verbatim}
%gives uppercase roman numerals.
%This works because \TeX\ expands
%tokens in order to find the opening brace of the argument
%of \verb=\uppercase=. If \cs{romannumeral} is applied to
%a negative number, the result is simply empty.
A roman numeral is a string of lowercase `roman digits',
which are characters of category code~12.
The sequence\howto Uppercase roman numberals\par
\begin{verbatim}
\uppercase\expandafter{\romannumeral ...}
\end{verbatim}
gives uppercase roman numerals.
This works because \TeX\ expands
tokens in order to find the opening brace of the argument
of \verb=\uppercase=. If \cs{romannumeral} is applied to
a negative number, the result is simply empty.
%%\point Integer registers
%\section{Integer registers}
%\point Integer registers
\section{Integer registers}
%Integers can be stored in \csidx{count} registers:
%\begin{Disp}\cs{count}\gr{8-bit number}\end{Disp}
%is an \gr{integer variable} and an \gr{internal integer}.
%As an integer variable it can be used in a
%\gr{variable assignment}:
%\begin{Disp}\gr{variable assignment} $\longrightarrow$
% \gr{integer variable}\gr{equals}\gr{number} $|$ \dots\end{Disp}
%As an internal integer it can be used as a \gr{number}:
%\begin{Disp}\gr{number} $\rightarrow$ \gr{optional signs}\gr{internal integer}
% $|$ \dots
%\end{Disp}
Integers can be stored in \csidx{count} registers:
\begin{Disp}\cs{count}\gr{8-bit number}\end{Disp}
is an \gr{integer variable} and an \gr{internal integer}.
As an integer variable it can be used in a
\gr{variable assignment}:
\begin{Disp}\gr{variable assignment} $\longrightarrow$
\gr{integer variable}\gr{equals}\gr{number} $|$ \dots\end{Disp}
As an internal integer it can be used as a \gr{number}:
\begin{Disp}\gr{number} $\rightarrow$ \gr{optional signs}\gr{internal integer}
$|$ \dots
\end{Disp}
%Synonyms for \cs{count} registers can be introduced by the
%\csidx{countdef} command in a \gr{shorthand definition}:
%\begin{Disp}\cs{countdef}\gr{control sequence}\gr{equals}\gr{8-bit number}
%\end{Disp} A control sequence defined this way
%is called a \gr{countdef token}, and it serves as an
%\gr{internal integer}.
Synonyms for \cs{count} registers can be introduced by the
\csidx{countdef} command in a \gr{shorthand definition}:
\begin{Disp}\cs{countdef}\gr{control sequence}\gr{equals}\gr{8-bit number}
\end{Disp} A control sequence defined this way
is called a \gr{countdef token}, and it serves as an
\gr{internal integer}.
%The plain \TeX\ macro \csidx{newcount}
%(which is declared \cs{outer}) uses the \cs{countdef} command
%to allocate an unused \cs{count} register.
%Counters 0--9 are scratch registers, like all
%registers with numbers~0--9.
%However, counters 0--9 are used for page identification
%in the \n{dvi} file (see Chapter~\ref{TeXcomm}),
%so they should be used as scratch
%registers only inside a group.
%Counters 10--22 are
%used for plain \TeX's bookkeeping of allocation of registers.
%Counter 255 is also scratch.
The plain \TeX\ macro \csidx{newcount}
(which is declared \cs{outer}) uses the \cs{countdef} command
to allocate an unused \cs{count} register.
Counters 0--9 are scratch registers, like all
registers with numbers~0--9.
However, counters 0--9 are used for page identification
in the \n{dvi} file (see Chapter~\ref{TeXcomm}),
so they should be used as scratch
registers only inside a group.
Counters 10--22 are
used for plain \TeX's bookkeeping of allocation of registers.
Counter 255 is also scratch.
%%\point Arithmetic
%\section{Arithmetic}
%\point Arithmetic
\section{Arithmetic}
%The user can perform some \indexterm{arithmetic}
%in \TeX, and
%\TeX\ also performs arithmetic internally. User arithmetic
%is concerned only with integers; the internal arithmetic
%is mostly on fixed-point quantities, and only in the
%case of glue setting on floating-point numbers.
The user can perform some \indexterm{arithmetic}
in \TeX, and
\TeX\ also performs arithmetic internally. User arithmetic
is concerned only with integers; the internal arithmetic
is mostly on fixed-point quantities, and only in the
case of glue setting on floating-point numbers.
%%\spoint Arithmetic statements
%\subsection{Arithmetic statements}
%\spoint Arithmetic statements
\subsection{Arithmetic statements}
%\TeX\ allows the user to
%\cstoidx advance\par\cstoidx multiply\par\cstoidx divide\par
%perform some arithmetic on integers. The statement
%\begin{Disp}\cs{advance}\gr{integer variable}\gr{optional \n{by}}%
% \gr{number}\end{Disp}
%adds the value of the \gr{number}
% \ldash which may be negative \rdash to the \gr{integer variable}.
%Similarly,
%\begin{Disp}\cs{multiply}\gr{integer variable}\gr{optional \n{by}}%
% \gr{number}\end{Disp}
%multiplies the value of the \gr{integer variable}, and
%\begin{Disp}\cs{divide}\gr{integer variable}\gr{optional \n{by}}%
% \gr{number}\end{Disp}
%divides an \gr{integer variable}.
\TeX\ allows the user to
\cstoidx advance\par\cstoidx multiply\par\cstoidx divide\par
perform some arithmetic on integers. The statement
\begin{Disp}\cs{advance}\gr{integer variable}\gr{optional \n{by}}%
\gr{number}\end{Disp}
adds the value of the \gr{number}
\ldash which may be negative \rdash to the \gr{integer variable}.
Similarly,
\begin{Disp}\cs{multiply}\gr{integer variable}\gr{optional \n{by}}%
\gr{number}\end{Disp}
multiplies the value of the \gr{integer variable}, and
\begin{Disp}\cs{divide}\gr{integer variable}\gr{optional \n{by}}%
\gr{number}\end{Disp}
divides an \gr{integer variable}.
%Multiplication and division are also available for any so-called
%\gr{numeric variable}: their most general form is
%\begin{disp}\cs{multiply}\gr{numeric variable}\gr{optional \n{by}}\gr{number}
%\end{disp} where
%\begin{disp}\gr{numeric variable} $\longrightarrow$
%\gr{integer variable} $|$ \gr{dimen variable}\nl
%\indent $|$ \gr{glue variable} $|$ \gr{muglue variable}\end{disp}
Multiplication and division are also available for any so-called
\gr{numeric variable}: their most general form is
\begin{disp}\cs{multiply}\gr{numeric variable}\gr{optional \n{by}}\gr{number}
\end{disp} where
\begin{disp}\gr{numeric variable} $\longrightarrow$
\gr{integer variable} $|$ \gr{dimen variable}\nl
\indent $|$ \gr{glue variable} $|$ \gr{muglue variable}\end{disp}
%The result of an arithmetic operation should not exceed
%$2^{30}$ in absolute value.
The result of an arithmetic operation should not exceed
$2^{30}$ in absolute value.
%Division of integers yields an integer; that is, the remainder
%is discarded. This raises the question of how rounding is performed
%when either operand is negative. In such cases \TeX\ performs
%the division with the absolute values of the operands, and
%takes the negative of the result if exactly one operand was negative.
Division of integers yields an integer; that is, the remainder
is discarded. This raises the question of how rounding is performed
when either operand is negative. In such cases \TeX\ performs
the division with the absolute values of the operands, and
takes the negative of the result if exactly one operand was negative.
%%\spoint Floating-point arithmetic
%\subsection{Floating-point arithmetic}
%\spoint Floating-point arithmetic
\subsection{Floating-point arithmetic}
%Internally some \indextermsub{floating-point}{arithmetic}
%is performed, namely
%in the calculation of glue set ratios.
%%and slant for accents!!
%However, machine-dependent aspects of rounding cannot
%influence the decision process of \TeX, so machine independence
%of \TeX\ is guaranteed in this respect (sufficient
%accuracy of rounding is enforced by the \n{Trip} test of~\cite{K:trip}).
Internally some \indextermsub{floating-point}{arithmetic}
is performed, namely
in the calculation of glue set ratios.
%and slant for accents!!
However, machine-dependent aspects of rounding cannot
influence the decision process of \TeX, so machine independence
of \TeX\ is guaranteed in this respect (sufficient
accuracy of rounding is enforced by the \n{Trip} test of~\cite{K:trip}).
%%\spoint Fixed-point arithmetic
%\subsection{Fixed-point arithmetic}
%\spoint Fixed-point arithmetic
\subsection{Fixed-point arithmetic}
%All fractional arithmetic in \TeX\ is performed in
%\indextermsub{fixed-point}{arithmetic}
%of `scaled integers': multiples of~$2^{-16}$.
%This ensures the machine independence of \TeX.
%Printed representations of scaled integers are rounded
%to 5 decimal digits.
All fractional arithmetic in \TeX\ is performed in
\indextermsub{fixed-point}{arithmetic}
of `scaled integers': multiples of~$2^{-16}$.
This ensures the machine independence of \TeX.
Printed representations of scaled integers are rounded
to 5 decimal digits.
%In ordinary 32-bit implementations of \TeX\ the largest
%integers are $2^{31}-1$ in absolute size.
%The user is not allowed to specify
%dimensions larger in absolute size than~$2^{30}-1$: two
%such dimensions can be added or subtracted without
%overflow on a 32-bit system.
In ordinary 32-bit implementations of \TeX\ the largest
integers are $2^{31}-1$ in absolute size.
The user is not allowed to specify
dimensions larger in absolute size than~$2^{30}-1$: two
such dimensions can be added or subtracted without
overflow on a 32-bit system.
%%\point Number testing
%\section{Number testing}
%\point Number testing
\section{Number testing}
%The most general test for integers in \TeX\ is
%\begin{disp}\cs{ifnum}\gr{number$_1$}\gr{relation}\gr{number$_2$}\end{disp}
%where \gr{relation} is a~\n<, \n>, or~\n= character,
%all of category~12\index{category!12}.
The most general test for integers in \TeX\ is
\begin{disp}\cs{ifnum}\gr{number$_1$}\gr{relation}\gr{number$_2$}\end{disp}
where \gr{relation} is a~\n<, \n>, or~\n= character,
all of category~12\index{category!12}.
%Distinguishing between odd and even numbers is done
%by \begin{disp}\cs{ifodd}\gr{number}\end{disp}
Distinguishing between odd and even numbers is done
by \begin{disp}\cs{ifodd}\gr{number}\end{disp}
%A numeric case statement is provided by
%\begin{disp}\cs{ifcase}\gr{number}\gr{case$_0$}\cs{or}\n{...}\cs{or}%
% \gr{case$_n$}\cs{else}\gr{other cases}\cs{fi}\end{disp}
%where the \cs{else}-part is optional. The tokens for \gr{case$_i$}
%are processed if the number turns out to be~$i$; other cases are
%skipped, similarly to what ordinarily happens in conditionals
%(see Chapter~\ref{if}).
A numeric case statement is provided by
\begin{disp}\cs{ifcase}\gr{number}\gr{case$_0$}\cs{or}\n{...}\cs{or}%
\gr{case$_n$}\cs{else}\gr{other cases}\cs{fi}\end{disp}
where the \cs{else}-part is optional. The tokens for \gr{case$_i$}
are processed if the number turns out to be~$i$; other cases are
skipped, similarly to what ordinarily happens in conditionals
(see Chapter~\ref{if}).
%%\point Remarks
%\section{Remarks}
%\point Remarks
\section{Remarks}
%%\spoint Character constants
%\subsection{Character constants}
%\spoint Character constants
\subsection{Character constants}
%In formats and macro collections numeric constants
%are often needed. There are several ways to implement these
%in \TeX.
In formats and macro collections numeric constants
are often needed. There are several ways to implement these
in \TeX.
%Firstly,
%\begin{verbatim}
%\newcount\SomeConstant \SomeConstant=42
%\end{verbatim}
%This is wasteful, as it uses up a \cs{count} register.
Firstly,
\begin{verbatim}
\newcount\SomeConstant \SomeConstant=42
\end{verbatim}
This is wasteful, as it uses up a \cs{count} register.
%Secondly,
%\begin{verbatim}
%\def\SomeConstant{42}
%\end{verbatim}
%Better but accident prone: \TeX\ has to expand to find the number
% \ldash which in itself is a slight overhead \rdash and may inadvertently
%expand some tokens that should have been left alone.
Secondly,
\begin{verbatim}
\def\SomeConstant{42}
\end{verbatim}
Better but accident prone: \TeX\ has to expand to find the number
\ldash which in itself is a slight overhead \rdash and may inadvertently
expand some tokens that should have been left alone.
%Thirdly,
%\begin{verbatim}
%\chardef\SomeConstant=42
%\end{verbatim}
%This one is fine.
%A \gr{chardef token} has the same status as a \cs{count}
%register: both are \gr{internal integer}s.
%Therefore a number defined this way can be used everywhere that
%a \cs{count} register is feasible.
%For large numbers the \cs{chardef} can be replaced by \cs{mathchardef},
%which runs to \verb>"7FFF>${}=32\,767$.
%Note that a \gr{mathchardef token} can usually only appear
%in math mode, but in the context of a number it can appear anywhere.
Thirdly,
\begin{verbatim}
\chardef\SomeConstant=42
\end{verbatim}
This one is fine.
A \gr{chardef token} has the same status as a \cs{count}
register: both are \gr{internal integer}s.
Therefore a number defined this way can be used everywhere that
a \cs{count} register is feasible.
For large numbers the \cs{chardef} can be replaced by \cs{mathchardef},
which runs to \verb>"7FFF>${}=32\,767$.
Note that a \gr{mathchardef token} can usually only appear
in math mode, but in the context of a number it can appear anywhere.
%%\spoint Expanding too far / how far
%\subsection{Expanding too far / how far}
%\spoint Expanding too far / how far
\subsection{Expanding too far / how far}
%It is a common mistake to write pieces of \TeX\ code
%where \TeX\ will inadvertently expand something because it
%is trying to compose a number. For example:
%\begin{verbatim}
%\def\par{\endgraf\penalty200}
%...\par \number\pageno
%\end{verbatim}
%Here the page number will be absorbed into the value of the penalty.
It is a common mistake to write pieces of \TeX\ code
where \TeX\ will inadvertently expand something because it
is trying to compose a number. For example:
\begin{verbatim}
\def\par{\endgraf\penalty200}
...\par \number\pageno
\end{verbatim}
Here the page number will be absorbed into the value of the penalty.
%Now consider
%\begin{verbatim}
%\newcount\midpenalty \midpenalty=200
%\def\par{\endgraf\penalty\midpenalty}
%...\par \number\pageno
%\end{verbatim}
%Here the page number is not scooped up by mistake:
%\TeX\ is trying to locate a \gr{number} after the \cs{penalty},
%and it finds a \gr{countdef token}. This is {\em not\/}
%converted to a representation in digits, so there is never any
%danger of the page number being touched.
Now consider