Problem

I am working on a template for my university. I have been able to create most of it, but I am stuck trying to create a frame called titlepage. Specifically in this frame I want the user to be able to replace part of the background of an image of their choice. Like the following

Ideally I want the following syntax

\begin{frame}{titlepage, img=example-image-a, pos=0.6}
content here
\end{frame}


or

\begin{titlepage}{img=example-image-a, pos=0.6}
content here
\end{titlepage}


With the help of Overlay image with parts of another image and Creating a simple university Beamer template from scratch I was able to come up with the MWE at the bottom. However, I have a few problems

• The frontpage image removes all the text on the slide
• I only want the user to be able to insert an image if the frontpage i selected
• I have not been able to create the key syntax described above

Code

\documentclass[aspectratio=169]{beamer}
% \usetheme{uit}
\usepackage[english]{babel} % Main language to the right ->
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\UiTtitlepageBackground}{%
\expandafter\includegraphics\expandafter[%
width=\paperwidth,
height=\paperheight]{uit-background-titlepage.png}%
}

\setbeamertemplate{background canvas}{
}

\usepackage{etoolbox}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background}{}%
}

\makeatletter
\define@key{beamerframe}{titlepage}[true]{%
\setbeamertemplate{background}{%
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
\UiTtitlepageBackground\hfil}\vfil}%
}%
}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\title{There Is No Largest Prime Number and way to to to much info}
\subtitle{subtitle na na na na na na na na na na na na na na na batman}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{euclid@alexandria.edu}}

\makeatletter
\AtBeginDocument{
\newlength\beamerleftmargin
\setlength\beamerleftmargin{\Gm@lmargin}
}
\makeatother

\newcommand{\titleimage}[2][0]{%
\pgfmathsetmacro\xpos{max(min(#1,1),0)*0.5855}
\begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
\node (X) {%
\hspace*{-\beamerleftmargin}%
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
\UiTtitlepageBackground\hfil}\vfil}%
};
\begin{scope}[x={(X.south east)},y={(X.north west)}]
\begin{scope}
\clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
\path let \p1=(X.north east) in (\xpos,0)
node{\includegraphics[width=\x1,height=\y1]{#2}};
\end{scope}
\end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}[titlepage]
\titleimage[0.55]{example-image-a}
\titlepage
\end{frame}

\begin{frame}
\titleimage[0.6]{example-image-c}
\begin{theorem}
Hmmm
\end{theorem}
\begin{example}
\begin{enumerate}
\item hello
\item hi
\item woah
\end{enumerate}
\end{example}
\end{frame}

\end{document}


I think I do not fully understand all problems you have but one of them seems to be to pass a set of options to the titleimage template. Since you are using pgf, this is easy. The following contains an example, which can be polished once I understand all aspects of the question. The template is now parsing the pgf keys and using them. For instance, if you are saying

\begin{frame}[t,titleimage={file=example-image-a}]
\frametitle{Something}
\begin{theorem}
Hmmm
\end{theorem}
\begin{example}
\begin{enumerate}
\item hello
\item hi
\item woah
\end{enumerate}
\end{example}
\end{frame}


you get

and

\begin{frame}[titleimage={file=example-image-duck,pos=0.6}]
\frametitle{Something else}
\begin{itemize}
\item blub
\item quack
\item pft
\item meow
\end{itemize}
\end{frame}


The important thing is that we added an optional key pos here. If you do not specify it, it assumes some default value. Crucially, you can add as many keys of that sort as you want, and you can always upgrade your template to allow for additional keys without losing backwards compatibility.

Here is the full code.

\documentclass[aspectratio=169]{beamer}
% \usetheme{uit}
\usepackage[english]{babel} % Main language to the right ->
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\UiTtitlepageBackground}{%
\expandafter\includegraphics\expandafter[%
width=\paperwidth,
height=\paperheight]{uit-background-titlepage.png}%
}

\setbeamertemplate{background canvas}{
}

\usepackage{etoolbox}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background}{}%
}

