I'd like to scale a line according to \figscale. Here it is said that the below syntax should work in general, but in this graphic it does not.

As the picture shows, the numbers are just concatenated to, e.g., -0.53cm instead of -0.5 * 3cm = 1.5cm, although I'd like to multiply them. Writing -0.5*\figscaleworks well.

Why is the solution provided in the link not applicable here?

\def \figscale{3cm}

        \draw (-1.0,2) -- (0,2) node[midway, anchor=south] {$A$};
        \draw (-0.5\figscale,1) -- (0,1) node[midway, anchor=south] {$B$};
        \draw (-1.0\figscale,0) -- (0,0) node[midway, anchor=south] {$C$};

enter image description here

  • 2
    \def \figscale{3cm} defines a macro that is simply replaced by 3cm where used, it's not a length. Try \newlength\figscale \setlength\figscale{3cm}. – clemens Jun 25 '14 at 10:07

In the answers to the linked question, \textwidth is used, which is a length parameter for TeX, so the syntax rules allow 4\textwidth (or any decimal number instead of 4).

When TeX is looking for a length, it expands tokens as it goes. Since it expects a length and it has seen -0.5 it expands the next token which might result in something that continues the decimal digits or something that begins with a length register. Your case is the former, because \figscale expands to 3cm and


is a perfect length specification for TeX. The situation is a bit more complicated because we're in the middle of a coordinate for TikZ and this explains why -0.5*\figscale works.

If you want a macro that behaves like a dimension, use


because TeX translates \dimexpr3cm\relax into a (nameless) internal length register. Nonetheless, you're probably best served with


Prefixing a "variable" with a number, for example, 4\textwidth only works if the variable is a TeX dimension or skip or box dimension. This is consistent with usual TeX behaviour.

As the latest PGF manual states (section 88.1 "Commands for Parsing Expressions")

The parser will recognize TEX registers and box dimensions, so \mydimen, 0.5\mydimen, \wd\mybox, 0.5\dp\mybox, \mycount\mydimen and so on can be parsed

The math parser expands every expression with \edef before parsing, so the MWE given above, -0.5\figscale becomes -0.53cm which is evaluated as -15.07993 (points) as opposed to the desired -42.67912.

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.