54

This is a follow up on beamer's fragile frame as default. What are the drawbacks of setting the default frame to be fragile (or passing the optional fragile argument to all frames). The beamer user guide says

If a frame contains fragile text, different internal mechanisms are used to typeset the frame to ensure that inside the frame the character codes can be reset. The price of switching to another internal mechanism is that either you cannot use overlays or an external file needs to be written and read back (which is not always desirable).

Presumably writing and reading a file takes time and so this increases the time it takes to compile, but are there things that do not work in a fragile frame?

As for an MWE:

\documentclass{beamer}
\def\foo{Something that makes the fragile frame fail is: }
\begin{document}
\begin{frame}
    \foo
\end{frame}
\begin{frame}[fragile]
    \foo
\end{frame}
\end{document}

I am trying to understand what \foo would need to be defined as to cause problems.

Ch'en Meng
  • 3,843
  • 1
  • 19
  • 45
StrongBad
  • 20,495
  • 4
    The only issue that I remember encountering so far is in debugging. If you get an error (e.g. \foo is undefined), then without fragile, you get the line number of the \end{frame} in which the error occurred. On the other hand, with fragile, you just get the line number within the frame (the .vrb file), not of the frame itself. – cyberSingularity Oct 03 '13 at 21:27
  • 1
    It's difficult to define a new command in a fragile frame. – Paul Gaborit Nov 07 '13 at 00:10
  • @PaulGaborit Doing \newcommand{\bar}{bar} inside a fragile frame doesn't work, but \def\bar{}\renewcommand{\bar}{bar} does work. I think \newcommand fails because of the writing a file and reading it back in issue, making this a potential answer. That said, the need to use \newcommand within a frame and the simple work around, means it is not much of a drawback. – StrongBad Nov 07 '13 at 10:56
  • @StrongBad Any verbatim stuff doesn't work inside a non-fragile frame (i.e. source code listings). – Henri Menke Jan 26 '14 at 16:30
  • 1
    See http://tex.stackexchange.com/questions/159172/build-kind-of-a-includeonlypart-for-beamer for one case in which the need to use fragile proved problematic and the solution to the problem involved an alternative approach which avoided the need for fragile. – cfr Feb 12 '14 at 01:17
  • @cfr Thanks for the lead. It is not quite what I was thinking, but it does show a way to cause a fragile frame to fail. – StrongBad Feb 12 '14 at 09:57
  • From my testing, [fragile] can't be used when the presentation is wrapped in \mode<presentation> { ... }. – Henk Metselaar Mar 08 '17 at 01:31

3 Answers3

36

there are no important drawbacks. It is also possible to define a new environment with the fragile option:

\documentclass{beamer}

\newenvironment{Foo}[1]
  {\begin{frame}[environment=Foo]{#1}}
  {\end{frame}}

\newenvironment{FooBar}[1]
  {\begin{frame}[fragile,environment=FooBar]{#1}}
  {\end{frame}}
\begin{document}

\begin{Foo}{title} 
\end{Foo}

\begin{FooBar}{title}
\end{FooBar}

\end{document} 

With fragile every contents is written into an external file and read back. Not a big deal but makes compiling slow. However, fragile is needed for verbatim material.

  • 1
    Well, does that mean that the option is useless and it should be activated always directly by the class? That seems strange to me :-/ – yo' Feb 15 '14 at 21:26
  • 17
    no, with fragile every contents is written into an external file and read back. Not a big deal but makes compiling slow. –  Feb 15 '14 at 21:28
  • Be aware of the effects on centering described in my answer. – jonas-schulze Oct 19 '23 at 14:27
12

See this thread. Apparently the fragile option is incompatible with the allowframebreaks option, without some awkward finagling. So that's one drawback, in addition to the much slower compilation mentioned in the comments of the accepted answer.

2

The fragile option has some impact on centering:

\documentclass{beamer}

\begin{document}

\begin{frame} \centering center \end{frame}

\begin{frame}[fragile] \centering not center \end{frame}

\begin{frame}[fragile] \begin{center} center again \end{center} \end{frame}

\end{document}