[Tex/LaTex] Simple way to multiply two values


I have a macro to define the scale of my figures:


Now I have a figure that needs to be scaled twice as big, so I tried to use something like this:

  \caption{My Caption}

This results a very big image, as 2\scale expands to 20.35

I tried/found:

  • Using scale=2*\myscale, but still get errors
  • Some more things using calc, again did not work
  • \real{}, but it does not seem to work also
  • intcalc, but this only seems to work for integers, which is not always the case for \myscale.
  • pgf package, but it seems a complex for a simple multiplication
  • fp package works, but still somewhat complex

The easiest way (that works for me), is this fp-based implementation:

  \caption{My Caption}

Am I missing something? Is there a more simple/elegant solution? Preferably directly usable with the \includegraphics command without creating the additional \calculatedScale.

Best Answer

The l3fp package allows expandable calculations with floating point numbers. Expandability means that you don't need to store the result in a temporary variable.

\usepackage{graphicx} % 

% Provide the command \fpeval as a copy of the code-level \fp_eval:n.
\cs_new_eq:NN \fpeval \fp_eval:n