TransWikia.com

How to evaluate an expression before printing it?

TeX - LaTeX Asked by Shashank Sawant on May 23, 2021

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.

One Answer

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

Correct answer by Dr. Manuel Kuehner on May 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP