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.

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?

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

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}
share|improve this answer
add comment

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

share|improve this answer
add comment

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}
share|improve this answer
    
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
add comment

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.

share|improve this answer
    
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
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.