# Is it possible to make Beamer pause-handout mode compatible with SageTeX?

I use SageTeX with Beamer for my classes. I need two sets of pdf files, one with the pause for the screen and the handout one to save trees. I use MikTeX under Windows.

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


and comment out one of them.

To use SageTeX I need to compile my file with a Linux virtual machine a second time to get the result of my computation such as

$2+2={\sage{2+2}}$


I expect to do it only once for the two versions but I encounter the following difficulty with the following MWE:

%\documentclass[handout]{beamer}
\documentclass{beamer}
\usepackage{sagetex}% To compute with SAGE within the text
\begin{document}
\begin{frame}[fragile]{Minimum Working Example}

\textit{Compatibility SageTeX - Beamer in HandOut - Pause mode}

This is the first slide with a first Sage operation
$2+2={\sage{2+2}}$
Result should be $4$! and we pause

\pause

\

We add some new text before the next slide

\

\end{frame}

\begin{frame}[fragile]{Minimum Working Example}

\textit{Compatibility SageTeX - Beamer in HandOut - Pause mode}

A new Sage operation on this second slide
$3+3={\sage{3+3}}$
Result should be $6$!

Beamer requests three inline formulas from SageTeX in pause mode but only two in Handout mode.

So the result is six in pause mode and four in handout mode.
\end{frame}
\end{document}


As described in the MWE, it does not seem to be possible to compile in SageTeX only once to get the paused and handout document.

If you compile in pause form, Beamer will request three inline formula from sageTeX , twice the 2+2 (because of the pause) and once the 3+3 so when you Texify again in Handout form, Beamer needs only the first two inline formulas and gives 3+3=4!

If you start with the handout form then Beamer requests only two formulas from SageTeX. It works Ok for the handout of course but when you want the paused version,you get 2+2=4 before the pause, 2+2=6 after the pause and on the second slide you get 3+3=??

It is a lose-lose situation. Of course I can solve it compiling both versions but then it makes the handout option useless because I need to change the name of the TeX source to avoid recompiling with SageTeX.

• Even though this is a TeX question I think that you are more likely to get hep if you ask this on google groups sage-support. – user30471 Jun 25 '14 at 6:14
• I am not sure because Sage is responding to the beamer request. It is the fact that Beamer recompile the whole page after a pause which is creating the problem. I will try anyhow but I may get for answer: Sage computes correctly it is the display which is wrong! – c05772 Jun 25 '14 at 9:21
• Why would you need to rename the source in order to avoid recompiling? How does renaming the source help? – cfr Mar 3 '15 at 23:20

The question has yet to generate a single answer. I really think that the two packages are incompatible at least when one wants to use Beamer overlays and SageTeX computation.

From a design point of view it is clear that if you have a slide with, e.g., five overlays and you need a fairly long computation done by Sage, let's say 5 min then the technique which consists in calling the same computation 5 times is inefficient.

Therefore as a work around I think the use of SageTeX and Beamer's overlay should be avoided EXCEPT if your call to SageTeX is done at the LAST overlay of a slide (between the last \pause instruction and \end{frame}). In this case everything works well. There should be a warning about it in both user manuals. To use this one the keywords "overlays" and "handout" should be added to this post (I don't think I can do it).

• The fact that beamer recompiles the whole frame for each slide is a well known issue, I think. In most cases, it simply greatly increases compilation time. (For example, if you want to reveal a complex graphic incrementally.) So this case is unusual in actually giving the wrong result but it is not so unusual in terms of the underlying issue. – cfr Jul 1 '14 at 2:28
• For long calculations, you might perform the calculation once and save it in a variable using a sagesilent environment, and then access the value of that variable in the actual slide using \sage. – G. Poore Jul 1 '14 at 12:18

I agree - one possible solution is to make a sagesilient environment before the start of the frame, assign your result a variable, then reference that variable in your frame using the \sage{var} command.

This will solve the ?? problem you mentioned - just be sure to compile the sagetex file using the [handout] option. You should be able to then toggle [handout] as required without having to recompile the sagetex file.

Otherwise simply recompile the sagetex file when you switch to handout mode and your MWE will work fine.

• Welcome to TeX.SX! Please remember that this is not a discussion forum, but a Question&Answer site. What you posted does not answer the question, so it shouldn't be posted as an answer. – yo' Mar 3 '15 at 23:21