[Tex/LaTex] \def macro with multiple parameters

macrosoptional arguments

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

Best Answer

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}
Related Question