Return-Path: 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: 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