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.
536
questions
1
vote
0
answers
34
views
Is \sp a reserved word in TikZ math library?
I was running a \tikzmath function as shown below:
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary {math}
\usetikzlibrary{calc} % required for coordinate calculations
\begin{...
1
vote
0
answers
17
views
Is it possible to access the cached value of \pgfarrowlength rather than recalculating it for purposes other than reusing an arrow tip in PGF/TikZ?
Is it possible to access the cached value of \pgfarrowlength rather than recalculating it for purposes other than reusing an arrow tip in PGF/TikZ?
I am trying to calculate the width (i.e. length) of ...
1
vote
0
answers
37
views
Progress bars stuck in pgfgantt
I'm experiencing some unexpected behaviour with progress bars in a little-endian format ganttchart environment. For example, with the MWE below:
\documentclass[crop]{standalone}
\usepackage{tikz}
\...
9
votes
1
answer
177
views
Calculating things with TikZ/pgf versus calculating things with l3fp
pgfmanual.pdf, VII Utilities, Repeating Things: The Foreach Statement, says:
\foreach \x in {0,0.1,...,0.5} {\x, } yields 0, 0.1, 0.20001, 0.30002, 0.40002,
and warns about rounding-errors causing ...
0
votes
1
answer
32
views
Executing a for loop inside PGF axis when #1 is in use
\foreach does not work inside PGF, so the alternative seems to be \pgfplotsinvokeforeach. My issue is that I want to define my own macros that will be inserted into the axis environment, something ...
3
votes
2
answers
270
views
tikz foreach floor function
It seems that in a tikz-foreach-loop mathematical expressions are not evaluated correctly:
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \c [count=\i] in {0,...
3
votes
1
answer
55
views
pgfmath rounding error?
I am doing a specific pgfmath calculation involving logs and trig functions.
Pgfmath evaluates: log10(-cot(97.1)) = -0.90466. My calculator gives the "true" answer of −0.904633, which is ...
0
votes
0
answers
25
views
Calculations involving pgfkeys?
I've begun using pgfkeys to set a bunch of custom variables. I'm also using pgfmath to do some calculations. I understand how to set and call the variables, but the manual is mind boggling to me, ...
1
vote
1
answer
27
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 ...
1
vote
0
answers
30
views
Automatic calculation of error bars based on data in a bar chart
I would like to draw a bar chart using PGFPlots with error bars that are automatically calculated from the data.
Here is a slightly simplified version of what I am attempting:
Suppose you have two ...
0
votes
1
answer
57
views
How to color a coordinate under a function condition
I would like to change the color of some points in a plot if its Euclidean distance to a cluster centroid coordinate is smaller or greater than to the other cluster centroid.
I have made different ...
3
votes
1
answer
52
views
pgfmathdeclarelist undefined control sequence error with item 33
I regularely use lists defined with pgfmath and encountered an error if one of the list items is "33" but not " 33" or "32".... Please find below a minimal example to ...
3
votes
1
answer
54
views
Asinh scale in pgfplots with small parameters
I have recently asked a question about introducing an asinh scale in pgfplots. While the solution given in there does implement an asinh scale, when I tried to implement it in my particular case I've ...
0
votes
1
answer
50
views
How to multply an scalar with a defined variable (\def) in Tikz
I currently have the following working code:
\begin{tikzpicture}
\def\myr{7}
\def\mytheta{45}
\def\myphi{50}
\def\px{{\myr*sin(\mytheta)*cos(\myphi)}}
\def\py{{\...
2
votes
1
answer
64
views
tikz externalize works on some figures but not on others
Trying to speed up the compilation of a book I'm writing, I learned about the "externalize" feature of tikz. However, there are some figures it bombs out on with the error
! Package tikz ...
1
vote
2
answers
41
views
polyglossia breaks pgf math (cont.)
I found that polyglossia with setlanguage to german breaks pgfmath. I read several hints on this and ended up with the following code:
\documentclass{article}
\usepackage{polyglossia}
\...
0
votes
2
answers
43
views
Naming a pgfmath macro depending on an element of a comma separated list
I want to create a new command, that has more than 9 arguments. Therefore, i am using \NewDocumentComannd and comma separated lists. With this new command i use \pgfmathsetmacro, too. A simplified (...
4
votes
1
answer
113
views
Dynamically generate values in matrix and calculate using them
I am using the following code to generate a matrix filled with random values. I would like to use this matrix to explain how a convolution is applied to an image (specifically the mean), so that's ...
2
votes
3
answers
68
views
\clist_item and \pgfmathsetmacro causing an error
My main aim was to be able to use more than 9 arguments when defining a new command. Therefore i am using the following code:
\documentclass[12pt]{article}
\usepackage{pgfmath}
\usepackage{xparse}
\...
1
vote
1
answer
105
views
How to draw geometric Brownian motions in tikz/pgf
I am trying to replicate this excellent answer which explains how to draw Brownian motions in TiKZ:
\newcommand{\Lathrop}[6]{% points, advance, rand factor, options, end label, truncate from point
...
4
votes
1
answer
52
views
At the end of the table, I would like the number of times that "yes" appears
My question is about using counters.
I would like the number of "yes" to appear at the bottom of the table. I don't know how to use counters.
\begin{tikzpicture}[scale=0.65]
\scriptsize
\...
1
vote
1
answer
82
views
Plotting saw-tooth functions with varying heights
I am preparing a note on example of an everywhere continuous nowhere differentiable function. The construction involves a saw-tooth function, viz., h in the following way:
I want to plot the ...
5
votes
1
answer
247
views
Access cryptographic secure random generator
I am writing my Master's Thesis in cryptography at the moment. The main part deals with randomness; therefore, I wanted to make a little Tikz picture in the introduction to show an example of ...
0
votes
1
answer
61
views
Pgfmath's height() fails with: Package PGF Math Error: Unknown function `H' (in 'height("H")')
The following code works as expected
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfmath}
\usetikzlibrary{
calc,
}
\begin{document}
\begin{tikzpicture}
\pgfmathsetlengthmacro{\...
0
votes
0
answers
34
views
\foreach \i in {1,...,\pgfmathresult} not working
After calculating \pgfmathresult and turning the output as an integer:
\pgfmathprintnumber{\pgfmathresult}
Which for example is 10, I want to iterate instead of
\foreach \i in {1,...,10}{%
some ...
0
votes
1
answer
77
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, ...
0
votes
0
answers
68
views
Graph of an advanced function (hard level)
I have to do on overleaf the graph of this function:
fo is =1. "w" is the variable and it's=angle/T so we don't need to know T. The final graph is:
N.B. When w=0 G(w) it's = Tfo because we ...
4
votes
1
answer
248
views
Strange syntax in pgfplot
I want to display propagation of a signal, obtained as addition of 2.
It works as I want writing:
\documentclass{standalone}
\usepackage[usenames,svgnames]{xcolor}
\usepackage{siunitx}
\usepackage{...
1
vote
2
answers
99
views
Unable to reuse variable using \pgfmathsetmacro
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand\routine[1] {
\pgfmathsetmacro\temp{0}
\foreach[parse=true][remember=\temp] \i in {1,...,#1} {
\pgfmathsetmacro\...
3
votes
1
answer
174
views
Are TIKZ and PGF the same thing or not?
When learning how to use tikz I've seen many guides and example using commands that begin with pgfmath and they used the two package names interchangeably so I assumed they refer to the same thing. ...
0
votes
2
answers
77
views
Defined an array but it is treated like an ordinary string
I defined an array that contains 4 integers. I accessed the 3rd element, modified the last element then accessed it. However instead of doing array operations latex simply replaces every instance of \...
1
vote
1
answer
45
views
Trouble with gaussian
Taking this example, I build my gaussian bell
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}...
11
votes
4
answers
989
views
How to calculate numbers bigger than 16383 in tikz? [duplicate]
I was trying to output the positive integer powers of 2 starting from 2^10=1024. I was met with a Dimension too large error. When I force compiled, every number from 2^14=16384 was output as 16383. My ...
1
vote
3
answers
80
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 ...
5
votes
2
answers
340
views
How to remove tikz node?
This codes places the english alphabet from a to y in a 5 by 5 square and then removes s in (3,3) from view by imposing a white square on it. Is there a way to properly delete a node instead of ...
3
votes
3
answers
255
views
Unable to shorten foreach statement
The following code is a simple double foreach statement that generates a staircase of coordinates.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{...
2
votes
1
answer
124
views
What is the right way to calculate square root in coordinates?
I am trying to create a file demonstrating the pythagorean theorem.
In this example the hypotenuse has length 4 while the base length 3. So the height should be square root of 7.
\documentclass{...
0
votes
1
answer
62
views
Trigonometry in coordinates not working
I am trying to precalculate cos and sin values and use them in coordinates.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\n{13}
\def\c{\pgfmathparse{cos(5*pi/\n)}...
1
vote
1
answer
44
views
Overriding nimsticks package not working as desired
nimsticks is a package that makes drawing nim games easier. For example \nimgame{5,3,4} generates three piles of 5,3,4 sticks respectively.
\documentclass{article}
\usepackage[utf8]{inputenc}
\...
1
vote
1
answer
40
views
Tikz - operation between integers results in decimal
The first example prints integers 0 to 3 as expected but the second changes all output to decimal despite the calculation only involving integers. How can I avoid this behavior?
Code:
\documentclass{...
0
votes
1
answer
34
views
splitting code on to separate pages in a worksheet
I am trying to split the following code onto 3 separate pages, as in page one being the question, page two the working and the third being the answers. but I can only seem to get it with all three on ...
3
votes
1
answer
80
views
How to improve rand from pgfmath in tkz-euclide?
I make this minimal file:
\documentclass{standalone}
\usepackage{tkz-base,tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-8,xmax=8,ymin=-7,ymax=7]
\tkzGrid
\tkzAxeXY
\pgfmathsetmacro{\...
0
votes
0
answers
42
views
How can solve this trouble, only need turn the arrow vertically
\documentclass[10pt,headinclude]{scrbook}
\usepackage[T1]{fontenc}%The package allows the user to select font encodings, and for each encoding provides an interface to ‘font-encoding-specific’ ...
0
votes
1
answer
81
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), ...
2
votes
2
answers
124
views
adding another node to a number line
I am using a numberline code from @Alain Matthes it works perfectly but I don't understand it enough to add another node, eg start, middle, end instead of just start end. Can anybody point me to the ...
1
vote
1
answer
209
views
Plotting Heaviside function shows staircase plot
I'm trying to plot a Heaviside function over [-1,1]x[-1,1] using pgfplots. The function has a value of 1 when x+y > 1/2 and 0 otherwise (so the line is not aligned with x nor y axes). The problem ...
2
votes
1
answer
138
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@.
...
1
vote
1
answer
106
views
separate random questions and answer onto different pages
I can create simple random addition questions, but when I try to separate the question and the answers onto 2 separate pages, I assume because its a random generator the answer sheet is not the same ...
0
votes
1
answer
171
views
A printing quarry
I know this is not a type setting issue, but if anybody could help with directing me to a site that could help or advise me what type of language I need to learn in order for me to do what I want...I ...
6
votes
1
answer
176
views
Use \pgfmathresult in siunitx
I try to do some calculation and then want to use the result in a siunitx qty.
However, this fails and I don't know why.
\documentclass{article}
\usepackage{pgfplots, siunitx}
\newcommand{\scale}[1]{\...