In your case, as you use #3
(and #5
in the second example) only to scale (the factor gets multiplied in both the width
and the height
key), you could just use:
\newcommand{\sxfigure}[4]{
\includegraphics[width=#1, height=#2, scale=#3]{#4}
}
and use it like
\sxfigure{<width length>}{<height length>}{<scale factor>}{<file>}
The calc
package can do simple multiplication, though using pgf
enables all sorts of calculations, for example:
\sxfigure[angle=30]{
image width = 1.1^3*3cm,
image height = exp(3)*3cm
}{example-image}
Code
\documentclass{article}
\usepackage{graphicx}
\usepackage{pgf}
\newlength{\includewidth}
\newlength{\includeheight}
\pgfset{
image width/.code={
\pgfmathsetlength\includewidth{#1}
},
image height/.code={
\pgfmathsetlength\includeheight{#1}
},
}
\newcommand{\sxfigure}[3][]{% #1 = \includegraphics key-value stuff
% #2 = width and height assignments
% #3 = the file
\pgfset{#2}%
\includegraphics[width=\includewidth, height=\includeheight,#1]{#3}%
}%
\newcommand{\sxFigure}[4][]{% #1 = \includegraphics key-value stuff
% #2 = width
% #3 = height
% #4 = the file
\pgfmathsetlength\includewidth{#2}%
\pgfmathsetlength\includeheight{#3}%
\includegraphics[width=\includewidth, height=\includeheight,#1]{#4}%
}%
\begin{document}
\sxfigure[angle=30]{image width = 2.5*3cm, image height = 3*3cm}{example-image}
\sxFigure[angle=30]{2.5*3cm}{3*3cm}{example-image}
\end{document}
Output
