proof.sty 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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@nii.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. % Style Parameters
  71. \newdimen\inferLineSkip \inferLineSkip=2pt
  72. \newdimen\inferLabelSkip \inferLabelSkip=5pt
  73. \def\inferTabSkip{\quad}
  74. % Variables
  75. \newdimen\@LeftOffset % global
  76. \newdimen\@RightOffset % global
  77. \newdimen\@SavedLeftOffset % safe from users
  78. \newdimen\UpperWidth
  79. \newdimen\LowerWidth
  80. \newdimen\LowerHeight
  81. \newdimen\UpperLeftOffset
  82. \newdimen\UpperRightOffset
  83. \newdimen\UpperCenter
  84. \newdimen\LowerCenter
  85. \newdimen\UpperAdjust
  86. \newdimen\RuleAdjust
  87. \newdimen\LowerAdjust
  88. \newdimen\RuleWidth
  89. \newdimen\HLabelAdjust
  90. \newdimen\VLabelAdjust
  91. \newdimen\WidthAdjust
  92. \newbox\@UpperPart
  93. \newbox\@LowerPart
  94. \newbox\@LabelPart
  95. \newbox\ResultBox
  96. % Flags
  97. \newif\if@inferRule % whether \@infer draws a rule.
  98. \newif\if@DoubleRule % whether \@infer draws doulbe rules.
  99. \newif\if@ReturnLeftOffset % whether \@infer returns \@LeftOffset.
  100. \newif\if@MathSaved % whether inner math mode where \infer or
  101. % \deduce appears.
  102. % Special Fonts
  103. \def\DeduceSym{\vtop{\baselineskip4\p@ \lineskiplimit\z@
  104. \vbox{\hbox{.}\hbox{.}\hbox{.}}\hbox{.}}}
  105. % Math Save Macros
  106. %
  107. % \@SaveMath is called in the very begining of toplevel macros
  108. % which are \infer and \deduce.
  109. % \@RestoreMath is called in the very last before toplevel macros end.
  110. % Remark \infer and \deduce ends calling \@infer.
  111. \def\@SaveMath{\@MathSavedfalse \ifmmode \ifinner
  112. \relax $\relax \@MathSavedtrue \fi\fi }
  113. \def\@RestoreMath{\if@MathSaved \relax $\relax\fi }
  114. % Macros
  115. % Renaming @ifnextchar and @ifnch of LaTeX2e to @IFnextchar and @IFnch.
  116. \def\@IFnextchar#1#2#3{%
  117. \let\reserved@e=#1\def\reserved@a{#2}\def\reserved@b{#3}\futurelet
  118. \reserved@c\@IFnch}
  119. \def\@IFnch{\ifx \reserved@c \@sptoken \let\reserved@d\@xifnch
  120. \else \ifx \reserved@c \reserved@e\let\reserved@d\reserved@a\else
  121. \let\reserved@d\reserved@b\fi
  122. \fi \reserved@d}
  123. \def\@ifEmpty#1#2#3{\def\@tempa{\@empty}\def\@tempb{#1}\relax
  124. \ifx \@tempa \@tempb #2\else #3\fi }
  125. \def\infer{\@SaveMath \@IFnextchar *{\@inferSteps}{\relax
  126. \@IFnextchar ={\@inferDoubleRule}{\@inferOneStep}}}
  127. \def\@inferOneStep{\@inferRuletrue \@DoubleRulefalse
  128. \@IFnextchar [{\@infer}{\@infer[\@empty]}}
  129. \def\@inferDoubleRule={\@inferRuletrue \@DoubleRuletrue
  130. \@IFnextchar [{\@infer}{\@infer[\@empty]}}
  131. \def\@inferSteps*{\@IFnextchar [{\@@inferSteps}{\@@inferSteps[\@empty]}}
  132. \def\@@inferSteps[#1]{\@deduce{#1}[\DeduceSym]}
  133. \def\deduce{\@SaveMath \@IFnextchar [{\@deduce{\@empty}}
  134. {\@inferRulefalse \@infer[\@empty]}}
  135. % \@deduce<Proof Label>[<Proof>]<Lower><Uppers>
  136. \def\@deduce#1[#2]#3#4{\@inferRulefalse
  137. \@infer[\@empty]{#3}{\@SaveMath \@infer[{#1}]{#2}{#4}}}
  138. % \@infer[<Label>]<Lower><Uppers>
  139. % If \@inferRuletrue, it draws a rule and <Label> is right to
  140. % a rule. In this case, if \@DoubleRuletrue, it draws
  141. % double rules.
  142. %
  143. % Otherwise, draws no rule and <Label> is right to <Lower>.
  144. \def\@infer[#1]#2#3{\relax
  145. % Get parameters
  146. \if@ReturnLeftOffset \else \@SavedLeftOffset=\@LeftOffset \fi
  147. \setbox\@LabelPart=\hbox{$#1$}\relax
  148. \setbox\@LowerPart=\hbox{$#2$}\relax
  149. %
  150. \global\@LeftOffset=0pt
  151. \setbox\@UpperPart=\vbox{\tabskip=0pt \halign{\relax
  152. \global\@RightOffset=0pt \@ReturnLeftOffsettrue $##$&&
  153. \inferTabSkip
  154. \global\@RightOffset=0pt \@ReturnLeftOffsetfalse $##$\cr
  155. #3\cr}}\relax
  156. % Here is a little trick.
  157. % \@ReturnLeftOffsettrue(false) influences on \infer or
  158. % \deduce placed in ## locally
  159. % because of \@SaveMath and \@RestoreMath.
  160. \UpperLeftOffset=\@LeftOffset
  161. \UpperRightOffset=\@RightOffset
  162. % Calculate Adjustments
  163. \LowerWidth=\wd\@LowerPart
  164. \LowerHeight=\ht\@LowerPart
  165. \LowerCenter=0.5\LowerWidth
  166. %
  167. \UpperWidth=\wd\@UpperPart \advance\UpperWidth by -\UpperLeftOffset
  168. \advance\UpperWidth by -\UpperRightOffset
  169. \UpperCenter=\UpperLeftOffset
  170. \advance\UpperCenter by 0.5\UpperWidth
  171. %
  172. \ifdim \UpperWidth > \LowerWidth
  173. % \UpperCenter > \LowerCenter
  174. \UpperAdjust=0pt
  175. \RuleAdjust=\UpperLeftOffset
  176. \LowerAdjust=\UpperCenter \advance\LowerAdjust by -\LowerCenter
  177. \RuleWidth=\UpperWidth
  178. \global\@LeftOffset=\LowerAdjust
  179. %
  180. \else % \UpperWidth <= \LowerWidth
  181. \ifdim \UpperCenter > \LowerCenter
  182. %
  183. \UpperAdjust=0pt
  184. \RuleAdjust=\UpperCenter \advance\RuleAdjust by -\LowerCenter
  185. \LowerAdjust=\RuleAdjust
  186. \RuleWidth=\LowerWidth
  187. \global\@LeftOffset=\LowerAdjust
  188. %
  189. \else % \UpperWidth <= \LowerWidth
  190. % \UpperCenter <= \LowerCenter
  191. %
  192. \UpperAdjust=\LowerCenter \advance\UpperAdjust by -\UpperCenter
  193. \RuleAdjust=0pt
  194. \LowerAdjust=0pt
  195. \RuleWidth=\LowerWidth
  196. \global\@LeftOffset=0pt
  197. %
  198. \fi\fi
  199. % Make a box
  200. \if@inferRule
  201. %
  202. \setbox\ResultBox=\vbox{
  203. \moveright \UpperAdjust \box\@UpperPart
  204. \nointerlineskip \kern\inferLineSkip
  205. \if@DoubleRule
  206. \moveright \RuleAdjust \vbox{\hrule width\RuleWidth
  207. \kern 1pt\hrule width\RuleWidth}\relax
  208. \else
  209. \moveright \RuleAdjust \vbox{\hrule width\RuleWidth}\relax
  210. \fi
  211. \nointerlineskip \kern\inferLineSkip
  212. \moveright \LowerAdjust \box\@LowerPart }\relax
  213. %
  214. \@ifEmpty{#1}{}{\relax
  215. %
  216. \HLabelAdjust=\wd\ResultBox \advance\HLabelAdjust by -\RuleAdjust
  217. \advance\HLabelAdjust by -\RuleWidth
  218. \WidthAdjust=\HLabelAdjust
  219. \advance\WidthAdjust by -\inferLabelSkip
  220. \advance\WidthAdjust by -\wd\@LabelPart
  221. \ifdim \WidthAdjust < 0pt \WidthAdjust=0pt \fi
  222. %
  223. \VLabelAdjust=\dp\@LabelPart
  224. \advance\VLabelAdjust by -\ht\@LabelPart
  225. \VLabelAdjust=0.5\VLabelAdjust \advance\VLabelAdjust by \LowerHeight
  226. \advance\VLabelAdjust by \inferLineSkip
  227. %
  228. \setbox\ResultBox=\hbox{\box\ResultBox
  229. \kern -\HLabelAdjust \kern\inferLabelSkip
  230. \raise\VLabelAdjust \box\@LabelPart \kern\WidthAdjust}\relax
  231. %
  232. }\relax % end @ifEmpty
  233. %
  234. \else % \@inferRulefalse
  235. %
  236. \setbox\ResultBox=\vbox{
  237. \moveright \UpperAdjust \box\@UpperPart
  238. \nointerlineskip \kern\inferLineSkip
  239. \moveright \LowerAdjust \hbox{\unhbox\@LowerPart
  240. \@ifEmpty{#1}{}{\relax
  241. \kern\inferLabelSkip \unhbox\@LabelPart}}}\relax
  242. \fi
  243. %
  244. \global\@RightOffset=\wd\ResultBox
  245. \global\advance\@RightOffset by -\@LeftOffset
  246. \global\advance\@RightOffset by -\LowerWidth
  247. \if@ReturnLeftOffset \else \global\@LeftOffset=\@SavedLeftOffset \fi
  248. %
  249. \box\ResultBox
  250. \@RestoreMath
  251. }