Debian Codegraph @

texmf-dist/doc/latex/fitch/fitch.hacker.txt

raw
1 This file describes the internals of the macros in fitch.sty. It is
2 intended for programmers who might want to hack this package. For
3 information on how to use the package, please see the user guide,
4 which is provided in the file fitchdoc.tex.
5
6 GENERAL
7
8 Global identifiers defined by this package start with '\nd@'. The only
9 exceptions are \ndref, \nddim, \ndindent, and the "nd" and "ndresume"
10 latex environments.
11
12 The macros provided by this package mix TeX and LaTeX primitives.
13 LaTeX is used for \rule, \settowidth, \addtolength, \hspace... All
14 macros are assumed to be called in math mode.
15
16 Translation proceeds through several layers of macros. Each layer
17 consist of macros which expand into macros of the previous layer. Each
18 layer may have some global state and initialization functions. Only
19 the topmost layer (layer D) is directly user-accessible.
20
21 REFERENCES
22
23 We start with some macros to facilitate automatic line numbering, and
24 for referencing of lines by labels. The macros defined here are:
25 \nd@reset to reset the line number count. \nd@num{x}, to generate the
26 next line number and store it in reference x; \nd@ref{x} to print the
27 line number referenced by x, \ndref{xxx} to parse a list of
28 references, separated by commas, periods, and hyphens, and translate
29 all references to line numbers. Note: \ndref ignores spaces in its
30 argument, but puts a space after each comma or period in the
31 output. Also note: \nd@ref can be useful outside a natded environment,
32 and thus it has a user accessible name. Most general ``line numbers''
33 actually consist of a name (such as ``n'') and a number (such as
34 ``2''), to produce output such as $n+2$. \nd@set{n}{m} is called to
35 set the letter to n and the number to m. As special cases, if the
36 second argument is empty, it is not set, and if the first argument is
37 \relax, it is not set.
38
39 Example for references:
40
41 \nd@reset \nd@num{x}; \nd@num{y}; \nd@numopt{n+1}{z}; \nd@num{zz};
42 \nd@ref{y}; \ndref{x, y-zz, z}
43 will produce: 1; 2; n+1; 3; 2; 1, 2-3, n+1
44
45 LAYER A
46
47 Layer A provides primitive picture elements which can be combined into
48 natural deduction derivations. These are: \nd@t to make a topmost
49 vertical line segment; \nd@v to make a continuation vertical line
50 segment, \nd@i to produce the indentation for a subproof, \nd@s to
51 produce the horizontal space between a vertical line and a formula,
52 \nd@u{x} to underline x with appropriate spacing for a
53 hypothesis. \nd@f{x} typesets the formula x with the appropriate
54 vertical spacing. \nd@g{x} is like \nd@i, except it puts a guard in
55 the space it creates. These elements are spaced so that they are
56 appropriate as left-aligned array entries. Line numberings and
57 justifications must be provided manually in this layer. All explicit
58 spacing information is contained in this layer; higher layers
59 manipulate only layer A primitives.
60
61 Example of a derivation using layer A syntax:
62
63 \[
64 \begin{array}{lll}
65 1 & \nd@t\nd@s\nd@f {P\vee Q} \\
66 2 & \nd@v\nd@s\nd@u {\neg Q} \\
67 3 & \nd@v\nd@i\nd@t\nd@s\nd@u {P} \\
68 4 & \nd@v\nd@i\nd@v\nd@s\nd@f {P} & \mbox{by 3} \\
69 5 & \nd@v\nd@i\nd@t\nd@s\nd@u {Q} \\
70 6 & \nd@v\nd@i\nd@v\nd@s\nd@f {\neg Q} & \mbox{by 2} \\
71 7 & \nd@v\nd@i\nd@v\nd@s\nd@f {\bot} & \mbox{by 5, 6} \\
72 8 & \nd@v\nd@i\nd@v\nd@s\nd@f {P} & \mbox{by 7} \\
73 9 & \nd@v\nd@s\nd@f {P} & \mbox{by 1, 3-4, 5-8} \\
74 \end{array}
75 \]
76
77 LISTS
78
79 This is a bit of a hack. We implement linked lists as follows: a list
80 is either \nd@nil, or \nd@cons{T}{H}, where T is another list, and H
81 is some arbitrary code. Note that lists grow to the right. The
82 following macros operate on a list that is stored in a macro \list.
83
84 \nd@push\list{item} pushes the item onto the list
85 \nd@pop\list{item} pops and discards the last item from the list
86 \nd@item\list{command} applies command to each element of the list
87 \nd@modify\list\n{elt} modifies the \n-th element of the
88 list, if there is such an element. Here \n is a counter. Elements
89 are counted from the right, starting from 1.
90
91 We use lists of items of the forms \nd@t, \nd@v, \nd@i, and \nd@g{...}
92 to represent the current indentation level and format (see Layer A,
93 above). The function \nd@cont computes the indentation for the
94 following line by replacing all items of the form \nd@t by \nd@v and
95 \nd@g{...} by \nd@i.
96
97 With the list syntax, a derivation can be expressed like this:
98
99 \[
100 \begin{array}{lll}
101 \gdef\stack{\nd@nil}
102 \newcount\n
103 \nd@push\stack{\nd@t}
104 1 & \nd@iter\stack\relax\nd@s\nd@u {\neg\exists xP(x)} \\
105 \nd@cont\stack
106 \nd@push\stack{\nd@i}
107 \nd@push\stack{\nd@t}
108 \nd@n=2\nd@modify\stack\n{\nd@g{u}}
109 \nd@push\stack{\nd@i}
110 \nd@push\stack{\nd@t}
111 2 & \nd@iter\stack\relax\nd@s\nd@u {P(u)} \\
112 \nd@cont\stack
113 3 & \nd@iter\stack\relax\nd@s\nd@f {\exists xP(x)} \\
114 \nd@cont\stack
115 4 & \nd@iter\stack\relax\nd@s\nd@f {\neg\exists xP(x)} \\
116 \nd@cont\stack
117 5 & \nd@iter\stack\relax\nd@s\nd@f {\bot} \\
118 \nd@cont\stack
119 \nd@pop\stack
120 \nd@pop\stack
121 6 & \nd@iter\stack\relax\nd@s\nd@f {\neg P(u)} \\
122 \nd@cont\stack
123 \nd@pop\stack
124 \nd@pop\stack
125 7 & \nd@iter\stack\relax\nd@s\nd@f {\forall y\neg P(y)} \\
126 \nd@cont\stack
127 \end{array}
128 \]
129
130 LAYER B
131
132 Layer B is simply a wrapper around layer A. It provides commands
133 \nd@beginb, \nd@resumeb, \nd@endb, \nd@openb, \nd@closeb, \nd@guardb,
134 \nd@hypob, and \nd@haveb which abstract from the layer A
135 primitives. This includes automatic line numbering, and automatic
136 indentation. \nd@hypocontb and \nd@havecontb are like \nd@hypob and
137 \nd@haveb, except that they introduce continuation lines that are
138 slightly indented and have no line number/label. \nd@beginb and
139 \nd@endb enclose a natural deduction in layer B syntax. \nd@resumeb is
140 like \nd@beginb, except that it resumes a deduction in progress (for
141 instance, after a manual page break). \nd@openb and \nd@closeb open,
142 respectively close, a subproof. \nd@guardb{n}{g} adds the guard g to
143 the nth enclosing subderivation (counted from 1 from the
144 inside). \nd@hypob introduces a hypothesis, and \nd@haveb introduces a
145 non-hypothesis line in a proof. Line numbering is integrated, but
146 justifications must still be given manually. Also, proof lines must
147 still be terminated by '\\'. An idiosyncracy of this layer is that in
148 a list of several hypotheses, all but the last one must be called with
149 \nd@haveb, not \nd@hypob, to avoid drawing a horizontal line under
150 each of them.
151
152 Example of a derivation using layer B syntax. Note that the "line
153 numbers" are really labels, which will be replaced by consecutive line
154 numbers in the output.
155
156 \[
157 \nd@beginb
158 \nd@haveb {1}{P\vee Q} \\
159 \nd@hypob {2}{\neg Q} \\
160 \nd@openb
161 \nd@hypob {3}{P} \\
162 \nd@haveb {4}{P} \mbox{by \ndref{3}} \\
163 \nd@closeb
164 \nd@openb
165 \nd@hypob {5}{Q} \\
166 \nd@haveb {6}{\neg Q} \mbox{by \ndref{2}} \\
167 \nd@haveb {6a}{\bot} \mbox{by \ndref{5,6}} \\
168 \nd@haveb {6b}{P} \mbox{by \ndref{6a}} \\
169 \nd@closeb
170 \nd@haveb {8}{P} \mbox{by \ndref{1,3-4,5-6b}} \\
171 \nd@endb
172 \]
173
174 Here is another example, using a guard.
175
176 \[
177 \nd@beginb
178 \nd@hypob {1}{\neg\exists xP(x)} \\
179 \nd@openb
180 \nd@guardb {1}{u}
181 \nd@openb
182 \nd@hypob {2}{P(u)} \\
183 \nd@haveb {3}{\exists xP(x)} \mbox{by \ndref{2}} \\
184 \nd@haveb {4}{\neg\exists xP(x)} \mbox{by \ndref{1}} \\
185 \nd@haveb {5}{\bot} \mbox{by \ndref{3,4}}\\
186 \nd@closeb
187 \nd@haveb {6}{\neg P(u)} \mbox{by \ndref{2-5}}\\
188 \nd@closeb
189 \nd@haveb {7}{\forall y\neg P(y)} \mbox{by \ndref{2-6}}\\
190 \nd@endb
191 \]
192
193 LAYER C
194
195 Layer C is a wrapper around layer B. It takes care of buffering
196 information and putting it correctly into an array. Specifically, in
197 layer C, it is no more necessary to explicitly give '\\', and all
198 hypotheses are denoted \hypo. Layer C also provides a convenient
199 syntax for writing justification labels. Further, layer C provides
200 ``multi-line'' commands, thus e.g. \nd@mhypoc{a}{x\\y\\z} is an
201 abbreviation for \nd@hypoc{a}{x}\nd@hypocontc{y}\nd@hypocontc{z}. In
202 addition there is a \nd@by command for writing justification labels,
203 in the style of \nd@by{$\vee$E}{1,2-4,5-6}.
204
205 Commands exported by layer C are: \nd@hypoc, \nd@havec, \nd@hypocontc,
206 \nd@havecontc, \nd@mhypoc, \nd@mhavec, \nd@mhypocontc, \nd@mhavecontc,
207 \nd@by, \nd@beginc, \nd@resumec, \nd@endc, \nd@openc, \nd@closec,
208 \nd@guardc.
209
210 The layer C macros work by storing each line in a data structure
211 \ppp,\nd@typ,\nd@byt. The line is ejected when the beginning of the
212 next line is read, and once at the very end. In this way, we can put
213 in the correct line breaks (whether or not the line carries a
214 justification), and a hypothesis does not get typeset until we know
215 whether it is followed by another hypothesis. \nd@sto stores a new
216 line, \nd@clr clears the current line, \nd@cmd outputs the current
217 line.
218
219 Example of layer C syntax:
220
221 \[
222 \nd@beginc
223 \nd@hypoc {1}{\neg\exists xP(x)}
224 \nd@openc
225 \nd@guardc {1}{u}
226 \nd@openc
227 \nd@hypoc {2}{P(u)}
228 \nd@havec {3}{\exists xP(x)} \nd@by{$\exists$I}{2}
229 \nd@havec {4}{\neg\exists xP(x)} \nd@by{R}{1}
230 \nd@havec {5}{\bot} \nd@by{$\neg$E}{3,4}
231 \nd@closec
232 \nd@havec {6}{\neg P(u)} \nd@by{$\neg$I}{2-5}
233 \nd@closec
234 \nd@havec {7}{\forall y\neg P(y)} \nd@by{$\forall$I}{2-6}
235 \nd@endc
236 \]
237
238 LAYER D
239
240 Layer D is the syntax used by the end user. It is implemented as a
241 wrapper around layer C, providing three additional conveniences: (1) a
242 latex environment, (2) guard as optional argument to \have, \hypo, or
243 \open, (3) optional relabeling arguments. The user level commands are
244 similar to those of layer C: they are called \begin{nd}, \end{nd},
245 \open, \close, \hypo, \have, \guard, \by. For convenience, a number
246 of abbreviations are also provided for writing justifications. For
247 instance \ie for \by{$\Rightarrow$E} etc. These commands are only
248 visible inside an nd-environment; thus they do not interfere with the
249 global name space. There is also an environment ndresume which is like
250 nd, except that it continues a proof in progress (with continuous
251 nesting and labeling).
252
253 The macros \nd@hypod, \nd@haved, \nd@opend, \nd@guardd are essentially
254 the user-level macros, but with all optional argument spelled-out. The
255 versions without the final "d" allow the optional arguments to be
256 omitted.
257
258 The functions \nd@optarg and \nd@optargg are used to handle optional
259 arguments. Usage: \nd@optarg{default}{continuation}xxx - reads an
260 optional argument, supplies default if necessary, then continues with
261 continuation. Continuation expects optional argument between
262 [...]. I.e., \nd@optarg{d}{c}[xxx] => c[xxx], and \nd@optarg{d}{c}x =>
263 c[d]x if x != '['. Behavior is undefined if x is {[...}. \nd@optargg
264 is similar except it takes two continuations: first one for optional
265 argument present, second for not present. It takes no default value.
266
267 The function \nd@five{\a} reads five, partly optional arguments of the
268 shape [][]{}[]{}, then call \a with these arguments.
269
270 Finally, \nd@init puts all the commands which are visible inside an
271 nd-environment in the current name space.
272
273 Example of a derivation using layer D syntax. As before, the "line
274 numbers" are really labels, which will be replaced by consecutive line
275 numbers in the output.
276
277 \[
278 \begin{nd}
279 \hypo{1} {P\vee Q}
280 \hypo{2} {\neg Q}
281 \open
282 \hypo{3a} {P}
283 \have{3b} {P} \r{3a}
284 \close
285 \open
286 \hypo{4a} {Q}
287 \have{4b} {\neg Q} \r{2}
288 \have{4c} {\bot} \ne{4a,4b}
289 \have{4d} {P} \be{4c}
290 \close
291 \have{5} {P} \oe{1,3a-3b,4a-4d}
292 \end{nd}
293 \]
294
295 Another example of layer D syntax, using guards and relabelings:
296
297 \[
298 \begin{nd}
299 \hypo {1} {P\vee Q}
300 \open[u]
301 \hypo {2} {P}
302 \have [\vdots] {3} {\vdots}
303 \have [n][-1] {4} {A\wedge B}
304 \close
305 \open
306 \hypo {5} {Q}
307 \have [\vdots] {6} {\vdots}
308 \have [m] {7} {A\wedge B}
309 \close
310 \have {8} {A\wedge B} \oe{1,2-(4),5-7}
311 \have [\vdots] {9} {\vdots}
312 \have [][100] {10} {A} \ae{8}
313 \end{nd}
314 \]