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.

7
  • 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. Commented Oct 3, 2013 at 21:27
  • 1
    It's difficult to define a new command in a fragile frame. Commented Nov 7, 2013 at 0: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
    Commented Nov 7, 2013 at 10:56
  • @StrongBad Any verbatim stuff doesn't work inside a non-fragile frame (i.e. source code listings). Commented Jan 26, 2014 at 16:30
  • 1
    See tex.stackexchange.com/questions/159172/… 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
    Commented Feb 12, 2014 at 1:17

3 Answers 3

36
+100

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.

3
  • 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'
    Commented Feb 15, 2014 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.
    – user2478
    Commented Feb 15, 2014 at 21:28
  • Be aware of the effects on centering described in my answer. Commented Oct 19, 2023 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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .