[Tex/LaTex] pgfmath expansion – call a command from within a pgfmath environment

expansionmacrostikz-pgf

I am trying to define a newcommand using pgfmath. This commands calls a previously defined command but it fails. It propably has to do something with expansion.

I've read this question about expanding pgf macros within commands but I can't get it to work.

\documentclass{article}
\usepackage{tikz}

\newcommand{\mathresult}[1]{\pgfmathparse{#1} \pgfmathresult}
\newcommand{\doublemathresult}[1]{\pgfmathparse{2 * \mathresult{#1}} \pgfmathresult}

\begin{document}
\mathresult{1}
\doublemathresult{1}
\end{document}

The error message is

Incomplete \iffalse; all text was ignored after line

Best Answer

You can try something like that but there are several possibilities but what do you want to do ?

\documentclass{article}
\usepackage{tikz}

\newcommand{\mathresult}[1]{%
\pgfmathparse{#1}\pgfmathsetmacro\mymathresult{\pgfmathresult}}
\newcommand{\doublemathresult}[1]{%
\mathresult{#1}%
\pgfmathparse{2 * \mymathresult}%
\pgfmathsetmacro\mymathresult{\pgfmathresult}}

\begin{document}
\mathresult{2}\mymathresult

\doublemathresult{2}\mymathresult
\end{document}
Related Question