summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/logicproof/logicproof.sty
blob: fa168dba5e00a7c0ee6264680f5fe7a921ec6c6b (plain)
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
%%
%% This is file `logicproof.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% logicproof.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2014 by Alan Davidson
%% 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.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{logicproof}[2014/03/20 v1.0 Box proofs for propositional logic]
\RequirePackage{array}
\RequirePackage{ifthen}
\newlength{\subproofhorizspace}
\setlength{\subproofhorizspace}{0.5em}
\newlength{\intersubproofvertspace}
\setlength{\intersubproofvertspace}{0.333em}
\newcounter{lp@line}% Current line number on the proof
\newcounter{lp@nested}% Number of nested subproofs we're currently in
\newcounter{lp@total@nests}% Maximum number of nested subproofs allowed
\newcounter{lp@cline@1}% Used to draw horizontal lines in subproofs
\newcounter{lp@cline@2}% Also used to draw horizontal lines in subproofs
\newcounter{lp@temp}% Temporary storage counter
\newenvironment{logicproof}[1]{%
  \setcounter{lp@line}{0}%
  \setcounter{lp@nested}{0}%
  \setcounter{lp@total@nests}{#1}%
  \setlength{\tabcolsep}{0mm}%
  \let\lp@orig@arraycr\@arraycr%
  \renewcommand{\@arraycr}{\lp@cr}%
  \renewcommand{\@currentlabel}{\p@lp@line\thelp@line}%
  \ifthenelse{%
    0=#1%
  }{%
    \def\lp@tab@format{{r@{~~~}>{$}l<{$}@{~~~~}l}}%
  }{%
    \def\lp@tab@format%
        {{r@{~~~}*{#1}{l}@{~}>{$}l<{$}@{~~~~}l@{~}*{#1}{r}}}
  }%
  \center%
  \expandafter\tabular\lp@tab@format%
  \lp@start@proof@line%
}{%
  \lp@stop@proof@line%
  \endtabular%
  \endcenter%
  \setcounter{lp@total@nests}{0}%
  \ifthenelse{%
    0=\value{lp@nested}
  }{% All is well.
  }{% There are still open subproofs.
    \def\@currenvir{subproof}%
  }
}
\newenvironment{subproof}{%
  \ifthenelse{%
    \value{lp@total@nests}>\value{lp@nested}%
  }{% All is well; don't do anything.
  }{%
    \PackageError{logicproof}{Too many nested subproofs!}{%
      Increase the maximum number of nested subproofs allowed
      in the current logicproof environment.%
    }%
  }%
  \endgroup%
  \lp@stop@proof@line%
  \lp@orig@arraycr%
  \lp@add@space%
  \lp@go@up@a@line%
  \stepcounter{lp@nested}%
  \lp@cr@clines%
  &%
  \lp@continue@proof@line%
}{%
  \ifthenelse{%
    0<\value{lp@nested}%
  }{% All is well; don't do anything.
  }{%
    \PackageError{logicproof}{Cannot end a subproof before it begins}{%
      You must have a \protect\begin{subproof} before you can use %
      \protect\end{subproof}.%
    }%
  }%
  \lp@stop@proof@line%
  \lp@cr@clines%
  \addtocounter{lp@nested}{-1}%
  \lp@extend@space%
  \lp@start@proof@line%
  \begingroup%
  \def\@currenvir{subproof}%
}
\newcommand{\lp@cr}{%
  \lp@stop@proof@line%
  \lp@orig@arraycr%
  \lp@extend@space%
  \lp@start@proof@line%
}
\newcommand{\lp@go@up@a@line}{%
  \vspace{-\ht\@arstrutbox}%
  \vspace{-\dp\@arstrutbox}%
  \vspace{-\intersubproofvertspace}%
}
\newcommand{\lp@add@space}{%
  \lp@extend@space%
  \vspace{-\ht\@arstrutbox}%
  \vspace{-\dp\@arstrutbox}%
  %\vspace{-\intersubproofvertspace}%
}
\newcommand{\lp@extend@space}{%
  \vspace{-\ht\@arstrutbox}%
  \vspace{-\dp\@arstrutbox}%
  \vspace{\intersubproofvertspace}%
  &%
  \lp@continue@proof@line%
  &%
  \lp@stop@proof@line%
  \lp@orig@arraycr%
}
\newcommand{\lp@amper}{&}
\newcommand{\lp@start@proof@line}{%
  \stepcounter{lp@line}%
  \arabic{lp@line}.%
  &%
  \lp@continue@proof@line%
}
\newcommand{\lp@continue@proof@line}{%
  \setcounter{lp@temp}{0}%
  \whiledo{\value{lp@temp}<\value{lp@nested}}{%
    \vline%
    \hspace*{\subproofhorizspace}%
    \lp@amper%
    \stepcounter{lp@temp}%
  }%
  \whiledo{\value{lp@temp}<\value{lp@total@nests}}{%
    \hspace*{\subproofhorizspace}%
    \lp@amper%
    \stepcounter{lp@temp}%
  }%
}
\newcommand{\lp@stop@proof@line}{%
  \whiledo{\value{lp@temp}>\value{lp@nested}}{%
    \addtocounter{lp@temp}{-1}%
    \lp@amper%
    \hspace*{\subproofhorizspace}%
  }%
  \whiledo{\value{lp@temp}>0}{%
    \addtocounter{lp@temp}{-1}%
    \lp@amper%
    \hspace*{\subproofhorizspace}%
    \vline%
  }%
}
\newcommand{\lp@subtract@from@counter}[2]{%
  \addtocounter{#2}{-#1}%
}
\newcommand{\lp@set@clines}{%
  \setcounter{lp@cline@1}{\value{lp@nested}}%
  \stepcounter{lp@cline@1}%
  \setcounter{lp@cline@2}{\value{lp@total@nests}}%
  \addtocounter{lp@cline@2}{\value{lp@total@nests}}%
  \addtocounter{lp@cline@2}{4}%
  \expandafter\lp@subtract@from@counter\expandafter{%
      \value{lp@nested}}{lp@cline@2}%
}
\newcommand{\lp@cr@clines}{%
  \lp@set@clines%
  \lp@orig@arraycr%
  \cline{\value{lp@cline@1}-\value{lp@cline@2}}%
}
\endinput
%%
%% End of file `logicproof.sty'.