ProgTutorial/document/proof.sty
changeset 189 069d525f8f1d
parent 21 2356e5c70d98
equal deleted inserted replaced
188:8939b8fd8603 189:069d525f8f1d
       
     1 %       proof.sty       (Proof Figure Macros)
       
     2 %
       
     3 %       version 3.0 (for both LaTeX 2.09 and LaTeX 2e)
       
     4 %       Mar 6, 1997
       
     5 %       Copyright (C) 1990 -- 1997, Makoto Tatsuta (tatsuta@kusm.kyoto-u.ac.jp)
       
     6 % 
       
     7 % This program is free software; you can redistribute it or modify
       
     8 % it under the terms of the GNU General Public License as published by
       
     9 % the Free Software Foundation; either versions 1, or (at your option)
       
    10 % any later version.
       
    11 % 
       
    12 % This program is distributed in the hope that it will be useful
       
    13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 % GNU General Public License for more details.
       
    16 %
       
    17 %       Usage:
       
    18 %               In \documentstyle, specify an optional style `proof', say,
       
    19 %                       \documentstyle[proof]{article}.
       
    20 %
       
    21 %       The following macros are available:
       
    22 %
       
    23 %       In all the following macros, all the arguments such as
       
    24 %       <Lowers> and <Uppers> are processed in math mode.
       
    25 %
       
    26 %       \infer<Lower><Uppers>
       
    27 %               draws an inference.
       
    28 %
       
    29 %               Use & in <Uppers> to delimit upper formulae.
       
    30 %               <Uppers> consists more than 0 formulae.
       
    31 %
       
    32 %               \infer returns \hbox{ ... } or \vbox{ ... } and
       
    33 %               sets \@LeftOffset and \@RightOffset globally.
       
    34 %
       
    35 %       \infer[<Label>]<Lower><Uppers>
       
    36 %               draws an inference labeled with <Label>.
       
    37 %
       
    38 %       \infer*<Lower><Uppers>
       
    39 %               draws a many step deduction.
       
    40 %
       
    41 %       \infer*[<Label>]<Lower><Uppers>
       
    42 %               draws a many step deduction labeled with <Label>.
       
    43 %
       
    44 %       \infer=<Lower><Uppers>
       
    45 %               draws a double-ruled deduction.
       
    46 %
       
    47 %       \infer=[<Label>]<Lower><Uppers>
       
    48 %               draws a double-ruled deduction labeled with <Label>.
       
    49 %
       
    50 %       \deduce<Lower><Uppers>
       
    51 %               draws an inference without a rule.
       
    52 %
       
    53 %       \deduce[<Proof>]<Lower><Uppers>
       
    54 %               draws a many step deduction with a proof name.
       
    55 %
       
    56 %       Example:
       
    57 %               If you want to write
       
    58 %                           B C
       
    59 %                          -----
       
    60 %                      A     D
       
    61 %                     ----------
       
    62 %                         E
       
    63 %       use
       
    64 %               \infer{E}{
       
    65 %                       A
       
    66 %                       &
       
    67 %                       \infer{D}{B & C}
       
    68 %               }
       
    69 %
       
    70 
       
    71 %       Style Parameters
       
    72 
       
    73 \newdimen\inferLineSkip         \inferLineSkip=2pt
       
    74 \newdimen\inferLabelSkip        \inferLabelSkip=5pt
       
    75 \def\inferTabSkip{\quad}
       
    76 
       
    77 %       Variables
       
    78 
       
    79 \newdimen\@LeftOffset   % global
       
    80 \newdimen\@RightOffset  % global
       
    81 \newdimen\@SavedLeftOffset      % safe from users
       
    82 
       
    83 \newdimen\UpperWidth
       
    84 \newdimen\LowerWidth
       
    85 \newdimen\LowerHeight
       
    86 \newdimen\UpperLeftOffset
       
    87 \newdimen\UpperRightOffset
       
    88 \newdimen\UpperCenter
       
    89 \newdimen\LowerCenter
       
    90 \newdimen\UpperAdjust
       
    91 \newdimen\RuleAdjust
       
    92 \newdimen\LowerAdjust
       
    93 \newdimen\RuleWidth
       
    94 \newdimen\HLabelAdjust
       
    95 \newdimen\VLabelAdjust
       
    96 \newdimen\WidthAdjust
       
    97 
       
    98 \newbox\@UpperPart
       
    99 \newbox\@LowerPart
       
   100 \newbox\@LabelPart
       
   101 \newbox\ResultBox
       
   102 
       
   103 %       Flags
       
   104 
       
   105 \newif\if@inferRule     % whether \@infer draws a rule.
       
   106 \newif\if@DoubleRule    % whether \@infer draws doulbe rules.
       
   107 \newif\if@ReturnLeftOffset      % whether \@infer returns \@LeftOffset.
       
   108 \newif\if@MathSaved     % whether inner math mode where \infer or
       
   109                        % \deduce appears.
       
   110 
       
   111 %       Special Fonts
       
   112 
       
   113 \def\DeduceSym{\vtop{\baselineskip4\p@ \lineskiplimit\z@
       
   114     \vbox{\hbox{.}\hbox{.}\hbox{.}}\hbox{.}}}
       
   115 
       
   116 %       Math Save Macros
       
   117 %
       
   118 %       \@SaveMath is called in the very begining of toplevel macros
       
   119 %       which are \infer and \deduce.
       
   120 %       \@RestoreMath is called in the very last before toplevel macros end.
       
   121 %       Remark \infer and \deduce ends calling \@infer.
       
   122 
       
   123 \def\@SaveMath{\@MathSavedfalse \ifmmode \ifinner
       
   124        \relax $\relax \@MathSavedtrue \fi\fi }
       
   125 
       
   126 \def\@RestoreMath{\if@MathSaved \relax $\relax\fi }
       
   127 
       
   128 %       Macros
       
   129 
       
   130 % Renaming @ifnextchar and @ifnch of LaTeX2e to @IFnextchar and @IFnch.
       
   131 
       
   132 \def\@IFnextchar#1#2#3{%
       
   133   \let\reserved@e=#1\def\reserved@a{#2}\def\reserved@b{#3}\futurelet
       
   134     \reserved@c\@IFnch}
       
   135 \def\@IFnch{\ifx \reserved@c \@sptoken \let\reserved@d\@xifnch
       
   136       \else \ifx \reserved@c \reserved@e\let\reserved@d\reserved@a\else
       
   137           \let\reserved@d\reserved@b\fi
       
   138       \fi \reserved@d}
       
   139 
       
   140 \def\@ifEmpty#1#2#3{\def\@tempa{\@empty}\def\@tempb{#1}\relax
       
   141        \ifx \@tempa \@tempb #2\else #3\fi }
       
   142 
       
   143 \def\infer{\@SaveMath \@IFnextchar *{\@inferSteps}{\relax
       
   144        \@IFnextchar ={\@inferDoubleRule}{\@inferOneStep}}}
       
   145 
       
   146 \def\@inferOneStep{\@inferRuletrue \@DoubleRulefalse
       
   147        \@IFnextchar [{\@infer}{\@infer[\@empty]}}
       
   148 
       
   149 \def\@inferDoubleRule={\@inferRuletrue \@DoubleRuletrue
       
   150        \@IFnextchar [{\@infer}{\@infer[\@empty]}}
       
   151 
       
   152 \def\@inferSteps*{\@IFnextchar [{\@@inferSteps}{\@@inferSteps[\@empty]}}
       
   153 
       
   154 \def\@@inferSteps[#1]{\@deduce{#1}[\DeduceSym]}
       
   155 
       
   156 \def\deduce{\@SaveMath \@IFnextchar [{\@deduce{\@empty}}
       
   157        {\@inferRulefalse \@infer[\@empty]}}
       
   158 
       
   159 %       \@deduce<Proof Label>[<Proof>]<Lower><Uppers>
       
   160 
       
   161 \def\@deduce#1[#2]#3#4{\@inferRulefalse
       
   162        \@infer[\@empty]{#3}{\@SaveMath \@infer[{#1}]{#2}{#4}}}
       
   163 
       
   164 %       \@infer[<Label>]<Lower><Uppers>
       
   165 %               If \@inferRuletrue, it draws a rule and <Label> is right to
       
   166 %               a rule. In this case, if \@DoubleRuletrue, it draws
       
   167 %               double rules.
       
   168 %
       
   169 %               Otherwise, draws no rule and <Label> is right to <Lower>.
       
   170 
       
   171 \def\@infer[#1]#2#3{\relax
       
   172 % Get parameters
       
   173        \if@ReturnLeftOffset \else \@SavedLeftOffset=\@LeftOffset \fi
       
   174        \setbox\@LabelPart=\hbox{$#1$}\relax
       
   175        \setbox\@LowerPart=\hbox{$#2$}\relax
       
   176 %
       
   177        \global\@LeftOffset=0pt
       
   178        \setbox\@UpperPart=\vbox{\tabskip=0pt \halign{\relax
       
   179                \global\@RightOffset=0pt \@ReturnLeftOffsettrue $##$&&
       
   180                \inferTabSkip
       
   181                \global\@RightOffset=0pt \@ReturnLeftOffsetfalse $##$\cr
       
   182                #3\cr}}\relax
       
   183 %                       Here is a little trick.
       
   184 %                       \@ReturnLeftOffsettrue(false) influences on \infer or
       
   185 %                       \deduce placed in ## locally
       
   186 %                       because of \@SaveMath and \@RestoreMath.
       
   187        \UpperLeftOffset=\@LeftOffset
       
   188        \UpperRightOffset=\@RightOffset
       
   189 % Calculate Adjustments
       
   190        \LowerWidth=\wd\@LowerPart
       
   191        \LowerHeight=\ht\@LowerPart
       
   192        \LowerCenter=0.5\LowerWidth
       
   193 %
       
   194        \UpperWidth=\wd\@UpperPart \advance\UpperWidth by -\UpperLeftOffset
       
   195        \advance\UpperWidth by -\UpperRightOffset
       
   196        \UpperCenter=\UpperLeftOffset
       
   197        \advance\UpperCenter by 0.5\UpperWidth
       
   198 %
       
   199        \ifdim \UpperWidth > \LowerWidth
       
   200                % \UpperCenter > \LowerCenter
       
   201        \UpperAdjust=0pt
       
   202        \RuleAdjust=\UpperLeftOffset
       
   203        \LowerAdjust=\UpperCenter \advance\LowerAdjust by -\LowerCenter
       
   204        \RuleWidth=\UpperWidth
       
   205        \global\@LeftOffset=\LowerAdjust
       
   206 %
       
   207        \else   % \UpperWidth <= \LowerWidth
       
   208        \ifdim \UpperCenter > \LowerCenter
       
   209 %
       
   210        \UpperAdjust=0pt
       
   211        \RuleAdjust=\UpperCenter \advance\RuleAdjust by -\LowerCenter
       
   212        \LowerAdjust=\RuleAdjust
       
   213        \RuleWidth=\LowerWidth
       
   214        \global\@LeftOffset=\LowerAdjust
       
   215 %
       
   216        \else   % \UpperWidth <= \LowerWidth
       
   217                % \UpperCenter <= \LowerCenter
       
   218 %
       
   219        \UpperAdjust=\LowerCenter \advance\UpperAdjust by -\UpperCenter
       
   220        \RuleAdjust=0pt
       
   221        \LowerAdjust=0pt
       
   222        \RuleWidth=\LowerWidth
       
   223        \global\@LeftOffset=0pt
       
   224 %
       
   225        \fi\fi
       
   226 % Make a box
       
   227        \if@inferRule
       
   228 %
       
   229        \setbox\ResultBox=\vbox{
       
   230                \moveright \UpperAdjust \box\@UpperPart
       
   231                \nointerlineskip \kern\inferLineSkip
       
   232                \if@DoubleRule
       
   233                \moveright \RuleAdjust \vbox{\hrule width\RuleWidth
       
   234                        \kern 1pt\hrule width\RuleWidth}\relax
       
   235                \else
       
   236                \moveright \RuleAdjust \vbox{\hrule width\RuleWidth}\relax
       
   237                \fi
       
   238                \nointerlineskip \kern\inferLineSkip
       
   239                \moveright \LowerAdjust \box\@LowerPart }\relax
       
   240 %
       
   241        \@ifEmpty{#1}{}{\relax
       
   242 %
       
   243        \HLabelAdjust=\wd\ResultBox     \advance\HLabelAdjust by -\RuleAdjust
       
   244        \advance\HLabelAdjust by -\RuleWidth
       
   245        \WidthAdjust=\HLabelAdjust
       
   246        \advance\WidthAdjust by -\inferLabelSkip
       
   247        \advance\WidthAdjust by -\wd\@LabelPart
       
   248        \ifdim \WidthAdjust < 0pt \WidthAdjust=0pt \fi
       
   249 %
       
   250        \VLabelAdjust=\dp\@LabelPart
       
   251        \advance\VLabelAdjust by -\ht\@LabelPart
       
   252        \VLabelAdjust=0.5\VLabelAdjust  \advance\VLabelAdjust by \LowerHeight
       
   253        \advance\VLabelAdjust by \inferLineSkip
       
   254 %
       
   255        \setbox\ResultBox=\hbox{\box\ResultBox
       
   256                \kern -\HLabelAdjust \kern\inferLabelSkip
       
   257                \raise\VLabelAdjust \box\@LabelPart \kern\WidthAdjust}\relax
       
   258 %
       
   259        }\relax % end @ifEmpty
       
   260 %
       
   261        \else % \@inferRulefalse
       
   262 %
       
   263        \setbox\ResultBox=\vbox{
       
   264                \moveright \UpperAdjust \box\@UpperPart
       
   265                \nointerlineskip \kern\inferLineSkip
       
   266                \moveright \LowerAdjust \hbox{\unhbox\@LowerPart
       
   267                        \@ifEmpty{#1}{}{\relax
       
   268                        \kern\inferLabelSkip \unhbox\@LabelPart}}}\relax
       
   269        \fi
       
   270 %
       
   271        \global\@RightOffset=\wd\ResultBox
       
   272        \global\advance\@RightOffset by -\@LeftOffset
       
   273        \global\advance\@RightOffset by -\LowerWidth
       
   274        \if@ReturnLeftOffset \else \global\@LeftOffset=\@SavedLeftOffset \fi
       
   275 %
       
   276        \box\ResultBox
       
   277        \@RestoreMath
       
   278 }