-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmm.sty
316 lines (212 loc) · 8.97 KB
/
mmm.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
\def\mmmversion{1.1 Time-stamp: <2005-12-14 16:38:57 wand>}
\message{mmm.sty - Mitch's Math Macros version \mmmversion}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Revision history:
%% Tue Dec 17 13:28:29 2002: initial version, based on material from
%% my various macros files.
%%%%%%%%%%%%%%%% TABLE OF CONTENTS %%%%%%%%%%%%%%%%
% 0. Imported Packages
% 1. Special TT Characters
% 2. Mathematics and Semantics
% 2.1 \ensuremath and friends
% 2.2 creating operators
% 2.3 Greek Letters Abbreviated
% 2.4 Metavariables
% 2.5 Some special things for semantics
% 2.6 {block} -- for calculations or indented formulas
% 2.7 opspace and friends
% 3. BNF Grammars
% 3.1 Grammar Elements
% 3.2 Grammar Environments
% 4. Diagrams (not much here)
% 5. Figures and Displays (handy!)
% 6. Miscellaneous Handy Things
%%%%%%%%%%%%%%%% 0. Imported Packages %%%%%%%%%%%%%%%%
\RequirePackage{alltt}
\RequirePackage{xspace}
%\RequirePackage{psfig}
\RequirePackage{epsf}
%%%%%%%%%%%%%%%% 1. Special TT Characters %%%%%%%%%%%%%%%%
% tilde, backslash
\def\til{{\tt\char'176}} % \tt tilde
\def\bs{{\tt\char'134}} % \tt backslashes
\def\hash{{\tt\char'043}} % \tt hash
\def\hasht{{\tt \hash t}} % \tt #t
\def\hashf{{\tt \hash f}} % \tt #f
\def\lbr{{\tt \char'173}} % \tt braces
\def\rbr{{\tt \char'175}}
\def\ttvert{{\tt \char'174}} % \tt vertical line
%%%%%%%%%%%%%%%% 2. Mathematics %%%%%%%%%%%%%%%%
%%%% 2.1 \ensuremath
% Like \ensuremath, only better. \xspace is your friend!
\newcommand{\ma}[1]{\ensuremath{#1}\xspace}
% use \mdef for 0-arg macros that are smart enough to go into mathmode without
% your telling them to.
\def\mdef#1#2{\def#1{\ma{#2}}}
%%%% 2.2 creating operators
\def\rmop#1{\ma{\mathop{\hbox{\rm #1\/}}\nolimits}}
\def\itop#1{\ma{\mathop{\hbox{\it #1\/}}\nolimits}}
\def\bfop#1{\ma{\mathop{\hbox{\bf #1\/}}\nolimits}}
\def\ttop#1{\ma{\mathop{\hbox{\tt #1\/}}\nolimits}}
\def\itord#1{\ma{\mathord{\hbox{\it #1\/}}}}
\def\rmord#1{\ma{\mathord{\hbox{\rm #1\/}}}}
\def\bford#1{\ma{\mathord{\hbox{\bf #1\/}}}}
\def\ttord#1{\ma{\mathord{\hbox{\tt #1\/}}}}
%% declaration syntax for these guys:
\def\newrmop#1#2{\def#1{\rmop{#2}}}
\def\newitop#1#2{\def#1{\itop{#2}}}
\def\newbfop#1#2{\def#1{\bfop{#2}}}
\def\newttop#1#2{\def#1{\ttop{#2}}}
\def\newitord#1#2{\def#1{\itord{#2}}}
\def\newrmord#1#2{\def#1{\rmord{#2}}}
\def\newbford#1#2{\def#1{\bford{#2}}}
\def\newttord#1#2{\def#1{\ttord{#2}}}
%%%% 2.3 Greek Letters abbreviated
\mdef\a{\alpha}
\mdef\b{\beta}
\mdef\g{\gamma}
\mdef\r{\rho}
\mdef\l{\lambda}
\mdef\m{\mu}
\mdef\G{\Gamma}
\mdef\s{\sigma}
\mdef\t{\tau}
\mdef\z{\zeta}
%%% 2.4 Metavariables: You should never write e, you should write \exp or
%%% the like.
%% \newmeta defines a new metavariable, which is automatically
%% subscripted.
\newcommand\newmeta[2]{\def#1##1{\ensuremath{#2_{##1}}}}
% Example:
% \newmeta\exp{\itop{e}}
% use as: \exp0, \exp1, \exp2, \exp{}
%%% 2.5 Math stuff for semantics:
% \setof creates a set with brackets around it. Use \alt for ``such
% that''.
% Example: \setof{\exp{} \alt \rmop{fv}(\exp{}) \not= \emptyset}
\def\setof#1{\ensuremath{\{#1\}}}
%% \semfcn takes two arguments: a semantic operator and an argument,
%% and surrounds the argument in open braces.
\def\semfcn#1#2{\mathop{#1}\nolimits\lbrack\!\lbrack{#2}\rbrack\!\rbrack}
% \newdom: declare a new domain (probably same as \newitop).
\def\newdom#1#2{\mdef#1{\mathop{\hbox{{\it #2}}}\nolimits\xspace}}
% \car, \cdr, \cons
\mdef\car{\rmop{car}}
\mdef\cdr{\rmop{cdr}}
\mdef\cons{\rmop{cons}}
%% 2.6 For block-structure & indented formulas
\newcommand{\block}[1]{\begin{array}[t]{@{}l@{}l@{}l@{}l@{}l@{}l}#1\end{array}}
%% 2.7 opspace and friends
\newcommand\opspace{\mathop{}{}} % from Krivine paper
\newcommand\opdots{\opspace \dots \opspace\opspace} % math mode only
\newcommand\commadots{, \dots, } % math mode only
%%%%%%%%%%%%%%%% 3. BNF Grammars %%%%%%%%%%%%%%%%
%%%% 3.1 Grammar Elements
% basic grammar elements
% nonterminal names default to roman, even in theorems.
\def\nt#1{\hbox{$\langle\hbox{\rm #1\/}\rangle$}}
\def\term#1{\hbox{\tt #1}} % I usually put \, before and after the hbox.
\def\alt{~~\vert~~}
\def\lparen{\term{(}} % deprecated, because it breaks paren matching.
\def\rparen{\term{)}} % likewise
\def\st#1{\ensuremath{\{#1\}^*}}
\def\pl#1{\ensuremath{\{#1\}^+}}
\def\seplist#1#2{\ensuremath{\{#1\}^{*({#2})}}}
\def\pst#1{\term(\st{#1}\term)}
%%%% 3.2 Grammar Environments
%% Adapted from eopl.sty
%% The grammar environment normally lives inside a displaymath.
%% It automatically generates a ::= on each line.
%% It has 3 fields: lll . The 3th field is for commentary.
%% Alas, Latex does not have a good way of automatically switching modes on a
%% per-field basis, so you'll have to put in $...$ around text-mode stuff,or
%% $|...|$ around tt-mode stuff.
%% If you want different things in place of the ::=, use altgrammar
%% instead.
%% Also you can use \multilineproduction for productions that are too
%% long to fit on a single line.
\newenvironment{grammar}{\begin{array}{l@{{}::={}}l@{\quad}l}}{\end{array}}
% This version puts about the right amount of space around the
% operator, at least to my eye.
\newenvironment{altgrammar}{\begin{array}{l@{\ }c@{\ }l@{\qquad}l}}{\end{array}}
% alternate version, with less space.
% \newenvironment{altgrammar}{\begin{array}{l@{{}}c@{}ll}}{\end{array}}
%% \production: for simple productions. rhs goes into tt by default.
%% If you want a comment in field 3, put it in an mbox. Example:
% \production{\nt{expression}}
% {if \nt{expression} then \nt{expression} else \nt{expression}}
% & \mbox{conditional expression} \\
\def\production#1#2{{#1} & \texttt{#2}}
% \altproduction: like \production, but for use with \altgrammar.
\def\altproduction#1#2#3{{#1} &{#2} \texttt{#3}}
% rhs for multiline production: This is like a little array that can be used
% for a production that spans multiple lines, as in:
%
% &\multilineproduction{
% \term{simpleclass}\ \nt{varlist}\ \nt{varlist}\ \nt{methdecls}\
% \nt{exp} \\
% \quad $|new-simpleclass (c-vars i-vars methdecls init-exp)|$ } \\
\def\multilineproduction#1{\multicolumn{2}{@{}l}{\begin{array}[t]{@{}l}#1\end{array}}}
%%%%%%%%%%%%%%%% 4. Diagrams %%%%%%%%%%%%%%%%
%% I don't really know how to get a diagram centered reliably. Here's
%% the code that I have.
%% Wed Mar 12 14:46:32 2003: This seems to work.
%% Wed Mar 12 14:47:12 2003 the diagramdirectory should end with a ``/''!
\def\diagramdirectory{}
\def\diagram#1{\centerline{\epsffile{\diagramdirectory#1}}}
%% http://mars.fis.uc.pt/hera-b/epsfigures.html#epslatex suggests
%% using epsfig, rather than psfig, and using \centering, as in:
%\begin{figure}[htbp]
%\centering
%\epsfig{file=example.eps, width=\textwidth}
%\caption{ Caption text. }
%\label{fig:example}
%\end{figure}
% We'll have to try this sometime.
%%%%%%%%%%%%%%%% 5. Figures and Displays %%%%%%%%%%%%%%%%
%% separators for top and bottom of displays and figures:
\def\dstart{\hbox to \hsize{\vrule depth 4pt\hrulefill\vrule depth 4pt}}
\def\dend{\hbox to \hsize{\vrule height 4pt\hrulefill\vrule height 4pt}}
% not used, I think.
% \def\niceline{\hrule height 0.75pt}
%% put nice lines at the top and bottom of figures to make them stand out from
%% text. Set these to {} to reset.
\def\figstart{\bigskip\dstart}
\def\figend{\dend\bigskip}
%% display: like displaymath, but with nice lines at beginning and end
\newenvironment{display}{\bigskip\dstart\begin{displaymath}}%
{\end{displaymath}\dend\bigskip}
%% titled displays: handy for grammars and stuff:
\newenvironment{tdisplay}[1]{\vbox\bgroup\bigskip{\bf #1}\vspace{-8pt}\\\dstart\begin{displaymath}}%
{\end{displaymath}\dend\bigskip\egroup}
\renewenvironment{display}{\begin{tdisplay}{\ }}{\end{tdisplay}}
% Example: this also shows short-form grammars (but see above about
% metavariables).
%\begin{tdisplay}{Sets2}
%\begin{altgrammar}
%v &\in& \Val &\mbox{Expressed Values} \\
%l &\in& \Loc &\mbox{Locations} \\
%s &\in& \Sto &\mbox{Stores} \\
%\end{altgrammar}
%\end{tdisplay}
% in an altgrammar environment, the lhs's are left-aligned, whereas
% they are right aligned in the first example. Right now, I am
% recommending altgrammar, which looks good to me. YMMV.
%%%%%%%%%%%%%%%% 6. Miscellaneous Handy Things %%%%%%%%%%%%%%%%
% Use this with emacs time-stamp mode.
\def\timestamp{}
\def\Time-stamp: <#1>{\gdef\timestamp{#1}}
% Put
% % \Time-stamp: <>
% somewhere in the first few lines of your file. Emacs will rewrite
% the <> to a timestamp, and then you can do things like put the
% following in your \author:
% {Draft of \timestamp}\\
% Better than \date!
% To use time-stamp mode in emacs, put the following lines in your
% .emacs :
% (add-hook 'write-file-hooks 'time-stamp)
% ; optional: for compatibility with Emacs 20, Y2K:
% (setq time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S %u")
% Mitch likes spaces between paragraphs!
\def\betterspacing{\parskip=0.75ex plus 0.25ex}