]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/doc/usd/22.trofftut/tt12
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / doc / usd / 22.trofftut / tt12
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).
4 .\"
5 .\"     @(#)tt12        8.1 (Berkeley) 6/8/93
6 .\" Copyright (C) Caldera International Inc. 2001-2002.  All rights reserved.
7 .\" 
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions are
10 .\" met:
11 .\" 
12 .\" Redistributions of source code and documentation must retain the above
13 .\" copyright notice, this list of conditions and the following
14 .\" disclaimer.
15 .\" 
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.
19 .\" 
20 .\" All advertising materials mentioning features or use of this software
21 .\" must display the following acknowledgement:
22 .\" 
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
27 .\" permission.
28 .\" 
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.
41 .\" 
42 .\" $FreeBSD$
43 .\"
44 .NH
45 Conditionals
46 .PP
47 Suppose we want the
48 .BD .SH
49 macro to leave two extra inches of space just before section 1,
50 but nowhere else.
51 The cleanest way to do that is to test inside the
52 .BD .SH
53 macro
54 whether
55 the section number is 1,
56 and add some space if it is.
57 The
58 .BD .if
59 command provides the conditional test
60 that we can add
61 just before the heading line is output:
62 .P1 4
63 ^if \e\en(SH=1 ^sp 2i   \e" first section only
64 .P2
65 .PP
66 The condition after the
67 .BD .if
68 can be any arithmetic or logical expression.
69 If the condition is logically true, or arithmetically greater than zero,
70 the rest of the line is treated as if
71 it were text _
72 here a command.
73 If the condition is false, or zero or negative,
74 the rest of the line is skipped.
75 .PP
76 It is possible to do more than one command if a condition is true.
77 Suppose several operations are to be done before section 1.
78 One possibility is to define a macro 
79 .BD .S1
80 and invoke it
81 if we are about to do section 1
82 (as determined by an
83 .BD .if ).
84 .P1
85 ^de S1
86 ---  processing for section 1 ---
87 ^^
88 ^de SH
89 ^^^
90 ^if \e\en(SH=1 ^S1
91 ^^^
92 ^^
93 .P2
94 .PP
95 An alternate way is to use the
96 extended form of the
97 .BD .if ,
98 like this:
99 .P1
100 ^if \e\en(SH=1 \e{--- processing
101 for section 1 ----\e}
102 .P2
103 The braces
104 .BD \e{
105 and
106 .BD \e}
107 must occur in the positions shown
108 or you will get unexpected extra lines in your output.
109 .UL troff
110 also provides
111 an `if-else' construction,
112 which we will not go into here.
113 .PP
114 A condition can be negated by preceding it with
115 .BD ! ;
116 we get the same effect as above (but less clearly) by using
117 .P1
118 ^if !\e\en(SH>1 ^S1
119 .P2
120 .PP
121 There are a handful of 
122 other conditions that can be tested with
123 .BD .if .
124 For example, is the current page even or odd?
125 .P1
126 ^if o ^tl 'odd page title''- % -'
127 ^if e ^tl '- % -''even page title'
128 .P2
129 gives facing pages different titles and page numbers on the
130 outside edge when used inside an appropriate new page macro.
131 .PP
132 Two other conditions
133 are
134 .BD t
135 and
136 .BD n ,
137 which tell you whether the formatter is
138 .UL troff
139 or
140 .UL nroff . 
141 .P1
142 ^if t troff stuff ...
143 ^if n nroff stuff ...
144 .P2
145 .PP
146 Finally, string comparisons may be made in an
147 .BD .if :
148 .P1
149 ^if  'string1'string2'  stuff
150 .P2
151 does `stuff' if
152 .ul
153 string1
154 is the same as
155 .ul
156 string2.
157 The character separating the strings can be anything
158 reasonable that is
159 not contained in either string.
160 The strings themselves can reference strings with
161 .BD \e* ,
162 arguments with 
163 .BD \e$ ,
164 and so on.