Questions tagged [pgfmath]

{pgfmath} concerns the pgfmath library used for internal computations in TikZ-pgf but which is also available for other computations in (La)TeX.

The tag concerns the pgfmath library in TikZ-pgf. pgfmath enables computations in TikZ-pgf but can also be used independently. The library enables features which are much more powerful than the similar ones in the calc package. Another packages with similar features is fp.

See the TikZ-pgf manual section on the pgfmath library for details.

549 questions
36
votes
5 answers

How to do mathematical programming in LaTeX?

I typically write my programs in Matlab and then port the picture into LaTeX. At times it appears that one has better efficiency or flexibility to have the program within LaTeX itself, either you have access to more control over graphing or that…
Maesumi
  • 9,059
20
votes
1 answer

Why is there no pgfmath macro that expands directly to the result?

Is there a specific reason that there is no default macro (e.g. \pgfmath{}) that directly expands to the result of the evaluated ? It always strikes me as particularly cumbersome when I have to type…
Fritz
  • 6,273
  • 31
  • 55
19
votes
2 answers

How to solve the 10.09999 rounding problem with pgfmath?

I'm trying to create a technical drawing of a magnetic write head with dimensions on it. I'm using some macros which help a lot from here: Dimensioning a technical…
Chah
  • 1,527
18
votes
6 answers

Random quadratic equation

I would like to produce quadratic equation with integer coefficients. Here's my code using pgfmath. \documentclass{article} \usepackage{tikz} \pgfmathsetseed{\pdfuniformdeviate 10000000}…
Roland
  • 193
16
votes
7 answers

Erf function in LaTeX

Is there a way to easily compute the erf function (or the cumulative distribution function of the normal law) in LaTeX? Currently, I use pgf to make computation, but I did not find a way to compute erf using pgf. I would be happy to use any package…
Xoff
  • 1,691
15
votes
1 answer

How to omit printing the decimal part in pgfmath macros

In Dimensioning of a technical drawing in TikZ a very nice solution to mark lengths on a drawing has been given that uses pgfmath's capability. How do I omit having the decimal part of the number printed, eg: 25 instead of 25.0?
Chah
  • 1,527
15
votes
1 answer

Simple example of pgfmath

I'm trying a small educational example using pgfmath. I want to calculate the minimum of a list of numbers. More accurately, I have a list of (number,string)-pairs, and I want the minimum of all the numbers. My \calculateMin command (see below)…
13
votes
2 answers

Why is there a decimal for 3x4=12.0?

Why does \pgfmathresult display the result of 3x4 as 12.0? \documentclass{article} \usepackage{pgf} \begin{document} \pgfmathparse{3*4} \pgfmathresult \end{document} This code yields a document whose sole contents is "12.0". In some parts of…
13
votes
3 answers

Precision in numeric calculations

When using pgfmathsetmacro with very small of high exponents, it doesn't work. The example below exits by complaining a division by zero. Is there any way to increase the precision that this works or another package which handles this…
student
  • 29,003
12
votes
4 answers

Compute denominator and numerator of irreducible fraction from arbitrary fraction

I would like to reduce each fraction i/n to its irreproducible form (and let's assume i is less than n) and displayed not as a \frac fraction but like it is used e.g. in the frame numbers used in latex beamer, i.e. also as j/m When using pgfmath the…
Ronny
  • 6,110
10
votes
1 answer

Unexpected results from pgfmath functions with numbers with leading 0

The pgfmath functions give me unexpected results when used on numbers with leading zeros. Are the output in the example below expected for 0011 and 0021? \documentclass{article} \usepackage{tikz} \newcommand\truncateline[2]{% #1 & #2 &…
Martin Heller
  • 11,391
8
votes
3 answers

pgfmath expression containing a \newtoks defined via a \def

This must be another of those expansion related issues as I don't know why the…
Peter Grill
  • 223,288
8
votes
1 answer

Using != in \pgfmathparse

In section 63.1 Operators of the pgf manual pgfmanual.pdf I see the claim that x != y returns 1 if x ≠ y, 0 otherwise. Unfortunately, I can't get that to work: \documentclass{article} \usepackage{pgf} \pgfmathparse{3!=4} gives me a Missing…
7
votes
2 answers

Worksheets with Big Numbers

I am trying to make mental math worksheets with exercises such as 25% of 80 trillion is ___ It seems that pgf and/or pgfmath is not capable of doing this as the numbers are too large. The code compiles with smaller numbers. How should I do…
7
votes
1 answer

Why does pgfmaths's ifthenelse evaluate both expressions?

Consider having to compute some value using an operation that might not be defined for certain values, like e.g. the tangent function. To avoid raising exceptions, I tried using pgfmath's ifthenelse(, , ), like in…
Tom Bombadil
  • 40,123
1
2 3