Optional parameters in titlepage

I have a small problem with a .sty file i'm creating.

I want to have the option to add a logo in the title, which was not problem.

But if I now have a situation where I don't add a logo (either by leaving the input empty or by not heaving the command in the main file) I create a ! Latex error: File ' not found.

The document is still created and looks fine.

Since I want to give the sty. to others I would still like to avoid the appearance of this error...

Here the code snippets i used so far:

%create a placeholder for a logo
\newcommand* {\@titlelogo}{}
\newcommand*{\titlelogo}[1]{\def\@titlelogo{#1}}


And my (unsuccessful) try of avoiding the error:

\ifdefined \titlelogo {\includegraphics[height=1.5cm]{\@titlelogo} }
\else \fi


Maybe there is an elegant solution for optional parameters in for example title pages that I'm simply not aware of.

Thanks a lot and cheers Claudia

You can use the built in boolean checks and create \iftitlelogo that is false from the beginning. When you set the logo you turn it to true. (There are more fancy ways to do boolean checks but I think this works here).

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newif\iftitlelogo
\titlelogofalse% default no logo picture
\newcommand{\@titlelogo}{}
\newcommand{\titlelogo}[1]{\titlelogotrue\def\@titlelogo{#1}}
\newcommand\mytitle[1]{%
\iftitlelogo
\includegraphics[width=1.5cm]{\@titlelogo} #1
\else
#1
\fi%
}
\makeatother
\begin{document}
\mytitle{Test without logo}

\titlelogo{example-image}
\mytitle{Test with logo}

\end{document}


Thanks a lot!

I meanwhile found a rather elegant workaround (to my taste), which just checks if the length of the String is larger 0

\stringlength[q]{\@titlepic}% Result is stored in \theresult

\def\mythresh{1}
\ifnum\theresult>\mythresh
\includegraphics[width=0.18\textwidth]{\@titlepic}
\else \fi


This requires the package:

\RequirePackage{stringstrings}
`