23

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.

12
  • 1
    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. Commented Nov 21, 2012 at 22:43
  • related tex.stackexchange.com/questions/70860/…
    – user11232
    Commented Nov 21, 2012 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? Commented Nov 21, 2012 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. Commented Nov 21, 2012 at 23:34
  • 1
    @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. Commented Nov 21, 2012 at 23:49

1 Answer 1

27

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 93.1 Parsing Expressions (as of pgfmanual version 3.1.1; 2019-03-03).

enter image description here

3
  • 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? Commented Nov 22, 2012 at 2:15
  • 1
    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. Commented Nov 22, 2012 at 8:27
  • 1
    @ShashankSawant In the context of your Python example, parsing is the Python interpreter reading the text of your code to figure out that it consists of an assignment operation of a variable to a value. This is before executing your code or actually running the assignment. I'm not sure if PGF uses the term exactly the same, but it's a similar idea. Commented Aug 16, 2019 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .