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

learn more… | top users | synonyms

30
votes
3answers
1k views

Programming Conway's Game of Life in LaTeX

My aim is to program Conway's Game of Life in LaTeX, and make the output into an animated PDF. I intend to use PGF/TikZ for this, especially pgfmath, but I'm stuck at the moment because I need to ...
28
votes
3answers
616 views

Why doesn't TikZ's \foreach iterate over the last element of the list?

This code \documentclass{report} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[dashed] (1,-1) -- (1,2) node[above] {$1$}; \draw[dashed] (2,-1) -- (2,2) node[above] {$2$}; \foreach ...
18
votes
2answers
2k views

Pascal's triangle in tikz

I would like to typeset the top part of Pascal's triangle. To get the triangle with the names of the binomial coefficients, i.e., {n \choose k}, I used the following code \begin{tikzpicture} \foreach ...
15
votes
6answers
1k views

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} ...
15
votes
1answer
623 views

Is it possible to load pgfmath without loading the full pgf package?

Update Oct 30th 2011 This has now been fixed in the CVS repository of PGF due to my bug report. With this version \usepackage{pgfmath} should work. I would like to use pgfmath in one of my ...
14
votes
1answer
513 views

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 ...
13
votes
3answers
575 views

How to find the length of a PGF array?

A few of my macros currently require the user to pass the length of an array along with the array itself. It would be nice if the length could be calculated for them, as the user in question (myself) ...
13
votes
2answers
2k views

Store \pgfmathresult in a variable

The result of \pgfmathparse is automatically stored in \pgfmathresult. Is it possible to store it in an other variable, too?
13
votes
2answers
107 views

Making a table independent of pgf

I use pgfplotstable to generate tables to be included in online submission to journals. I would like to make my paper independant of pgfplotsable because compilation of the document is made online ...
12
votes
2answers
880 views

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 drawing. \documentclass{beamer} ...
12
votes
1answer
2k views

\ifnum and pgfmath: error

In the following example I want to use \ifnum to compare two numbers computed by pgfmath, for simplicity I use simply 1 and 2 in the example below. Compiling this code gives me the error: ERROR: ...
12
votes
1answer
367 views

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{<expression>}) that directly expands to the result of the evaluated <expression>? It always strikes me as ...
11
votes
2answers
215 views

\pgfmath and \foreach in TikZ

I am quite new to TikZ. I have the following code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{chains} \begin{document} \begin{tikzpicture}[start chain=circle placed ...
11
votes
3answers
2k views

\pgfmathsetmacro - dimension too large (biggest value allowed?)

I want to import some data with parameters to parametrize some plots. After importing a table, I assign specific variables of the table to a placeholder by using \pgfplotstablegetelem. And it works ...
11
votes
2answers
2k views

Variables in TikZ

I use TikZ to draw graphics in LaTeX. I'd like to do arithmetic on variables. For example I haves nodes named after N-1 and N-2 and I'd like to create the N-3 and N-4 nodes as +2 from the first nodes. ...
10
votes
5answers
2k views

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 ...
10
votes
4answers
63 views

Checking for valid floating point number

I want to do the following: I am generating a report which can be set to be in imperial or metric units. All values are originally in metric units, so in the case of imperial units all values should ...
10
votes
1answer
411 views

How to scale existing coordinates data in pgfplots?

I have a plot with its data, for example \documentclass[]{article} \usepackage[]{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[] \addplot+[%multiply x data by a factor here, multiply y ...
10
votes
1answer
2k views

Increment loop variable in inner foreach loop

I need the following pairs of numbers: 12 13 14 23 24 34 My first attempt was to use two nested foreach loops: \foreach \x in {1,...,4} { \foreach \y in {\x+1,...,4} { % This would be very easy in ...
10
votes
1answer
2k views

pgfplots and calculations; without fpu 'dimension too large', with fpu 'Illegal unit of measure (pt inserted)'

I'm trying to multiply some numbers that will end up in the legend of a plot. I can't get it to work: If I naively try \pgfmathmultiply, I get a dimension too large error, with the code in MWE 1 ...
9
votes
1answer
555 views

pgfplot: use pgfmathdeclarefunction defined function within coordinate

This code snippet defines a simple function using \pgfmathdeclarefunction (e.g. f()) and \pgfmathparse. I would like to use the defined function f() within other coordinate, e.g. (0.2, f(0.2)) vs. ...
9
votes
1answer
2k views

TikZ \foreach loop evaluate variable using pgfmath function

I have problem with defining a new variable within the \foreach loop using the evaluate option using a pgfmath function: \documentclass{article} \usepackage{tikz} \begin{document} ...
9
votes
2answers
192 views

Calculating Beamer presentation progress excluding appendix

Problem description In trying to calculate the progress of a Beamer presentation, one can use \pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertdocumentendpage)} where \prog tracks the ...
9
votes
1answer
191 views

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} ...
9
votes
1answer
140 views

Is it possible to store \pgfmathresult in a pgfkey?

I would like to perform a calculation using \pgfmathparse and then store \pgfmathresult as the value of a pgfkey. \documentclass{article} \usepackage{tikz} \begin{document} ...
9
votes
1answer
251 views

Macros and pgfmath within put in picture environment

I am trying to put some TikZ pictures into a Beamer slide to enhance readability. The position of the TikZ pictures on the slide will depend on how much text comes before. Since there will be many ...
8
votes
3answers
203 views

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 following \def\MaxValueOfTok{8}% \newtoks{\SomeTokDefinedViaDef} \SomeTokDefinedViaDef={\MaxValueOfTok} ...
8
votes
4answers
3k views

PGF Math Function to compute cube root

When I found that a simple x^(1.0/3.0) does not yield a graph in PGFplots for negative values of x, I attempted to define my own function for CubeRoot using pgfmathdeclarefunction as below. But, am ...
8
votes
2answers
215 views

Confusion regarding strings and numbers in tikz

I'm using a macro that uses \StrBetween from xstring It seems to be working great. However, when I try to use a value that it returns as a coordinate in a tikz picture, I get a confusing error. ...
8
votes
1answer
993 views

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 ...
8
votes
1answer
2k views

Using ifthenelse in pgfmath

Following questions on constructing functions on the forum, I tried to build some myself. I can't seem to get the ifthenelse function in TikZ/PGF to work. Here is an example: ...
8
votes
1answer
866 views

Persistent random steps decorations during beamer \uncover

I'm using a random steps decoration with a path that appears through several uncover transitions. Currently the decoration is redrawn in each instance of the slide. How can I change this behavior. ...
8
votes
1answer
454 views

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} ...
8
votes
1answer
549 views

How to prevent small values from being plotted with nodes near coords?

I'm trying to finalize my first pgfplots chart. I've managed to get is almost the way I would like it to be with thanks to all examples I found here. The last thing I can't seem to figure out is how ...
8
votes
1answer
95 views

“Argument of \pgfmath@@onquick has an extra }” when using pgfmathsetmacro or pgfmathtruncatemacro with &&-operator inside tabular

