Go to the first, previous, next, last section, table of contents.

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/packages/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 NFSS outside of LaTeX2e, because the command \rm behaves differently there.

Labels on lists

If 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). If you are lazy and just change \labelenumi in one go then your cross-references will be wrong.

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/packages/tools) offers similar facilities. With enumerate.sty, the example above would be achieved simply by starting the enumeration \begin{enumerate}[I/].

Unnumbered sections in the Table of Contents

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/latex209/contrib/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/latex209/contrib/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/packages/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.

Style of section headings

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 NFSS outside of LaTeX2e, because the font-changing commands behave differently there.

Indent after section headings

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/packages/tools) suppresses the mechanism, so that the first paragraph is indented.

Footnotes in LaTeX section headings

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.

To suppress the footnote in headings and table of contents:

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.

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/packages/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

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: fonts/ams/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 logos such as AMS-TeX, PicTeX, BibTeX, and so on. Lamport invented LaTeX, and marketing input led to the current logo LaTeX2e.

The common people 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; the METAFONT logo can be set in fonts that LaTeX2e knows about (so that it scales with the surrounding text) using the package macros/latex/contrib/supported/mflogo

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


Go to the first, previous, next, last section, table of contents.