Is there a specific reason that there is no default macro (e.g. \pgfmath{<expression>}
) that directly expands to the result of the evaluated <expression>
? It always strikes me as particularly cumbersome when I have to type \pgfmathparse{\linewidth-2.7cm}\pgfmathresult
just to calculate some length that's only used once.
Since such macros would come quite handy for single-use calculations I tried to define my own, but to no avail. Can you help me out with these definitions or at least expain why such a thing is not possible?
What bothers me is the fact that both my \pgflength
and the default \pgfmathresult
are just macros (according to \show
) and both ultimately expand to a sequence of numbers. :-(
\documentclass{article}
\usepackage{pgf}
\newcommand\pgfmath[1]{\pgfmathparse{#1}\pgfmathresult}
\newcommand\pgftrunc[1]{\pgfmathparse{int(#1)}\pgfmathresult}
\newcommand\pgflength[1]{\pgfmathparse{#1}\pgfmathresult pt}
\begin{document}
% Fails:
%\hspace{\pgflength{1cm+2cm}}
% Error message:
% ! Missing number, treated as zero.
% <to be read again>
% \begingroup
% l.14 \hspace{\pgflength{1cm+2cm}}
% Works:
\pgfmathparse{1cm+2cm}
\hspace{\pgfmathresult pt}
% Curiously this also fails:
%\edef\mylength{\pgflength{1cm+2cm}}
% Error message:
% ! Incomplete \iffalse; all text was ignored after line 24.
% <inserted text>
% \fi
\end{document}