\makeatletter
\define@key{beamerframe}{titlepage}[true]{%
\setbeamertemplate{background}{%
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
\UiTtitlepageBackground\hfil}\vfil}%
}%
}

\define@key{beamerframe}{titleimage}[]{%
\Titleimage{#1}%
}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\title{There Is No Largest Prime Number and way to to to much info}
\subtitle{subtitle na na na na na na na na na na na na na na na batman}
\date[ISPN '80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{euclid@alexandria.edu}}

\makeatletter
\AtBeginDocument{
\newlength\beamerleftmargin
\setlength\beamerleftmargin{\Gm@lmargin}
}
\makeatother
\pgfkeys{/title image/.cd,pos/.initial=0,file/.initial=example-image-duck}
\newcommand{\Titleimage}[1]{%
\setbeamertemplate{background}{%
\pgfkeys{title image/.cd,#1}%
\pgfmathsetmacro\xpos{max(min(\pgfkeysvalueof{/title image/pos},1),0)*0.5855}%
\begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
\node (X) {%
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
\UiTtitlepageBackground\hfil}\vfil}%
};
\begin{scope}[x={(X.south east)},y={(X.north west)}]
\begin{scope}
\clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
\path let \p1=(X.north east) in (\xpos,0)
node{\includegraphics[width=\x1,height=\y1]{\pgfkeysvalueof{/title
image/file}}};
\end{scope}
\end{scope}
\end{tikzpicture}}
}
\newcommand{\titleimage}[2][0]{%
\pgfmathsetmacro\xpos{max(min(#1,1),0)*0.5855}
\begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
\node (X) {%
\hspace*{-\beamerleftmargin}%
\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
\UiTtitlepageBackground\hfil}\vfil}%
};
\begin{scope}[x={(X.south east)},y={(X.north west)}]
\begin{scope}
\clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
\path let \p1=(X.north east) in (\xpos,0)
node{\includegraphics[width=\x1,height=\y1]{#2}};
\end{scope}
\end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}[t,titleimage={file=example-image-a}]
\frametitle{Something}
\begin{theorem}
Hmmm
\end{theorem}
\begin{example}
\begin{enumerate}
\item hello
\item hi
\item woah
\end{enumerate}
\end{example}
\end{frame}

\begin{frame}[titleimage={file=example-image-duck,pos=0.6}]
\frametitle{Something else}
\begin{itemize}
\item blub
\item quack
\item pft
\item meow
\end{itemize}
\end{frame}

\end{document}


As I said, it is not streamlined yet because I have the strong feeling that I did not address all the points you raised (but I could not understand them, also because I fail to understand e.g. "I only want the user to be able to insert an image if the frontpage i selected" grammatically and logically.)

• Great answer! Sorry about the borken English. The image uit-background-titlepage.png is only supposed to be used on titlepage frames, thus it does not make sense to insert a cut image on pages other than titlepages. In my template \begin{frame} ... \end{frame} uses a different background image. Apr 6 '20 at 22:11
• @N3buchadnezzar OK, assume one renames titleimage to titlepage, and adds another style for a generic background picture, would this be what you want? Is the generic background picture also to be clipped?
– user194703
Apr 6 '20 at 22:18
• I think the answer is perfect as it stands =) Apr 6 '20 at 22:48
• Hmm. I am not able to compile your example locally. Am I doing something wrong? I get the following error message: Use of \G@ii does not match its definition Apr 7 '20 at 9:39
• @N3buchadnezzar I have compiled this code with pdflatex, lualatex and xelatex. All of these compilations worked fine. I use a TeXLive 2019 installation, but in a few days I will go to 2020 (when the new MacTeX is out). So I cannot reproduce the issue. If you have a very new TeX installation, you may have found a bug there, or if you have a very old one, then you may want to update. I am sorry, I cannot reproduce the problem, which makes it hard for me to fix it.
– user194703
Apr 7 '20 at 9:44