[Tex/LaTex] \includegraphics optional argument not resolved if macro

graphicsmacros

\documentclass[a4paper,10pt,twoside]{book}
\usepackage[demo]{graphicx}

\begin{document}

\newcommand{\scalefactor}{scale = 0.25}

\begin{figure}[!ht]
  \centering
  %Next line does not work
  \includegraphics[\scalefactor]{image}
  % The following line works
  %\includegraphics[scale = 0.25]{image}
\end{figure}

\end{document}

Output:

! Package keyval Error: scale = 0.25 undefined.

I need to scale a number of images by the same factor, hence the command.

  1. How to solve this and more importantly
  2. Why is this only specific to \includegraphics

Best Answer

Try this way:

\newcommand{\scalefactor}{.25}
\includegraphics[scale=\scalefactor]{image}
Related Question