# Use "length without unit" as scale parameter

I'd like to have a number variable in Latex to be used for the scale parameter in an includegraphics command (for example, to let all finite state machine pictures be scaled to the same size). This works if I just use a makro like this:

\newcommand{\fsmScale}{0.7}
\includegraphics[scale=\fsmScale]{...}


But sometime a figure might be a little to large (or so), and I might want to do something like this:

\includegraphics[scale=0.9\fsmScale]{...}


But this only works for lengths, and lengths have units (pt, mm etc.) that do not work as a scale.

This is a minimal non-working example of what I'd like to do:

\documentclass{article}
\newlength{\mylength}
\setlength{\mylength}{0.7}

\begin{document}
\includegraphics[scale=0.9\mylength]{...}
\end{document}


Is there a way to do that or something similar?

• I think your plan is scratched. You want to give a universal rule (scale), but want to be able to change single instances. Do all scales by hand. Jul 16, 2016 at 8:49
• That might be true - but I'm at the end of a quite big project... This might not be the nicest way to do this in general, but it's certainly the easiest way without changing too much of the given stuff. (I don't want to set single values by hand as I still want to be able to scale them altogether. Also, the additional correction is supposed to be minimal, like 0.97 or so.) Jul 16, 2016 at 8:56
• Also, there certainly are other applications for my problem. Jul 16, 2016 at 9:19
• if you want them all the same size better to use height= than scale=, but you can do the arithmetic you suggest by [scale=\mylenth,scale=0.9] Jul 16, 2016 at 9:40
• That's actually working!! Thank you so much - didn't know that. If you post an answer, I'll definitely accept it. Jul 16, 2016 at 9:56

You can't unfortunatly calculate the product of two non-integer factors and get a factor using (La)TeX, at least not directly. One must be a dimension and the result will be a dimension. However, LaTeX has an internal macro \rem@pt to remove the trailing pt from dimensional values to turn them to factors. The multiplication can be done using eTeX \dimexpr:

\documentclass{article}
\usepackage{graphicx}
\newcommand{\myfactor}{0.7}

\newcommand{\scaletomyfactor}[1]{%
\csname rem@pt\expandafter\endcsname\the\dimexpr #1\dimexpr\myfactor pt\relax\relax
}

\begin{document}

\includegraphics[scale=\scaletomyfactor{0.7}]{example-image}
\end{document}


If \myfactor is a LaTeX length register you can change \dimexpr\myfactor pt\relax to simply \myfactor.

If you want them all the same size better to use height= than scale=, but you can do the arithmetic you suggest by

\includegraphics[scale=\mylength,scale=0.9]{...}