Debian Codegraph @

texmf-dist/source/latex/ebproof/ebproof.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2015-2021 by Emmanuel Beffara
4 %
5 % This file may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License, either version 1.3 of this license or (at
7 % your option) any later version. The latest version of this license is in:
8 %
9 % http://www.latex-project.org/lppl.txt
10 %
11 % and version 1.3 or later is part of all distributions of LaTeX version
12 % 2005/12/01 or later.
13 %
14 %<*driver>
15 \documentclass[full]{l3doc}
16 \usepackage{ebproof}
17 \usepackage{multicol}
18 \usepackage{tikz}
19 \usetikzlibrary{decorations.pathmorphing}
20 \EnableCrossrefs
21 \newenvironment{example}{%
22 \VerbatimEnvironment
23 \begin{VerbatimOut}{example.tex}}{%
24 \end{VerbatimOut}
25 \begin{center}
26 \begin{minipage}{.4\textwidth}
27 \input{example.tex}
28 \end{minipage}%
29 \begin{minipage}{.6\textwidth}
30 \small\VerbatimInput[gobble=0]{example.tex}
31 \end{minipage}%
32 \end{center}
33 }
34 \begin{document}
35 \DocInput{\jobname.dtx}
36 \end{document}
37 %</driver>
38 % \fi
39 %
40 % \title{^^A
41 % The \pkg{ebproof} package \\
42 % Formal proofs in the style of sequent calculus^^A
43 % }
44 %
45 % \author{^^A
46 % Emmanuel Beffara\thanks
47 % {^^A
48 % E-mail: \href{mailto:[email protected]}{[email protected]}^^A
49 % }^^A
50 % }
51 %
52 % \date{Version 2.1.1 -- Released 2021-01-28}
53 %
54 % \maketitle
55 %
56 % \setcounter{tocdepth}{2}
57 % \begin{multicols}{2}
58 % \tableofcontents
59 % \end{multicols}
60 %
61 % \begin{documentation}
62 %
63 % \section{Introduction}
64 %
65 % The \pkg{ebproof} package provides commands to typeset proof trees, in the
66 % style of sequent calculus and related systems:
67 %
68 % \begin{example}
69 % \begin{prooftree}
70 % \hypo{ \Gamma, A &\vdash B }
71 % \infer1[abs]{ \Gamma &\vdash A\to B }
72 % \hypo{ \Gamma \vdash A }
73 % \infer2[app]{ \Gamma \vdash B }
74 % \end{prooftree}
75 % \end{example}
76 %
77 % The structure is very much inspired by the
78 % \href{http://math.ucsd.edu/~sbuss/ResearchWeb/bussproofs/}{\pkg{bussproofs}}
79 % package, in particular for the postfix notation.
80 % I actually wrote \pkg{ebproof} because there were some limitations in
81 % \pkg{bussproofs} that I did not know how to lift, and also because I did
82 % not like some choices in that package (and also because it was fun to write).
83 %
84 % Any feedback is welcome, in the form of bug reports, feature requests or
85 % suggestions, through the web page of the project at \url{https://framagit.org/manu/ebproof}.
86 %
87 % \section{Environments}
88 %
89 % \begin{function}{prooftree,prooftree*}
90 % \begin{syntax}
91 % \verb|\begin{prooftree}|\oarg{options}
92 % ~ \meta{statements}
93 % \verb|\end{prooftree}|
94 % \end{syntax}
95 % The package provides the \env{prooftree} environment, in standard and
96 % starred variants.
97 % This typesets the proof tree described by the \meta{statements}, as
98 % described in section~\ref{sec:statements}.
99 % The \meta{options} provide default formatting options for the proof tree,
100 % available options are described in section~\ref{sec:options}.
101 %
102 % Following the conventions of \pkg{amsmath} for alignment environments, the
103 % non-starred version produces a proof tree at the current position in the
104 % text flow (it can be used in math mode or text mode) while the starred
105 % version typesets the proof on a line of its own, like a displayed formula.
106 % \end{function}
107 %
108 % \begin{example}
109 % \[
110 % \begin{prooftree}
111 % \infer0{ \vdash A }
112 % \hypo{ \vdash B } \infer1{ \vdash B, C }
113 % \infer2{ \vdash A\wedge B, C }
114 % \end{prooftree}
115 % \quad \rightsquigarrow \quad
116 % \begin{prooftree}
117 % \infer0{ \vdash A } \hypo{ \vdash B }
118 % \infer2{ \vdash A\wedge B }
119 % \infer1{ \vdash A\wedge B, C }
120 % \end{prooftree}
121 % \]
122 % \end{example}
123 %
124 % \section{Statements}
125 % \label{sec:statements}
126 %
127 % Statements describe proofs in postfix notation: when typesetting a proof tree
128 % whose last rule has, say, two premisses, you will first write statements for
129 % the subtree of the first premiss, then statements for the subtree of the
130 % second premiss, then a statement like \cs{infer2}\{\meta{conclusion}\} to
131 % build an inference with these two subtrees as premisses and the given text as
132 % conclusion.
133 %
134 % Hence statements operate on a stack of proof trees.
135 % At the beginning of a \env{prooftree} environment, the stack is empty.
136 % At the end, it must contain exactly one tree, which is the one that will be
137 % printed.
138 %
139 % Note that the commands defined in this section only exist right inside
140 % \env{prooftree} environments.
141 % If you have a macro with the same name as one of the statements, for instance
142 % \cs{hypo}, then this macro will keep its meaning outside \env{prooftree}
143 % environments as well as inside the arguments of a statement.
144 % If you really need to access the statements in another context, you can can
145 % always call them by prefixing their names with \texttt{ebproof}, for instance as
146 % \cs{ebproofhypo}.
147 %
148 % \subsection{Basic statements}
149 %
150 % The basic statements for building proofs are the following, where
151 % \meta{options} stands for arbitrary options as described in
152 % section~\ref{sec:options}.
153 %
154 % \begin{function}{\hypo}
155 % \begin{syntax}
156 % \cs{hypo}\oarg{options}\marg{text}
157 % \end{syntax}
158 % The statement \cs{hypo} pushes a new proof tree consisting only in one
159 % conclusion line, with no premiss and no line above, in other words a tree
160 % with only a leaf (\cs{hypo} stands for \emph{hypothesis}).
161 % \end{function}
162 %
163 % \begin{function}{\infer}
164 % \begin{syntax}
165 % \cs{infer}\oarg{options}\meta{arity}\oarg{label}\marg{text}
166 % \end{syntax}
167 % The statement \cs{infer} builds an inference step by taking some proof
168 % trees from the top of the stack, assembling them with a rule joining their
169 % conclusions and putting a new conclusion below.
170 % The \meta{arity} is the number of sub-proofs, it may be any number
171 % including 0 (in this case there will be a line above the conclusion but no
172 % sub-proof).
173 % If \meta{label} is present, it is used as the label on the right of the
174 % inference line; it is equivalent to using the \cmd{right label} option.
175 % \end{function}
176 %
177 % \medskip
178 %
179 % The \meta{text} in these statements is the contents of the conclusion at the
180 % root of the tree that the statements create.
181 % It is typeset in math mode by default but any kind of formatting can be used
182 % instead, using the \cmd{template} option.
183 % The \meta{label} text is formatted in horizontal text mode by default.
184 %
185 % Each proof tree has a vertical axis, used for alignment of successive steps.
186 % The position of the axis is deduced from the text of the conclusion at the
187 % root of the tree: if \meta{text} contains the alignment character \verb|&|
188 % then the axis is set at that position, otherwise the axis is set at the center
189 % of the conclusion text.
190 % The \cs{infer} statement makes sure that the axis of the premiss is at the
191 % same position as the axis of the conclusion.
192 % If there are several premisses, it places the axis at the center between the
193 % left of the leftmost conclusion and the right of the rightmost conclusion:
194 %
195 % \begin{example}
196 % \begin{prooftree}
197 % \hypo{ &\vdash A, B, C }
198 % \infer1{ A &\vdash B, C }
199 % \infer1{ A, B &\vdash C }
200 % \hypo{ D &\vdash E }
201 % \infer2{ A, B, D &\vdash C, E }
202 % \infer1{ A, B &\vdash C, D, E }
203 % \infer1{ A &\vdash B, C, D, E }
204 % \end{prooftree}
205 % \end{example}
206 %
207 % \begin{function}{\ellipsis}
208 % \begin{syntax}
209 % \cs{ellipsis}\marg{label}\marg{text}
210 % \end{syntax}
211 % The statement \cs{ellipsis} typesets vertical dots, with a label on the right,
212 % and a new conclusion. No inference lines are inserted.
213 % \end{function}
214 %
215 % \begin{example}
216 % \begin{prooftree}
217 % \hypo{ \Gamma &\vdash A }
218 % \ellipsis{foo}{ \Gamma &\vdash A, B }
219 % \end{prooftree}
220 % \end{example}
221 %
222 %
223 % \subsection{Modifying proof trees}
224 %
225 % The following additional statements may be used to affect the format of the
226 % last proof tree on the stack.
227 %
228 % \begin{function}{\rewrite}
229 % \begin{syntax}
230 % \cs{rewrite}\marg{code}
231 % \end{syntax}
232 % The statement \cs{rewrite} is used to modify the proof of the stack while
233 % preserving its size and alignment.
234 % The \meta{code} is typeset in horizontal mode, with the following control
235 % sequences defined:
236 % \begin{itemize}
237 % \item \cs{treebox} is a box register that contains the original material,
238 % \item \cs{treemark}\marg{name} expands as the position of a given mark with
239 % respect to the left of the box.
240 % \end{itemize}
241 % \end{function}
242 %
243 % A simple use of this statement is to change the color of a proof tree:
244 % \begin{example}
245 % \begin{prooftree}
246 % \hypo{ \Gamma, A &\vdash B }
247 % \infer1[abs]{ \Gamma &\vdash A\to B }
248 % \rewrite{\color{red}\box\treebox}
249 % \hypo{ \Gamma \vdash A }
250 % \infer2[app]{ \Gamma \vdash B }
251 % \end{prooftree}
252 % \end{example}
253 % Note the absence of spaces inside the call to \cs{rewrite}, because spaces
254 % would affect the position of the tree box.
255 % Note also that explicit use of \cs{treebox} is required to actually draw the
256 % subtree.
257 % Not using it will effectively not render the subtree, while still reserving
258 % its space in the enclosing tree:
259 % \begin{example}
260 % \begin{prooftree}
261 % \hypo{ \Gamma, A &\vdash B }
262 % \infer1[abs]{ \Gamma &\vdash A\to B }
263 % \rewrite{}
264 % \hypo{ \Gamma \vdash A }
265 % \infer2[app]{ \Gamma \vdash B }
266 % \end{prooftree}
267 % \end{example}
268 % This kind of manipulation is useful for instance in conjunction with the
269 % \pkg{beamer} package to allow revealing subtrees of a proof tree
270 % progressively in successive slides of a given frame.
271 %
272 % \begin{function}{\delims}
273 % \begin{syntax}
274 % \cs{delims}\marg{left}\marg{right}
275 % \end{syntax}
276 % The statement \cs{delims} puts left and right delimiters around the whole
277 % sub-proof, without changing the alignment (the spacing is affected by the
278 % delimiters, however).
279 % The \meta{left} text must contain an opening occurrence of \cs{left} and
280 % the \meta{right} text must contain a matching occurrence of \cs{right}.
281 % For instance, \verb|\delims{\left(}{\right)}| will put the sub-proof
282 % between parentheses.
283 % \end{function}
284 %
285 % \begin{example}
286 % \begin{prooftree}
287 % \hypo{ A_1 \vee \cdots \vee A_n }
288 % \hypo{ [A_i] }
289 % \ellipsis{}{ B }
290 % \delims{ \left( }{ \right)_{1\leq i\leq n} }
291 % \infer2{ B }
292 % \end{prooftree}
293 % \end{example}
294 %
295 % \begin{function}{\overlay}
296 % \begin{syntax}
297 % \cs{overlay}
298 % \end{syntax}
299 % The statement \cs{overlay} combines the last two proofs on the stack into
300 % a single one, so that their conclusions are placed at the same point.
301 % \end{function}
302 %
303 % \begin{example}
304 % \begin{prooftree}
305 % \hypo{Z}
306 % \hypo{A} \hypo{B} \infer2{C} \hypo{D} \infer2{D}
307 % \rewrite{\color{blue}\box\treebox}
308 % \hypo{E} \hypo{F} \hypo{G} \infer2{H} \infer2{I}
309 % \rewrite{\color{red}\box\treebox}
310 % \overlay \hypo{J} \infer3{K}
311 % \end{prooftree}
312 % \end{example}
313 %
314 % The primary use of this feature is for building animated presentations where
315 % a subtree in a proof has to be modified without affecting the general
316 % alignment of the surrounding proof. For instance, the example above could be
317 % used in Beamer to build successive slides in a given frame with two
318 % different subtrees:
319 %
320 % \begin{verbatim}
321 % \begin{prooftree}
322 % \hypo{Z}
323 % \hypo{A} \hypo{B} \infer2{C} \hypo{D} \infer2{D}
324 % \only<2>{\rewrite{}} % erases this version on slide 2
325 % \hypo{E} \hypo{F} \hypo{G} \infer2{H} \infer2{I}
326 % \only<1>{\rewrite{}} % erases this version on slide 1
327 % \overlay \hypo{J} \infer3{K}
328 % \end{prooftree}
329 % \end{verbatim}
330 %
331 % \section{Options}
332 % \label{sec:options}
333 %
334 % The formatting of trees, conclusion texts and inference rules is affected by
335 % options, specified using the \LaTeX3 key-value system.
336 % All options are in the \texttt{ebproof} module in the key tree.
337 % They can be set locally for a proof tree or for a single statement using
338 % optional arguments in the associated commands.
339 %
340 % \begin{function}{\ebproofset,\set}
341 % \begin{syntax}
342 % \cs{ebproofset}\marg{options}
343 % \end{syntax}
344 % The statement \cs{ebproofset} is used to set some options. When used
345 % inside a \env{prooftree} environment, it can written \cs{set}.
346 % The options will apply in the current scope; using this in preamble will
347 % effectively set options globally.
348 % Specific options may also be specified for each proof tree and for each
349 % statement in a proof tree, using optional arguments.
350 % \end{function}
351 %
352 % \subsection{General shape}
353 %
354 % The options in this section only make sense at the global level and at the
355 % proof level.
356 % Changing the proof style inside a \env{proof} environment has undefined
357 % behaviour.
358 %
359 % \begin{variable}{proof style}
360 % The option \cmd{proof style} sets the general shape for representing proofs.
361 % The following styles are provided:
362 % \begin{description}
363 % \item[upwards]
364 % This is the default style.
365 % Proof trees grow upwards, with conclusions below and premisses above.
366 % \item[downwards]
367 % Proof trees grow downwards, with conclusions above and premisses below.
368 % \fvset{gobble=6}
369 % \begin{example}
370 % \begin{prooftree}[proof style=downwards]
371 % \hypo{ \Gamma, A &\vdash B }
372 % \infer1[abs]{ \Gamma &\vdash A\to B }
373 % \hypo{ \Gamma \vdash A }
374 % \infer2[app]{ \Gamma \vdash B }
375 % \end{prooftree}
376 % \end{example}
377 % \end{description}
378 % \end{variable}
379 %
380 % In the optional argument of \env{prooftree} environments, proof styles can
381 % be specified directly, without prefixing the name by ``\texttt{proof style=}''.
382 % For instance, the first line of the example above could be written
383 % \verb|\begin{prooftree}| equivalently.
384 %
385 % \begin{variable}{center}
386 % The option \cmd{center} toggles vertical centering of typeset proofs.
387 % If set to \texttt{true}, the tree produced by the \env{prooftree}
388 % environment will be vertically centered around the text line.
389 % If set to \texttt{false}, the base line of the tree will be the base line
390 % of the conclusion.
391 % The default value is \texttt{true}.
392 % \end{variable}
393 %
394 % \begin{example}
395 % \begin{prooftree}[center=false]
396 % \infer0{ A \vdash A }
397 % \end{prooftree}
398 % \qquad
399 % \begin{prooftree}[center=false]
400 % \hypo{ \Gamma, A \vdash B }
401 % \infer1{ \Gamma \vdash A \to B }
402 % \end{prooftree}
403 % \end{example}
404 %
405 % \subsection{Spacing}
406 %
407 % \begin{variable}{separation}
408 % Horizontal separation between sub-proofs in an inference is defined by the
409 % option \cmd{separation}.
410 % The default value is \texttt{1.5em}.
411 % \end{variable}
412 %
413 % \begin{example}
414 % \begin{prooftree}[separation=0.5em]
415 % \hypo{ A } \hypo{ B } \infer2{ C }
416 % \hypo{ D } \hypo{ E } \hypo{ F } \infer3{ G }
417 % \hypo{ H } \infer[separation=3em]3{ K }
418 % \end{prooftree}
419 % \end{example}
420 %
421 % \begin{variable}{rule margin}
422 % The spacing above and below inference lines is defined by the option
423 % \cmd{rule margin}.
424 % The default value is \texttt{0.7ex}.
425 % \end{variable}
426 %
427 % \begin{example}
428 % \begin{prooftree}[rule margin=2ex]
429 % \hypo{ \Gamma, A &\vdash B }
430 % \infer1[abs]{ \Gamma &\vdash A\to B }
431 % \hypo{ \Gamma \vdash A }
432 % \infer2[app]{ \Gamma \vdash B }
433 % \end{prooftree}
434 % \end{example}
435 %
436 % \subsection{Shape of inference lines}
437 %
438 % \begin{variable}{rule style}
439 % The shape of inference lines is set by the option \cmd{rule style}.
440 % The following values are provided:
441 % \begin{center}
442 % \begin{tabular}{@{}l@{\qquad}l@{}}
443 % \toprule
444 % \cmd{simple} & a simple line (this is the default style) \\
445 % \cmd{no rule} & no rule, only a single space of length \texttt{rule margin} \\
446 % \cmd{double} & a double line \\
447 % \cmd{dashed} & a single dashed line \\
448 % \bottomrule
449 % \end{tabular}
450 % \end{center}
451 % \end{variable}
452 %
453 % The precise rendering is influenced by parameters specified below.
454 % Arbitrary new shapes can defined using the \cs{ebproofnewrulestyle} command
455 % described in section~\ref{sec:styles}, using \texttt{rule code} option
456 % described below.
457 %
458 % In the optional argument of the \cs{infer} statement, rule styles can be
459 % specified directly, without prefixing the style name by ``\texttt{rule style=}''.
460 % For instance, \verb|\infer[dashed]| is equivalent to
461 % \verb|\infer[rule style=dashed]|.
462 %
463 % \begin{example}
464 % \begin{prooftree}
465 % \hypo{ \Gamma &\vdash A \to B }
466 % \infer[no rule]1{ \Gamma &\vdash {!A} \multimap B }
467 % \hypo{ \Delta &\vdash A }
468 % \infer[rule thickness=2pt]1{ \Delta &\vdash {!A} }
469 % \infer0{ B \vdash B }
470 % \infer[dashed]2{ \Delta, {!A}\multimap B \vdash B }
471 % \infer2{ \Gamma, \Delta &\vdash B }
472 % \infer[double]1{ \Gamma \cup \Delta &\vdash B }
473 % \end{prooftree}
474 % \end{example}
475 %
476 % \begin{variable}{rule thickness,rule separation}
477 % The thickness of inference lines is defined by option \cmd{rule
478 % thickness}, it is \texttt{0.4pt} by default.
479 % The distance between the two lines in the \texttt{double} rule style is
480 % defined by the \cmd{rule separation} option.
481 % It is \texttt{2pt} by default.
482 % \end{variable}
483 % \begin{variable}{rule dash length,rule dash space}
484 % For dashed rules, the length of dashes is defined by the option
485 % \cmd{rule dash length} and the space between dashes is defined by the
486 % option \cmd{rule dash space}.
487 % The default values are \texttt{0.2em} and \texttt{0.3em} respectively.
488 % \end{variable}
489 %
490 % \begin{variable}{rule code}
491 % Arbitrary rule shapes can be optained using the \cmd{rule code} option.
492 % The argument is code is used to render the rule, it is executed in
493 % vertical mode in a \cs{vbox} whose \cs{hsize} is set to the width of the
494 % rule.
495 % Margins above and below are inserted automatically (they can be removed by
496 % setting \texttt{rule margin} to \texttt{0pt}).
497 % \end{variable}
498 %
499 % \begin{example}
500 % \begin{prooftree}[rule code={\hbox{\tikz
501 % \draw[decorate,decoration={snake,amplitude=.3ex}]
502 % (0,0) -- (\hsize,0);}}]
503 % \hypo{ \Gamma &\vdash A }
504 % \infer1{ \Gamma &\vdash A, \ldots, A }
505 % \hypo{ \Delta, A, \ldots, A \vdash \Theta }
506 % \infer2{ \Gamma, \Delta \vdash \Theta }
507 % \end{prooftree}
508 % \end{example}
509 % Note that this example requires the \pkg{tikz} package, with the
510 % \pkg{decorations.pathmorphing} library for the \texttt{snake} decoration.
511 %
512 % \subsection{Format of conclusions and labels}
513 %
514 % \begin{variable}{template,left template,right template}
515 % The format of text in inferences is defined by templates.
516 % The option \cmd{template} is used for text with no alignment mark, the
517 % options \cmd{left template} and \cmd{right template} are used for the left
518 % and right side of the alignment mark when it is present.
519 % The value of these options is arbitrary \TeX\ code, composed in horizontal mode.
520 % The macro \cs{inserttext} is used to insert the actual text passed to the
521 % \cs{hypo} and \cs{infer} statements.
522 % The default value for \cmd{template} is simply \verb|$\inserttext$|, so
523 % that conclusions are set in math mode.
524 % The default values for \cmd{left template} and \cmd{right template} are
525 % similar, with spacing assuming that a relation symbol is put near the
526 % alignment mark, so that \verb|\infer1{A &\vdash B}| is spaced correctly.
527 % \end{variable}
528 %
529 % \begin{example}
530 % \begin{prooftree}[template=(\textbf\inserttext)]
531 % \hypo{ foo }
532 % \hypo{ bar }
533 % \infer1{ baz }
534 % \infer2{ quux }
535 % \end{prooftree}
536 % \end{example}
537 %
538 % \begin{variable}{left label,right label}
539 % The text to use as the labels of the rules, on the left and on the right
540 % of the inference line, is defined by the options \cmd{left label} and
541 % \cmd{right label}.
542 % Using the second optional argument in \cs{infer} is equivalent to setting
543 % the \env{right label} option with the value of that argument.
544 % \end{variable}
545 %
546 % \begin{example}
547 % \begin{prooftree}
548 % \hypo{ \Gamma, A &\vdash B }
549 % \infer[left label=$\lambda$]1[abs]
550 % { \Gamma &\vdash A\to B }
551 % \hypo{ \Gamma \vdash A }
552 % \infer[left label=@]2[app]{ \Gamma \vdash B }
553 % \end{prooftree}
554 % \end{example}
555 %
556 % \begin{variable}{left label template,right label template}
557 % Similarly to conclusions, labels are formatted according to templates.
558 % The code is arbitrary \TeX\ code, composed in horizontal mode, where the
559 % macro \cs{inserttext} can be used to insert the actual label text.
560 % The default values are simply \cs{inserttext} so that labels are set in
561 % plain text mode.
562 % \end{variable}
563 % \begin{variable}{label separation}
564 % The spacing between an inference line and its labels is defined by the
565 % option \cmd{label separation}, the default value is \texttt{0.5em}.
566 % The height of the horizontal axis used for aligning the labels with the
567 % rules is defined by the option \cmd{label axis}, the default value is
568 % \texttt{0.5ex}.
569 % \end{variable}
570 %
571 %
572 % \subsection{Style macros}
573 % \label{sec:styles}
574 %
575 % The following commands allow for the definition of custom styles using the
576 % basic style options, in a way similar to PGF's ``styles'' and \LaTeX3's
577 % ``meta-keys''.
578 % This allows setting a bunch of options with the same values in many proofs
579 % using a single definition.
580 %
581 % \begin{function}{\ebproofnewstyle}
582 % \begin{syntax}
583 % \cs{ebproofnewstyle}\marg{name}\marg{options}
584 % \end{syntax}
585 % The statement \cs{ebproofnewstyle} defines a new style option with some
586 % \meta{name} that sets a given set of \meta{options}.
587 % \end{function}
588 % For instance, the following code defines a new option \cmd{small} that sets
589 % various parameters so that proofs are rendered smaller.
590 % \begin{example}
591 % \ebproofnewstyle{small}{
592 % separation = 1em, rule margin = .5ex,
593 % template = \footnotesize$\inserttext$ }
594 % \begin{prooftree}[small]
595 % \hypo{ \Gamma, A \vdash B }
596 % \infer1{ \Gamma \vdash A\to B }
597 % \hypo{ \Gamma \vdash A } \infer2{ \Gamma \vdash B }
598 % \end{prooftree}
599 % \end{example}
600 %
601 % \begin{function}{\ebproofnewrulestyle}
602 % \begin{syntax}
603 % \cs{ebproofnewrulestyle}\marg{name}\marg{options}
604 % \end{syntax}
605 % The statement \cs{ebproofnewrulestyle} does the same for rule styles.
606 % The \meta{options} part includes options used to set how to draw rules in
607 % the new style.
608 % \end{function}
609 %
610 % The option \cmd{rule code} is useful in this command as it allows to
611 % define arbitrary rule styles.
612 % For instance, the squiggly rule example above could be turned into a new
613 % rule style \texttt{zigzag} with the following code:
614 % \begin{example}
615 % \ebproofnewrulestyle{zigzag}{
616 % rule code = {\hbox{\tikz
617 % \draw[decorate,decoration={snake,amplitude=.3ex}]
618 % (0,0) -- (\hsize,0);}}}
619 % \begin{prooftree}
620 % \hypo{ \Gamma &\vdash A }
621 % \infer1{ \Gamma &\vdash A, \ldots, A }
622 % \hypo{ \Delta, A, \ldots, A \vdash \Theta }
623 % \infer[zigzag]2{ \Gamma, \Delta \vdash \Theta }
624 % \end{prooftree}
625 % \end{example}
626 %
627 %
628 % \section{License}
629 %
630 % This work may be distributed and/or modified under the
631 % conditions of the \LaTeX\ Project Public License, either version 1.3
632 % of this license or (at your option) any later version.
633 % The latest version of this license is in
634 % \begin{center}
635 % \url{http://www.latex-project.org/lppl.txt}
636 % \end{center}
637 % and version 1.3 or later is part of all distributions of \LaTeX\
638 % version 2005/12/01 or later.
639 %
640 % This work has the LPPL maintenance status `maintained'.
641 %
642 % The Current Maintainer of this work is Emmanuel Beffara.
643 %
644 % This work consists of the files \texttt{ebproof.sty} and \texttt{ebproof.tex}.
645 %
646 % \section{History}
647 %
648 % This section lists the principal evolutions of the package, in reverse
649 % chronological order.
650 % \begin{description}
651 % \item[Version 2.1.1 (2021-01-28)]
652 % Bugfix release, no changes in the user interface.
653 % \begin{itemize}
654 % \item Fixes a deprecation issue with \LaTeX3 release 2021-01-09 and
655 % various warnings that appear in \LaTeX3 debugging mode.
656 % \item Fixes \cmd{proof style=downwards}.
657 % \end{itemize}
658 % \item[Version 2.1 (2020-08-19)]
659 % Mostly a bugfix release.
660 % \begin{itemize}
661 % \item Makes the \env{prooftree} environment robust to use in tabular
662 % contexts.
663 % \item Adds the \cs{overlay} statement.
664 % \item Fixes a compatibility issue with \LaTeX\ release 2020-10-01.
665 % \end{itemize}
666 % \item[Version 2.0 (2017-05-17)]
667 % A complete rewrite of the code using the \LaTeX3 programming environment.
668 % The incompatible changes from the user's point of view are the following:
669 % \begin{itemize}
670 % \item Proof statements are now writtten in lowercase ({i.e.} \cs{Infer} is
671 % now written \cs{infer} etc.) but the syntax is otherwise unchanged.
672 % The old uppercase commands still work but produce a deprecation warning,
673 % they will be removed in a future version.
674 % \item New styles are now defined using \cs{ebproofnewstyle} and
675 % \cs{ebproofnewrulestyle}. The previous method using PGF styles does not
676 % work anymore (because PGF is not used anymore).
677 % \end{itemize}
678 % The new commands and options are the following:
679 % \begin{itemize}
680 % \item The statement \cs{rewrite} generalizes \cs{Alter},
681 % \item The option \cmd{label axis} controls vertical alignment of labels.
682 % \end{itemize}
683 % \item[Version 1.1 (2015-03-13)]
684 % A bugfix release.
685 % In \cmd{template} options, one now uses \cs{inserttext} instead of \verb|#1|
686 % for the text arguments, which improves robustness.
687 % \item[Version 1.0 (2015-02-04)]
688 % The first public release.
689 % \end{description}
690 %
691 % \end{documentation}
692 %
693 % \clearpage \appendix
694 %
695 % \begin{implementation}
696 %
697 % \section{Implementation}
698 %
699 % \begin{macrocode}
700 %<*package>
701 \NeedsTeXFormat{LaTeX2e}
702 \RequirePackage{expl3}
703 \RequirePackage{xparse}
704 \ProvidesExplPackage{ebproof}{2021/01/28}{2.1.1}{EB's proof trees}
705 %<@@=ebproof>
706 % \end{macrocode}
707 %
708 % \subsection{Parameters}
709 %
710 % We first declare all options. For the meaning of options, see
711 % section~\ref{sec:options}.
712 %
713 % \begin{macrocode}
714 \bool_new:N \l_@@_updown_bool
715 \keys_define:nn { ebproof } {
716 center .bool_set:N = \l_@@_center_bool,
717 proof~style .choice: ,
718 proof~style / upwards .code:n = \bool_set_false:N \l_@@_updown_bool,
719 proof~style / downwards .code:n = \bool_set_true:N \l_@@_updown_bool,
720 separation .dim_set:N = \l_@@_separation_dim,
721 rule~margin .dim_set:N = \l_@@_rule_margin_dim,
722 rule~thickness .dim_set:N = \l_@@_rule_thickness_dim,
723 rule~separation .dim_set:N = \l_@@_rule_separation_dim,
724 rule~dash~length .dim_set:N = \l_@@_rule_dash_length_dim,
725 rule~dash~space .dim_set:N = \l_@@_rule_dash_space_dim,
726 rule~code .tl_set:N = \l_@@_rule_code_tl,
727 rule~style .choice:,
728 template .tl_set:N = \l_@@_template_tl,
729 left~template .tl_set:N = \l_@@_left_template_tl,
730 right~template .tl_set:N = \l_@@_right_template_tl,
731 left~label .tl_set:N = \l_@@_left_label_tl,
732 right~label .tl_set:N = \l_@@_right_label_tl,
733 left~label~template .tl_set:N = \l_@@_left_label_template_tl,
734 right~label~template .tl_set:N = \l_@@_right_label_template_tl,
735 label~separation .dim_set:N = \l_@@_label_separation_dim,
736 label~axis .dim_set:N = \l_@@_label_axis_dim,
737 }
738 % \end{macrocode}
739 %
740 % \begin{macro}{\ebproofnewrulestyle}
741 % We then define the document-level macro \cs{ebproofnewrulestyle} and use
742 % it to define the default styles. This simply consists in defining a
743 % meta-key.
744 % \begin{macrocode}
745 \NewDocumentCommand \ebproofnewrulestyle { mm } {
746 \keys_define:nn { ebproof } {
747 rule~style / #1 .meta:nn = { ebproof } { #2 }
748 }
749 }
750 % \end{macrocode}
751 % \end{macro}
752 %
753 % The styles |simple|, |no rule| and |double| are defined in a straightforward
754 % way.
755 %
756 % \begin{macrocode}
757 \ebproofnewrulestyle { simple } {
758 rule~code = { \tex_hrule:D height \l_@@_rule_thickness_dim }
759 }
760 \ebproofnewrulestyle { no~rule } {
761 rule~code =
762 }
763 \ebproofnewrulestyle { double } {
764 rule~code = {
765 \tex_hrule:D height \l_@@_rule_thickness_dim
766 \skip_vertical:N \l_@@_rule_separation_dim
767 \tex_hrule:D height \l_@@_rule_thickness_dim
768 }
769 }
770 % \end{macrocode}
771 %
772 % The |dashed| style uses leaders and filling for repeating a single dash. We
773 % use \TeX\ primitives that have no \LaTeX3 counterpart for this.
774 %
775 % \begin{macrocode}
776 \ebproofnewrulestyle { dashed } {
777 rule~code = {
778 \hbox_to_wd:nn { \tex_hsize:D } {
779 \dim_set:Nn \l_tmpa_dim { \l_@@_rule_dash_space_dim / 2 }
780 \skip_horizontal:n { -\l_tmpa_dim }
781 \tex_cleaders:D \hbox:n {
782 \skip_horizontal:N \l_tmpa_dim
783 \tex_vrule:D
784 height \l_@@_rule_thickness_dim
785 width \l_@@_rule_dash_length_dim
786 \skip_horizontal:N \l_tmpa_dim
787 } \tex_hfill:D
788 \skip_horizontal:n { -\l_tmpa_dim }
789 }
790 }
791 }
792 % \end{macrocode}
793 %
794 % Now we can define the default values, including the default rule style.
795 %
796 % \begin{macrocode}
797 \keys_set:nn { ebproof } {
798 center = true,
799 proof~style = upwards,
800 separation = 1.5em,
801 rule~margin = .7ex,
802 rule~thickness = .4pt,
803 rule~separation = 2pt,
804 rule~dash~length = .2em,
805 rule~dash~space = .3em,
806 rule~style = simple,
807 template = $\inserttext$,
808 left~template = $\inserttext\mathrel{}$,
809 right~template = $\mathrel{}\inserttext$,
810 left~label = ,
811 right~label = ,
812 left~label~template = \inserttext,
813 right~label~template = \inserttext,
814 label~separation = 0.5em,
815 label~axis = 0.5ex
816 }
817 % \end{macrocode}
818 %
819 % \begin{macro}{\ebproofnewstyle}
820 % Defining a style simply means defining a meta-key.
821 % \begin{macrocode}
822 \NewDocumentCommand \ebproofnewstyle { mm } {
823 \keys_define:nn { ebproof } { #1 .meta:n = { #2 } }
824 }
825 % \end{macrocode}
826 % \end{macro}
827 %
828 %
829 % \subsection{Proof boxes}
830 %
831 % \TeX\ does not actually provide data structures, so we have to encode things.
832 % We provide an allocator for ``registers'' holding boxes with attributes. Such
833 % a register consists in a box register and a property list for marks, which
834 % maps mark names to values as explicit dimensions with units.
835 %
836 % \begin{macro}{\@@_new:N}
837 % Using only public interfaces forces a convoluted approach to allocation:
838 % we use a global counter \cs{g_ebproof_register_int} to number registers,
839 % then each allocation creates registers named \cs{S_ebproof_K_N} where
840 % S is the scope of the register (local or global, deduced from the argument),
841 % K is the kind of component (box or marks) and N is the identifier of the
842 % register. The proof box register itself only contains the identifier used
843 % for indirection.
844 % \begin{macrocode}
845 \int_new:N \g_@@_register_int
846 \cs_new:Nn \@@_box:N {
847 \str_item:nn { #1 } { 2 } __ebproof_ \tl_use:N #1 _box
848 }
849 \cs_new:Nn \@@_marks:N {
850 \str_item:nn { #1 } { 2 } __ebproof_ \tl_use:N #1 _prop
851 }
852 \cs_new:Nn \@@_new:N {
853 \tl_new:N #1
854 \int_gincr:N \g_@@_register_int
855 \str_if_eq:eeTF { \str_item:nn { #1 } { 2 } } { g }
856 { \tl_gset:Nx #1 { \int_to_arabic:n { \g_@@_register_int } } }
857 { \tl_set:Nx #1 { \int_to_arabic:n { \g_@@_register_int } } }
858 \box_new:c { \@@_box:N #1 }
859 \prop_new:c { \@@_marks:N #1 }
860 }
861 % \end{macrocode}
862 % \end{macro}
863 %
864 % \begin{macro}{\@@_clear:N}
865 % The box is cleared by setting it to an empty hbox.
866 % Using \cs{box_clear:N} instead would not work because trying to push this
867 % box on the stack would not actually append any box.
868 % \begin{macrocode}
869 \cs_new:Nn \@@_clear:N {
870 \hbox_set:cn { \@@_box:N #1 } {}
871 \prop_clear:c { \@@_marks:N #1 }
872 \@@_set_mark:Nnn #1 { left } { 0pt }
873 \@@_set_mark:Nnn #1 { right } { 0pt }
874 \@@_set_mark:Nnn #1 { axis } { 0pt }
875 }
876 % \end{macrocode}
877 % \end{macro}
878 %
879 % \subsubsection{Mark operations}
880 %
881 % \begin{macro}{\@@_set_mark:Nnn}
882 % Setting the value of a mark uses a temporary register to evaluate the
883 % dimension expression because values are stored textually in a property
884 % list.
885 % \begin{macrocode}
886 \dim_new:N \l_@@_transit_dim
887 \cs_new:Nn \@@_set_mark:Nnn {
888 \dim_set:Nn \l_@@_transit_dim { #3 }
889 \prop_put:cnV { \@@_marks:N #1 } { #2 }
890 \l_@@_transit_dim
891 }
892 % \end{macrocode}
893 % \end{macro}
894 %
895 % \begin{macro}{\@@_mark:Nn}
896 % Getting the value of a mark simply consists in getting an item in a
897 % property list.
898 % \begin{macrocode}
899 \cs_new:Nn \@@_mark:Nn {
900 \prop_item:cn { \@@_marks:N #1 } { #2 }
901 }
902 % \end{macrocode}
903 % \end{macro}
904 %
905 % \begin{macro}{\@@_shift_x:Nn}
906 % This function shifts the marks by a specified amount, without modifying
907 % the box.
908 % \begin{macrocode}
909 \cs_new:Nn \@@_shift_x:Nn {
910 \prop_map_inline:cn { \@@_marks:N #1 } {
911 \@@_set_mark:Nnn #1 { ##1 } { ##2 + #2 }
912 }
913 }
914 % \end{macrocode}
915 % \end{macro}
916 %
917 % \begin{macro}{\@@_enlarge_conclusion:NN}
918 % This function moves the left and right marks of the first tree so that
919 % they are at least as far from the axis as they are in the second tree.
920 % For instance we get the following:
921 % \begin{center}
922 % \begin{tikzpicture}[y=-3ex]
923 % \node (L1) at (1,0) {L}; \node (A1) at (2,0) {A}; \node (R1) at (4,0) {R};
924 % \node (L2) at (0,1) {L}; \node (A2) at (2,1) {A}; \node (R2) at (3,1) {R};
925 % \node (L3) at (0,2) {L}; \node (A3) at (2,2) {A}; \node (R3) at (4,2) {R};
926 % \draw (L1) -- (A1) -- (R1);
927 % \draw (L2) -- (A2) -- (R2);
928 % \draw (L3) -- (A3) -- (R3);
929 % \node[anchor=west] at (5,0) {box 1 before};
930 % \node[anchor=west] at (5,1) {box 2 before};
931 % \node[anchor=west] at (5,2) {box 1 after};
932 % \end{tikzpicture}
933 % \end{center}
934 % The contents of the trees are unchanged.
935 % \begin{macrocode}
936 \cs_new:Nn \@@_enlarge_conclusion:NN {
937 \dim_set:Nn \l_tmpa_dim { \@@_mark:Nn #1 {axis}
938 + \@@_mark:Nn #2 {left} - \@@_mark:Nn #2 {axis} }
939 \dim_compare:nNnT { \l_tmpa_dim } < { \@@_mark:Nn #1 {left} } {
940 \@@_set_mark:Nnn #1 {left} { \l_tmpa_dim } }
941 \dim_set:Nn \l_tmpa_dim { \@@_mark:Nn #1 {axis}
942 + \@@_mark:Nn #2 {right} - \@@_mark:Nn #2 {axis} }
943 \dim_compare:nNnT { \l_tmpa_dim } > { \@@_mark:Nn #1 {right} } {
944 \@@_set_mark:Nnn #1 {right} { \l_tmpa_dim } }
945 }
946 % \end{macrocode}
947 % \end{macro}
948 %
949 % \subsubsection{Building blocks}
950 %
951 % \begin{macro}{\@@_make_simple:Nn}
952 % Make a tree with explicit material in horizontal mode. Set the left and
953 % right marks to extremal positions and set the axis in the middle.
954 % \begin{macrocode}
955 \cs_new:Nn \@@_make_simple:Nn {
956 \hbox_set:cn { \@@_box:N #1 } { #2 }
957 \@@_set_mark:Nnn #1 { left } { 0pt }
958 \@@_set_mark:Nnn #1 { axis } { \box_wd:c { \@@_box:N #1 } / 2 }
959 \@@_set_mark:Nnn #1 { right } { \box_wd:c { \@@_box:N #1 } }
960 }
961 % \end{macrocode}
962 % \end{macro}
963 %
964 % \begin{macro}{\@@_make_split:Nnn}
965 % Make a tree with explicit material in horizontal mode, split in two parts.
966 % Set the left and right marks to extremal positions and set the axis
967 % between the two parts.
968 % \begin{macrocode}
969 \cs_new:Nn \@@_make_split:Nnn {
970 \@@_set_mark:Nnn #1 { left } { 0pt }
971 \hbox_set:cn { \@@_box:N #1 } { #2 }
972 \@@_set_mark:Nnn #1 { axis } { \box_wd:c { \@@_box:N #1 } }
973 \hbox_set:cn { \@@_box:N #1 } { \hbox_unpack:c { \@@_box:N #1 } #3 }
974 \@@_set_mark:Nnn #1 { right } { \box_wd:c { \@@_box:N #1 } }
975 }
976 % \end{macrocode}
977 % \end{macro}
978 %
979 % \begin{macro}{\@@_make_vertical:Nnnn}
980 % Make a tree with explicit material in vertical mode, using an explicit
981 % width and axis.
982 % \begin{macrocode}
983 \cs_new:Nn \@@_make_vertical:Nnnn {
984 \@@_set_mark:Nnn #1 { left } { 0pt }
985 \@@_set_mark:Nnn #1 { axis } { #2 }
986 \@@_set_mark:Nnn #1 { right } { #3 }
987 \vbox_set:cn { \@@_box:N #1 } {
988 \dim_set:Nn \tex_hsize:D { \@@_mark:Nn #1 {right} }
989 #4
990 }
991 \box_set_wd:cn { \@@_box:N #1 } { \@@_mark:Nn #1 {right} }
992 }
993 % \end{macrocode}
994 % \end{macro}
995 %
996 % \subsubsection{Assembling boxes}
997 %
998 % \begin{macro}{\@@_extend:Nnnnn}
999 % Extend a tree box. The marks are shifted so that alignment is preserved.
1000 % The arguments are dimensions for the left, top, right and bottom sides
1001 % respectively.
1002 % \begin{macrocode}
1003 \cs_new:Nn \@@_extend:Nnnnn {
1004 \dim_compare:nNnF { #2 } = { 0pt } {
1005 \hbox_set:cn { \@@_box:N #1 } {
1006 \skip_horizontal:n { #2 }
1007 \box_use:c { \@@_box:N #1 }
1008 }
1009 \@@_shift_x:Nn #1 { #2 }
1010 }
1011 \box_set_ht:Nn #1 { \box_ht:c { \@@_box:N #1 } + #3 }
1012 \box_set_wd:Nn #1 { \box_wd:c { \@@_box:N #1 } + #4 }
1013 \box_set_dp:Nn #1 { \box_dp:c { \@@_box:N #1 } + #5 }
1014 }
1015 % \end{macrocode}
1016 % \end{macro}
1017 %
1018 % \begin{macro}{\@@_append_right:NnN}
1019 % Append the contents of the second tree to the first one on the right, with
1020 % matching baselines. The marks of both trees are preserved. The middle
1021 % argument specifies the space to insert between boxes.
1022 % \begin{macrocode}
1023 \cs_new:Nn \@@_append_right:NnN {
1024 \hbox_set:cn { \@@_box:N #1 } {
1025 \box_use:c { \@@_box:N #1 }
1026 \dim_compare:nNnF { #2 } = { 0pt } { \skip_horizontal:n { #2 } }
1027 \box_use:c { \@@_box:N #3 }
1028 }
1029 }
1030 % \end{macrocode}
1031 % \end{macro}
1032 %
1033 % \begin{macro}{\@@_append_left:NnN}
1034 % Append the contents of the second tree to the first one on the left, with
1035 % matching baselines. The marks of the first tree are shifted accordingly.
1036 % The middle argument specifies the space to insert between boxes.
1037 % \begin{macrocode}
1038 \cs_new:Nn \@@_append_left:NnN {
1039 \@@_shift_x:Nn #1 { \box_wd:c { \@@_box:N #3 } + #2 }
1040 \hbox_set:cn { \@@_box:N #1 } {
1041 \box_use:c { \@@_box:N #3 }
1042 \dim_compare:nNnF { #2 } = { 0pt } { \skip_horizontal:n { #2 } }
1043 \box_use:c { \@@_box:N #1 }
1044 }
1045 }
1046 % \end{macrocode}
1047 % \end{macro}
1048 %
1049 % \begin{macro}{\@@_align:NN}
1050 % Shift one of two trees to the right so that their axes match. The marks of
1051 % the one that is shifted are updated accordingly.
1052 % \begin{macrocode}
1053 \cs_new:Nn \@@_align:NN {
1054 \dim_set:Nn \l_tmpa_dim
1055 { \@@_mark:Nn #2 {axis} - \@@_mark:Nn #1 {axis} }
1056 \dim_compare:nNnTF \l_tmpa_dim < { 0pt } {
1057 \@@_extend:Nnnnn #2 { -\l_tmpa_dim } { 0pt } { 0pt } { 0pt }
1058 } {
1059 \@@_extend:Nnnnn #1 { \l_tmpa_dim } { 0pt } { 0pt } { 0pt }
1060 }
1061 }
1062 % \end{macrocode}
1063 % \end{macro}
1064 %
1065 % \begin{macro}{\@@_append_above:NN}
1066 % Append the contents of the second tree above the first one, with matching
1067 % axes. The marks of the first tree are preserved.
1068 % \begin{macrocode}
1069 \cs_new:Nn \@@_append_above:NN {
1070 \@@_align:NN #1 #2
1071 \vbox_set:cn { \@@_box:N #1 } {
1072 \box_use:c { \@@_box:N #2 }
1073 \tex_prevdepth:D -1000pt
1074 \box_use:c { \@@_box:N #1 }
1075 }
1076 }
1077 % \end{macrocode}
1078 % \end{macro}
1079 %
1080 % \begin{macro}{\@@_append_below:NN}
1081 % Append the contents of the second tree below the first one, with matching
1082 % axes. The marks of the first tree are preserved.
1083 % \begin{macrocode}
1084 \cs_new:Nn \@@_append_below:NN {
1085 \@@_align:NN #1 #2
1086 \vbox_set_top:cn { \@@_box:N #1 } {
1087 \box_use:c { \@@_box:N #1 }
1088 \tex_prevdepth:D -1000pt
1089 \box_use:c { \@@_box:N #2 }
1090 }
1091 }
1092 % \end{macrocode}
1093 % \end{macro}
1094 %
1095 % \begin{macro}{\@@_overlay:NN}
1096 % Append the second tree as an overlay over the first one, so that the
1097 % baselines and axes match. The bounding box of the result adjusts to
1098 % contain both trees.
1099 % \begin{macrocode}
1100 \cs_new:Nn \@@_overlay:NN {
1101 \@@_align:NN #1 #2
1102 \hbox_set:cn { \@@_box:N #1 } {
1103 \hbox_overlap_right:n { \box_use:c { \@@_box:N #1 } }
1104 \box_use:c { \@@_box:N #2 }
1105 \dim_compare:nNnT
1106 { \box_wd:c { \@@_box:N #2 } } < { \box_wd:c { \@@_box:N #1 } }
1107 { \skip_horizontal:n
1108 { \box_wd:c { \@@_box:N #1 } - \box_wd:c { \@@_box:N #2 } } }
1109 }
1110 }
1111 % \end{macrocode}
1112 % \end{macro}
1113 %
1114 % \begin{macro}{\@@_vcenter:N}
1115 % Shift the material in a tree vertically so that the height and depth are
1116 % equal (like \TeX's \cs{vcenter} but around the baseline).
1117 % \begin{macrocode}
1118 \cs_new:Nn \@@_vcenter:N {
1119 \dim_set:Nn \l_tmpa_dim
1120 { ( \box_ht:c { \@@_box:N #1 } - \box_dp:c { \@@_box:N #1 } ) / 2 }
1121 \box_set_eq:Nc \l_tmpa_box { \@@_box:N #1 }
1122 \hbox_set:cn { \@@_box:N #1 }
1123 { \box_move_down:nn { \l_tmpa_dim } { \box_use:N \l_tmpa_box } }
1124 }
1125 % \end{macrocode}
1126 % \end{macro}
1127 %
1128 % \subsection{Making inferences}
1129 %
1130 % The following commands use the parameters defined at the beginning of the
1131 % package for actually building proof trees using the commands defined above.
1132 %
1133 % \begin{macro}{\@@_append_vertical:NN}
1134 % Append the contents of the second tree above or below the first one,
1135 % depending on current settings. Axes are aligned and the marks of the first
1136 % tree are preserved.
1137 % \begin{macrocode}
1138 \cs_new:Nn \@@_append_vertical:NN {
1139 \bool_if:NTF \l_@@_updown_bool
1140 { \@@_append_below:NN #1 #2 }
1141 { \@@_append_above:NN #1 #2 }
1142 }
1143 % \end{macrocode}
1144 % \end{macro}
1145 %
1146 % \begin{macro}{\@@_make_rule_for:NNN}
1147 % Make a box containing an inference rule with labels, using the current
1148 % settings. The width and axis position are taken as those of the conclusion
1149 % of another tree box. The third argument is used as a temporary register
1150 % for building labels.
1151 % \begin{macrocode}
1152 \cs_new:Nn \@@_make_rule_for:NNN {
1153 % \end{macrocode}
1154 % Build the rule.
1155 % \begin{macrocode}
1156 \@@_make_vertical:Nnnn #1
1157 { \@@_mark:Nn #2 {axis} - \@@_mark:Nn #2 {left} }
1158 { \@@_mark:Nn #2 {right} - \@@_mark:Nn #2 {left} }
1159 {
1160 \skip_vertical:N \l_@@_rule_margin_dim
1161 \tl_if_empty:NF { \l_@@_rule_code_tl } {
1162 \tl_use:N \l_@@_rule_code_tl
1163 \skip_vertical:N \l_@@_rule_margin_dim
1164 }
1165 }
1166 \@@_vcenter:N #1
1167 % \end{macrocode}
1168 % Append the left label.
1169 % \begin{macrocode}
1170 \tl_if_blank:VF \l_@@_left_label_tl {
1171 \@@_make_simple:Nn #3 {
1172 \box_move_down:nn { \l_@@_label_axis_dim } { \hbox:n {
1173 \cs_set_eq:NN \inserttext \l_@@_left_label_tl
1174 \tl_use:N \l_@@_left_label_template_tl
1175 } }
1176 }
1177 \box_set_ht:cn { \@@_box:N #3 } { 0pt }
1178 \box_set_dp:cn { \@@_box:N #3 } { 0pt }
1179 \@@_append_left:NnN
1180 \l_@@_c_box \l_@@_label_separation_dim \l_@@_d_box
1181 }
1182 % \end{macrocode}
1183 % Append the right label.
1184 % \begin{macrocode}
1185 \tl_if_blank:VF \l_@@_right_label_tl {
1186 \@@_make_simple:Nn #3 {
1187 \box_move_down:nn { \l_@@_label_axis_dim } { \hbox:n {
1188 \cs_set_eq:NN \inserttext \l_@@_right_label_tl
1189 \tl_use:N \l_@@_right_label_template_tl
1190 } }
1191 }
1192 \box_set_ht:cn { \@@_box:N #3 } { 0pt }
1193 \box_set_dp:cn { \@@_box:N #3 } { 0pt }
1194 \@@_append_right:NnN
1195 \l_@@_c_box \l_@@_label_separation_dim \l_@@_d_box
1196 }
1197 }
1198 % \end{macrocode}
1199 % \end{macro}
1200 %
1201 % \subsection{Stack-based interface}
1202 %
1203 % \subsubsection{The stack}
1204 %
1205 % Logically, box structures are stored on a stack. However, \TeX\ does not
1206 % provide data structures for that and the grouping mechanism is not flexible
1207 % enough, so we encode them using what we actually have. A stack for boxes is
1208 % implemented using a global hbox \cs{g_@@_stack_box} that contains all the
1209 % boxes successively. A sequence \cs{g_@@_stack_seq} is used to store the
1210 % dimensions property lists textually. We maintain a counter
1211 % \cs{g_@@_level_int} with the number of elements on the stack, for
1212 % consistency checks.
1213 % \begin{macrocode}
1214 \int_new:N \g_@@_level_int
1215 \box_new:N \g_@@_stack_box
1216 \seq_new:N \g_@@_stack_seq
1217 % \end{macrocode}
1218 %
1219 % \begin{macro}{\@@_clear_stack:}
1220 % Clear the stack.
1221 % \begin{macrocode}
1222 \cs_new:Nn \@@_clear_stack: {
1223 \int_gset:Nn \g_@@_level_int { 0 }
1224 \hbox_gset:Nn \g_@@_stack_box { }
1225 \seq_gclear:N \g_@@_stack_seq
1226 }
1227 % \end{macrocode}
1228 % \end{macro}
1229 %
1230 % \begin{macro}{\@@_push:N}
1231 % Push the contents of a register on the stack.
1232 % \begin{macrocode}
1233 \cs_new:Nn \@@_push:N {
1234 \int_gincr:N \g_@@_level_int
1235 \hbox_gset:Nn \g_@@_stack_box
1236 { \hbox_unpack:N \g_@@_stack_box \box_use:c { \@@_box:N #1 } }
1237 \seq_gput_left:Nv \g_@@_stack_seq
1238 { \@@_marks:N #1 }
1239 }
1240 % \end{macrocode}
1241 % \end{macro}
1242 %
1243 % \begin{macro}{\@@_pop:N}
1244 % Pop the value from the top of the stack into a register.
1245 % \begin{macrocode}
1246 \cs_new:Nn \@@_pop:N {
1247 \int_compare:nNnTF { \g_@@_level_int } > { 0 } {
1248 \int_gdecr:N \g_@@_level_int
1249 \hbox_gset:Nn \g_@@_stack_box {
1250 \hbox_unpack:N \g_@@_stack_box
1251 \box_gset_to_last:N \g_tmpa_box
1252 }
1253 \box_set_eq_drop:cN { \@@_box:N #1 } \g_tmpa_box
1254 \seq_gpop_left:NN \g_@@_stack_seq \l_tmpa_tl
1255 \tl_set_eq:cN { \@@_marks:N #1 } \l_tmpa_tl
1256 } {
1257 \PackageError{ebproof}{Missing~premiss~in~a~proof~tree}{}
1258 \@@_clear:N #1
1259 }
1260 }
1261 % \end{macrocode}
1262 % \end{macro}
1263 %
1264 % \subsubsection{Assembling trees}
1265 %
1266 % \begin{macrocode}
1267 \@@_new:N \l_@@_a_box
1268 \@@_new:N \l_@@_b_box
1269 \@@_new:N \l_@@_c_box
1270 \@@_new:N \l_@@_d_box
1271 % \end{macrocode}
1272 %
1273 % \begin{macro}{\@@_join_horizontal:n}
1274 % Join horizontally a number of elements at the top of the stack. If several
1275 % trees are joined, use the left mark of the left tree, the right mark of
1276 % the right tree and set the axis in the middle of these marks.
1277 % \begin{macrocode}
1278 \cs_new:Nn \@@_join_horizontal:n {
1279 \int_case:nnF { #1 } {
1280 { 0 } {
1281 \group_begin:
1282 \@@_clear:N \l_@@_a_box
1283 \@@_push:N \l_@@_a_box
1284 \group_end:
1285 }
1286 { 1 } { }
1287 } {
1288 \group_begin:
1289 \@@_pop:N \l_@@_a_box
1290 \prg_replicate:nn { #1 - 1 } {
1291 \@@_pop:N \l_@@_b_box
1292 \@@_append_left:NnN
1293 \l_@@_a_box \l_@@_separation_dim \l_@@_b_box
1294 }
1295 \@@_set_mark:Nnn \l_@@_a_box { left }
1296 { \@@_mark:Nn \l_@@_b_box { left } }
1297 \@@_set_mark:Nnn \l_@@_a_box { axis }
1298 { ( \@@_mark:Nn \l_@@_a_box { left }
1299 + \@@_mark:Nn \l_@@_a_box { right } ) / 2 }
1300 \@@_push:N \l_@@_a_box
1301 \group_end:
1302 }
1303 }
1304 % \end{macrocode}
1305 % \end{macro}
1306 %
1307 % \begin{macro}{\@@_join_vertical:}
1308 % Join vertically the two elements at the top of the stack, with a
1309 % horizontal rule of the appropriate size.
1310 % \begin{macrocode}
1311 \cs_new:Nn \@@_join_vertical: {
1312 \group_begin:
1313 \@@_pop:N \l_@@_a_box
1314 \@@_pop:N \l_@@_b_box
1315 \@@_enlarge_conclusion:NN \l_@@_b_box \l_@@_a_box
1316 \@@_make_rule_for:NNN \l_@@_c_box \l_@@_b_box
1317 \l_@@_d_box
1318 \@@_append_vertical:NN \l_@@_a_box \l_@@_c_box
1319 \@@_append_vertical:NN \l_@@_a_box \l_@@_b_box
1320 \@@_push:N \l_@@_a_box
1321 \group_end:
1322 }
1323 % \end{macrocode}
1324 % \end{macro}
1325 %
1326 % \subsubsection{High-level commands}
1327 %
1328 % \begin{macro}{\@@_statement_parse:w}
1329 % An auxiliary function for parsing the argument in
1330 % \cs{@@_push_statement:n}.
1331 % \begin{macrocode}
1332 \cs_new:Npn \@@_statement_parse:w #1 & #2 & #3 \q_stop {
1333 \tl_if_empty:nTF { #3 } {
1334 \@@_make_simple:Nn \l_@@_a_box
1335 { \cs_set:Npn \inserttext { #1 } \tl_use:N \l_@@_template_tl }
1336 } {
1337 \@@_make_split:Nnn \l_@@_a_box
1338 { \cs_set:Npn \inserttext { #1 } \tl_use:N \l_@@_left_template_tl }
1339 { \cs_set:Npn \inserttext { #2 } \tl_use:N \l_@@_right_template_tl }
1340 }
1341 \@@_push:N \l_@@_a_box
1342 }
1343 % \end{macrocode}
1344 % \end{macro}
1345 %
1346 % \begin{macro}{\@@_push_statement:n}
1347 % Push a box with default formatting, using explicit alignment if the code
1348 % contains a |&| character
1349 % \begin{macrocode}
1350 \cs_new:Nn \@@_push_statement:n {
1351 \@@_statement_parse:w #1 & & \q_stop
1352 }
1353 % \end{macrocode}
1354 % \end{macro}
1355 %
1356 % \subsection{Document interface}
1357 %
1358 % \subsubsection{Functions to define statements}
1359 %
1360 % The \cs{g_@@_statements_seq} variable contains the list of all defined
1361 % statements. For each statement |X|, there is a document command \cs{ebproofX}
1362 % and the alias \cs{X} is defined when entering a |prooftree| environment.
1363 % \begin{macrocode}
1364 \seq_new:N \g_@@_statements_seq
1365 % \end{macrocode}
1366 %
1367 % \begin{macro}{\@@_setup_statements:}
1368 % Install the aliases for statements, saving the original value of the control
1369 % sequences.
1370 % \begin{macrocode}
1371 \cs_new:Nn \@@_setup_statements: {
1372 \seq_map_inline:Nn \g_@@_statements_seq {
1373 \cs_set_eq:cc { ebproof_saved_ ##1 } { ##1 }
1374 \cs_set_eq:cc { ##1 } { ebproof ##1 }
1375 }
1376 }
1377 % \end{macrocode}
1378 % \end{macro}
1379 %
1380 % \begin{macro}{\@@_restore_statements:}
1381 % Restore the saved meanings of the control sequences. This is useful when
1382 % interpreting user-provided code in statement arguments. The meanings are
1383 % automatically restored when leaving a |prooftree| environment because of
1384 % grouping.
1385 % \begin{macrocode}
1386 \cs_new:Nn \@@_restore_statements: {
1387 \seq_map_inline:Nn \g_@@_statements_seq {
1388 \cs_set_eq:cc { ##1 } { ebproof_saved_ ##1 }
1389 }
1390 }
1391 % \end{macrocode}
1392 % \end{macro}
1393 %
1394 % \begin{macro}{\@@_new_statement:nnn}
1395 % Define a new statement. The first argument is the name, the second one is
1396 % an argument specifier as used by |xparse| and the third one is the body of
1397 % the command.
1398 % \begin{macrocode}
1399 \cs_new:Nn \@@_new_statement:nnn {
1400 \exp_args:Nc \NewDocumentCommand { ebproof#1 }{ #2 } { #3 }
1401 \seq_gput_right:Nn \g_@@_statements_seq { #1 }
1402 }
1403 % \end{macrocode}
1404 % \end{macro}
1405 %
1406 % \begin{macro}{\@@_new_deprecated_statement:nnnn}
1407 % Define a deprecated statement. The syntax is the same as above except that
1408 % an extra argument in third position indicates what should be used instead.
1409 % The effect is the same except that a warning message is issued the first
1410 % time the statement is used.
1411 % \begin{macrocode}
1412 \cs_new:Nn \@@_new_deprecated_statement:nnnn {
1413 \cs_new:cpn { ebproof_#1_warning: } {
1414 \PackageWarning { ebproof } { \token_to_str:c{#1}~is~deprecated,~#3 }
1415 \cs_gset:cn { ebproof_#1_warning: } { }
1416 }
1417 \@@_new_statement:nnn { #1 } { #2 }
1418 { \use:c { ebproof_#1_warning: } #4 }
1419 }
1420 % \end{macrocode}
1421 % \end{macro}
1422 %
1423 %
1424 % \subsubsection{Basic commands}
1425 %
1426 % \begin{macro}{\ebproofset,\set}
1427 % This is a simple wrapper around \cs{keys_set:nn}.
1428 % \begin{macrocode}
1429 \@@_new_statement:nnn { set } { m } {
1430 \keys_set:nn { ebproof } { #1 }
1431 }
1432 % \end{macrocode}
1433 % \end{macro}
1434 %
1435 % \begin{macro}{\hypo}
1436 % This is mostly a wrapper around \cs{ebproof_push_statement:n}, with
1437 % material to handle options and the statements macros.
1438 % \begin{macrocode}
1439 \@@_new_statement:nnn { hypo } { O{} m } {
1440 \group_begin:
1441 \@@_restore_statements:
1442 \keys_set:nn { ebproof } { #1 }
1443 \@@_push_statement:n { #2 }
1444 \group_end:
1445 }
1446 % \end{macrocode}
1447 % \end{macro}
1448 %
1449 % \begin{macro}{\infer}
1450 % This is a bit more involved than \cs{hypo} because we have to handle rule
1451 % style options and joining.
1452 % \begin{macrocode}
1453 \@@_new_statement:nnn { infer } { O{} m O{} m } {
1454 \group_begin:
1455 \@@_restore_statements:
1456 \keys_set_known:nnN { ebproof / rule~style } { #1 } \l_tmpa_tl
1457 \keys_set:nV { ebproof } \l_tmpa_tl
1458 \tl_set:Nn \l_@@_right_label_tl { #3 }
1459 \@@_join_horizontal:n { #2 }
1460 \@@_push_statement:n { #4 }
1461 \@@_join_vertical:
1462 \group_end:
1463 }
1464 % \end{macrocode}
1465 % \end{macro}
1466 %
1467 % \begin{macro}{\ellipsis}
1468 % An ellipsis is made by hand using vertical leaders to render the dots
1469 % after rendering the label.
1470 % \begin{macrocode}
1471 \@@_new_statement:nnn { ellipsis } { m m } {
1472 \group_begin:
1473 \@@_restore_statements:
1474 \tl_clear:N \l_@@_rule_code_tl
1475 \@@_make_split:Nnn \l_@@_a_box { } {
1476 \vbox_set:Nn \l_tmpa_box {
1477 \skip_vertical:n { 1.2ex }
1478 \hbox:n { \tex_ignorespaces:D #1 }
1479 \skip_vertical:n { 1.2ex }
1480 }
1481 \vbox_to_ht:nn { \box_ht:N \l_tmpa_box } {
1482 \tex_xleaders:D \vbox_to_ht:nn { .8ex }
1483 { \tex_vss:D \hbox:n { . } \tex_vss:D }
1484 \tex_vfill:D
1485 }
1486 \hbox_overlap_right:n { ~ \box_use:N \l_tmpa_box }
1487 }
1488 \@@_push:N \l_@@_a_box
1489 \@@_join_vertical:
1490 \@@_push_statement:n {#2}
1491 \@@_join_vertical:
1492 \group_end:
1493 }
1494 % \end{macrocode}
1495 % \end{macro}
1496 %
1497 % \subsubsection{Modifying trees}
1498 %
1499 % \begin{macro}{\rewrite}
1500 % Rewrite the box at the top of the stack while preserving its dimensions an
1501 % marks. The code is typeset in horizontal mode, with control sequences to
1502 % access the original box and its marks.
1503 % \begin{macrocode}
1504 \@@_new_statement:nnn { rewrite } { m } {
1505 \group_begin:
1506 \@@_restore_statements:
1507 \@@_pop:N \l_@@_a_box
1508 \box_set_eq:Nc \l_tmpa_box { \@@_box:N \l_@@_a_box }
1509 \hbox_set:Nn \l_tmpb_box {
1510 \cs_set_eq:NN \treebox \l_tmpa_box
1511 \cs_set:Npn \treemark { \@@_mark:Nn \l_@@_a_box }
1512 { #1 }
1513 }
1514 \box_set_wd:Nn \l_tmpb_box { \box_wd:c { \@@_box:N \l_@@_a_box } }
1515 \box_set_ht:Nn \l_tmpb_box { \box_ht:c { \@@_box:N \l_@@_a_box } }
1516 \box_set_dp:Nn \l_tmpb_box { \box_dp:c { \@@_box:N \l_@@_a_box } }
1517 \box_set_eq:cN { \@@_box:N \l_@@_a_box } \l_tmpb_box
1518 \@@_push:N \l_@@_a_box
1519 \group_end:
1520 }
1521 % \end{macrocode}
1522 % \end{macro}
1523 %
1524 % \begin{macro}{\delims}
1525 % Insert \cs{left} and \cs{right} delimiters without changing the alignment.
1526 % \begin{macrocode}
1527 \@@_new_statement:nnn { delims } { m m } {
1528 \group_begin:
1529 \@@_restore_statements:
1530 \@@_pop:N \l_@@_a_box
1531 \hbox_set:Nn \l_tmpa_box
1532 { $ \tex_vcenter:D { \box_use:c { \@@_box:N \l_@@_a_box } } $ }
1533 \dim_set:Nn \l_tmpa_dim
1534 { \box_ht:N \l_tmpa_box - \box_ht:c { \@@_box:N \l_@@_a_box } }
1535 \hbox_set:cn { \@@_box:N \l_@@_a_box } {
1536 $ #1 \tex_vrule:D
1537 height \box_ht:N \l_tmpa_box depth \box_dp:N \l_tmpa_box width 0pt
1538 \tex_right:D . $
1539 }
1540 \@@_shift_x:Nn \l_@@_a_box
1541 { \box_wd:c { \@@_box:N \l_@@_a_box } }
1542 \hbox_set:cn { \@@_box:N \l_@@_a_box } {
1543 \hbox_unpack:c { \@@_box:N \l_@@_a_box }
1544 $ \tex_left:D . \box_use:N \l_tmpa_box #2 $
1545 }
1546 \hbox_set:cn { \@@_box:N \l_@@_a_box }
1547 { \box_move_down:nn { \l_tmpa_dim }
1548 { \box_use:c { \@@_box:N \l_@@_a_box } } }
1549 \@@_push:N \l_@@_a_box
1550 \group_end:
1551 }
1552 % \end{macrocode}
1553 % \end{macro}
1554 %
1555 % \begin{macro}{\overlay}
1556 % Pop two trees and append the second tree as an overlay over the first one,
1557 % so that the baselines and axes match. The bounding box of the result
1558 % adjusts to contain both trees.
1559 % \begin{macrocode}
1560 \@@_new_statement:nnn { overlay } { } {
1561 \group_begin:
1562 \@@_pop:N \l_@@_a_box
1563 \@@_pop:N \l_@@_b_box
1564 \@@_overlay:NN \l_@@_a_box \l_@@_b_box
1565 \@@_push:N \l_@@_a_box
1566 \group_end:
1567 }
1568 % \end{macrocode}
1569 % \end{macro}
1570 %
1571 % \subsubsection{Deprecated statements}
1572 %
1573 % These statements were defined in versions 1.x of the package, they are
1574 % preserved for temporary upwards compatibility and will be removed in a
1575 % future version.
1576 % \begin{macrocode}
1577 \@@_new_deprecated_statement:nnnn { Alter } { m }
1578 { use~\token_to_str:c{rewrite}~instead } { \ebproofrewrite{ #1 \box\treebox } }
1579 \@@_new_deprecated_statement:nnnn { Delims } { }
1580 { use~\token_to_str:c{delims}~instead } { \ebproofdelims }
1581 \@@_new_deprecated_statement:nnnn { Ellipsis } { }
1582 { use~\token_to_str:c{ellipsis}~instead } { \ebproofellipsis }
1583 \@@_new_deprecated_statement:nnnn { Hypo } { }
1584 { use~\token_to_str:c{hypo}~instead } { \ebproofhypo }
1585 \@@_new_deprecated_statement:nnnn { Infer } { }
1586 { use~\token_to_str:c{infer}~instead } { \ebproofinfer }
1587 % \end{macrocode}
1588 %
1589 %
1590 % \subsubsection{Environment interface}
1591 %
1592 % The stack is initialised globally. The \env{prooftree} environment does not
1593 % clear the stack, instead it saves the initial level in order to check that
1594 % statements are properly balanced. This allows for nested uses of the
1595 % environment, if it ever happens to be useful.
1596 %
1597 % \begin{macrocode}
1598 \@@_clear_stack:
1599 \tl_new:N \l_@@_start_level_tl
1600 % \end{macrocode}
1601 %
1602 % \begin{macro}{prooftree,prooftree*}
1603 % The \env{prooftree} environment.
1604 % \begin{macrocode}
1605 \NewDocumentEnvironment { prooftree } { s O{} } {
1606 \group_align_safe_begin:
1607 \keys_set_known:nnN { ebproof / proof~style } { #2 } \l_tmpa_tl
1608 \keys_set:nV { ebproof } \l_tmpa_tl
1609 \tl_set:Nx \l_@@_start_level_tl { \int_use:N \g_@@_level_int }
1610 \vbox_set:Nw \l_tmpa_box
1611 \@@_setup_statements:
1612 } {
1613 \vbox_set_end:
1614 \@@_pop:N \l_@@_a_box
1615 \int_compare:nNnF { \g_@@_level_int } = { \tl_use:N \l_@@_start_level_tl } {
1616 \PackageError{ebproof}{Malformed~proof~tree}{
1617 Some~hypotheses~were~declared~but~not~used~in~this~tree.}
1618 }
1619 \IfBooleanTF { #1 } {
1620 \[ \box_use:c { \@@_box:N \l_@@_a_box } \]
1621 \ignorespacesafterend
1622 } {
1623 \hbox_unpack:N \c_empty_box
1624 \bool_if:NTF \l_@@_center_bool {
1625 \hbox:n { $ \tex_vcenter:D { \box_use:c { \@@_box:N \l_@@_a_box } } $ }
1626 } {
1627 \box_use:c { \@@_box:N \l_@@_a_box }
1628 }
1629 }
1630 \group_align_safe_end:
1631 }
1632 % \end{macrocode}
1633 % A trick for the starred version:
1634 % \begin{macrocode}
1635 \cs_new:cpn { prooftree* } { \prooftree* }
1636 \cs_new:cpn { endprooftree* } { \endprooftree }
1637 % \end{macrocode}
1638 % \end{macro}
1639 %
1640 % \begin{macrocode}
1641 %</package>
1642 % \end{macrocode}
1643 %
1644 % \end{implementation}