# Changing \mode in beamer makes a new paragraph. Is it possible to avoid it?

I want to write different text in the middle of a sentence in a beamer presentation and its corresponding beamerarticle. But it seems that \mode<...>{...} introduces a new paragraph and breaks the sentence.

Please look at the code and results:

\documentclass[ignorenonframetext]{beamer}
%\documentclass{article}
%\usepackage{beamerarticle}
\begin{document}
\begin{frame}{This is a frame}

This is some text in \texttt{beamer} and \texttt{article} modes.

This is some text in \mode<article>{\texttt{article}}\mode<beamer>{\texttt{beamer}} mode.
\end{frame}
\end{document}

This is the result in beamer mode. It looks like \mode<beamer>{text} introduces \par (or something similar) before and after text.

while \mode<article>{text} just introduces \par after text.

In any case I would like t have some mechanism to alternate text without introducing paragraph breaks. Is it possible?

-

Here's an alternative way to achieve the same end: replace your \mode with \only. I tend to think of \mode as something for Big Chunks and don't think I've ever used it within a frame. That's purely subjective, but based on the question it would appear that inadvertently stumbled on a Good Practice.

Overlay specifications as used by \only, \alt, and \temporal (amongst others) can include "output type" specifications. Quite often I'll do some complicated overlay stuff, for example I might want to iterate through approximations of \pi. In my presentation, I'd want something like:

\only<+>{3}
\only<+>{3.2}
\only<+>{3.14}

But in handout or trans mode, these all get processed and the overlay specification collapses so that they all appear. That isn't what I want. So I actually do:

\only<+|handout: 0|trans: 0>{3}

and so on. This suppresses the text completely in handout and trans modes.

In your example, you can make use of this facility and have:

\documentclass[ignorenonframetext]{beamer}
%\documentclass{article}
%\usepackage{beamerarticle}
\begin{document}
\begin{frame}{This is a frame}

This is some text in \texttt{beamer} and \texttt{article} modes.

This is some text in
\only<article>{\texttt{article}}\only<beamer>{\texttt{beamer}} mode.
\end{frame}
\end{document}

This produces:

-

You can redefine \beamer@modeinline defined in beamerbasemodes.sty; here's the original definition:

\long\def\beamer@modeinline<#1>#2{%
\gdef\beamer@closer{}%
\def\beamer@doifnotinframe{\@gobble}\def\beamer@doifinframe{\@firstofone}%
{\beamer@saveanother\beamer@slideinframe=1\relax%
\beamer@masterdecode{#1}%
\beamer@restoreanother}\beamer@donow{#2}%
\beamer@mode\par}

and the final \par produces the end of paragraph you mentioned; deleting this \par command gives you what you want:

\documentclass[ignorenonframetext]{beamer}
%\documentclass{article}
%\usepackage{beamerarticle}

\makeatletter
\long\def\beamer@modeinline<#1>#2{%
\gdef\beamer@closer{}%
\def\beamer@doifnotinframe{\@gobble}\def\beamer@doifinframe{\@firstofone}%
{\beamer@saveanother\beamer@slideinframe=1\relax%
\beamer@masterdecode{#1}%
\beamer@restoreanother}\beamer@donow{#2}%
\beamer@mode}
\makeatother

\begin{document}
\begin{frame}{This is a frame}

This is some text in \texttt{beamer} and \texttt{article} modes.

This is some text in \mode<article>{\texttt{article}}\mode<beamer>{\texttt{beamer}} mode.

\end{frame}

\end{document}

The etoolbox package simplifies the code:

\documentclass[ignorenonframetext]{beamer}
%\documentclass{article}
%\usepackage{beamerarticle}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\beamer@modeinline}{\par}{}{}{}
\makeatother

\begin{document}
\begin{frame}{This is a frame}

This is some text in \texttt{beamer} and \texttt{article} modes.

This is some text in \mode<article>{\texttt{article}}\mode<beamer>{\texttt{beamer}} mode.

\end{frame}

\end{document}
-
Thank you for your fast answer. I'll test as soon as possible. I still have a curiosity, with your example both \par, before and after beamer disappear but your solition just supresses one \par from \beamer@modeinline, so, where does the other one come from? –  Ignasi Jul 25 '12 at 16:38
@Ignasi: every use of the original \mode<...>{...} command will result in introducing one \par command after the contents has been typeset. Schematically, what happens with the second line of text in your example is the following: in beamer mode the text becomes This is some text in \par \texttt{beamer} \par mode. (producing three paragraphs of text), but in article mode you will have This is some text in \texttt{article} \par\par mode. and two consecutive \par commands are equivalent to just one \par command, so you'll get only two paragraphs. –  Gonzalo Medina Jul 25 '12 at 16:51
@Ignasi the redefinition suppresses \par from every occurrence of \mode<...>{...} so, in both cases of your example, after the redefinition, the two \par commands are suppressed producing just one paragraph in the output. –  Gonzalo Medina Jul 25 '12 at 16:58