How do I do X in TeX or LaTeX

Proof environment

It is not possible to make a proof environment which automatically includes an end-of-proof' symbol. Some proofs end in displayed maths; others do not. If the input file contains ...\] \end{proof} then LaTeX finishes off the displayed maths and gets ready for a new line before it reads any instructions connected with ending the proof. But traditionally the end-of-proof sign goes in the display, not on a new line. So you just have to put it in by hand in every proof.

Symbols for the number sets

It is a good idea to have commands such as \R for the real numbers and other standard number sets. Traditionally these were typeset in bold. Because mathematicians usually do not have access to bold chalk, they invented the special symbols that are now often used for \R, \C, etc. These symbols are known as blackboard bold''. Before insisting on using them, consider whether going back to the old system of ordinary bold might not be acceptable (it is certainly simpler).

A set of blackboard bold capitals is available in the AMS fonts msam'' (e.g., msam10'' for 10pt) and msbm''. The fonts have a large number of mathematical symbols to supplement the ones in the standard TeX distribution. The fonts are available in fonts/ams/amsfonts/sources/symbols

Two files which load the fonts and define the symbols are provided, and both work with either TeX or LaTeX. Questions or suggestions regarding these fonts should be directed to tech-support@math.ams.org.

Another complete set of blackboard bold fonts, the bbold family, is available in METAFONT (in fonts/bbold). This set has the interesting property of offering blackboard bold forms of lower-case letters, something rather rarely seen on actual blackboards.

The lazy person's'' blackboard bold macros:

  \newcommand{\R}{{\sf R\hspace*{-0.9ex}%
\rule{0.15ex}{1.5ex}\hspace*{0.9ex}}}
\newcommand{\N}{{\sf N\hspace*{-1.0ex}%
\rule{0.15ex}{1.3ex}\hspace*{1.0ex}}}
\newcommand{\Q}{{\sf Q\hspace*{-1.1ex}%
\rule{0.15ex}{1.5ex}\hspace*{1.1ex}}}
\newcommand{\C}{{\sf C\hspace*{-0.9ex}%
\rule{0.15ex}{1.3ex}\hspace*{0.9ex}}}


work well at normal size if the surrounding text is cmr10. However, they are not part of a proper maths font, and so do not work in sub- and superscripts. Moreover, the size and position of the vertical bar is affected by the font of the surrounding text.

Roman theorems

If you want to take advantage of the powerful \newtheorem command without the constraint that the contents of the theorem is in a sloped font (for example, to use it to create remarks, examples, proofs, ...) then you can use the style file theorem.sty (part of macros/latex/required/tools). Alternatively, the following sets up an environment remark whose content is in roman.

  \newtheorem{preremark}{Remark}
\newenvironment{remark}%
{\begin{preremark}\rm}{\end{preremark}}


This will not work if you are using the prototype NFSS outside of LaTeX2e, because the command \rm behaves differently there.

Fancy enumeration lists

Suppose you want your top-level enumerates to be labelled I/', II/', ..., then give these commands:

   \renewcommand{\theenumi}{\Roman{enumi}}
\renewcommand{\labelenumi}{\theenumi/}


The possible styles of numbering are given in Section 6.3 of Lamport's book (see TeX-related books). Both \theenumi and \labelenumi must be changed, since \theenumi is used in cross-references to the list.

For lower level enumerates, replace enumi by enumii, enumiii or enumiv, according to the level. If your label is much larger than the default, you should also change \leftmargini, \leftmarginii, etc.

If you're running LaTeX2e, the package enumerate.sty (part of macros/latex/required/tools) offers similar facilities. With enumerate.sty, the example above would be achieved simply by starting the enumeration \begin{enumerate}[I/].

The easiest way to get headings of funny sections' such as prefaces in the table of contents is to use the counter secnumdepth described in Appendix C of the LaTeX manual. For example:

    \setcounter{secnumdepth}{-1}
\chapter{Preface}


Of course, you have to set secnumdepth back to its usual value (which is 2 in the standard styles) before you do any section' which you want to be numbered.

Similar settings are made automatically in the LaTeX book class by the \frontmatter and \backmatter commands.

This is why it works. \chapter without the star does

1. put something in the .toc file;
2. if the secnumdepth counter is greater than or equal to zero, increase the counter for the chapter and write it out.
3. write the chapter title.
Other sectioning commands are similar, but with other values used in the test.

Footnotes in tables

The standard LaTeX \footnote command doesn't work in tables; the table traps the footnotes and they can't escape to the bottom of the page.

If your table is floating, your best bet is (unfortunately) to put the table in a minipage environment and to put the notes underneath the table, or to use Donald Arseneau's package macros/latex/contrib/other/misc/threeparttable.sty

Otherwise, if your table is not floating (it's just a tabular' in the middle of some text), there are several things you can do to fix the problem.

