beamer add tag
samcarter
My beamer document take ages to compile. How can I speed things up?

Top Answer
samcarter
There are many different methods one can try. Some ideas in no particular order

### 1. Compile only the frames I'm working on

This can be done using the `\includeonlyframes` command (or `\includeonlylecture` for longer elements)

```
\documentclass{beamer}

\includeonlyframes{foo}

\begin{document}
	
\begin{frame}[label=bar]
  abc
\end{frame}  
  
\begin{frame}[label=foo]
	def
\end{frame}	
	
\end{document}
```

### 2. Avoid time consuming elements

Things like complicate tikz pictures can take quite long to compile. Instead of recompiling them every time one changes something somewhere else in the presentation, one could make a standalone pdf out of them and then include this with `\includegraphics{...}`.

If there are only a few of such images, a simple standalone document can be used:

```
\documentclass{standalone}
\usepackage{tikzducks}

\begin{document}
	
\begin{tikzpicture}
	\duck[]
\end{tikzpicture}	
	
\end{document}
```

If you have many complicate tikz images, using the `external` library might be more comfortable (this needs to be compiled with shell-escape enabled)

```
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\usepackage{tikzducks}

\begin{document}
	
\begin{frame}
	\begin{tikzpicture}
    \duck
  \end{tikzpicture}
\end{frame}	
	
\end{document}
```

### 3. Temporarily disabling overlays

Animations with a lot of individual slides can also slow down things. Will work is still in progress, it can make sense to disable them. For individual frames one can temporally restrict which overlays will be show 

```
\begin{frame}<1>
a \pause b
\end{frame}
```

or one can disable them for the whole presentation using the `handout` option

```
\documentclass[handout]{beamer}
```

### 4. Dedicated compilation tools

There are a couple of dedicated compilation tools, which try to recompile only slides that have been modified, e.g. 

- https://github.com/misc0110/beamer-preview

- https://github.com/theHamsta/faster-beamer

(remember to compile the final version normally to get page numbers, cross-refs etc. right)

----

With all these approaches, keep an eye on how long it would take you to implement vs. how much time it safes 

https://xkcd.com/1205/

Answer #2
Skillmon
**Note:** The following is applicable for any document which is compiled multiple times without changes to the preamble and not restricted to `beamer`. However dumping a format doesn't work (easily) when you're using LuaTeX, as the Lua state isn't included in the format at all.

-----
 # Build your own format

If your preamble contains many big packages (Ti*k*Z & `pgf` for example) you can speed up the compilation by building your own format from your preamble and using that one instead (actually this speeds up the compilation in almost every case, but it is more noticeable the bigger your preamble is, obviously).

Most things should work this way (I use this way of compiling for all my bigger projects and so far only had problems with two things, one of which was freezing the date by explicitly setting the values of `\day`, `\month`, and `\year`, the other was setting the display skips, both of which were easily fixed with `\AtBeginDocument`). But your mileage my vary.

This uses the handy [`mylatexformat`](https://ctan.org/pkg/mylatexformat), with it you can compile your preamble into a format by using:

```sh
<engine> -ini -jobname="<file>" "&<engine>" mylatexformat.ltx """<file>.tex"""
```

With `<engine>` being one of `pdflatex`, `lualatex`, or `xelatex`, and with `<file>` being the name of your main file without the `.tex` ending. This will produce a file called `<file>.fmt`, afterwards you can compile your document with

```sh
<engine> -fmt="<file>" <file>.tex
```

(with the same substitutions for `<engine>` and `<file>` as above).

Keep in mind that you have to recreate the format every time you make changes to your preamble if you want to use this approach (else your changes wouldn't have any effect).

This approach compiles everything until `\begin{document}` into a format, you can however end this earlier by putting `\csname endofdump\endcsname` into your preamble. Note that if you use the `minitoc` package, it has to be loaded after `\csname endofdump\endcsname` according to `mylatexformat`'s documentation.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.