Problems with pgfmath

I drew a parabola graphic y = 0.5 - a x^2 which crosses the x axis at the "roots" points 0.75 and -0.75 and has a bend at coordinate (0, 0.5). And I want to mark a point on the parabola, which has a coordinate 0.33 * \rootPosition on the x-axis. (Here \rootPosition is a number 0.75). I wrote the following code

\documentclass[tikz]{standalone}
\usepackage{tikz, pgfmath}

\begin{document}
\begin{tikzpicture} [scale=3, >=stealth]

\def\bendPosition{0.5};
\def\rootPosition{0.75};
\def\coeffA{\pgfmathdivide{\bendPosition}{\pgfmathpow{\rootPosition}{2}}};

\draw[thick] (-\rootPosition,0) parabola bend (0, \bendPosition) (\rootPosition, 0);

\def\arbitraryPosition{0.33 * \rootPosition};

\coordinate (arbitrary_point) at (\arbitraryPosition, \bendPosition - \coeffA* \pgfmathpow{\arbitraryPosition}{2}));

\filldraw[black] (arbitrary_point) circle(0.4pt);
\end{tikzpicture}
\end{document}

But when I compile this code, I get the error ! Incomplete \iffalse; all the text ignored after line 14, where 14 line begins with \coordinate (arbitrary_point)..

What's wrong?

• In pgfmath if you do an operation the result is saved under the macro \pgfmathresult. So they don't expand to the result value. If you want to save it you need to use the typical expressions inside \pgfmathsetmacro{\coeffA}{<math stuff>}. Or each time you have to use the \pgfmathresult macro for nesting. And tikz loads pgfmath automatically so you don't need to add it explicitly Dec 12, 2014 at 15:14
• I wrote \coordinate (arbitrary_point) at (\arbitraryPosition, \pgfmathsetmacro{\coeffA}{\bendPosition - \coeffA * \pgfmathpow{\arbitraryPosition}{2}} \pgfmathresult); but got the same error ! Incomplete \iffalse; all the text ignored. Dec 12, 2014 at 15:30
• Please accept the correct answer to conclude this question. Thank you! Dec 16, 2017 at 9:28

1 Answer

You should not use the underscore character in the macro names even though TikZ handles it sufficiently well for most cases. Underscore character is a mathmode subscript command and you can safely avoid it with other types.

The main problem is that math operations don't expand to a result when found on the path. They save the result in a macro called \pgfmathresult and the parser has to see that one but not the math operators.

\begin{tikzpicture} [scale=3, >=stealth]
\def\bendPosition{0.5};
\def\rootPosition{0.75};
\pgfmathsetmacro\coeffA{\bendPosition/(\rootPosition)^2}
\draw[thick] (-\rootPosition,0) parabola bend (0, \bendPosition) (\rootPosition, 0);
\pgfmathsetmacro\arbitraryPosition{0.33 * \rootPosition}
\coordinate (arbitrary_point) at (\arbitraryPosition, {\bendPosition - \coeffA* (\arbitraryPosition)^2});
\filldraw[black] (arbitrary_point) circle(0.4pt);
\end{tikzpicture}