1 .\" This module is believed to contain source code proprietary to AT&T.
2 .\" Use and redistribution is subject to the Berkeley Software License
3 .\" Agreement and your Software Agreement with AT&T (Western Electric).
5 .\" @(#)tt10 8.1 (Berkeley) 6/8/93
6 .\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions are
12 .\" Redistributions of source code and documentation must retain the above
13 .\" copyright notice, this list of conditions and the following
16 .\" Redistributions in binary form must reproduce the above copyright
17 .\" notice, this list of conditions and the following disclaimer in the
18 .\" documentation and/or other materials provided with the distribution.
20 .\" All advertising materials mentioning features or use of this software
21 .\" must display the following acknowledgement:
23 .\" This product includes software developed or owned by Caldera
24 .\" International, Inc. Neither the name of Caldera International, Inc.
25 .\" nor the names of other contributors may be used to endorse or promote
26 .\" products derived from this software without specific prior written
29 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
30 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
31 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 .\" DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
34 .\" FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
37 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
39 .\" OR OTHERWISE) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
40 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 Number Registers and Arithmetic
48 has a facility for doing arithmetic,
49 and for defining and using variables with numeric values,
53 Number registers, like strings and macros, can be useful in setting up a document
54 so it is easy to change later.
55 And of course they serve for any sort of arithmetic computation.
57 Like strings, number registers have one or two character names.
61 and are referenced anywhere by
63 (one character name) or
67 There are quite a few pre-defined number registers maintained by
71 for the current page number;
73 for the current vertical position on the page;
78 for the current day, month and year; and
82 for the current size and font.
83 (The font is a number from 1 to 4.)
84 Any of these can be used in computations like any other register,
89 cannot be changed with
92 As an example of the use of number registers,
96 most significant parameters are defined in terms of the values
97 of a handful of number registers.
98 These include the point size for text, the vertical spacing,
99 and the line and title lengths.
100 To set the point size and vertical spacing for the following paragraphs, for example, a user may say
107 is defined (roughly) as follows:
111 ^ps \e\en(PS \e" reset size
112 ^vs \e\en(VSp \e" spacing
114 ^sp 0.5v \e" half a line
118 This sets the font to Roman and the point size and line spacing
119 to whatever values are stored in the number registers
124 Why are there two backslashes?
125 This is the eternal problem of how to quote a quote.
128 originally reads the macro definition,
129 it peels off one backslash
130 to see what's coming next.
131 To ensure that another is left in the definition when the
135 we have to put in two backslashes in the definition.
136 If only one backslash is used,
137 point size and vertical spacing will be frozen at the time the macro
138 is defined, not when it is used.
140 Protecting by an extra layer of backslashes
145 (which we haven't come to yet),
154 and so on do not need an extra backslash,
155 since they are converted by
157 to an internal code immediately upon being seen.
160 Arithmetic expressions can appear anywhere that
161 a number is expected.
162 As a trivial example,
167 Expressions can use the arithmetic operators +, \-, *, /, % (mod),
168 the relational operators >, >=, <, <=, =, and != (not equal),
171 Although the arithmetic we have done so far
172 has been straightforward,
173 more complicated things are somewhat tricky.
175 number registers hold only integers.
177 arithmetic uses truncating integer division, just like Fortran.
178 Second, in the absence of parentheses,
179 evaluation is done left-to-right
180 without any operator precedence
181 (including relational operators).
187 Number registers can occur anywhere in an expression,
188 and so can scale indicators like
192 and so on (but no spaces).
193 Although integer division causes truncation,
194 each number and its scale indicator is converted
195 to machine units (1/432 inch) before any arithmetic is done,
205 when you wouldn't expect it _
206 in particular, when arithmetic is being done
207 in a context that implies horizontal or vertical dimensions.
212 would seem obvious enough _
215 Remember that the default units for horizontal parameters like
218 That's really `7 ems / 2 inches',
219 and when translated into machine units, it becomes zero.
224 Sorry, still no good _
225 the `2' is `2 ems', so `7i/2' is small,
234 So again, a safe rule is to
235 attach a scale indicator to every number,
238 For arithmetic done within a
241 there is no implication of horizontal or vertical dimension,
242 so the default units are `units',
250 does just what you want,