LaTeX Tips

July 28, 2008

Contents

  1. Add backlinks to the bibliography
  2. Stochastic independence
  3. Roots
  4. Natbib
  5. Conditional Probability and Expectation

You can add backlinks to the end of bibliography items using the hyperref package as follows:

\usepackage[backref]{hyperref}

This will add links to the section where each reference was cited. If you prefer to link to the page, use

\usepackage[pagebackref]{hyperref}

instead. The style of the links can be customized by modifying the \backref and \backrefalt macros as described in the hyperref README file. For example, to place the backlinks in square brackets, use:

\renewcommand*{\backref}[1]{[#1]}

The result is a bibliography entry like the following:

Künsch, H. R. (2005). Recursive Monte Carlo filters: algorithms and theoretical analysis. Annals of Statistics 33, 1983–2021. [3, 27]

where 3 and 27 are hyperlinks to the pages where the paper was cited.

Stochastic Independence

The stochastic independence symbol is not part of LaTeX itself, nor is it included in any of the AMS-LaTeX packages. The closest thing is \perp or \bot. There is, however, a \Perp macro defined in the txfonts/psfonts packages but these change the default fonts. Here is a cheap hack that fakes the symbol by using two \perps separarated by some negative spacing:

\newcommand{\Perp}{\perp \! \! \! \perp}

The macro above is not robust to different math fonts, however, Donald Arseneau posted the following definition of an independence symbol to comp.text.tex which works well with any font:

\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}

Roots

\sqrt{n} will produce the square root of n while \sqrt[k]{n} will produce the k-th root of n. For example, for the cube root of n use \sqrt[3]{n}.

Natbib

The Natbib package provides much better default citation behavior as well as finer control over citations in your documents.

\usepackage[longnamesfirst]{natbib}

The longnamesfirst option prints out all authors in full the first time a reference is cited and abbreviates subsequent citations using “et al.” if there are more than two authors.

Natbib provides many new citation commands for citing references in various situations. See the Natbib notes for details.

Natbib also provides several nice bibliography styles such as chicago:

\bibliographystyle{chicago}

Conditional Probability and Expectation

For simple, normal sized conditional probability and conditional expectation expressions, the \mid command from AMS-LaTeX should be used instead of the pipe (|) or the \vert macro because it is defined as a binary relation and gets the spacing right. For example, instead of

\Pr( A | B )

it is better to write

\Pr( A \mid B )

However, like braces, parentheses, and other delimiters, \mid is not stretchy on its own. For taller expressions, such as fractions, there are two options. LaTeX will try to automatically choose the correct size if you use a \left, \middle, and \right construct such as the following:

\Pr\left( A \;\middle\vert\; B \right)

Note that since \mid is not a stretchy delimiter, we have to use \vert here and add the spacing manually with the surrounding \; commands.

Alternatively, if you need to control the size manually, the \big, \Big, \bigg, and \Bigg contructs will be useful:

\Pr\bigl( A \bigm\vert B \bigr)
\Pr\Bigl( A \Bigm\vert B \Bigr)
\Pr\biggl( A \biggm\vert B \biggr)
\Pr\Biggl( A \Biggm\vert B \Biggr)