[Tex/LaTex] Beamer/Beamerarticle: \mode
is ignored after was set, and vice versa

beamerbeamerarticleinclude

I have a problem with latex ignoring text after \mode<presentation> or \mode<article> was set.

MWE description

I have a large document that changes modes often, and I also \include some more latex files. I've reduced it to the following MWE.

\documentclass{article}
\usepackage{beamerarticle}

%\documentclass{beamer}

\begin{document}

  1. Text without a mode being set. This should be shown
     in both presentation and article mode.

  \mode
  <presentation>
    \begin{frame}
      2. This is text inside a frame. It should only appear in presentation
    \end{frame}

  \mode
  <article>
    3. Text outside a frame. Only in article.

  \mode
  <all>
   \include{in}

\end{document}

With the file in.tex closely following the example in the beamer user guide ver. 3.26, p. 210

\mode*
4. This is some text outside a frame. Shouldn't be shown in presentation mode.

\begin{frame}
  5. This is text inside a frame. This is expected to show in article mode.
\end{frame}

\mode<all>

Problem description

There are two cases to be considered here, compiling with \documentclass{beamer}, or with \documentclass{article} and \usepackage{beamerarticle}.

As I understand the relevant documentation, I should get the results as described in the body of the MWE. Instead, I get the following:

  • Case "article"

    • Everything after \mode<presentation> seems to be ignored. I get a single page with sentence 1. Switching back to \mode<article> does not produce sentence 3, and the \include command does not seem to be processed.
  • Case "beamer"

    • Sentence 1. and 2. get typest, the included file is ignored, even though it should be processed in all modes.

Experimentation with the third flavour of the mode command and ignorenonframetext has yielded the same results, please see the output here and here (can't include directly due to lack of reputation). I am using the second mode flavour for \include to work, and because I need to do fancy things like set backgrounds on some slides.

Question

What am I missing here? As far as I can tell I have structured the document correctly. Am I misunderstanding how modes are set and processed? Is this a bug in beamer or beamerarticle? I would like to achieve the result as described in the MWE.

I am compiling this document on Arch Linux with texlive 2012, which at the moment represents rev. 28273.

Best Answer

When using the \mode command in the 'ongoing' sense (without a braced argument), the command has to be on a line on its own with no comments or whitespace. This is becuase the line needs to be compared 'verbatim-like' with the check value. Thus

Some text
\mode
  <all>

will work but

Some text
  \mode
  <all>

will fail. (\mode* is also allowed, but again with nothing else on the line.) The example in the question works correctly if the whitespace is tidied up.