2022 Developer Survey is open! Take survey.

Questions tagged [pgfmathparse]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
33 views

Using addplot and pgfmathresult for color

I could use some help. I am trying to color a bar chart assigning different colors using a foreach loop and pgfmathresult to get a color gradient. Here is a minimal example: \documentclass{minimal} \...
user avatar
  • 145
4 votes
1 answer
87 views

problem when using radians with tikz

My initial problem occurred with this code: \def\a{pi/2} \pgfmathparse{\a r}\pgfmathresult output : 89.99937 When I modified the macro \a thus \def\a{pi} I get the error: Package PGF Math Error: ...
user avatar
0 votes
1 answer
48 views

Summing up float values inside a tabularx

Note: this question is very similar to this one, but differs since I am using float values instead of int. I am auto-generating a LaTeX table with a python script which contains times in decimal hour ...
user avatar
4 votes
1 answer
73 views

Using pgfmath in draw options

I would like to set draw options in tikz depending on some pgfmath calculations. More specifically, I would like to draw or not draw an edge depending on some value in an array. This works fine if ...
user avatar
1 vote
1 answer
97 views

Nested use of `\pgfmathparse` for graph drawing

I am using the trees tikzlibrary combined with some pgfmath commands to draw the ternary tree below: To each vertex u_i, a certain v_i is associated. So far, all of these v_i's are labelled with v_1, ...
user avatar
3 votes
1 answer
54 views

Nested pgfmath functions give wrong value

I am trying to have a "base" common implementation of two pgfmath functions defined via \pgfmathdeclarefunction which vary only by one number. I have successfully done so and when I print ...
user avatar
  • 133
3 votes
2 answers
66 views

Why does \pgfmathresult seem to give two different answers?

I am trying to use \foreach loops to make some alternating chains of circles that are connected by lines. I have used \pgfmathparse to make the small blue circle oscillate on each side of the big ...
user avatar
2 votes
1 answer
105 views

Graph of Thomae function by an amateur

I am trying to plot the Thomae function, which is defined in the following way: Now, I went through this answer, but unfortunately, could not grasp much. My idea is simple. Run two nested loops for ...
user avatar
2 votes
1 answer
57 views

Trying to do simple calculation in TikZ, results in "Dimension too large." error

I am working on a pgfplot where I want to calculate some coordinate. For some reason I always get a "Dimension too large." error, but I can't figure out why since I don't understand how a ...
user avatar
  • 23
2 votes
2 answers
63 views

pgfmath: comparison of a large number of number combinations

I have a function Zstart(n, l) that outputs a start number for certain combinations (n, l) (from which on the corresponding orbitals are filled). Everything works, but question out of interest: Can ...
user avatar
  • 6,217
1 vote
2 answers
43 views

writeout collapses with pgfmathprintnumber

% Density Show Test \pgfmathdeclarefunction{DensityShowTest}{2}{% \pgfmathparse{dim("#1")==3}% \ifnum\pgfmathresult=1% \pgfmathparse{1000*#2}% \pgfmathparse{"\pgfmathprintnumber[...
user avatar
  • 6,217
2 votes
1 answer
70 views

pgfmath: optional argument for a pgfmathdeclarefunction

Is it possible to create an optional argument for a \pgfmathdeclarefunction? Something like \pgfmathdeclarefunction{Plus}{2}[1.567]{\pgfmathparse{#1+#2}}, where #1 becomes 1.567 at Plus(2), but #1 ...
user avatar
  • 6,217
4 votes
4 answers
185 views

pgfmath: rounded number without pgfmathprintnumber

If I have a decimal number, say 0.09155, but I want to display a rounded version with two digits after the point: 0.09. The standard way is to use \pgfmathprintnumber[fixed, precision=2]{0.09155}. So ...
user avatar
  • 6,217
1 vote
1 answer
80 views

TikZ / pgfmath: pgfmathprintnumber if not a number

I need a function 1) x=-1 ---> ERROR 2) x < 0.01 --> 1000*x 3) x --> x else The problem: The result should appear into \pgfmathprintnumber and that collapses in case 1), because the ...
user avatar
  • 6,217
2 votes
1 answer
97 views

pgf: "Dimension too large" in a function which fits into a graph, /pgf/fpu=true does not help

