As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [pgfmathparse]

The tag has no usage guidance.

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

Incomplete \iffalse error with pgfmathparse in a caption

I am calculating a value with pgfmathparse, pgfmathroundto and pgfmathresult. It works all fine in normal text mode, but when I call the command in a caption, I get an "Incomplete \iffalse; all ...
asbjos's user avatar
  • 23
2 votes
2 answers
65 views

Floating points calculation problem (with pgfmathparse via length)

The subtraction of the calculated height of an input via sbox (in this case = 116.43562 pt) and 17.68 pt gives an incorrect result at the 5th floating point. Here is the full tex file \usepackage[T1]{...
Bilal Yilmaz's user avatar
0 votes
1 answer
66 views

How to read values interms of milli(m), femto(f), micro(u) into float values

I have a .csv file, which contains values interms of milli(m), femto(f) and micro(u)etc. which I want to process it as float value inside pgfmathparse \begin{filecontents*}{mycsv.csv} Device, betaeff, ...
Raja's user avatar
  • 450
0 votes
0 answers
16 views

Why does \pgfmathresult automatically add spaces when used inside a loop? [duplicate]

Compare the following two pieces of code. Both of them output consecutive positive odd numbers starting from 1. The first one defines a command that uses a for loop then calls the command. The second ...
fied75759's user avatar
1 vote
3 answers
69 views

tikz - pgfmathresult prints nothing

I am trying to use a foreach statement to print the powers of 2. I start by defining n as 2 then I print n and multiply it by 2 10 times. The code does compile without errors but the only number I see ...
suf2630's user avatar
  • 11
0 votes
1 answer
72 views

Plotting function with polygonal domain using pgfplots

I am trying to plot the product between a Heaviside function and a trigonometric function in the domain [-1,1]x[-1,1] using pgfplots. I can use Mathematica to obtain the required result (see image), ...
aaragon's user avatar
  • 3,009
2 votes
1 answer
100 views

Function within a function in \pgfmathdeclarefunction

I'm trying to plot a complex function and to that end I'm using pgfmathdeclarefunction. Still, I'm unable to get it to work, I get the error: ! Illegal parameter number in definition of \pgfmathNi@. ...
aaragon's user avatar
  • 3,009
1 vote
1 answer
99 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} \...
Florian's user avatar
  • 167
4 votes
1 answer
174 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: ...
Alain Matthes's user avatar
0 votes
1 answer
107 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 ...
lug_wrench's user avatar
4 votes
1 answer
134 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 ...
user631620's user avatar
1 vote
1 answer
132 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, ...
user631620's user avatar
3 votes
1 answer
67 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 ...
ghlecl's user avatar
  • 133
3 votes
2 answers
68 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 ...
user3264392's user avatar
2 votes
1 answer
146 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 ...
Subhajit Paul's user avatar
2 votes
1 answer
76 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 ...
rlakoda's user avatar
  • 23
2 votes
2 answers
93 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 ...
cis's user avatar
  • 7,185
1 vote
2 answers
50 views

writeout collapses with pgfmathprintnumber

% Density Show Test \pgfmathdeclarefunction{DensityShowTest}{2}{% \pgfmathparse{dim("#1")==3}% \ifnum\pgfmathresult=1% \pgfmathparse{1000*#2}% \pgfmathparse{"\pgfmathprintnumber[...
cis's user avatar
  • 7,185
2 votes
1 answer
101 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 ...
cis's user avatar
  • 7,185
4 votes
4 answers
298 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 ...
cis's user avatar
  • 7,185
1 vote
1 answer
185 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 ...
cis's user avatar
  • 7,185
2 votes
1 answer
117 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(...
scriptfoo's user avatar
  • 229
4 votes
1 answer
87 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 ...
Ulrich Diez's user avatar
  • 26.2k
0 votes
3 answers
139 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} \...
Herman Jaramillo's user avatar
4 votes
1 answer
116 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=...
cis's user avatar
  • 7,185
0 votes
1 answer
87 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} \...
user125198's user avatar
0 votes
1 answer
521 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 ...
Michael Banucu's user avatar
5 votes
2 answers
1k 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 ...
mathbekunkus's user avatar
  • 1,379
3 votes
1 answer
118 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}% \...
Rmano's user avatar
  • 36.5k
5 votes
2 answers
250 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 ...
optical's user avatar
  • 253
2 votes
1 answer
224 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 ...
Alex's user avatar
  • 23
2 votes
1 answer
140 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{...
e7lT2P's user avatar
  • 181
3 votes
1 answer
113 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 ...
vasana1's user avatar
  • 31
1 vote
1 answer
133 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+\...
user34241's user avatar
  • 421
1 vote
1 answer
856 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 ...
thesilencer's user avatar
1 vote
2 answers
652 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{\...
cis's user avatar
  • 7,185
3 votes
1 answer
209 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 ...
Parthiban Rajendran's user avatar
2 votes
1 answer
77 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{...
Pablo Stickar's user avatar
3 votes
1 answer
314 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 ...
Arrow M's user avatar
  • 45
5 votes
2 answers
599 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 (...
Taekwondavide's user avatar
0 votes
1 answer
2k 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 ...
moradov's user avatar
  • 407
1 vote
2 answers
488 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?
Anakhand's user avatar
  • 426
2 votes
0 answers
209 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 ...
iluvatar's 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 ...
Jared's user avatar
  • 182
2 votes
1 answer
297 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 ...
Carucel's user avatar
  • 1,035
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. ...
nicoco's user avatar
  • 336
2 votes
1 answer
351 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} \...
ckamath's user avatar
  • 177
8 votes
3 answers
380 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: ...
Urukann's user avatar
  • 232
6 votes
2 answers
544 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 ...
Somenath Sinha's user avatar
14 votes
2 answers
17k 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{...
pasaba por aqui's user avatar