Day 6 - Beamer and Slides

Video

Motivation

Beamer is the premier way of presenting mathematics on a computer. If you have ever been to a math conference, you are already familiar with its output - even if you do not know it yet. Beamer is the #1 reason why mathematicians are not plagued by the PowerPoint setup fiascos that cost businesses thousands of hours.

More specifically, Beamer is a $\LaTeX$ document class and set of tools which allow you to compile to presentations, not just to printable documents. These pdfs can be paged through on nearly any modern computer - including, with the right adapters, your phone - without hassle, for a presentation free from technical difficulties.

We are going to cover the very basics of Beamer, but good presentations are an art form in every aspect. Designing and presenting them is a life long skill for which Beamer is just a small component.

Your First Beamer Document

A minimal Beamer document looks much like any other minimal $\LaTeX$ document:

\documentclass{beamer}
\usepackage{amsmath,amsthm,amssymb,physics}
\begin{document}
My First Beamer
\end{document}

If you compile this document, however, you will notice it is missing a lot of things.

While it is in the right aspect ratio, the text is in small and in the top left as usual, and the slide is bland and not very colorful.

Beamer controls everything with frame objects, so add one:

\documentclass{beamer}
\usepackage{amsmath,amsthm,amssymb,physics}
\begin{document}
\begin{frame}
My First Beamer
\end{frame}
\end{document}

That looks a bit better! But we can also make the colors nicer.

Themes

A key part of $\LaTeX$ is the separation of content and formatting, and Beamer does not completely abandon that. You can put your Beamer document in a different style. We're going to punch up our document with a theme: Add

\usetheme{Madrid}

To the document header. Now Beamer will be prettier!

Installing New Themes

But this is not compliant with the purdue brand. Technically it might be a violation of your grad student agreement to give a talk like that at a conference. (the rules are nonsense.) Fortunately, it is not too difficult to modify a theme to comply; even more fortunately, Professor Peterson has already done that for you.

You can use beamer themes by putting all the files in the current directory, and that is a great way to make changes and develop new themes. But for themes you want to use and reuse, it is best to install them.

To do that, you have to put them in your themes directory in the $\LaTeX$ files.

Like bash execution, LaTeX has its own search path. It is stored in the variable TEXMF.

In bash, run the command:

kpsewhich -var-value TEXMF

and it will print out a list of diretories. For example, MikTeX 2.9 on Windows prints:

{C:/Users/cwb/AppData/Roaming/MiKTeX/2.9,C:/Users/cwb/AppData/Local/MiKTeX/2.9,C:/ProgramData/MiKTeX/2.9,C:/Program Files/MiKTeX 2.9}

We need to put our beamer files in one of these directories for $\LaTeX$ to find it. I would recommend putting it in your personal $\LaTeX$ configuration - in your user directory. On Windows, the correct place for that is in ~/AppData/Roaming, the folder for computer-agnostic (able to "roam") app configuration and data.

Download Peterson's purdue theme and unzip it. In a browser, open the hidden AppData folder in your home directory, navigate to the Roaming/MikTeX/ directory, into the version number, and drag the tex folder there.

bash checks its path for updates every time it launches - and checks the contents of its path each time, but $\LaTeX$ checks periodically and stores its data in a hash. To get it to update its knowledge of your files, run the command:

texhash

Now, if everything went correctly, you should be able to compile $\LaTeX$ with the new theme.

Metadata

When you are giving a presentation (or writing a paper), there are a lot of standard things you want to communicate - such as the title and author.

To communicate them, we are going to add that information to the header:

\documentclass{beamer}
\usepackage{amsmath,amsthm,amssymb,physics}
\title{Beamer}
\author{Your Name}
\begin{document}
\begin{frame}
My First Beamer
\end{frame}
\end{document}

That didn't show them enough, because Beamer didn't make a title page. To do that, add another frame:

\documentclass{beamer}
\usepackage{amsmath,amsthm,amssymb,physics}
\title{Beamer}
\author{Your Name}
\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}
My First Beamer
\end{frame}
\end{document}

Beamer's \titlepage is actually a special case of the general \maketitle command, which you can use to make title pages in normal $\LaTeX$ documents.

Sections and Names

You can add sections as normal, and page names as parameters to frame, to organize things:

\documentclass{beamer}
\usepackage{amsmath,amsthm,amssymb,physics}
\title{Beamer}
\author{Your Name}
\begin{document}

\begin{frame}
\titlepage
\end{frame}
\section{Introductions}
\begin{frame}{First Content Slide}
My First Beamer
\end{frame}
\end{document}

Including Images

Presentations with only text are often dull. We are going to include images in our document. Specifically, this penguin family:

cute penguins

To do this, we are going to add the graphicx package to the header:

\usepackage{graphicx}

And then, where we want our picture to occur:

\includegraphics{cutepenguins.jpg}

This places an image at full size, at the current position. That is too big for our purposes. There are two things we can do about it - resize the image using image editing software, or embed it with an explicit size:

\includegraphics[width=100px]{cutepenguins.jpg}

In academic papers, it is often recommended to place figures on either the top or bottom, or on their own pages if they are sufficiently large.

This is done using the figure environment:

\begin{figure}
\includegraphics{cutepenguins.jpg}
\end{figure}

Moving On

Advanced Topic: Slides that Change During The Presentation You can make a perfectly good presentation with just static slides, but Beamer contains extensive support for making content appear or disappear.

The simplest way is to place the \pause command at various lines in your page. Beamer will display everything before that line, then create a new slide with everything before and after until the next \pause command, or the end of the page.

\onslide<a-b> is a more advanced control, which renders the content - until the next \onslide, \pause, or other beamer control - on slides starting at the left number. For example, \onslide<2-> renders the following $\LaTeX$ on the second slide for that frame, until the last slide of the frame.

Several $\LaTeX$ options, such as the \item command in the \enumerate and \itemize environments, support the <a-b> syntax directly; a numbered list such as

\begin{enumerate}
\item Hi
\item<2-> This text
\item<3-> Shows up over multiple slides
\end{enumerate}

Would render on multiple slides.

So far, these commands hide content from the viewer, but still place it in the document.

To get more precise control, \only<a-b>{} allows you to render the content in its brackets ONLY on certain lines. For example, you can change a word in a paragraph:

\only<1>{Their}\only<2->{There} is a cute \only<1>{pingling}\only<2->{penguin}.

There are several other Beamer controls available - more syntaxes to do these same actions, including environments - but this basic set should let you do what you want to with relative ease.


To continue learning Beamer, do today's worksheet. When you have finished, you can proceed to the next day.

Department of Mathematics, Purdue University
150 N. University Street, West Lafayette, IN 47907-2067
Phone: (765) 494-1901 - FAX: (765) 494-0548
Contact the Webmaster for technical and content concerns about this webpage.
Copyright© 2018, Purdue University, all rights reserved.
West Lafayette, IN 47907 USA, 765-494-4600
An equal access/equal opportunity university
Accessibility issues? Contact the Web Editor (webeditor@math.purdue.edu).