\documentclass[11pt]{article} \usepackage[mtbold]{mathtime} \usepackage{graphics} \input{page} \newcommand{\defn}[1]{\textbf{\textit{#1}}} \newcommand{\subheading}[1]{\subsubsection*{#1}} \begin{document} \title{Intermediate-Level Issues in \LaTeX2e} \author{} \date{} \maketitle \listoffigures \subheading{Defining commands} Section 3.4.1 of Lamport spends a lot of space on dealing with curly braces in macro definitions. Luckily, that is rarely an issue in practice. I usually use \verb`\newcommand` to define a macro. If it already exists, and you want to redefine it, use \verb`\renewcommand`. If there are parameters, you specify how many by a square-bracket-enclosed argument. Then come a pair of curly braces with the body of the macro definition. The arguments are indicated by \verb`#1`, \verb`#2`, etc. I won't say much else about defining macros, except that the ifthen package, documented by Lamport in Section~C.8.5 is great on paper, but it just doesn't work for me. I end up using the raw \TeX{} commands for conditional compilation. I'm not going to go into them here, but feel free to ask about them. \subheading{Defining environments and theorem-like environments} Sections 3.4.2 and~3.4.3 of Lamport are pretty straightforward. One question that often comes up is whether to draw numbers for theorems, lemmas, corollaries from one big pool or instead number theorems separately from everything else, lemmas separately from everything else, etc. In other words, should a paper have \begin{itemize} \item Lemma~1, Lemma~2, Theorem~3, Corollary~4, Lemma~5, \ldots, or \item Lemma~1, Lemma~2, Theorem~1, Corollary~1, Lemma~3, \ldots ? \end{itemize} Although you can make a decent argument for either way, I favor the one-big-pool approach (i.e., the first way above). \newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary} \newcommand{\qedsymbol}{\rule{1ex}{1ex}} \newcommand{\qed}{\mbox{}\hfill\qedsymbol} \newenvironment{proof}{\noindent\textbf{\textit{Proof:\hspace*{0.75em}}}}% {\qed\medskip} Do use labels for your theorem-like numbers. For example: \noindent\mbox{}\hrulefill\mbox{} \begin{theorem} All numbers are interesting. \label{thm:interesting-numbers} \end{theorem} \begin{proof} We prove the theorem by contradiction. Suppose that there exists a number~$x$ that is not interesting. Without loss of generality, let $x$ be the lowest such number. Then $x$ is the smallest non-interesting number, which is in itself interesting. Hence, $x$ is interesting, thus contradicting our supposition that $x$ is not interesting. \end{proof} \begin{corollary} No number is boring. \label{cor:no-boring} \end{corollary} \begin{proof} Immediate from Theorem~\ref{thm:interesting-numbers}. \end{proof} Hence, by Corollary~\ref{cor:no-boring}, we cannot use any numbers as drill bits. \noindent\mbox{}\hrulefill\mbox{} \medskip When the qed symbol appears at the end of a math display (including an eqnarray), the \verb`\qed` macro does not quite work: \smallskip \begin{proof} We have \begin{eqnarray*} T(n) & = & 2T(n/2) + \Theta(n) \\ & = & \Theta(n \lg n) \ . \end{eqnarray*} \end{proof} We'd really like the qed symbol to appear on the last line of the display. We can do that, with varying degrees of effort. The biggest change would require us to redefine all the math display environments. Rather than doing that, let's explicitly ask for a qed symbol in math display modes. \newif\ifmathqed \newcommand{\mqed}{\global\mathqedtrue} \makeatletter \def\@@eqncr{\let\reserved@a\relax \ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}% \or \def\reserved@a{&}\else \let\reserved@a\@empty \@latex@error{Too many columns in eqnarray environment}\@ehc\fi \reserved@a \if@eqnsw\@eqnnum\stepcounter{equation}\fi \ifmathqed\qedsymbol\fi \global\@eqnswtrue\global\@eqcnt\z@\cr} \makeatother \renewenvironment{proof}{\global\mathqedfalse\noindent% \textbf{\textit{Proof:\hspace*{0.75em}}}}% {\ifmathqed\else\qed\fi\medskip} Now we get what we want: \smallskip \begin{lemma} The running time $T(n)$ is $\Theta(n \lg n)$. \label{lem:running-time} \end{lemma} \begin{proof} We have \begin{eqnarray*} T(n) & = & 2T(n/2) + \Theta(n) \\ & = & \Theta(n \lg n) \ . \mqed \end{eqnarray*} \end{proof} \vspace{-4\medskipamount} \begin{corollary} The running time $T(n)$ is polynomial in~$n$. \label{cor:poly-in-n} \end{corollary} \begin{proof} Since $T(n)$ is $\Theta(n \lg n)$, it is also $O(n^2)$. \end{proof} With more macro hacking, we can eliminate the need for the negative vspace when a math display ends a proof. Again, that would require us to redefine all the math display environments. \subheading{Figures} Of course you want to put figures in your papers! There are several aspects to including figures, some of which we'll cover later in the course. Produce .eps (Encapsulated PostScript) files for your figures. Make sure that the bounding box is correct in each .eps file. You'll see the bounding box in a line like \begin{verbatim} %%BoundingBox: 85 490 503 694 \end{verbatim} near the top of the .eps file. You can use gv to verify that you've got the right bounding box. You then can include the figure via the \verb`\includegraphics` command. Make sure you use the graphics package in your preamble! \begin{center} \includegraphics{Dijkstra-proof.eps} \end{center} You can also make your figure be flush left against the page margin: \begin{flushleft} \includegraphics{Dijkstra-proof.eps} \end{flushleft} Or, if you're from another planet, flush right: \begin{flushright} \includegraphics{Dijkstra-proof.eps} \end{flushright} Getting the bounding box right in the .eps file is the key. You can scale the figure easily by using the \verb`\resizebox` command. Its first two arguments give the width and height of the figure. If you use \verb`!` as one of the arguments, that dimension scales automatically to preserve the aspect ratio of the original figure. If you use \verb`\textwidth` as your first argument, your figure will be exactly the width of the text page. \begin{center} \resizebox{1in}{2in}{\includegraphics{Dijkstra-proof.eps}}\\ \resizebox{!}{2in}{\includegraphics{Dijkstra-proof.eps}}\\ \resizebox{\textwidth}{!}{\includegraphics{Dijkstra-proof.eps}} \end{center} I almost always use the figure environment for figures in papers (and books). The figure environment numbers the figure, allows the figure to get a symbolic label, and it allows a caption. The label allows me to refer to Figure~\ref{fig:Dijkstra-proof-1}. \begin{figure} \begin{center} \includegraphics{Dijkstra-proof.eps} \end{center} \caption{Why Dijkstra's algorithm works.} \label{fig:Dijkstra-proof-1} \end{figure} \LaTeX2e{} has its own notions of where it will put figures. Pages 199--200 of Lamport list several parameters that \LaTeX2e{} uses to decide whether it will put a figure at the top of a page or on a page of only figures. I do not particularly like the default values; they tend to favor pages of only figures. I have redefined several of these values in \verb`~`thc/mytex/page.tex. Nor am I particularly fond of how captions appear by default. I like captions to be in a smaller font than the main text. I like the text ``Figure~X'' to be in boldface. There's another issue with the \verb`\caption` macro. By default, it takes the argument and puts it in a list of figures, assuming that you ask for a list of figures. Who wants a list of figures? Not me! I've asked for one in this file, and I don't think I ever have before. Nor do I expect to ever again. But here's the problem. Suppose you have a loooong caption. Then by default you get a loooong entry is your list of figures. Here's an example: \begin{figure} \begin{center} \includegraphics{Dijkstra-proof.eps} \end{center} \caption{Why Dijkstra's algorithm works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works and works.} \label{fig:Dijkstra-proof-2} \end{figure} \makeatletter \long\def\@makecaption#1#2{% \vskip\abovecaptionskip \sbox\@tempboxa{\small\textbf{#1:} #2}% \ifdim \wd\@tempboxa >\hsize {\small\textbf{#1:} #2}\par \else \global \@minipagefalse \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% \fi \vskip\belowcaptionskip} \makeatother \newcommand{\figcaption}[1]{\caption[]{#1}} \newcommand{\figpart}[1]{\textbf{(#1)}~\ignorespaces} To solve all of these problems, I have my own \verb`\figcaption` macro. It puts ``Figure~X'' in bold, uses a small font, and gives an empty optional argument to \verb`\caption` so that there'll be no entry in the list of figures: \begin{figure} \begin{center} \includegraphics{Dijkstra-proof.eps} \end{center} \figcaption{Why Dijkstra's algorithm works.} \label{fig:Dijkstra-proof-3} \end{figure} That looks better. I also have a \verb`\figpart` macro for when a figure has multiple parts: \begin{figure} \begin{center} \includegraphics{assembly-line-example.eps} \end{center} \figcaption{\figpart{a} An instance of the assembly-line problem with costs $e_i$, $a_{i,j}$, $t_{i,j}$, and~$x_i$ indicated. The heavily shaded path indicates the fastest way through the factory. \figpart{b} The values of $f_i[j]$, $f^*$, $l_i[j]$, and~$l^*$ for the instance in part~(a).} \label{fig:assembly-line-example} \end{figure} \end{document}