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:

\usepackage{ifplatform}
...
\ifwindows\def\home{d:/}\else\def\home{/Users/nick/}\fi
%              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:

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

\item
...

\end{itemize}

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:

\usepackage{fancyvrb}
\begin{Verbatim}[fontseries=b,formatcom=\blue]
...
\end{Verbatim}

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.

2 thoughts on “More LaTeX and Beamer Tips

  1. Thanks to Vedran Sego for pointing out a way to get the tilde recognized as a path in Tip 1:
    \ifwindows\def\home{d:}\else\def\home{\detokenize{~}}\fi
    This uses the \detokenize command added in e-TeX, which is part of TeX-Live
    (which I use) and I presume is available in most modern distributions.
    I also removed an unnecessary forward slash after “D:”.
    And yes, that is “D:”! I reserve C: for Windows and keep my data on D:.

  2. You can use \string~ although actually my preferred solution is to work similarly to class and package files and just use \includegraphics{fig1} with no path and no extension, then arrange that the relevant directories are in your tex input path.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s