More LaTeX and Beamer Tips

Following my earlier posts Top 5 Beamer Tips and Fine-Tuning Spacing in LaTeX Equations I offer four further tips that I’ve been using over the last few months.

1. Platform-independent specification of paths

I use both Windows and Mac machines and want my LaTeX files to run equally well on both. The only difficulty arises when a file is included from another directory (usually a PDF or jpeg file or a program listing). If the file name is specified relative to the current location then forward slash syntax can be used and works on both Mac and Windows. For example

\includegraphics[width = 8cm]{../figs/fig1.pdf}

However, if files are being pulled in from many different directories it can be tedious to specify relative paths and absolute paths are preferable. The problem is that the home directory is system-dependent. My solution is to use the ifplatform package as follows:

%              Windows            Mac or Linux
\includegraphics[width = 8cm]{\home/tex/figs/fig1.pdf}

The \ifwindows construct sets up \home, which is then used as the prefix to the paths of the files to be included. (I initially tried using \home{~} for the Mac, but could not find a way of making this work, since LaTeX interprets the tilde as a hard space.)

2. Spacier Lists

If a Beamer slide consists mostly of a list and has lots of space below the list it can aid readability if the list is opened up a little, by increasing the spacing between items. This can be done as follows:

\setlength{\itemsep}{10pt}  % Adjust to taste.



3. Code listings

The standard verbatim environment does not look very good in Beamer, as the font it uses is rather thin. I prefer to use the Verbatim environment provide by fanycvrb, which allows me to customize the font style and color:


This example uses a bold font in blue. Lots of other options are available for customizing the way the Verbatim environment is rendered.

4. Emacs-RefTeX Table of Contents

In Emacs, with the RefTeX package, the command reftex-toc produces a table of contents for a LaTeX document, allowing navigation by sectional unit. By default, this command does not know about Beamer. You can tell reftex-toc about Beamer frames by adding the following to your .emacs, after (require 'reftex):

  (setq reftex-section-levels
  (append '(("begin{frame}" . -3) ) reftex-section-levels))

This works even if the frame title is set with the \frametitle command.