3

I just want to pass as an optional argument, a macro with an optional argument. If you look at the minimal exampel below, if I use [scale=1] in the optional arguement of the new macro it does not work.

Another point that I do not understand, is that I defined an optional arguments. So why does it work if I use brace instead of squarre paranthesis.

\documentclass{minimal}
\usepackage{graphicx}
\newcommand{\test}[1][]{#1}

\begin{document}
un test

% does not work
\test[\includegraphics[scale=1]{logo}]

% work
\test[\includegraphics{logo}]
\test{\includegraphics[scale=1]{logo}}
\test{\includegraphics{logo}}
\end{document}
  • You can also use a temporary variable: \def\tmp{\includegraphics[scale=1]{logo}} \test[\tmp] Perhaps this is functionally equivalent to David's answer. – Steven B. Segletes Oct 9 '14 at 13:46
5

An optional argument ends at the first top level ] it does not count matching [] pairs.

use

\test[{\includegraphics[scale=1]{logo}}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.