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?

TeXnician
  • 33,589
  • 1
    off-topic: graphicx is loaded by beamer. why you not use solution in given link as it is? – Zarko Oct 28 '18 at 09: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. – Timothy Truckle Oct 28 '18 at 09:20

1 Answers1

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...

Ian Thompson
  • 43,767