# How to evaluate an expression before printing it?

Start of Edit
In response to the comments I have added the following mwe:

\documentclass{article}
\usepackage{tikz}
\begin{document}
Let's see if this prints: \pgfmathparse{sin(60)}.
\end{document}


Unfortunately the output is just: "Let's see if this prints: ."
End of Edit

I wanted to populate a table with entries calculated on the basis of constants depending on experiment parameters (like room temperature, pressure and humidity). Instead of hand-calculating the entries each time I make the table, I wanted to code the LaTeX table in the form of expressions that can be evaluated. This way, just by changing the experiment parameters, I can populate the new tables.

Somewhat similar questions have been asked before, e.g. example 1, example 2, and example 3. Sage, calc and fp are some of the solutions that have been suggested.

Submission to journals forms a very important factor in my consideration. Many journals these days accept the TeX files and I am reluctant to make submissions that involve heavy packages. Sage in spite of being able to evaluate expression the way I intend them to be, is ruled out for the same reason. I found calc too cumbersome. Somehow I am not able to find the documentation for fp.

All recommendations are welcome. If the TikZ package can be somehow employed, that would be perfect. I use it in almost all of my manuscripts.

-
The one I would recommend is to use \pgfmathparse/\pgfmathsetmacro. If you put together a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. –  Peter Grill Nov 21 '12 at 22:43
–  Harish Kumar Nov 21 '12 at 22:43
I am reluctant to make submissions that involve heavy packages.... If the TikZ package can be somehow employed, that would be perfect. They seem to be somewhat in contradiction, Tikz is a good package but it is massively heavyweight and probably more code than all the other packages that you mention combined. I wonder what are your criterion for acceptable packages in solutions? –  David Carlisle Nov 21 '12 at 23:31
@DavidCarlisle Sorry for my ignorance. My criterion for now is that packages which do not depend on other software are alright. Therefore SageTex is rejected because it requires the user to install Sage. –  Shashank Sawant Nov 21 '12 at 23:34
@ShashankSawant (Re-Comment:) \pgfmathparse{<arg>} only parses the argument. \pgfmathresult gives back the result. (PGF manual says to \pgfmathparse: “This macro parses <arg> and returns the result without units in the macro \pgfmathresult.” | MWE: Let's see if this prints: \pgfmathparse{sin(60)}\pgfmathresult. –  Qrrbrbirlbel Nov 21 '12 at 23:49

You just forgot to return the result of \pgfmathparse by calling \pgfmathresult:

\documentclass{article}
\usepackage{tikz}
\begin{document}
Let's see if this prints: \pgfmathparse{sin(60)}\pgfmathresult.
\end{document}


In the pgfmanual you find more information in section 62.1 Commands for Parsing Expressions. Here's a link.

Finally:

-
Thanks for the answer! But I guess most of you are computer science/engg guys. I have no clue as to what parsing is. I do understand the basics of programming. But in the basics it is simple. Say in python (for that matter any language) you define a variable a=2 and if you wish to see it in the control you say print(a). What is parsing in this context? –  Shashank Sawant Nov 22 '12 at 2:15
Hello. I am not a geek either. I would say that the author of pgf just designed it that way: \pgfmathparse reads the expression and evaluates (calculates) it. The result is now known to pgf. If you want to use the result in the document then the commands \pgfmathresult is used to get the last calculated value. –  Manuel Kuehner Nov 22 '12 at 8:27