1

This question already has an answer here:

I'm making a slideshow with LaTeX beamer class like this :

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{listings}
\usepackage{listingsutf8}

\begin{document}

\begin{frame}[fragile]
\frametitle{Découpage et assemblage de lignes}
\begin{lstlisting}[language=bash]
some code
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{Autres opérations}
\begin{lstlisting}[language=bash]
some code
\end{lstlisting}
\end{frame}

\end{document}

For convenient reasons, I would like the code of each frame to be inside a command created with \newcommand like this :

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{listingsutf8}

\newcommand{\framei}{%
\begin{frame}[fragile]
\frametitle{Decoupage et assemblage de lignes}
\begin{lstlisting}[language=bash]
some code
\end{lstlisting}
\end{frame}}

\newcommand{\frameii}{%
\begin{frame}[fragile]
\frametitle{Autres operations}
\begin{lstlisting}[language=bash]
some code
\end{lstlisting}
\end{frame}}

\begin{document}

\framei

\frameii

\end{document}

But when I try to build my slideshow with these modifications, pdftex fail with a Runaway argument? error.

Is there something wrong with my sources? or is it a LaTeX/beamer bug ?

marked as duplicate by user36296, user13907, Jesse, Werner beamer Oct 9 '16 at 0:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    Related: tex.stackexchange.com/questions/29971/… – Benjamin Mar 1 '16 at 20:15
  • 2
    you can not put any verbatim like commands in the argument of another command, that is a general rule due to the way tex parses arguments, not specific to beamer. – David Carlisle Mar 1 '16 at 20:20
  • "For convenient reasons" could mean several things. For example, if you wanted to reuse slide content across several documents, using \input{framei} could work to grab content from framei.tex. If you want to enforce a consistent style, there may be other options. If you want something else entirely, please clarify. – Mike Renfro Mar 1 '16 at 20:47
  • The reason I want to use \newcommand is to reuse frames in other presentations. \input could be a solution but I'll had to make many files (I have about 100 frames and more) and imports with \input seams very slow. – JeanJouX Mar 1 '16 at 21:12