I want to plot a lognormal function: \documentclass{article} \usepackage{pgfplots} \begin{document} \pgfmathdeclarefunction{lognormal}{2}{% % \pgfkeys{/pgf/fpu=true} \pgfmathparse{1/(x*#2*sqrt(...
user avatar
  • 229
4 votes
1 answer
80 views

How to detect if expansion takes place while evaluating a \pgfmathparse-expression/if inside a \pgfmathparse-expression?

I intend to write a macro which behaves differently depending on whether used within a \pgfmathparse-expression or used outside a \pgfmathparse-expression. For example a commend \MyNicePi which ...
user avatar
0 votes
3 answers
96 views

pgfmath gives me a wrong computation

I am trying to do some plots with spherical coordinates and have a problem when computing some numbers in PGFPLOTS. I add a MWE here: \documentclass[12pt]{standalone} \usepackage[pdftex]{graphicx} \...
user avatar
4 votes
1 answer
76 views

TikZ: How to create a list with calculated entries for a style

I have a TikZ-matrix. And I want to highlight the rows 1, 3, 6, 10, 15, 21, 28,... =n*(n+1)/2 For small examples, I could do it this way: highlight/.style={ row #1/.style={....} }, highlight/.list=...
user avatar
  • 6,217
0 votes
1 answer
42 views

pgfmathmin and pgfmathsetmacro and array

I am trying to calculate the minimum and maximum of an array. The only problem unsolved is to save the value in a macro/variable. \documentclass[utf8,fleqn]{scrartcl} \usepackage[ngerman]{babel} \...
user avatar
  • 111
0 votes
1 answer
312 views

Format \pgfmathresult with \pgfmathprintnumber and using it in \TextField

I want to use \pgfmathprintnumber to format the \pgfmathresult but without printing it because I want to then use it in a \TextField as value that does not accept \pgfmathprintnumber for some ...
user avatar
5 votes
2 answers
700 views

TikZ: Get (dimensionless) distance between node anchors

In the following picture I want node C to be as wide as the distance between (A.north east) and (B.south west) as indicated in the picture; I tried defining a new node D with \n1 as minimum width, and ...
user avatar
  • 1,359
3 votes
1 answer
79 views

Reserved names in "declare function"?

This must be my week for stepping on reserved words... please look at this MWE: \documentclass{article} \usepackage{tikz} \newcommand{\formula}[1]{% \pgfmathsetmacro{\rpval}{#1}% \...
user avatar
  • 29k
4 votes
2 answers
111 views

Change font size in a section as a function of the current font size

This answer shows how to get the current font size, using \makeatletter\f@size\makeatother. This answer shows how to parse and evaluate a mathematical expression before printing it, using for example ...
user avatar
  • 143
2 votes
1 answer
180 views

Pgfplots and pgfmathparse, lack of precision

I am using pgfplots to draw a graph and I would like to modify the abscissa values of the data when they are plotted. I am currently using x filter/.code={\pgfmathparse{1/#1} \pgfmathresult} to take ...
user avatar
  • 23
2 votes
1 answer
114 views

Counter does not work properly in \pgfmathparse

I have this code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{graphicx} \usepackage{pgfplots} \usepackage{tikz} \pgfplotsset{compat=1.15} \usetikzlibrary{patterns} \newcounter{...
user avatar
  • 181
3 votes
1 answer
94 views

circuitikz: setting color using \pgfmathparse

\documentclass[a4paper]{article} \usepackage{tikz} \usepackage{circuitikz} \usetikzlibrary{shapes.geometric,arrows,shapes,decorations.markings} \begin{document} \begin{circuitikz} [american ...
user avatar
  • 31
1 vote
1 answer
99 views

Defining math functions

\documentclass[aspectratio=1610]{beamer} \usepackage{amsmath} \begin{document} \def\function(#1){ 96* (#1)-16 *(#1)^2 } %1. I am trying to condense the following two lines \pgfmathparse{3+\...
user avatar
  • 421
1 vote
1 answer
610 views

Stacked bar chart, nodes near coords remove small values and show sum

I know it is possible to have only the sum shown on top of the bar chart and remove the other values in the stacked bar chart (as shown in picture attached), but I can't figure out what went wrong in ...
user avatar
1 vote
2 answers
484 views

pgfmath: Function for strings and numbers?

Is there a pgfmath-function for something like ? \documentclass[]{article} \usepackage{tikz} \usepackage{array} \begin{document} \def\myarray{{1,0,"-1","a"}} \foreach \i in {0,...,3}{\pgfmathparse{\...
user avatar
  • 6,217
3 votes
1 answer
162 views

\pgfmathsetmacro creates "Dimensions too large" for t distribution

I am trying to plot 't' distribution with area of interest shaded. I have done both plotting and sharing area. Next tried to draw vertical lines closing the shaded area on both sides. For this, I need ...
user avatar
2 votes
1 answer
72 views

Problem with `\pgfmathresult pt = 1 pt` when forming xticklabel (very large values)

I'm having difficulties with the comparison \pgfmathresult pt = 1 pt . A complete example, with a situation in which it works, and a second one that doesn't (both in the x-axis): \documentclass{...
user avatar
3 votes
1 answer
258 views

TikZ PGF - Minus sign being interpreted as a unit of measure

I'm trying to write a macro that draws a number line given a number of tick marks to use. However, there are a couple of spots in the code where I try to do arithmetic using the argument of the ...
user avatar
  • 45
5 votes
2 answers
435 views

Coordinate calculation with TikZ

I need to draw some plots with vertical lines from the x axis to the function. For example, I defined the gauss(x) function for the normal distribution and I drew this plot, with a vertical line from (...
user avatar
0 votes
1 answer
1k views

! TeX capacity exceeded, sorry [main memory size=5000000]. for foreach

I was blocked on this point, I'm going to compile a code in which I'm using the command foreach: \pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 ...
user avatar
  • 387
1 vote
2 answers
339 views

Error trying to parse with \pgfmathparse

I'm trying to evaluate the following expression with \pgfmathparse, but I get error messages: \pgfmathparse{\sqrt{{5.8186/{\pi}}}}\pgfmathresult\ Any idea why?
user avatar
  • 426
2 votes
0 answers
185 views

Calling pgf rand inside pgfmathsetmacro creates extra text

I am using pgf and tikz for some latex questions. The code below illustrates a problem I am facing: when I use the rand function from pgf inside a pgfmathsetmacro I get some extra text at the ...
user avatar
  • 315
6 votes
2 answers
2k views

How to Draw Horizontal Line in tikzpicture

I am trying to draw a dotted line from a defined function value to the x-axis in order to "close off" a shaded area below the curve. Because I defined a function in order to be plotted, I don't know ...
user avatar
  • 182
2 votes
1 answer
250 views

Computing color for a mesh using the parametric coordinates

Question: Is there a way to use the parametric parameters (instead of the absolute x and y) inside the mathparse used to calculate the color of a surf? Motivation: The function I have to plot has a ...
user avatar
  • 1,005
5 votes
3 answers
2k views

pgfmathparse in foreach, use result as node coordinates

I'm trying to use a counter inside a TikZ picture, and use values resulting on calculations with this counter. Let's say for instance, I want i to be ranging from 0 to 9, j to be i*5 and k to be i*10. ...
user avatar
  • 336
2 votes
1 answer
309 views

Drawing a graph with pgfmathparse+matrix

I want to draw a graph. I use tikz matrix to draw the vertices, and then would like to add edges from an array. I tried the following code: \documentclass{article} \usepackage{tikz,pgfmath} \...
user avatar
  • 177
8 votes
3 answers
359 views

pgfmathparse does not correctly parse zero left-padded integers?

I am currently trying to realize a slightly complicated graphic, wherein I have a bunch files all named with the value of a certain parameter, represented by its left-padded value. Namely, I have: ...
user avatar
  • 232
5 votes
2 answers
505 views

For each loop showing decimal point when I don't want it to

My Code is: \documentclass[tikz,border=10pt]{standalone} \begin{document} \begin{tikzpicture}[timeSlot/.style={draw, rectangle, minimum size =1cm}] \foreach [count=\x] [evaluate=\x as \xx ...
user avatar
13 votes
2 answers
14k views

pgfmathparse basic usage

Please, what I'm doing wrong in this test: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \pgfmathparse{10*2} \node at (4,-5) {$2 \cdot 10 = \pgfmathresult$}; \end{...
user avatar
2 votes
1 answer
249 views

How to calculate many coordinates inside pgfplots axis in a clever way?

What I want is which could be drawn by the following code. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.13} \begin{document} \begin{tikzpicture} \begin{axis}[xmin=...
user avatar
  • 309
1 vote
1 answer
274 views

Why is this small example not working any more when using pgfmathparse?

The following small example worked until \pgfmathparse{\myvalue+1}\pgfmathresult was added instead of just 1. I am not getting any error message, the compiling process just doesn't end. This is the ...
user avatar
  • 309
2 votes
1 answer
205 views

Math with TikZ Strange Behaviour

I am working on a Tikz figure, which uses the sin and cos functions. Currently I use a Python script to compute the six function parameters, which are given to the Tikz "g" function, as shown below: \...
user avatar
1 vote
0 answers
150 views

pgfplots: Problem with ticks in logarithmic scale - math parse error [closed]

Why do I get the error ! Package PGF Math Error: Could not parse input '0.005,0.0005' as a floating po int number, sorry. The unreadable part was near ',0.0005'.. when pdflatexing the following ...
user avatar
3 votes
1 answer
437 views

Parsing input for table automatically generated from csv file

I have a .csv file which looks like: {one},{two},{three} 11/07/2014,14:49:54,(100,100) 2,2,2 I have some code which creates a table from the .csv file. \documentclass{article} \usepackage{...
user avatar
  • 153
4 votes
1 answer
491 views

avoid logarithm of zero in pgfmathparse conditional assignment

How can i avoid the error message ! Package PGF Math Error: I cannot calculate the logarithm of '0' (in ' 0>1 ? ln(0) : 0'). in the following code? If possible, i want to evaluate the statement ...
user avatar
  • 2,065
11 votes
2 answers
4k views

\ifthenelse with inequalities and expressions, using \pgfmathparse

I'm trying to write a function that draws a matrix with a some ones (in black) and zeros (white) in it with a certain pattern to the distribution of ones and zeros. I want to draw ones, only if they ...
user avatar
  • 1,427