File: mathpartir.hva

package info (click to toggle)
hevea 2.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,824 kB
  • sloc: ml: 19,525; sh: 505; makefile: 311; ansic: 132
file content (192 lines) | stat: -rw-r--r-- 7,330 bytes parent folder | download
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
%  Mathpartir --- Math Paragraph for Typesetting Inference Rules
%
%  Copyright (C) 2001--2005 Didier Rémy
%  Hevea version by Luc Maranget
%
%  Author         : Didier Remy 
%  Version        : 1.2
%  Bug Reports    : to author
%  Web Site       : http://pauillac.inria.fr/~remy/latex/
% 
%  WhizzyTeX is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation; either version 2, or (at your option)
%  any later version.
%  
%  Mathpartir is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details 
%  (http://pauillac.inria.fr/~remy/license/GPL).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  File mathpartir.hva (LaTeX macros)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% See the interface of mathpartir.sty
% However, by default \\ does a vertical break in mathpar and a horizontal cut
% in mathrule
% 
% Preceeding \\ by \hva \\ does a horizontal break in mathpar and a vertical
% break in mathrule.
%
% \hva is ignored in latex more.

\usepackage {keyval}
\let\latexcr\\
%%% Styles for mathpar
\newcommand{\mp@row@style}
  {border-collapse:separate;border-spacing:2ex;width:100\%;margin:0ex;}
\newstyle{.mprow}{\mp@row@style}
\newstyle{.vmprow}{\mp@row@style empty-cells:show; border:solid \@magenta{} 2px}
\newcommand{\mp@cell@style}{padding:0px;width:auto;}
\newstyle{.mprcell}{\mp@cell@style}
\newstyle{.vmprcell}{\mp@cell@style border:dotted \@magenta{} 2px;}
\setenvclass{mathpar}{mathpar}
\ifverbd
\setenvclass{mprow}{vmprow}
\setenvclass{mprcell}{vmprcell}
\else
\setenvclass{mprow}{mprow}
\setenvclass{mprcell}{mprcell}
\fi
%% Open/close table elements
\def\open@mathpar@table{\@open{table}{\envclass@attr{mprow}}}
\def\open@mprow{\@open{tr}{style="vertical-align:middle"}}
\def\close@mprow{\@close{tr}}
\def\open@mpcell{\@open{td}{\@addstyle{text-align:center}{\envclass@attr[ ]{mprcell}}}\displaymath}
\def\close@mpcell{\enddisplaymath\@close{td}}
\def\force@mpcell{\enddisplaymath\@force{td}}
\def\open@mpfstcell{\open@mpcell}
\def\close@mplstcell{\force@mpcell}
\def\mathpar@hspace{\push@styles\close@mpcell\open@mpcell\pop@styles\@skip@blanks}
\def\mathpar@vspace
{\push@styles\close@mplstcell\close@mprow\@close{table}%
\open@mathpar@table\open@mprow\open@mpfstcell\pop@styles\@skip@blanks}%
\def\mathpar@hva#1{\ifx#1\and\mathpar@vspace\else\mathpar@hspace\fi}%
%%exported mathpar
\newenvironment{mathpar}[1][]
  {\@open{div}{\envclass@attr{mathpar}}
  \let\and\mathpar@hspace\let\par\mathpar@vspace\let\\\mathpar@vspace\let\hva\mathpar@hva%
  \open@mathpar@table\open@mprow\open@mpfstcell}
  {\close@mplstcell\close@mprow\@close{table}\@close{div}}
%%%% Type Inference Rules (TIR)
\newsavebox{\mpr@save@arg}%
\newcommand{\mpr@globle}[1]{}
\newcommand {\@mpr@name}[1]{\@tir@name{#1}\let\mpr@name\mpr@globle}
\def \mpr@line@hva #1{\mpr@break@display}
\def \mpr@break@display
{\sbox{\mpr@save@arg}{\mpr@line@arg}%
\endmpr@line\mpr@line{\usebox{\mpr@save@arg}}}
%%% this may not be robust (if nextchar is special char)
%%% also may not want this semantics
\def \@latexcr #1{%
\def \@test {#1}\ifx \@test \@latexcr@char \latexcr \else
\qquad #1\fi}
\newcommand{\mpr@valign}[1]
{\ifthenelse{\equal{#1}{}}{}{style="vertical-align:#1"}}
\newcommand{\mpr@line}[1]
{\@open{tr}{\mpr@valign{#1}}%
\ifx\mpr@label\mpr@L\@open{td}{}\mpr@name{\@rule@name}~\@force{td}\fi
\@open{td}{style="whitespace:nowrap;text-align:\ifmpr@center{}center\else{}left\fi"}%
\bgroup\def\mpr@line@arg{#1}%
\@open{display}{\mpr@valign{#1}}%
\def\\{\@latexcr{\qquad}}\def\and{\@latexcr{\qquad}}%
\let\hva\mpr@line@hva}
\newcommand{\endmpr@line}
{\@close{display}\egroup\@force{td}%
\ifx\mpr@label\mpr@R\@open{td}{}~\mpr@name{\@rule@name}\@force{td}\fi
\@close{tr}}
\def \mpr@empty {}
\newif \ifmpr@center \mpr@centertrue
\newif \ifmpr@vdots \mpr@vdotsfalse
\newcounter{mpr@count}
\newcommand{\mpr@output@vdots}
{\vdots%
\setcounter{mpr@count}{\@lengthtonchar{\mpr@vdots}}%
\whiledo{\value{mpr@count}>1}{\@br\vdots\addtocounter{mpr@count}{-1}}}
\def\mpr@emptyL{\ifx\mpr@label\mpr@L\@open{td}{}\@force{td}\fi}
\def\mpr@emptyR{\ifx\mpr@label\mpr@R\@open{td}{}\@force{td}\fi}
\newcommand{\@mpr@table}{\@open{table}{style="border:0;border-spacing:1px;border-collapse:separate" class="cellpadding0"}}
%Vertical alignement of premise and conclusion
\newcommand{\mpr@vert@premise}{bottom}
\newcommand{\mpr@vert@conclusion}{bottom}
\newcommand {\@inferrule}[2]
   {\bgroup
    \let \\ \latexcr%
    \@mpr@table%
    \ifx\mpr@label\mpr@C
      \@open{tr}{}\@open{td}{style="text-align:left"}%
      \mpr@name{\@rule@name}%
      \@close{td}\@close{tr}%
    \fi
    \def \@@arg{#1}\ifx \@@arg \mpr@empty%
      \mpr@line{}#2\endmpr@line%
    \else
      \def \@@arg{#2}\ifx \@@arg \mpr@empty%
      \mpr@line{}#1\endmpr@line%
    \else
      \mpr@line{\mpr@vert@premise}#1\endmpr@line%
      \@hhline%
      \mpr@line{\mpr@vert@conclusion}#2\endmpr@line%
    \fi\fi%
    \ifmpr@vdots%
      \@open{tr}{style="vertical-align:middle"}%
      \mpr@emptyL
      \@open{td}{style="text-align:center"}\mpr@output@vdots\@force{td}%
      \mpr@emptyR
      \@close{tr}%
    \fi
    \@force{table}%
    \egroup%
}
\def\mpr@hhline@color{green}
\def \@hhline
{\@open{tr}{}%
\mpr@emptyL
\@open{td}{style="background-color:\mpr@hhline@color;height:3px"}\@force{td}%
\mpr@emptyR
\@force{tr}}

\newcommand {\inferrule*}[3][]{%
   \bgroup\let\@tir@name\RefTirName%
   \mpr@vdotsfalse\let\mpr@label\mpr@N\let\mpr@name\@mpr@name%Default
   \@setkeys {mpr}{#1}%
   \@inferrule{#2}{#3}%
   \egroup}
\newcommand {\inferrule}[3][]{%
   \def\mpr@arg{#1}\ifx\mpr@arg\mpr@empty
   \inferrule*{#2}{#3}\else
   \inferrule*[before={\let\@tir@name\TirName},lab={#1},center]{#2}{#3}\fi}

\def \mprset {\setkeys{mprset}}
\define@key {mprset}{flushleft}[]{\mpr@centerfalse}
\define@key {mprset}{center}[]{\mpr@centertrue}
\define@key {mpr}{flushleft}[]{\mpr@centerfalse}
\define@key {mpr}{center}[]{\mpr@centertrue}
\define@key {mpr}{width}{}
\define@key {mpr}{before}{#1}
\define@key {mpr}{narrower}{}
\define@key {mpr}{leftskip}{}
\define@key {mpr}{rightskip}{}
\def\mpr@N{N}\def\mpr@C{C}\def\mpr@R{R}\def\mpr@L{L}\let\mpr@label\mpr@N
\def\mpr@set@name#1{\def \@rule@name {\mpr@name{#1}}}
\define@key {mpr}{lab}{\let\mpr@label\mpr@C\mpr@set@name{#1}}
\define@key {mpr}{Lab}{\let\mpr@label\mpr@C\mpr@set@name{#1}}
\define@key {mpr}{left}{\let\mpr@label\mpr@L\mpr@set@name{#1}}
\define@key {mpr}{Left}{\let\mpr@label\mpr@L\mpr@set@name{#1}}
\define@key {mpr}{Right}{\let\mpr@label\mpr@R\mpr@set@name{#1}}
\define@key {mpr}{right}{\let\mpr@label\mpr@R\mpr@set@name{#1}}
\define@key {mpr}{vdots}{\mpr@vdotstrue\def\mpr@vdots{#1}}
\define@key {mpr}{after}{}
\define@key {mpr}{fraction}{\hva@warn{fraction key ignored (mathpartir)}}
\define@key {mpr}{myfraction}{\hva@warn{myfraction key ignored (mathpartir)}}
%%%%Synonyms
\@ifundefined{infer}{\let\infer\inferrule}{}
\@ifundefined{infer*}{\let\infer*\inferrule*}{}
%%%Label formatting
\newcommand {\tir@name}[1]{\textsc{\scriptsize {#1}}}
\let\RefTirName\tir@name
\let\TirName\tir@name
\endinput