2

I'm trying to set up a template for a section frame. On this frame I want to load an image selected by the section title as described in this question.

But when applying the suggested solution I get an endless loop. The following MWE throws an error:

\documentclass{beamer}
\usetheme{default}
\usepackage{graphicx}
\usepackage{inputenc}
\usepackage[space]{grffile}
\begin{document}
\section{some section name}
    \begin{frame}{\insertsectionhead}
          \insertsectionhead

% this line causes: 
% TeX capacity exceeded, sorry [input stack size=5000]. \section{some section name}
          \includegraphics[draft]{\insertsectionhead}

    \end{frame}
\end{document}

how can I use the section name as file name in \includegraphics{} avoiding the endless loop?

2
  • 1
    off-topic: graphicx is loaded by beamer. why you not use solution in given link as it is?
    – Zarko
    Commented Oct 28, 2018 at 9:14
  • @Zarko "why you not use solution in given link as it is?" The solution currently says to use the section number which also throws the "capacity exeeded" exception. Commented Oct 28, 2018 at 9:20

1 Answer 1

2

Borrowing shamelessly from an excellent answer by @egreg:

\documentclass{beamer}
\usetheme{default}
\usepackage{graphicx}
\usepackage{inputenc}
\usepackage[space]{grffile}

\newcommand\insertsectionHEAD{%
  \expandafter\insertsectionHEADaux\insertsectionhead}
\def\insertsectionHEADaux#1#2#3{#3}


\begin{document}
\section{some section name}
    \begin{frame}
          \includegraphics[draft]{\insertsectionHEAD}
    \end{frame}
\end{document}

Explanation to follow later, I have to go now...

You must log in to answer this question.

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