Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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}
share|improve this answer
    
This is where we need an expandable version of \pgfmathparse... –  Bruno Le Floch Jun 9 '11 at 13:32
    
Thank you. I am just trying to make some geometry calculations. Like a library of help-functions or something. Par example, to find the intersection of 2 lines when you know a single point on each line and their slopes etc. There are more cases. I can always calculate them by hand of course, but I like my drawings to be parametrized so that I can easily make changes on them. –  pmav99 Jun 9 '11 at 14:32
    
@Bruno, Yeah that would be great –  pmav99 Jun 9 '11 at 14:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.