# AUCTeX previews are not displayed correctly with beamer

I am working on a beamer presentation with AUCTeX on OS X. When I use preview (C-c C-p C-b) on the following document the equation is displayed right after \end{frame} and not in the line of the equation. When I use \documentclass{article} the equation is displayed correctly.

\documentclass{beamer}
\begin{document}
\begin{frame}
$$a^2 + b^2 = c^2$$
\end{frame}
\end{document}


How can I get Preview-Latex to work with beamer?

• I have a slightly related issue with preview in a beamer presentation when I have images included. Having latex \includegraphics[width=3.0in]{img/themen_20200413_154517.png}  inside the document I get a preview image, but I am still seeing the source along the image (see the snapshot) when I am in beamer presentation ![enter image description here](i.stack.imgur.com/ZJcEH.png) But I don't have this issue with a article class. Do you have an idea how to avoid showing still the source along the image? Thank you in advance! Fabian – Fabian Apr 18 '20 at 7:41

preview as an Emacs package depends on preview as a LaTeX package.

When you generate previews, a line \usepackage{preview} is automatically injected in your buffer before processing it with LaTeX, so that LaTeX generates the imagelets that will be inserted in your buffer instead of your whole document.

preview as a Latex package uses a set of defaults that are tailored for the most usual document classes and, so it happens, these defaults (as you've discovered) are no good for the beamer document class...

All this is documented in the fine docs for preview.sty (i.e., the file that is sourced from \usepackage{preview}). I access the docs using texdoc preview (I use a TeXlive distribution) but if you cannot find the docs on your system they are available on CTAN too...

That said, what you want to do is loading explicitly the preview LaTeX package in your document, so that you can pass to it options different from the default ones.

Here it is what works for me, you may want to modify the lists of environments to preview or not preview according to your needs. You must put these lines close to the end of the preamble in your file.

% load preview.sty at the end please
\usepackage[displaymath,textmath,sections,graphics]{preview}
\PreviewEnvironment{align*}
\PreviewEnvironment{multline*}
\PreviewEnvironment{tabular}
\PreviewEnvironment{verbatim}
\PreviewEnvironment{lstlisting}
\PreviewEnvironment*{frame}


Note the last line, the starred command (different from previous ones) means exclude the frame environment from the previewing. Omitting this line will break previewing.