# Debugging pgf-math

Just learned about pgfmath, but how can I debug it?

\pgfmathparse{..} \pgfmathresult


doesn't print anything inside a tikzpicture environment. How can I simply print the result of an expression to check weather the calculation was done correctly?

-

Christoph mentioned this but it's worth making explicit. If you don't want to actually draw anything you don't need a tikzpicture environment and you don't need to put \pgfmathresult in nodes.

\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfmathparse{2+3}
\pgfmathresult
\end{document}

-

If you want to "just print out the result", you don't need to use pgfmath inside a tikzpicture. If you want to place the result in a picture, put it into a node:

\documentclass{article}

\usepackage{tikz}

\begin{document}
2 + 3 = \pgfmathparse{2+3}\pgfmathresult\\
\begin{tikzpicture}
\node at (0,0) {2 + 2 = \pgfmathparse{2+2}\pgfmathresult};
\end{tikzpicture}

\end{document}


Note: Calculating the value before placing the node will not work, because the placing the node will overwrite the old result.

-
NO EASIER WAY?! –  Nils Jun 6 '11 at 14:44
You will need to tell tikz where to place your result. If in doubt, your node will be placed at the current point, so you can omit the at (x,y) part. If your're currently constructing a path, you can get away with node {\pgfmathparse{...}\pgfmathresult}, so all you have to add is node {}. –  Christoph Jun 6 '11 at 14:50

You don't need to launch pgf completely

\documentclass{article}
\input{pgfutil-common.tex}
\usepackage{pgfkeys,pgfmath}
\begin{document}
\pgfmathparse{2+3*2}
\pgfmathresult
\end{document}

-
Thanks for finding the minimal set of packages. I started with pgfmath, then found I needed pgfkeys, but then got funny errors that I couldn't diagnose. So I just went with pgf. –  Matthew Leingang Jun 6 '11 at 17:01

If you have to do the math in tikzpicture, you can also use \show\pgfmathresult to display the result in the console.

-