When I run the following code... \documentclass{article} \usepackage{tikz} \begin{document} \begin{tabular}{c} \pgfmathsetmacro\foo{(2<3) && (3<4)} \foo \end{tabular} \end{document} ...
8
votes
1answer
147 views

Arcs not being properly drawn for some special coordinates

While attempting to draw some geometry diagrams in TikZ, I was having problems drawing an arc to mark off an angle. The arc kept falling too short and would not intersect both rays of the angle. (It ...
7
votes
3answers
641 views

\uline within a pgfmath expression produces an error

Why does using \uline within a pgfmath expression result in an error? \documentclass{article} \usepackage[normalem]{ulem} \usepackage{tikz} \begin{document} \pgfmathparse{width("\uline{blabla}")} ...
7
votes
3answers
170 views

Adjusting command behavior based on argument type

I have a following command in my latex document: \newcommand{\ApplyGradient}[1]{ \pgfmathsetmacro{\PercentColor}{100.0*(#1+0.2)/1.3} \textcolor{black!\PercentColor}{#1}} ...
7
votes
2answers
232 views

How to keep hue from going beyond 300° in xcolor/pgf? (Doing math in pgfplotstable)

Ok, this is probably an incredibly trivial question for anyone who knows more about xcolor or pgf or TikZ or whatever really. I tried to use a hue scale for a heat map/color matrix with values ...
7
votes
3answers
81 views

Is there a simple way of improving the precision of pgfmath for trig functions?

I wanted to build a table of trig values using pgfmath. However, the precision is a bit off. Is there a way to improve this within TikZ? This is related to a similar question I just posted: Is ...
7
votes
1answer
248 views

Gaussian random numbers

The Tikz manual has all sorts of different options regarding math, but the following is the first version which actually worked. Is there a better way to do this? \documentclass{article} ...
7
votes
1answer
246 views

Using pgfmath declared function in pgfplots/tikz commands

The commented rows of the following code give me errors. It seems that functions declared with \pgfmathdeclarefunction do not work with tikz commands... \documentclass{standalone} ...
7
votes
2answers
354 views

Increasing precision in \pgfmathsetmacro

I would like to use \pgfmathprintnumber[/pgf/number format/frac]{\var} where \var is a variable set by \pgfmathsetmacro and I'm having similar difficulties as in this and this question. I'm aware ...
7
votes
1answer
186 views

pgfmathprintnumber in bold and/or sans serif

I've set some pgfkeys such as precision=2 and use comma. Now I wonder how do I get the results of \pgfmathprintnumber{123.567} to be bold and/or sans serif? I thought this is easy, but everything ...
7
votes
1answer
141 views

Why can't I use max() here?

When I make presentations (with beamer), I like to have a bar along the bottom showing progress through the presentation visually. The interesting bit of the code below is the division on the ...
6
votes
3answers
2k views

Print integer without fraction part

In a Tikz Figure, I'm doing some computation and want to print results as label of nodes. The problem is that I only need the integer part of the number to print. I tried with round() function. It ...
6
votes
2answers
294 views

Plot x=3 in PGFPlots

I just started to use pgfplots and I'm trying to plot the line x=3 (a line parallel to the y axis where x is 3). I've tried to find an answer on the net, but all the examples always show how to ploy ...
6
votes
1answer
567 views

Computing value using pgfmath for use in coordinates?

Why can't I use the outcome of using pgfmath in a TikZ coordinate? Here is a (minimal) example that does not work: \documentclass[11pt]{article} \usepackage{tikz} \begin{document} ...
6
votes
1answer
155 views

evaluate a string like `sin(x)+3` with `x` given

I defined a macro that gets as input a string like sin(x)+3, a starting x and an ending x, which is plotted using \addplot from PGFplots. Now I want to evaluate this function for x equal to the ...
6
votes
1answer
284 views

Programming with pgf arrays : how to create an array?

I am trying to do some automatic drawing in tikz. The point is I want to be able to provide the minimal quantity of information to my macro, and still have it work. More precisely (but without ...