-
Notifications
You must be signed in to change notification settings - Fork 6
/
nd.sty
executable file
·75 lines (64 loc) · 3.55 KB
/
nd.sty
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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ND}[23/03/2010 ND environment for typesetting Lemmon-style natural deduction proofs by Alex Steinberg]
\RequirePackage{xargs,calc}
%%%%%counters, lengths etc.
\newcounter{@NDnumber}
\newcounter{@NDlw}
\newcounter{@NDrw}
\newcounter{@NDtit}
\newlength\@NDitemsep
\setlength\@NDitemsep{2em}
\newlength\@NDboxwidth
\newcounter{@NDlines}
\newlength\@NDrulewidth
\newlength\@NDitemindent
\newlength\@NDlwin
\newlength\@NDrwin
\newlength\@NDlwf
\newlength\@NDlwtmp
\newlength\@NDrwf
\newlength\@NDrwtmp
\newlength\@NDsep
\newlength\@NDsepe
%%%from pbox:
\newcommand{\widthofpbox}[1]{%
\widthof{\begin{tabular}{@{}l@{}}#1\end{tabular}}}
%%%%%Definition of auxilliary commands for the ND environment
\newcommand\@NDwriteout[2]{\immediate\write\@auxout{\noexpand\expandafter\gdef\noexpand\csname @ND#1w\@NDident\endcsname{#2}}}
\def\@NDinsertbreakingcomma{%
\ifnum \@tempcnta = 0 \else,\linebreak[0] \fi
\advance\@tempcnta\@ne
}
\newcommand\NDalist[1]{\ensuremath{\@tempcnta = 0\@for\@ii:=#1\do{\@NDinsertbreakingcomma\@ii}}}
\newcommand\@NDlabel[1]{\refstepcounter{@NDlines}\begin{minipage}[t]{\csname @NDlw\@NDident\endcsname}%
\NDalist{#1}\hfill\end{minipage}\makebox[2\@NDitemsep][c]{\ensuremath{\ensuremath{\left(\the@NDlines\right)}}}}
\newcommand\@NDrules[1]{\hspace{\@NDitemsep}\begin{minipage}[t]{\@NDrulewidth}#1\end{minipage}}
%%%%%Definition of the ND environment and ndl command
\newenvironmentx{ND}[5][1,2,3,4,5]%
{\refstepcounter{@NDnumber}\setcounter{@NDlines}{0}%
\newcommand{\ndl}[3]{\settowidth\@NDlwtmp{\NDalist{##1}}\ifdim\@NDlwtmp > \@NDlwf \setlength\@NDlwf{\@NDlwtmp}\fi%
\settowidth\@NDrwtmp{\widthofpbox{##3}}\ifdim\@NDrwtmp > \@NDrwf \setlength\@NDrwf{\@NDrwtmp}\fi%
\par\addvspace{\topsep}\noindent\@NDlabel{##1}\begin{minipage}[t]{\@NDboxwidth}##2\end{minipage}\@NDrules{##3}}%
\def\@NDtempa{#3}\def\@NDtempb{}\ifx\@NDtempa\@NDtempb\setcounter{@NDlw}{0}\setlength\@NDlwin{2em}\else\setcounter{@NDlw}{1}\setlength\@NDlwin{#3}\fi%
\def\@NDtempa{#4}\ifx\@NDtempa\@NDtempb\setcounter{@NDrw}{0}\setlength\@NDrwin{2cm}\else\setcounter{@NDrw}{1}\setlength\@NDrwin{#4}\fi%
\def\@NDtempa{#1}\ifx\@NDtempa\@NDtempb\setcounter{@NDtit}{0}\else\setcounter{@NDtit}{1}\fi%
\def\@NDtempa{#5}\ifx\@NDtempa\@NDtempb\def\@NDol{\linewidth}\else\def\@NDol{#5}\fi%
\def\@NDtempa{#2}\ifx\@NDtempa\@NDtempb\def\@NDident{\the@NDnumber}\else\def\@NDident{#2}\fi%
\let\@NDoldlabel\label\let\@NDoldref\ref%
\def\label##1{\@NDoldlabel{@ND\@NDident:line##1}}\def\ref##1{\@NDoldref{@ND\@NDident:line##1}}
%
\expandafter\ifx\csname @NDlw\@NDident\endcsname\relax
\expandafter\gdef\csname @NDlw\@NDident\endcsname{\the\@NDlwin}\fi%
\expandafter\ifx\csname @NDrw\@NDident\endcsname\relax
\expandafter\gdef\csname @NDrw\@NDident\endcsname{\the\@NDrwin}\fi
\setlength\@NDrulewidth{\csname @NDrw\@NDident\endcsname}
\def\@NDtempc{\csname @NDlw\@NDident\endcsname}
\setlength\@NDsep{\topsep+\partopsep}\setlength\@NDsepe{\topsep+2\partopsep}
\ifnum\the@NDtit = 1\par\addvspace{\@NDsep}\noindent\hfil\begin{minipage}{\@NDol}\noindent\textbf{#1}\penalty10000\else\vspace{\@NDsep}\par\noindent\hfil\begin{minipage}{\@NDol}\fi\setlength\@NDboxwidth{\linewidth-\@NDrulewidth-\@NDtempc-3\@NDitemsep}}%
{\ifnum\the@NDlw = 1 \@NDwriteout{l}{\the\@NDlwin}\else\@NDwriteout{l}{\the\@NDlwf}\fi%
\ifnum\the@NDrw = 1 \@NDwriteout{r}{\the\@NDrwin}\else\@NDwriteout{r}{\the\@NDrwf}\fi
\end{minipage}\hfil\par\addvspace{\@NDsepe}\ignorespacesafterend}
%%%%%%user commands
\newcommand\awidth[1]{\csname @NDlw#1\endcsname}
\newcommand\rwidth[1]{\csname @NDrw#1\endcsname}
\newcommand\ndref[2]{\ref{@ND#1:line#2}}