# \def macro with multiple parameters

I'm trying to tweak a style file, I have a 'def' as follows:

\def\logo#1{\gdef\@logo{#1}} \gdef\@logo{}


Inside of a custom 'make title':

\includegraphics[scale=0.1]{\@logo}


I'm new to Tex/Macros, I was just wondering how I can add the scale parameter to the 'logo' def macro? i.e. I'd like to fully parameterise the call to \includegraphics.

Edit: As per below, I've added the logo into the 'maketitle', on a simple style, not sure if there is a better way to do that?

\newcommand{\logo}[2][]{%
\gdef\make@logo{\includegraphics[#1]{#2}}%
}
\let\make@logo\relax

%% title
\def\@maketitle
{
\clearpage
\vskip -3em

\ifx\make@logo\relax
\else
\make@logo
\fi

\newpage
\thispagestyle{empty}
\vspace*{-24pt}
\begin{center}
{\Large \bf \@title \par}\vspace*{24pt}{
\lineskip 1em
\begin{tabular}[t]{c}
\@author \\
\vspace*{1pt}\
\end{tabular}
}
\vskip 1em
\vspace*{12pt}
\end{center}
}

• Could you show what you mean by "fully parameterise"? – Werner Apr 18 '17 at 16:19
• I mean, \logo{my-pic.png} will mean \includegraphics[scale=0.1]{my-pic.png} will get called in my 'maketitle'. I'd like to be able to specify the scale parameter too, i.e. \logo[0.7]{my-pic.png} thanks --Mike – Michael Lewis Apr 18 '17 at 16:24
• Consider voting on the answers below, and accepting the one that helped you most. – Werner Apr 18 '17 at 16:37
• hi, I've just signed up for tex stack exchange, lots of good answers, not sure how to vote yet, or if I have enough "reputation" to vote – Michael Lewis Apr 18 '17 at 17:00

Macro \logo can be defined with an optional parameter that takes the options for \includegraphics:

\newcommand*{\logo}[2][]{%
\gdef\@logo@params{#1}%
\gdef\@logo{#2}%
}
\newcommand*{\@logo@params}{}
\newcommand*{\@logo}{}


Usage for \includegraphics:

\expandafter\includegraphics\expandafter[\@logo@params]{\@logo}


The options need to be expanded first, because the syntax characters comma and equal sign for the key value list must not be hidden inside macros.

Example for \logo:

\logo[scale=0.1]{example-image-a}


Or

\logo[width=2cm, angle=90]{example-image-a}


You can do

\newcommand{\logo}[2][]{%
\gdef\make@logo{\includegraphics[#1]{#2}}%
}
\let\make@logo\relax


and use \make@logo at the point where you build the custom title, maybe like

\ifx\make@logo\relax
% code for no logo, maybe nothing
\else
% code before the logo, maybe \begin{center}
\make@logo
% code after the logo, maybe \end{center}
\fi


So if the document preamble using your style file has

\logo[scale=0.1]{file}


when the title is being typeset you'll get

\includegraphics[scale=0.1]{file}


Without a \logo command, you'll get nothing.

The \logo command accepts, in its optional argument, any options valid for \includegraphics, so for instance

\logo[width=3cm]{file}
\logo[width=3cm,height=4cm,keepaspectratio]{file}


and so on.

• Thanks, switching having the logo optional is what I'm after. – Michael Lewis Apr 18 '17 at 16:51

If scale is all you're after and you're comfortable with an interface like \logo[0.7]{my-pic.png}, then a simple \newcommand with optional parameter works:

\newcommand{\logo}[2][1]{\includegraphics[scale=#1]{#2}}


If you're not using the optional argument, it defaults to 1.

• I think one point is to define the logo with \logo in one place and to use it with \@logo in another, like \author or \title. – gernot Apr 18 '17 at 16:29
• @gernot: All title content are typically stored and only expanded with \maketitle. So there's no real need to use both \logo and \@logo somewhere else. Moreover, it requires additional \makeatletter...\makeatother delimiting (if not used inside a .sty). – Werner Apr 18 '17 at 16:36
• How does one use your \logo command? How does one specify the image to be used, and how does \maketitle access it? In analogy to \author and \title, \logo should just store the image. – gernot Apr 18 '17 at 16:40
• @gernot: You'd use \title{...\logo[.7]{my-pic.png}...} and then \maketitle in your document. – Werner Apr 18 '17 at 16:41
• I'm including as per \author etc.. so that it gets 'built' by \maketitle, its just for a trivial style file, for some technical notes. – Michael Lewis Apr 18 '17 at 16:45