# LaTeX Beamer: Create own variable

I am trying to create an own variable like \author{} or \date{} in the LaTeX Beamer class. I need it for a title image that I use multiple times in the document. In the preamble I would like to specify the path to that image like \setTitleImage{path/to/image} and then in the document it should be possible to get that path by using \titleImage. I tried it with \newcommand{} but somehow it won't work as expected. Does anybody have an idea of how to do that?

Thank you very much in advance.

Daniel

• Can you edit your question and add MWE with what you tried? – Jérôme Dequeker Jan 26 '17 at 9:44

beamer-fuberlin theme defines commands \titlegraphic and \inserttitlegraphic which can do what you want.

\documentclass{beamer}

\mode
<all>
{
\renewcommand\titlegraphic[2][]{%
\edef\inserttitlegraphic{%
\ifx\relax#2\relax\else
\noexpand\includegraphics[#1]{#2}%
\fi}%
}%
\titlegraphic{}
}

\titlegraphic[width=5cm,keepaspectratio]{images/valley}

\begin{document}
\begin{frame}
\inserttitlegraphic{}
\titlegraphic[width=3cm,keepaspectratio]{example-image}
\inserttitlegraphic{}
\end{frame}
\end{document}


\documentclass{beamer}

\titlegraphic{\includegraphics[width=.5\textwidth]{example-image}}

\begin{document}

\begin{frame}
\inserttitlegraphic
\end{frame}

\end{document}


\newcommand\insertsupervisor{}  % Empty by default.

We can now use \supervisor{} in the preamble, just like we would use \author{}. To display the (content of) supervisor, we can use \insertsupervisor.