Math & ScienceSimple calculations package

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User1802

Simple calculations package

Post by User1802 »

@unbonpetit
Thanks for helping. The FP package is a good idea, the example you posted is not working properly.

@torbjorn t.
I suppose this is the answer to my second question. Anyway, overall, the math performed using the pgf package is what I need at the moment.

So, the solution is:
torbjorn t. wrote:

Code: Select all

\documentclass{article}
\usepackage{pgf}
\begin{document}
87 divided by 17 is approximately \pgfmathparse{int(round(87/17))}\pgfmathresult.
\end{document}
Thanks again everyone.
VG

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Graf_Zahnlos
Posts: 2
Joined: Tue Nov 08, 2011 4:07 pm

Simple calculations package

Post by Graf_Zahnlos »

Hi!

I'm trying to use PGF's calculation facility to generate labels and want them to be integers. Unfortunately the code from the first post doesn't work for me.
torbjorn t. wrote:

Code: Select all

\documentclass{article}
\usepackage{pgf}
\begin{document}
87 divided by 17 is approximately \pgfmathparse{int(round(87/17))}\pgfmathresult.
\end{document}
Copied it to a new file 'a.tex' and on compilation pdflatex shows this error which seems to imply that the function "int()" is not available:

Code: Select all

[...]
(/usr/share/texmf/tex/latex/pgf/compatibility/pgfcomp-version-0-65.sty)
(/usr/share/texmf/tex/latex/pgf/compatibility/pgfcomp-version-1-18.sty))
No file a.aux.
(/usr/share/texmf-texlive/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)

! Package PGF Math Error: Unknown function `int'.

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.4 ...roximately \pgfmathparse{int(round(87/17))}
                                                  \pgfmathresult.
The PFG documentation also does not mention "int()" but noone here seems to have any problems. Is my version of PGF outdated? I use Ubuntu 11.4 and Synaptic says PGF version is 2.00-1 with no updates available.

Any help is appreciated.
torbjorn t.
Posts: 162
Joined: Wed Jun 17, 2009 10:18 pm

Simple calculations package

Post by torbjorn t. »

Yes, your PGF version is outdated. It would be better to not install TeXlive using Synaptic, but the installer provided by TUG. This also allows you to update your distribution using tlmgr.

See also:
http://tex.stackexchange.com/questions/ ... 8533#28533
http://tex.stackexchange.com/questions/ ... -or-ubuntu

P.S. Though you could probably use \pgfmathtruncatemacro{\macro}{<PGF math code>} which evaluates <PGF math code> and saves it to \macro without decimals. I'm pretty sure this exists in PGF 2.0, search the manual.

P.P.S. I would still recommend updating to TeXlive 2011, instead of TeXlive 2009 that Synaptic installs.
Graf_Zahnlos
Posts: 2
Joined: Tue Nov 08, 2011 4:07 pm

Simple calculations package

Post by Graf_Zahnlos »

torbjorn t. wrote:P.S. Though you could probably use \pgfmathtruncatemacro{\macro}{<PGF math code>} which evaluates <PGF math code> and saves it to \macro without decimals. I'm pretty sure this exists in PGF 2.0, search the manual.
Thanks! That did the trick.

I'll also look into getting an up to date TeXlive. So thanks for that hint, too :-)
Post Reply