-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathebproof.dtx
More file actions
1644 lines (1644 loc) · 54.8 KB
/
ebproof.dtx
File metadata and controls
1644 lines (1644 loc) · 54.8 KB
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
% \iffalse meta-comment
%
% Copyright (C) 2015-2021 by Emmanuel Beffara
%
% This file may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3 of this license or (at
% your option) any later version. The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
%
%<*driver>
\documentclass[full]{l3doc}
\usepackage{ebproof}
\usepackage{multicol}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\EnableCrossrefs
\newenvironment{example}{%
\VerbatimEnvironment
\begin{VerbatimOut}{example.tex}}{%
\end{VerbatimOut}
\begin{center}
\begin{minipage}{.4\textwidth}
\input{example.tex}
\end{minipage}%
\begin{minipage}{.6\textwidth}
\small\VerbatimInput[gobble=0]{example.tex}
\end{minipage}%
\end{center}
}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
% The \pkg{ebproof} package \\
% Formal proofs in the style of sequent calculus^^A
% }
%
% \author{^^A
% Emmanuel Beffara\thanks
% {^^A
% E-mail: \href{mailto:manu@beffara.org}{manu@beffara.org}^^A
% }^^A
% }
%
% \date{Version 2.1.1 -- Released 2021-01-28}
%
% \maketitle
%
% \setcounter{tocdepth}{2}
% \begin{multicols}{2}
% \tableofcontents
% \end{multicols}
%
% \begin{documentation}
%
% \section{Introduction}
%
% The \pkg{ebproof} package provides commands to typeset proof trees, in the
% style of sequent calculus and related systems:
%
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma, A &\vdash B }
% \infer1[abs]{ \Gamma &\vdash A\to B }
% \hypo{ \Gamma \vdash A }
% \infer2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
%
% The structure is very much inspired by the
% \href{http://math.ucsd.edu/~sbuss/ResearchWeb/bussproofs/}{\pkg{bussproofs}}
% package, in particular for the postfix notation.
% I actually wrote \pkg{ebproof} because there were some limitations in
% \pkg{bussproofs} that I did not know how to lift, and also because I did
% not like some choices in that package (and also because it was fun to write).
%
% Any feedback is welcome, in the form of bug reports, feature requests or
% suggestions, through the web page of the project at \url{https://framagit.org/manu/ebproof}.
%
% \section{Environments}
%
% \begin{function}{prooftree,prooftree*}
% \begin{syntax}
% \verb|\begin{prooftree}|\oarg{options}
% ~ \meta{statements}
% \verb|\end{prooftree}|
% \end{syntax}
% The package provides the \env{prooftree} environment, in standard and
% starred variants.
% This typesets the proof tree described by the \meta{statements}, as
% described in section~\ref{sec:statements}.
% The \meta{options} provide default formatting options for the proof tree,
% available options are described in section~\ref{sec:options}.
%
% Following the conventions of \pkg{amsmath} for alignment environments, the
% non-starred version produces a proof tree at the current position in the
% text flow (it can be used in math mode or text mode) while the starred
% version typesets the proof on a line of its own, like a displayed formula.
% \end{function}
%
% \begin{example}
% \[
% \begin{prooftree}
% \infer0{ \vdash A }
% \hypo{ \vdash B } \infer1{ \vdash B, C }
% \infer2{ \vdash A\wedge B, C }
% \end{prooftree}
% \quad \rightsquigarrow \quad
% \begin{prooftree}
% \infer0{ \vdash A } \hypo{ \vdash B }
% \infer2{ \vdash A\wedge B }
% \infer1{ \vdash A\wedge B, C }
% \end{prooftree}
% \]
% \end{example}
%
% \section{Statements}
% \label{sec:statements}
%
% Statements describe proofs in postfix notation: when typesetting a proof tree
% whose last rule has, say, two premisses, you will first write statements for
% the subtree of the first premiss, then statements for the subtree of the
% second premiss, then a statement like \cs{infer2}\{\meta{conclusion}\} to
% build an inference with these two subtrees as premisses and the given text as
% conclusion.
%
% Hence statements operate on a stack of proof trees.
% At the beginning of a \env{prooftree} environment, the stack is empty.
% At the end, it must contain exactly one tree, which is the one that will be
% printed.
%
% Note that the commands defined in this section only exist right inside
% \env{prooftree} environments.
% If you have a macro with the same name as one of the statements, for instance
% \cs{hypo}, then this macro will keep its meaning outside \env{prooftree}
% environments as well as inside the arguments of a statement.
% If you really need to access the statements in another context, you can can
% always call them by prefixing their names with \texttt{ebproof}, for instance as
% \cs{ebproofhypo}.
%
% \subsection{Basic statements}
%
% The basic statements for building proofs are the following, where
% \meta{options} stands for arbitrary options as described in
% section~\ref{sec:options}.
%
% \begin{function}{\hypo}
% \begin{syntax}
% \cs{hypo}\oarg{options}\marg{text}
% \end{syntax}
% The statement \cs{hypo} pushes a new proof tree consisting only in one
% conclusion line, with no premiss and no line above, in other words a tree
% with only a leaf (\cs{hypo} stands for \emph{hypothesis}).
% \end{function}
%
% \begin{function}{\infer}
% \begin{syntax}
% \cs{infer}\oarg{options}\meta{arity}\oarg{label}\marg{text}
% \end{syntax}
% The statement \cs{infer} builds an inference step by taking some proof
% trees from the top of the stack, assembling them with a rule joining their
% conclusions and putting a new conclusion below.
% The \meta{arity} is the number of sub-proofs, it may be any number
% including 0 (in this case there will be a line above the conclusion but no
% sub-proof).
% If \meta{label} is present, it is used as the label on the right of the
% inference line; it is equivalent to using the \cmd{right label} option.
% \end{function}
%
% \medskip
%
% The \meta{text} in these statements is the contents of the conclusion at the
% root of the tree that the statements create.
% It is typeset in math mode by default but any kind of formatting can be used
% instead, using the \cmd{template} option.
% The \meta{label} text is formatted in horizontal text mode by default.
%
% Each proof tree has a vertical axis, used for alignment of successive steps.
% The position of the axis is deduced from the text of the conclusion at the
% root of the tree: if \meta{text} contains the alignment character \verb|&|
% then the axis is set at that position, otherwise the axis is set at the center
% of the conclusion text.
% The \cs{infer} statement makes sure that the axis of the premiss is at the
% same position as the axis of the conclusion.
% If there are several premisses, it places the axis at the center between the
% left of the leftmost conclusion and the right of the rightmost conclusion:
%
% \begin{example}
% \begin{prooftree}
% \hypo{ &\vdash A, B, C }
% \infer1{ A &\vdash B, C }
% \infer1{ A, B &\vdash C }
% \hypo{ D &\vdash E }
% \infer2{ A, B, D &\vdash C, E }
% \infer1{ A, B &\vdash C, D, E }
% \infer1{ A &\vdash B, C, D, E }
% \end{prooftree}
% \end{example}
%
% \begin{function}{\ellipsis}
% \begin{syntax}
% \cs{ellipsis}\marg{label}\marg{text}
% \end{syntax}
% The statement \cs{ellipsis} typesets vertical dots, with a label on the right,
% and a new conclusion. No inference lines are inserted.
% \end{function}
%
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma &\vdash A }
% \ellipsis{foo}{ \Gamma &\vdash A, B }
% \end{prooftree}
% \end{example}
%
%
% \subsection{Modifying proof trees}
%
% The following additional statements may be used to affect the format of the
% last proof tree on the stack.
%
% \begin{function}{\rewrite}
% \begin{syntax}
% \cs{rewrite}\marg{code}
% \end{syntax}
% The statement \cs{rewrite} is used to modify the proof of the stack while
% preserving its size and alignment.
% The \meta{code} is typeset in horizontal mode, with the following control
% sequences defined:
% \begin{itemize}
% \item \cs{treebox} is a box register that contains the original material,
% \item \cs{treemark}\marg{name} expands as the position of a given mark with
% respect to the left of the box.
% \end{itemize}
% \end{function}
%
% A simple use of this statement is to change the color of a proof tree:
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma, A &\vdash B }
% \infer1[abs]{ \Gamma &\vdash A\to B }
% \rewrite{\color{red}\box\treebox}
% \hypo{ \Gamma \vdash A }
% \infer2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
% Note the absence of spaces inside the call to \cs{rewrite}, because spaces
% would affect the position of the tree box.
% Note also that explicit use of \cs{treebox} is required to actually draw the
% subtree.
% Not using it will effectively not render the subtree, while still reserving
% its space in the enclosing tree:
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma, A &\vdash B }
% \infer1[abs]{ \Gamma &\vdash A\to B }
% \rewrite{}
% \hypo{ \Gamma \vdash A }
% \infer2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
% This kind of manipulation is useful for instance in conjunction with the
% \pkg{beamer} package to allow revealing subtrees of a proof tree
% progressively in successive slides of a given frame.
%
% \begin{function}{\delims}
% \begin{syntax}
% \cs{delims}\marg{left}\marg{right}
% \end{syntax}
% The statement \cs{delims} puts left and right delimiters around the whole
% sub-proof, without changing the alignment (the spacing is affected by the
% delimiters, however).
% The \meta{left} text must contain an opening occurrence of \cs{left} and
% the \meta{right} text must contain a matching occurrence of \cs{right}.
% For instance, \verb|\delims{\left(}{\right)}| will put the sub-proof
% between parentheses.
% \end{function}
%
% \begin{example}
% \begin{prooftree}
% \hypo{ A_1 \vee \cdots \vee A_n }
% \hypo{ [A_i] }
% \ellipsis{}{ B }
% \delims{ \left( }{ \right)_{1\leq i\leq n} }
% \infer2{ B }
% \end{prooftree}
% \end{example}
%
% \begin{function}{\overlay}
% \begin{syntax}
% \cs{overlay}
% \end{syntax}
% The statement \cs{overlay} combines the last two proofs on the stack into
% a single one, so that their conclusions are placed at the same point.
% \end{function}
%
% \begin{example}
% \begin{prooftree}
% \hypo{Z}
% \hypo{A} \hypo{B} \infer2{C} \hypo{D} \infer2{D}
% \rewrite{\color{blue}\box\treebox}
% \hypo{E} \hypo{F} \hypo{G} \infer2{H} \infer2{I}
% \rewrite{\color{red}\box\treebox}
% \overlay \hypo{J} \infer3{K}
% \end{prooftree}
% \end{example}
%
% The primary use of this feature is for building animated presentations where
% a subtree in a proof has to be modified without affecting the general
% alignment of the surrounding proof. For instance, the example above could be
% used in Beamer to build successive slides in a given frame with two
% different subtrees:
%
% \begin{verbatim}
% \begin{prooftree}
% \hypo{Z}
% \hypo{A} \hypo{B} \infer2{C} \hypo{D} \infer2{D}
% \only<2>{\rewrite{}} % erases this version on slide 2
% \hypo{E} \hypo{F} \hypo{G} \infer2{H} \infer2{I}
% \only<1>{\rewrite{}} % erases this version on slide 1
% \overlay \hypo{J} \infer3{K}
% \end{prooftree}
% \end{verbatim}
%
% \section{Options}
% \label{sec:options}
%
% The formatting of trees, conclusion texts and inference rules is affected by
% options, specified using the \LaTeX3 key-value system.
% All options are in the \texttt{ebproof} module in the key tree.
% They can be set locally for a proof tree or for a single statement using
% optional arguments in the associated commands.
%
% \begin{function}{\ebproofset,\set}
% \begin{syntax}
% \cs{ebproofset}\marg{options}
% \end{syntax}
% The statement \cs{ebproofset} is used to set some options. When used
% inside a \env{prooftree} environment, it can written \cs{set}.
% The options will apply in the current scope; using this in preamble will
% effectively set options globally.
% Specific options may also be specified for each proof tree and for each
% statement in a proof tree, using optional arguments.
% \end{function}
%
% \subsection{General shape}
%
% The options in this section only make sense at the global level and at the
% proof level.
% Changing the proof style inside a \env{proof} environment has undefined
% behaviour.
%
% \begin{variable}{proof style}
% The option \cmd{proof style} sets the general shape for representing proofs.
% The following styles are provided:
% \begin{description}
% \item[upwards]
% This is the default style.
% Proof trees grow upwards, with conclusions below and premisses above.
% \item[downwards]
% Proof trees grow downwards, with conclusions above and premisses below.
% \fvset{gobble=6}
% \begin{example}
% \begin{prooftree}[proof style=downwards]
% \hypo{ \Gamma, A &\vdash B }
% \infer1[abs]{ \Gamma &\vdash A\to B }
% \hypo{ \Gamma \vdash A }
% \infer2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
% \end{description}
% \end{variable}
%
% In the optional argument of \env{prooftree} environments, proof styles can
% be specified directly, without prefixing the name by ``\texttt{proof style=}''.
% For instance, the first line of the example above could be written
% \verb|\begin{prooftree}| equivalently.
%
% \begin{variable}{center}
% The option \cmd{center} toggles vertical centering of typeset proofs.
% If set to \texttt{true}, the tree produced by the \env{prooftree}
% environment will be vertically centered around the text line.
% If set to \texttt{false}, the base line of the tree will be the base line
% of the conclusion.
% The default value is \texttt{true}.
% \end{variable}
%
% \begin{example}
% \begin{prooftree}[center=false]
% \infer0{ A \vdash A }
% \end{prooftree}
% \qquad
% \begin{prooftree}[center=false]
% \hypo{ \Gamma, A \vdash B }
% \infer1{ \Gamma \vdash A \to B }
% \end{prooftree}
% \end{example}
%
% \subsection{Spacing}
%
% \begin{variable}{separation}
% Horizontal separation between sub-proofs in an inference is defined by the
% option \cmd{separation}.
% The default value is \texttt{1.5em}.
% \end{variable}
%
% \begin{example}
% \begin{prooftree}[separation=0.5em]
% \hypo{ A } \hypo{ B } \infer2{ C }
% \hypo{ D } \hypo{ E } \hypo{ F } \infer3{ G }
% \hypo{ H } \infer[separation=3em]3{ K }
% \end{prooftree}
% \end{example}
%
% \begin{variable}{rule margin}
% The spacing above and below inference lines is defined by the option
% \cmd{rule margin}.
% The default value is \texttt{0.7ex}.
% \end{variable}
%
% \begin{example}
% \begin{prooftree}[rule margin=2ex]
% \hypo{ \Gamma, A &\vdash B }
% \infer1[abs]{ \Gamma &\vdash A\to B }
% \hypo{ \Gamma \vdash A }
% \infer2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
%
% \subsection{Shape of inference lines}
%
% \begin{variable}{rule style}
% The shape of inference lines is set by the option \cmd{rule style}.
% The following values are provided:
% \begin{center}
% \begin{tabular}{@{}l@{\qquad}l@{}}
% \toprule
% \cmd{simple} & a simple line (this is the default style) \\
% \cmd{no rule} & no rule, only a single space of length \texttt{rule margin} \\
% \cmd{double} & a double line \\
% \cmd{dashed} & a single dashed line \\
% \bottomrule
% \end{tabular}
% \end{center}
% \end{variable}
%
% The precise rendering is influenced by parameters specified below.
% Arbitrary new shapes can defined using the \cs{ebproofnewrulestyle} command
% described in section~\ref{sec:styles}, using \texttt{rule code} option
% described below.
%
% In the optional argument of the \cs{infer} statement, rule styles can be
% specified directly, without prefixing the style name by ``\texttt{rule style=}''.
% For instance, \verb|\infer[dashed]| is equivalent to
% \verb|\infer[rule style=dashed]|.
%
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma &\vdash A \to B }
% \infer[no rule]1{ \Gamma &\vdash {!A} \multimap B }
% \hypo{ \Delta &\vdash A }
% \infer[rule thickness=2pt]1{ \Delta &\vdash {!A} }
% \infer0{ B \vdash B }
% \infer[dashed]2{ \Delta, {!A}\multimap B \vdash B }
% \infer2{ \Gamma, \Delta &\vdash B }
% \infer[double]1{ \Gamma \cup \Delta &\vdash B }
% \end{prooftree}
% \end{example}
%
% \begin{variable}{rule thickness,rule separation}
% The thickness of inference lines is defined by option \cmd{rule
% thickness}, it is \texttt{0.4pt} by default.
% The distance between the two lines in the \texttt{double} rule style is
% defined by the \cmd{rule separation} option.
% It is \texttt{2pt} by default.
% \end{variable}
% \begin{variable}{rule dash length,rule dash space}
% For dashed rules, the length of dashes is defined by the option
% \cmd{rule dash length} and the space between dashes is defined by the
% option \cmd{rule dash space}.
% The default values are \texttt{0.2em} and \texttt{0.3em} respectively.
% \end{variable}
%
% \begin{variable}{rule code}
% Arbitrary rule shapes can be optained using the \cmd{rule code} option.
% The argument is code is used to render the rule, it is executed in
% vertical mode in a \cs{vbox} whose \cs{hsize} is set to the width of the
% rule.
% Margins above and below are inserted automatically (they can be removed by
% setting \texttt{rule margin} to \texttt{0pt}).
% \end{variable}
%
% \begin{example}
% \begin{prooftree}[rule code={\hbox{\tikz
% \draw[decorate,decoration={snake,amplitude=.3ex}]
% (0,0) -- (\hsize,0);}}]
% \hypo{ \Gamma &\vdash A }
% \infer1{ \Gamma &\vdash A, \ldots, A }
% \hypo{ \Delta, A, \ldots, A \vdash \Theta }
% \infer2{ \Gamma, \Delta \vdash \Theta }
% \end{prooftree}
% \end{example}
% Note that this example requires the \pkg{tikz} package, with the
% \pkg{decorations.pathmorphing} library for the \texttt{snake} decoration.
%
% \subsection{Format of conclusions and labels}
%
% \begin{variable}{template,left template,right template}
% The format of text in inferences is defined by templates.
% The option \cmd{template} is used for text with no alignment mark, the
% options \cmd{left template} and \cmd{right template} are used for the left
% and right side of the alignment mark when it is present.
% The value of these options is arbitrary \TeX\ code, composed in horizontal mode.
% The macro \cs{inserttext} is used to insert the actual text passed to the
% \cs{hypo} and \cs{infer} statements.
% The default value for \cmd{template} is simply \verb|$\inserttext$|, so
% that conclusions are set in math mode.
% The default values for \cmd{left template} and \cmd{right template} are
% similar, with spacing assuming that a relation symbol is put near the
% alignment mark, so that \verb|\infer1{A &\vdash B}| is spaced correctly.
% \end{variable}
%
% \begin{example}
% \begin{prooftree}[template=(\textbf\inserttext)]
% \hypo{ foo }
% \hypo{ bar }
% \infer1{ baz }
% \infer2{ quux }
% \end{prooftree}
% \end{example}
%
% \begin{variable}{left label,right label}
% The text to use as the labels of the rules, on the left and on the right
% of the inference line, is defined by the options \cmd{left label} and
% \cmd{right label}.
% Using the second optional argument in \cs{infer} is equivalent to setting
% the \env{right label} option with the value of that argument.
% \end{variable}
%
% \begin{example}
% \begin{prooftree}
% \hypo{ \Gamma, A &\vdash B }
% \infer[left label=$\lambda$]1[abs]
% { \Gamma &\vdash A\to B }
% \hypo{ \Gamma \vdash A }
% \infer[left label=@]2[app]{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
%
% \begin{variable}{left label template,right label template}
% Similarly to conclusions, labels are formatted according to templates.
% The code is arbitrary \TeX\ code, composed in horizontal mode, where the
% macro \cs{inserttext} can be used to insert the actual label text.
% The default values are simply \cs{inserttext} so that labels are set in
% plain text mode.
% \end{variable}
% \begin{variable}{label separation}
% The spacing between an inference line and its labels is defined by the
% option \cmd{label separation}, the default value is \texttt{0.5em}.
% The height of the horizontal axis used for aligning the labels with the
% rules is defined by the option \cmd{label axis}, the default value is
% \texttt{0.5ex}.
% \end{variable}
%
%
% \subsection{Style macros}
% \label{sec:styles}
%
% The following commands allow for the definition of custom styles using the
% basic style options, in a way similar to PGF's ``styles'' and \LaTeX3's
% ``meta-keys''.
% This allows setting a bunch of options with the same values in many proofs
% using a single definition.
%
% \begin{function}{\ebproofnewstyle}
% \begin{syntax}
% \cs{ebproofnewstyle}\marg{name}\marg{options}
% \end{syntax}
% The statement \cs{ebproofnewstyle} defines a new style option with some
% \meta{name} that sets a given set of \meta{options}.
% \end{function}
% For instance, the following code defines a new option \cmd{small} that sets
% various parameters so that proofs are rendered smaller.
% \begin{example}
% \ebproofnewstyle{small}{
% separation = 1em, rule margin = .5ex,
% template = \footnotesize$\inserttext$ }
% \begin{prooftree}[small]
% \hypo{ \Gamma, A \vdash B }
% \infer1{ \Gamma \vdash A\to B }
% \hypo{ \Gamma \vdash A } \infer2{ \Gamma \vdash B }
% \end{prooftree}
% \end{example}
%
% \begin{function}{\ebproofnewrulestyle}
% \begin{syntax}
% \cs{ebproofnewrulestyle}\marg{name}\marg{options}
% \end{syntax}
% The statement \cs{ebproofnewrulestyle} does the same for rule styles.
% The \meta{options} part includes options used to set how to draw rules in
% the new style.
% \end{function}
%
% The option \cmd{rule code} is useful in this command as it allows to
% define arbitrary rule styles.
% For instance, the squiggly rule example above could be turned into a new
% rule style \texttt{zigzag} with the following code:
% \begin{example}
% \ebproofnewrulestyle{zigzag}{
% rule code = {\hbox{\tikz
% \draw[decorate,decoration={snake,amplitude=.3ex}]
% (0,0) -- (\hsize,0);}}}
% \begin{prooftree}
% \hypo{ \Gamma &\vdash A }
% \infer1{ \Gamma &\vdash A, \ldots, A }
% \hypo{ \Delta, A, \ldots, A \vdash \Theta }
% \infer[zigzag]2{ \Gamma, \Delta \vdash \Theta }
% \end{prooftree}
% \end{example}
%
%
% \section{License}
%
% This work may be distributed and/or modified under the
% conditions of the \LaTeX\ Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% \begin{center}
% \url{http://www.latex-project.org/lppl.txt}
% \end{center}
% and version 1.3 or later is part of all distributions of \LaTeX\
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Emmanuel Beffara.
%
% This work consists of the files \texttt{ebproof.sty} and \texttt{ebproof.tex}.
%
% \section{History}
%
% This section lists the principal evolutions of the package, in reverse
% chronological order.
% \begin{description}
% \item[Version 2.1.1 (2021-01-28)]
% Bugfix release, no changes in the user interface.
% \begin{itemize}
% \item Fixes a deprecation issue with \LaTeX3 release 2021-01-09 and
% various warnings that appear in \LaTeX3 debugging mode.
% \item Fixes \cmd{proof style=downwards}.
% \end{itemize}
% \item[Version 2.1 (2020-08-19)]
% Mostly a bugfix release.
% \begin{itemize}
% \item Makes the \env{prooftree} environment robust to use in tabular
% contexts.
% \item Adds the \cs{overlay} statement.
% \item Fixes a compatibility issue with \LaTeX\ release 2020-10-01.
% \end{itemize}
% \item[Version 2.0 (2017-05-17)]
% A complete rewrite of the code using the \LaTeX3 programming environment.
% The incompatible changes from the user's point of view are the following:
% \begin{itemize}
% \item Proof statements are now writtten in lowercase ({i.e.} \cs{Infer} is
% now written \cs{infer} etc.) but the syntax is otherwise unchanged.
% The old uppercase commands still work but produce a deprecation warning,
% they will be removed in a future version.
% \item New styles are now defined using \cs{ebproofnewstyle} and
% \cs{ebproofnewrulestyle}. The previous method using PGF styles does not
% work anymore (because PGF is not used anymore).
% \end{itemize}
% The new commands and options are the following:
% \begin{itemize}
% \item The statement \cs{rewrite} generalizes \cs{Alter},
% \item The option \cmd{label axis} controls vertical alignment of labels.
% \end{itemize}
% \item[Version 1.1 (2015-03-13)]
% A bugfix release.
% In \cmd{template} options, one now uses \cs{inserttext} instead of \verb|#1|
% for the text arguments, which improves robustness.
% \item[Version 1.0 (2015-02-04)]
% The first public release.
% \end{description}
%
% \end{documentation}
%
% \clearpage \appendix
%
% \begin{implementation}
%
% \section{Implementation}
%
% \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\RequirePackage{xparse}
\ProvidesExplPackage{ebproof}{2021/01/28}{2.1.1}{EB's proof trees}
%<@@=ebproof>
% \end{macrocode}
%
% \subsection{Parameters}
%
% We first declare all options. For the meaning of options, see
% section~\ref{sec:options}.
%
% \begin{macrocode}
\bool_new:N \l_@@_updown_bool
\keys_define:nn { ebproof } {
center .bool_set:N = \l_@@_center_bool,
proof~style .choice: ,
proof~style / upwards .code:n = \bool_set_false:N \l_@@_updown_bool,
proof~style / downwards .code:n = \bool_set_true:N \l_@@_updown_bool,
separation .dim_set:N = \l_@@_separation_dim,
rule~margin .dim_set:N = \l_@@_rule_margin_dim,
rule~thickness .dim_set:N = \l_@@_rule_thickness_dim,
rule~separation .dim_set:N = \l_@@_rule_separation_dim,
rule~dash~length .dim_set:N = \l_@@_rule_dash_length_dim,
rule~dash~space .dim_set:N = \l_@@_rule_dash_space_dim,
rule~code .tl_set:N = \l_@@_rule_code_tl,
rule~style .choice:,
template .tl_set:N = \l_@@_template_tl,
left~template .tl_set:N = \l_@@_left_template_tl,
right~template .tl_set:N = \l_@@_right_template_tl,
left~label .tl_set:N = \l_@@_left_label_tl,
right~label .tl_set:N = \l_@@_right_label_tl,
left~label~template .tl_set:N = \l_@@_left_label_template_tl,
right~label~template .tl_set:N = \l_@@_right_label_template_tl,
label~separation .dim_set:N = \l_@@_label_separation_dim,
label~axis .dim_set:N = \l_@@_label_axis_dim,
}
% \end{macrocode}
%
% \begin{macro}{\ebproofnewrulestyle}
% We then define the document-level macro \cs{ebproofnewrulestyle} and use
% it to define the default styles. This simply consists in defining a
% meta-key.
% \begin{macrocode}
\NewDocumentCommand \ebproofnewrulestyle { mm } {
\keys_define:nn { ebproof } {
rule~style / #1 .meta:nn = { ebproof } { #2 }
}
}
% \end{macrocode}
% \end{macro}
%
% The styles |simple|, |no rule| and |double| are defined in a straightforward
% way.
%
% \begin{macrocode}
\ebproofnewrulestyle { simple } {
rule~code = { \tex_hrule:D height \l_@@_rule_thickness_dim }
}
\ebproofnewrulestyle { no~rule } {
rule~code =
}
\ebproofnewrulestyle { double } {
rule~code = {
\tex_hrule:D height \l_@@_rule_thickness_dim
\skip_vertical:N \l_@@_rule_separation_dim
\tex_hrule:D height \l_@@_rule_thickness_dim
}
}
% \end{macrocode}
%
% The |dashed| style uses leaders and filling for repeating a single dash. We
% use \TeX\ primitives that have no \LaTeX3 counterpart for this.
%
% \begin{macrocode}
\ebproofnewrulestyle { dashed } {
rule~code = {
\hbox_to_wd:nn { \tex_hsize:D } {
\dim_set:Nn \l_tmpa_dim { \l_@@_rule_dash_space_dim / 2 }
\skip_horizontal:n { -\l_tmpa_dim }
\tex_cleaders:D \hbox:n {
\skip_horizontal:N \l_tmpa_dim
\tex_vrule:D
height \l_@@_rule_thickness_dim
width \l_@@_rule_dash_length_dim
\skip_horizontal:N \l_tmpa_dim
} \tex_hfill:D
\skip_horizontal:n { -\l_tmpa_dim }
}
}
}
% \end{macrocode}
%
% Now we can define the default values, including the default rule style.
%
% \begin{macrocode}
\keys_set:nn { ebproof } {
center = true,
proof~style = upwards,
separation = 1.5em,
rule~margin = .7ex,
rule~thickness = .4pt,
rule~separation = 2pt,
rule~dash~length = .2em,
rule~dash~space = .3em,
rule~style = simple,
template = $\inserttext$,
left~template = $\inserttext\mathrel{}$,
right~template = $\mathrel{}\inserttext$,
left~label = ,
right~label = ,
left~label~template = \inserttext,
right~label~template = \inserttext,
label~separation = 0.5em,
label~axis = 0.5ex
}
% \end{macrocode}
%
% \begin{macro}{\ebproofnewstyle}
% Defining a style simply means defining a meta-key.
% \begin{macrocode}
\NewDocumentCommand \ebproofnewstyle { mm } {
\keys_define:nn { ebproof } { #1 .meta:n = { #2 } }
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Proof boxes}
%
% \TeX\ does not actually provide data structures, so we have to encode things.
% We provide an allocator for ``registers'' holding boxes with attributes. Such
% a register consists in a box register and a property list for marks, which
% maps mark names to values as explicit dimensions with units.
%
% \begin{macro}{\@@_new:N}
% Using only public interfaces forces a convoluted approach to allocation:
% we use a global counter \cs{g_ebproof_register_int} to number registers,
% then each allocation creates registers named \cs{S_ebproof_K_N} where
% S is the scope of the register (local or global, deduced from the argument),
% K is the kind of component (box or marks) and N is the identifier of the
% register. The proof box register itself only contains the identifier used
% for indirection.
% \begin{macrocode}
\int_new:N \g_@@_register_int
\cs_new:Nn \@@_box:N {
\str_item:nn { #1 } { 2 } __ebproof_ \tl_use:N #1 _box
}
\cs_new:Nn \@@_marks:N {
\str_item:nn { #1 } { 2 } __ebproof_ \tl_use:N #1 _prop
}
\cs_new:Nn \@@_new:N {
\tl_new:N #1
\int_gincr:N \g_@@_register_int
\str_if_eq:eeTF { \str_item:nn { #1 } { 2 } } { g }
{ \tl_gset:Nx #1 { \int_to_arabic:n { \g_@@_register_int } } }
{ \tl_set:Nx #1 { \int_to_arabic:n { \g_@@_register_int } } }
\box_new:c { \@@_box:N #1 }
\prop_new:c { \@@_marks:N #1 }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_clear:N}
% The box is cleared by setting it to an empty hbox.
% Using \cs{box_clear:N} instead would not work because trying to push this
% box on the stack would not actually append any box.
% \begin{macrocode}
\cs_new:Nn \@@_clear:N {
\hbox_set:cn { \@@_box:N #1 } {}
\prop_clear:c { \@@_marks:N #1 }
\@@_set_mark:Nnn #1 { left } { 0pt }
\@@_set_mark:Nnn #1 { right } { 0pt }
\@@_set_mark:Nnn #1 { axis } { 0pt }
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Mark operations}
%
% \begin{macro}{\@@_set_mark:Nnn}
% Setting the value of a mark uses a temporary register to evaluate the
% dimension expression because values are stored textually in a property
% list.
% \begin{macrocode}
\dim_new:N \l_@@_transit_dim
\cs_new:Nn \@@_set_mark:Nnn {
\dim_set:Nn \l_@@_transit_dim { #3 }
\prop_put:cnV { \@@_marks:N #1 } { #2 }
\l_@@_transit_dim
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_mark:Nn}
% Getting the value of a mark simply consists in getting an item in a
% property list.
% \begin{macrocode}
\cs_new:Nn \@@_mark:Nn {
\prop_item:cn { \@@_marks:N #1 } { #2 }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_shift_x:Nn}
% This function shifts the marks by a specified amount, without modifying
% the box.
% \begin{macrocode}
\cs_new:Nn \@@_shift_x:Nn {
\prop_map_inline:cn { \@@_marks:N #1 } {
\@@_set_mark:Nnn #1 { ##1 } { ##2 + #2 }
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_enlarge_conclusion:NN}
% This function moves the left and right marks of the first tree so that
% they are at least as far from the axis as they are in the second tree.
% For instance we get the following:
% \begin{center}
% \begin{tikzpicture}[y=-3ex]
% \node (L1) at (1,0) {L}; \node (A1) at (2,0) {A}; \node (R1) at (4,0) {R};
% \node (L2) at (0,1) {L}; \node (A2) at (2,1) {A}; \node (R2) at (3,1) {R};
% \node (L3) at (0,2) {L}; \node (A3) at (2,2) {A}; \node (R3) at (4,2) {R};
% \draw (L1) -- (A1) -- (R1);
% \draw (L2) -- (A2) -- (R2);
% \draw (L3) -- (A3) -- (R3);
% \node[anchor=west] at (5,0) {box 1 before};
% \node[anchor=west] at (5,1) {box 2 before};
% \node[anchor=west] at (5,2) {box 1 after};
% \end{tikzpicture}
% \end{center}
% The contents of the trees are unchanged.
% \begin{macrocode}
\cs_new:Nn \@@_enlarge_conclusion:NN {
\dim_set:Nn \l_tmpa_dim { \@@_mark:Nn #1 {axis}
+ \@@_mark:Nn #2 {left} - \@@_mark:Nn #2 {axis} }
\dim_compare:nNnT { \l_tmpa_dim } < { \@@_mark:Nn #1 {left} } {
\@@_set_mark:Nnn #1 {left} { \l_tmpa_dim } }
\dim_set:Nn \l_tmpa_dim { \@@_mark:Nn #1 {axis}
+ \@@_mark:Nn #2 {right} - \@@_mark:Nn #2 {axis} }
\dim_compare:nNnT { \l_tmpa_dim } > { \@@_mark:Nn #1 {right} } {
\@@_set_mark:Nnn #1 {right} { \l_tmpa_dim } }
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Building blocks}
%
% \begin{macro}{\@@_make_simple:Nn}
% Make a tree with explicit material in horizontal mode. Set the left and
% right marks to extremal positions and set the axis in the middle.
% \begin{macrocode}
\cs_new:Nn \@@_make_simple:Nn {
\hbox_set:cn { \@@_box:N #1 } { #2 }
\@@_set_mark:Nnn #1 { left } { 0pt }
\@@_set_mark:Nnn #1 { axis } { \box_wd:c { \@@_box:N #1 } / 2 }
\@@_set_mark:Nnn #1 { right } { \box_wd:c { \@@_box:N #1 } }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_make_split:Nnn}
% Make a tree with explicit material in horizontal mode, split in two parts.
% Set the left and right marks to extremal positions and set the axis
% between the two parts.
% \begin{macrocode}
\cs_new:Nn \@@_make_split:Nnn {
\@@_set_mark:Nnn #1 { left } { 0pt }
\hbox_set:cn { \@@_box:N #1 } { #2 }
\@@_set_mark:Nnn #1 { axis } { \box_wd:c { \@@_box:N #1 } }
\hbox_set:cn { \@@_box:N #1 } { \hbox_unpack:c { \@@_box:N #1 } #3 }
\@@_set_mark:Nnn #1 { right } { \box_wd:c { \@@_box:N #1 } }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_make_vertical:Nnnn}
% Make a tree with explicit material in vertical mode, using an explicit
% width and axis.
% \begin{macrocode}
\cs_new:Nn \@@_make_vertical:Nnnn {
\@@_set_mark:Nnn #1 { left } { 0pt }
\@@_set_mark:Nnn #1 { axis } { #2 }
\@@_set_mark:Nnn #1 { right } { #3 }
\vbox_set:cn { \@@_box:N #1 } {
\dim_set:Nn \tex_hsize:D { \@@_mark:Nn #1 {right} }
#4
}
\box_set_wd:cn { \@@_box:N #1 } { \@@_mark:Nn #1 {right} }
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Assembling boxes}
%
% \begin{macro}{\@@_extend:Nnnnn}
% Extend a tree box. The marks are shifted so that alignment is preserved.
% The arguments are dimensions for the left, top, right and bottom sides