summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/steveshacks.tex
blob: d2aea18eb24f7124dcf8199f4520528f021455ad (plain)
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
Return-Path: <spqr@minster.york.ac.uk>
Received: from minster.york.ac.uk by ftp.tex.ac.uk (4.1/SMI-4.1)
	id AA04969; Tue, 9 Mar 93 09:31:49 GMT
From: spqr@minster.york.ac.uk
Date: Tue, 9 Mar 93 09:29:08
Message-Id: <swordfish.731669420@minster.york.ac.uk>
To: archive@ftp.tex.ac.uk
In-Reply-To: smith@gramian.harvard.edu's message of 2 Mar 93 23:02:22 GMT
Subject: Steve's LaTeX Hacks
Status: RO

   From: smith@gramian.harvard.edu (Steven Smith)
   Newsgroups: comp.text.tex
   Date: 2 Mar 93 23:02:22 GMT
   Distribution: comp.text.tex
   Organization: Harvard Robotics Lab, Harvard University

   I recently submitted a paper to a publisher who demanded that it be in
   LaTeX format.  At first I hated this.  But later, I grew to like it as
   I learned to hack LaTeX to get it to do what I wanted.  I've heard
   several people complain about some of the LaTeX problems that I faced,
   so I've included my fixes here for people to use.

   The code is arranged in three sections: (i) LaTeX bug fixes, where I
   fix LaTeX so that it doesn't do things that are plain wrong, (ii) LaTeX
   hacks, where I hack LaTeX to make it conform to a style that I prefer,
   and (iii) useful macros from Plain TeX that for some specious reason
   are not included in LaTeX.  I've also included a proof environment
   that gives Halmos's tombstone.


       Note to LaTeX-but-non-TeX users: I highly recommend using Plain
       TeX macros like \pmatrix etc.  You will find typing

	       $$\pmatrix{a&b\cr c&d}$$

       much faster and easier than typing

	       \[\left(\begin{array}{cc}a&b\\c&d\end{array}\right)\].

       Most of these macros, described in Chapters 16-19 of the TeXbook,
       are defined in standard LaTeX, so you may use them.


   Included below are the following:

   LaTeX bug fixes:

   1. Fix eqnarray to delete those awful spaces around the relation.
   2. Use correct 12-point math extension font.
   3. Define correct 12-point \big,...,\Bigg macros.

   LaTeX hacks:

   1. Add 10-point bold roman subscripts.
   2. Put stretchiness and new hooks in the theorem environment.
   3. Add an environment for proofs.
   4. Change LaTeX's \cite command for bold citations separated by thinspaces.
   5. Add Plain TeX's \headline and \footline to plain pagestyle.

   Plain TeX additions:

   1. Add \eqalign.
   2. \overfullrule=5pt (Plain TeX's setting).


   The code follows.  All of this code should be placed in LaTeX's
   preamble (between \documentstyle and \begin{document}).  If you only
   take part of this code, be sure to surround it in your preamble with
   the LaTeX commands \makeatletter and \makeatother.  And, of course, if
   you don't like anything about these macros, you are free to change them.


   \makeatletter

   % LaTeX bug fixes:

   % 1. Fix eqnarray to delete those awful spaces around the relation.

   % Fix eqnarray's \def so that it uses the correct spacing (cf. latex.tex).
   \def\eqnarray{\stepcounter{equation}\let\@currentlabel=\theequation
     \global\@eqnswtrue
     \global\@eqcnt\z@\tabskip\@centering\let\\=\@eqncr
     $$\halign to \displaywidth\bgroup\@eqnsel\hskip\@centering
       $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne 
       ${{}##{}}$&\global\@eqcnt\tw@$\displaystyle\tabskip\z@{##}$\hfil
       \tabskip\@centering&\llap{##}\tabskip\z@\cr}

   % 2. Use correct 12-point math extension font.

   % Use correct 12-point fonts (cf. lfonts.tex).
   \font\twlex=cmex10 at 12pt
   \font\eightex=cmex8
   \font\eightbf=cmbx8
   \font\sixbf=cmbx6

   \def\xiipt{\textfont\z@\twlrm
     \scriptfont\z@\egtrm \scriptscriptfont\z@\sixrm
   \textfont\@ne\twlmi \scriptfont\@ne\egtmi \scriptscriptfont\@ne\sixmi
   \textfont\tw@\twlsy \scriptfont\tw@\egtsy \scriptscriptfont\tw@\sixsy
   \textfont\thr@@\twlex \scriptfont\thr@@\eightex \scriptscriptfont\thr@@\eightex
   \def\unboldmath{\everymath{}\everydisplay{}\@nomath\unboldmath
	     \textfont\@ne\twlmi
	     \textfont\tw@\twlsy \textfont\lyfam\twlly
	     \@boldfalse}\@boldfalse
   \def\boldmath{\@ifundefined{twlmib}{\global\font\twlmib\@mbi\@magscale1\global
	   \font\twlsyb\@mbsy \@magscale1\global\font
	    \twllyb\@lasyb\@magscale1\relax\@addfontinfo\@xiipt
		 {\def\boldmath{\everymath
		   {\mit}\everydisplay{\mit}\@prtct\@nomathbold
		   \textfont\@ne\twlmib \textfont\tw@\twlsyb
		   \textfont\lyfam\twllyb\@prtct\@boldtrue}}}{}\@xiipt\boldmath}%
   \def\prm{\fam\z@\twlrm}%
   \def\pit{\fam\itfam\twlit}\textfont\itfam\twlit \scriptfont\itfam\egtit
      \scriptscriptfont\itfam\sevit
   \def\psl{\fam\slfam\twlsl}\textfont\slfam\twlsl
	\scriptfont\slfam\tensl \scriptscriptfont\slfam\tensl
   \def\pbf{\fam\bffam\twlbf}\textfont\bffam\twlbf
      \scriptfont\bffam\eightbf \scriptscriptfont\bffam\sixbf
   \def\ptt{\fam\ttfam\twltt}\textfont\ttfam\twltt
      \scriptfont\ttfam\nintt \scriptscriptfont\ttfam\nintt
   \def\psf{\fam\sffam\twlsf}\textfont\sffam\twlsf
       \scriptfont\sffam\tensf \scriptscriptfont\sffam\tensf
   \def\psc{\@getfont\psc\scfam\@xiipt{\@mcsc\@magscale1}}%
   \def\ly{\fam\lyfam\twlly}\textfont\lyfam\twlly
      \scriptfont\lyfam\egtly \scriptscriptfont\lyfam\sixly
    \@setstrut \rm}

   % 3. Define correct 12-point \big,...,\Bigg macros (cf. lplain.tex).

   \def\big#1{{\hbox{$\left#1\vbox to10\p@{}\right.\n@space$}}}
   \def\Big#1{{\hbox{$\left#1\vbox to13\p@{}\right.\n@space$}}}%
   \def\bigg#1{{\hbox{$\left#1\vbox to17.5\p@{}\right.\n@space$}}}%
   \def\Bigg#1{{\hbox{$\left#1\vbox to21\p@{}\right.\n@space$}}}%


   % LaTeX hacks:

   % 1. Add 10-point bold roman subscripts.

   % Use correct 10-point bold subscript fonts like Plain TeX (cf. lfonts.tex).
   \font\eightex=cmex8
   \font\sevenbf=cmbx7
   \font\fivebf=cmbx5

   \def\xpt{\textfont\z@\tenrm
     \scriptfont\z@\sevrm \scriptscriptfont\z@\fivrm
   \textfont\@ne\tenmi \scriptfont\@ne\sevmi \scriptscriptfont\@ne\fivmi
   \textfont\tw@\tensy \scriptfont\tw@\sevsy \scriptscriptfont\tw@\fivsy
   \textfont\thr@@\tenex \scriptfont\thr@@\eightex \scriptscriptfont\thr@@\eightex
   \def\unboldmath{\everymath{}\everydisplay{}\@nomath\unboldmath
	     \textfont\@ne\tenmi
	     \textfont\tw@\tensy \textfont\lyfam\tenly
	     \@boldfalse}\@boldfalse
   \def\boldmath{\@ifundefined{tenmib}{\global\font\tenmib\@mbi
      \global\font\tensyb\@mbsy
      \global\font\tenlyb\@lasyb\relax\@addfontinfo\@xpt
      {\def\boldmath{\everymath{\mit}\everydisplay{\mit}\@prtct\@nomathbold
	   \textfont\@ne\tenmib \textfont\tw@\tensyb
	   \textfont\lyfam\tenlyb \@prtct\@boldtrue}}}{}\@xpt\boldmath}%
   \def\prm{\fam\z@\tenrm}%
   \def\pit{\fam\itfam\tenit}\textfont\itfam\tenit \scriptfont\itfam\sevit
       \scriptscriptfont\itfam\sevit
   \def\psl{\fam\slfam\tensl}\textfont\slfam\tensl
	\scriptfont\slfam\tensl \scriptscriptfont\slfam\tensl
   \def\pbf{\fam\bffam\tenbf}\textfont\bffam\tenbf
       \scriptfont\bffam\sevenbf \scriptscriptfont\bffam\fivebf
   \def\ptt{\fam\ttfam\tentt}\textfont\ttfam\tentt
       \scriptfont\ttfam\tentt \scriptscriptfont\ttfam\tentt
   \def\psf{\fam\sffam\tensf}\textfont\sffam\tensf
       \scriptfont\sffam\tensf \scriptscriptfont\sffam\tensf
   \def\psc{\@getfont\psc\scfam\@xpt{\@mcsc}}%
   \def\ly{\fam\lyfam\tenly}\textfont\lyfam\tenly
      \scriptfont\lyfam\sevly \scriptscriptfont\lyfam\fivly
   \@setstrut \rm}

   % 2. Put stretchiness and new hooks in the theorem environment.

   \def\thmstretch{plus.5em minus.1em }
   \def\thmskip{0pt \thmstretch}
   \def\thmstart{\hskip\thmskip\ignorespaces}
   \let\thmtextfont=\it
   \newif\ifthmtitle \thmtitletrue  % If TRUE, print text (e.g., ``Theorem'').

   % Macros for paper's structure:

   % These are utility macros:
   \newtheorem{THEOREM}{Theorem}[section]
   \newtheorem{PROPOSITION}[THEOREM]{Proposition}
   \newtheorem{DEFINITION}[THEOREM]{Definition}
   \newtheorem{LEMMA}[THEOREM]{Lemma}
   \newtheorem{COROLLARY}[THEOREM]{Corollary}
   \newtheorem{EXAMPLE}[THEOREM]{Example}
   \newtheorem{REMARK}[THEOREM]{Remark}
   \newtheorem{REMARKS}[THEOREM]{Remarks}
   \newtheorem{DISCUSSION}[THEOREM]{}
   \newtheorem{ALGORITHM}[THEOREM]{Algorithm}
   \newtheorem{PROBLEM}[THEOREM]{Problem}

   % Use these environments for their stated purpose.
   \newenvironment{theorem}%
     {\let\thmtextfont=\it \thmtitletrue \begin{THEOREM}}%
   {\end{THEOREM}}
   \newenvironment{proposition}%
     {\let\thmtextfont=\it \thmtitletrue \begin{PROPOSITION}}%
     {\end{PROPOSITION}}
   \newenvironment{definition}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{DEFINITION}}%
     {\end{DEFINITION}}
   \newenvironment{lemma}%
     {\let\thmtextfont=\it \thmtitletrue \begin{LEMMA}}%
     {\end{LEMMA}}
   \newenvironment{corollary}%
     {\let\thmtextfont=\it \thmtitletrue \begin{COROLLARY}}%
     {\end{COROLLARY}}
   \newenvironment{example}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{EXAMPLE}}%
     {\end{EXAMPLE}}
   \newenvironment{remark}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{REMARK}}%
     {\end{REMARK}}
   \newenvironment{remarks}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{REMARKS}}%
     {\end{REMARKS}}
   \newenvironment{discussion}%
     {\let\thmtextfont=\rm \thmtitlefalse \begin{DISCUSSION}}%
     {\end{DISCUSSION}}
   \newenvironment{algorithm}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{ALGORITHM}}%
     {\end{ALGORITHM}}
   \newenvironment{problem}%
     {\let\thmtextfont=\rm \thmtitletrue \begin{PROBLEM}}%
     {\end{PROBLEM}}

   \newenvironment{steps}{\begin{description}}{\end{description}}
   \def\step[#1]{\item[\rm{\it Step\/}~#1]}

   % Change LaTeX's theorem format somewhat (cf. latex.tex)
   \def\@begintheorem#1#2{\thmtextfont \trivlist \ifthmtitle
     \item[\hskip \labelsep{\bf #1\ #2.}]\else
     \item[\hskip \labelsep{\bf #2.}]\fi\thmstart}
   \def\@opargbegintheorem#1#2#3{\thmtextfont \trivlist
	 \item[\hskip\labelsep{\bf #1\ #2\ {\rm(#3)}.}]\thmstart}

   % 3. Add an environment for proofs.

   % Proof environment with Halmos's tombstone
   \newif\ifmathtomb \mathtombfalse

   %\def\tombstone{\unskip\penalty50  % Tombstone breaks to left margin.
   %  \enskip \vrule width.3333em height.7em depth.2em
   %  \ifmmode \global\mathtombtrue \else \global\mathtombfalse \fi}

   \def\tombstone{\unskip\penalty50   % Tombstone breaks to right margin.
     \hskip 0pt plus-1fill \null\nobreak\hskip 0pt plus1fill
     \enskip \vrule width.3333em height.7em depth.2em
     \ifmmode \global\mathtombtrue \else \global\mathtombfalse \fi}
				      % Tombstone scores!

   \newenvironment{proof}% Use \tombstone explicitly in display math
     {\futurelet\next\pr@oftext}% Optional argument for proof text.
     {\ifmathtomb \else \tombstone \fi \par
      \ifmathtomb \else \addvspace{\medskipamount}\fi \global\mathtombfalse}
   \def\pr@oftext{\ifx\next[\let\temp\opr@@ftext\else\let\temp\pr@@ftext\fi\temp}
   \def\pr@@ftext{\beginpr@@f{Proof}}
   \def\opr@@ftext[#1]{\beginpr@@f{#1}}
   \def\beginpr@@f#1{\par \addvspace{\bigskipamount}\widowpenalty=10000
     \noindent{\bf #1.}\hskip\labelsep\thmstretch   % No widow lines in proofs.
     \ignorespaces}

   % The text will be ``Proof'' unless an optional argument [] is used.
   % The syntax should be TeX-equivalent to one of the following:
   % 
   %         \begin{proof} Text. \end{proof}
   %         \begin{proof} Text $$math.\tombstone$$ \end{proof}

   % 4. Change LaTeX's \cite command for bold citations separated by thinspaces.

   \def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
     \def\@citea{}\@cite{\@for\@citeb:=#2\do
       {\@citea\def\@citea{,\penalty\@m\thinspace }\@ifundefined
	  {b@\@citeb}{{\bf ?}\@warning
	  {Citation `\@citeb' on page \thepage \space undefined}}%
   \hbox{\bf\csname b@\@citeb\endcsname}}}{#1}}
   %\hbox{\small\bf\csname b@\@citeb\endcsname}}}{#1}} % Give \small citation #'s.

   % 5. Add Plain TeX's \headline and \footline to plain pagestyle.

   \newtoks\headline \headline={\hfil} % headline is normally blank
   \newtoks\footline \footline={\hss\rm\thepage\hss}
     % footline is normally a centered page number in font \tenrm

   % Change \ps@plain to include running headline information (cf. latex.tex).
   \def\ps@plain{\let\@mkboth\@gobbletwo
     \def\@oddhead{\the\headline}\let\@evenhead\@oddhead
     \def\@oddfoot{\the\footline}\let\@evenfoot\@oddfoot}
     % Odd and even cases are lumped into one macro as in Plain TeX.

   \pagestyle{plain}  % Run \pagestyle to incorporate changes.


   % Plain TeX additions:

   % 1. Add \eqalign.

   \def\eqalign#1{\null\,\vcenter{\openup\jot\m@th
     \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
	 \crcr#1\crcr}}\,}

   % 2. \overfullrule=5pt (Plain TeX's setting).

   \overfullrule=5pt  % Plain TeX's setting

   \makeatother