1. Use \footnotemark to position the little marker appropriately, and then put in \footnotetext commands to fill in the text once you've closed the tabular environment. This is described in Lamport's book, but it gets messy if there's more than one footnote.
2. Stick the table in a minipage anyway. This provides all the ugliness of footnotes in a minipage with no extra effort.
3. Use macros/latex/contrib/other/misc/threeparttable.sty anyway; the package is intended for floating tables, and the result might look odd if the table is not floating, but it will be reasonable.
4. Use tabularx or longtable from the LaTeX tools distribution (macros/latex/required/tools); they're noticeably less efficient than the standard tabular environment, but they do allow footnotes.
5. Grab hold of footnote.sty from CTAN, lurking in macros/latex/contrib/supported/mdwtools

Then put your tabular environment inside a savenotes environment. Alternatively, say \makesavenoteenv{tabular} in the preamble of your document, and tables will all handle footnotes correctly.

6. Use mdwtab.sty from the same directory (macros/latex/contrib/supported/mdwtools).

This will handle footnotes properly, and has other facilities to increase the beauty of your tables. It may also cause other table-related packages (not the standard tools' ones, though) to become very unhappy and stop working.

Suppose that the editor of your favourite journal has specified that section headings must be centred, in small capitals, and subsection headings ragged right in italic, but that you don't want to get involved in the sort of programming described in The LaTeX Companion (see TeX-related books; the programming itself is discussed under @'). The following hack will probably satisfy your editor. Define yourself new commands

  \newcommand{\ssection}[1]{%
\section[#1]{\centering\sc #1}}
\newcommand{\ssubsection}[1]{%
\subsection[#1]{\raggedright\it #1}}


and then use \ssection and \ssubsection in place of \section and \subsection. This isn't perfect: section numbers remain in bold, and starred forms need a separate redefinition. Also, this will not work if you are using the prototype NFSS with LaTeX 2.09, because the font-changing commands behave differently there.

The macros/latex/contrib/supported/sectsty package provides an easy-to-use set of tools to do this job, while the macros/latex/contrib/supported/titlesec package permits more advanced usage as well. (titlesec comes with a second package, titletoc, which is used to adjust the format of table of contents entries.)

The headings of \chapter and \part commands are produced by a different mechanism; sectsty deals with both, but titlesec deals only with \chapter. The macros/latex/contrib/supported/fncychap package provides a nice collection of customised chapter heading designs.

LaTeX implements a style that doesn't indent the first paragraph after a section heading. There are coherent reasons for this, but not everyone likes it. The package indentfirst.sty (part of macros/latex/required/tools) suppresses the mechanism, so that the first paragraph is indented.

The \footnote command is fragile, so that simply placing the command in \section's arguments isn't satisfactory. Using \protect\footnote isn't a good idea either: the arguments of a section command are used in the table of contents and (more dangerously) potentially also in page headings. Unfortunately, there's no mechanism to suppress the footnote in the heading while allowing it in the table of contents, though having footnotes in the table of contents is probably unsatisfactory anyway.

• Take advantage of the fact that the mandatory argument doesn't move' if the optional argument is present: \section[title]{title\footnote{title ftnt}}
• Use the macros/latex/contrib/supported/footmisc package, with package option stable -this modifies footnotes so that they softly and silently vanish away if used in a moving argument.

Changing the margins in LaTeX

Don't do it. Learn some LaTeX, produce some documents, and then ask again.

You can never change the margins of a document by software, because they depend on the actual size of the paper. What you can change are the distances from the apparent top and left edges of the paper, and the width and height of the text. Changing the last two requires more skill than you might expect. The height should bear a certain relationship to \baselineskip. And the width should not be more than 75 characters. Lamport's warning in his section on Customizing the Style' really must be taken seriously. One-inch margins on A4 paper are fine for 10- or 12-pitch typewriters, but not for 10pt type (or even 11pt or 12pt) because so many characters per line will irritate the reader. However...

Perhaps the easiest way to get more out of a page in LaTeX is to get macros/latex209/contrib/misc/fullpage.sty, which sets the margins of the page identical to those of plain TeX, i.e., 1-inch margins at all four sides of the paper. It also contains an adjustment for A4 paper.

Somewhat more flexible is macros/latex/contrib/other/misc/vmargin.sty, which has a canned set of paper sizes (a superset of that provided in LaTeX2e), provision for custom paper, margin adjustments and provision for two-sided printing.

For details of LaTeX's page parameters, see section C.5.3 of the LaTeX manual (pp. 181-182). The origin in DVI coordinates is one inch from the top of the paper and one inch from the left side; positive horizontal measurements extend right across the page, and positive vertical measurements extend down the page. Thus, for margins closer to the left and top edges of the page than 1 inch, the corresponding parameters, i.e., \evensidemargin, \oddsidemargin, \topmargin, can be set to negative values.

You cannot simply change the margins of part of a document within the document by modifying the parameters shown in Lamport's figure C.3. They should only be changed in the preamble of the document, i.e., before the \begin{document} statement. To adjust the margins within a document we define an environment:

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}


This environment takes two arguments, and will indent the left and right margins by their values, respectively. Negative values will cause the margins to be narrowed, so \begin{changemargin}{-1cm}{-1cm} narrows the left and right margins by 1cm.

Finding the width of a letter, word, or phrase

Put the word in a box, and measure the width of the box. For example,

  \newdimen\stringwidth
\setbox0=\hbox{hi}
\stringwidth=\wd0


Note that if the quantity in the \hbox is a phrase, the actual measurement only approximates the width that the phrase will occupy in running text, since the inter-word glue can be adjusted in paragraph mode.

The same sort of thing is expressed in LaTeX by:

  \newlength{\gnat}
\settowidth{\gnat}{\textbf{small}}


This sets the value of the length command \gnat to the width of small'' in bold-face text.

Changing the space between letters

A common technique in advertising copy (and other text whose actual content need not actually be read) is to alter the space between the letters (otherwise known as the tracking). As a general rule, this is a very bad idea: it detracts from legibility, which is contrary to the principles of typesetting (any respectable font you might be using should already have optimum tracking built into it).

The great type designer, Eric Gill, is (possibly apocryphally) credited with saying he who would letterspace lower-case text, would steal sheep'' (stealing sheep was, before Gill's time, a capital offence in Britain). As the remark suggests, though, letterspacing of upper-case text is less awful a crime; the technique used also to be used for emphasis of text set in gothic (or similar) fonts.

Straightforward macros (usable, in principle, with any TeX macro package) may be found in macros/generic/letterspacing.tex

A more comprehensive package is macros/latex/contrib/supported/soul (which is optimised for use with LaTeX, but also works with Plain TeX. Soul also permits hyphenation of letterspaced text; Gill's view of such an activity is not (even apocryphally) recorded.

Excluding blocks of text from the DVI file

Rainer Schöpf's verbatim.sty provides a comment environment which excludes everything between \begin{comment} and \end{comment}. This package is available as part of macros/latex/required/tools

A more general environment for doing the job is Victor Eijkhout's comment.sty, which lets you define environments for inclusion or exclusion in a document, thus offering a primitive configuration structure. It is available from the CTAN sites in macros/latex209/contrib/misc/comment.sty

Setting bold Greek letters in LaTeX

The simple solution (\mathbf) doesn't always work, because lower-case Greek letters behave differently from upper-case Greek letters (due to Knuth's esoteric font encoding decisions). However, \mathbf can be used for upper-case Greek letters in ordinary circumstances, but the AMS-LaTeX package amsmath.sty disables this font-switching and you must use one of the techniques outlined below.

The plain TeX solution does work, in a limited way:

  {\boldmath$\theta$}


but \boldmath may not be used in maths mode, so this solution' requires arcana such as:

  $... \mbox{\boldmath$\theta$} ...$


which then causes problems in superscripts, etc.

These problems may be addressed by using a bold mathematics package.

• The package bm.sty, which is part of the LaTeX tools distribution (macros/latex/required/tools), defines a command \bm which may be used anywhere in maths mode.
• The package amsbsy.sty, which is part of AMS-LaTeX (macros/latex/required/amslatex) defines a command \boldsymbol, which (though slightly less comprehensive than \bm) covers almost all common cases.

All these solutions cover all mathematical symbols, not merely Greek letters.

Defining a new log-like function in LaTeX

Use the \mathop command, as in:

  \newcommand{\diag}{\mathop{\rm diag}}


Subscripts and superscripts on \diag will be placed exactly as they are on \lim. If you want your subscripts and superscripts always placed to the right, do:

\newcommand{\diag}{\mathop{\rm diag}\nolimits}


This works in LaTeX 2.09 and in LaTeX2e, but not under NFSS alone (see problems with \rm, etc.). However, the canonical method for doing this in LaTeX2e is to use the the \DeclareMathOperator command of amsopn.sty (which is part of the AMS-LaTeX package: macros/latex/required/amslatex).

(It should be noted that log-like'' was reportedly a joke on Lamport's part; it is of course clear what was meant.)

Typesetting all those TeX-related logos

Knuth was making a particular point about the capabilities of TeX when he defined the logo. Unfortunately, many believe, he thereby opened floodgates to give the world a whole range of rather silly bumpy road' logos such as AMS-TeX, PicTeX, BibTeX, and so on, produced in a flurry of different fonts, sizes, and baselines - indeed, everything one might hope to cause them to obstruct the reading process. In articular, Lamport invented LaTeX (silly enough in itself, with a raised small A' and a lowered E') and marketing input from Addison-Wesley led to the even stranger current logo LaTeX2e, which appends a lowered single-stroke greek letter epsilon.

Sensible users don't have to follow this stuff wherever it goes, but, for those who insist, a large collection of logos is defined in macros/eplain/texnames.sty (but note that this set of macros isn't entirely reliable in LaTeX2e). The METAFONT and MetaPost logos can be set in fonts that LaTeX2e knows about (so that they scale with the surrounding text) using the package macros/latex/contrib/supported/mflogo; but be aware that booby-traps surround the use of the Knuthian font for MetaPost (you might get something like META O T'). You needn't despair, however - the author himself uses just MetaPost'.

For those who don't wish to acquire the proper' logos, the canonical thing to do is to say AMS-\TeX{} for AMS-TeX, Pic\TeX{} for PicTeX, Bib\TeX{}` for BibTeX, and so on.

While the author of this FAQ list can't quite bring himself to do away with the bumpy-road logos herein, he regularly advises everyone else to\dots