2022 Developer Survey is open! Take survey.

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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
101 views

How to use dynamic numerical variables in tikzpicture?

I am currently creating technical documentation that depicts through a tikzpicture the data flow across something called the I2C bus (example-like graphic). I initially started doing this by hand with ...
user avatar
-1 votes
1 answer
36 views

Pgfmath code conflict

I am using the following code, and it works except for the custom macro \QuadraticEquations. However, it works in a stand alone file. Am I missing something obvious? \documentclass{article} \...
user avatar
  • 11
0 votes
1 answer
41 views

Make quadratic equation with pgfmath

I have used this code to produce quadratic equations, is there a way to make the solutions real and solvable for lower levels? \documentclass{article} \usepackage{mathtools} \usepackage{enumitem} \...
user avatar
  • 11
1 vote
0 answers
31 views

Something in my preamble breaks this tikz newcommand but only when used inside a foreach?

In a standalone document which I use to tinker with Tikz pictures before compiling in my main document as a way of saving compile time, I have used the following expression \documentclass[tikz,border=...
user avatar
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
51 views

Error using tikzmark with multiple tikzcd's

I wish to create a figure like the one shown below. I am getting the error above with the following code. Can someone tell me where I may be going wrong? \begin{tikzcd}[arrows={-latex, outer sep=-1....
user avatar
0 votes
0 answers
20 views

Error in IEEE Access template (xdef) [duplicate]

I download the IEEE Access template from their webpage. The only thing I did was adding \usepackage{tikz} to access.tex. Changed nothing else. Compiling with pdflatex produces the following error: $ ...
user avatar
  • 377
1 vote
0 answers
93 views

How to make a number spirale front cover to a book?

UPDATE: I'm currently rewriting a new edition with my math teacher's self-published maths textbook. I have looked online for similar problems with number spirals cover but couldn't find anything ...
user avatar
2 votes
1 answer
62 views

Use a variable in foreach

I am trying to use a variable in my foreach loop. It would make things a lot easier, because i only need to change one value and multiple loops are affected. Something like this: \begin{tikzpicture}[y=...
user avatar
2 votes
1 answer
54 views

Why does \ifthenelse not work?

Im currently dealing with a problem in my code. I keep getting the error use of \nextx does not match its definition From the \pgfmathsetmacro\nextAsInt... line. But i cant see the problem. It should ...
user avatar
0 votes
0 answers
36 views

How to make a spiral in coordinate system using Tikz [duplicate]

How do I generate a figure similar to this, but the value of 600° must be 1201°, and the spiral must take 3 revolutions (1201°/360°=3 revolutions).
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
1 vote
0 answers
34 views

Can we use random variables in \polylongdiv

I would like to randomly generate polynomials before using \polylongdiv for long division. I tried the code below to make one of the coefficients of the divisor random but the compilation takes ...
user avatar
  • 189
0 votes
0 answers
50 views

Dimension too large - Tikzmath

I have the following code: \documentclass[tikz,border=5mm]{standalone} \usepackage{tikz} \usepackage{amsmath} \usepackage{xfp} \usetikzlibrary{math} \usepackage{etoolbox} \usepackage{fp} \...
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
0 votes
0 answers
54 views

tikz/pgfmath: Draw a signal-flow diagram from a transfer function

Following up this great answer, the following code needs to be fixed to make the transfer function with coefficients \edef\NumCoeffMat{{4, 32, 62}} % numerator \edef\DenCoeffMat{{1, 12, 66, 60}} % ...
user avatar
  • 8,759
0 votes
0 answers
65 views

Dealing with arrays in Tikzmath

I have the following working code to build the Lagrange Polynom of a given set of points: \documentclass[tikz,border=5mm]{standalone} \usepackage{tikz} \usepackage{xfp} \usepackage{amsmath} \...
user avatar
1 vote
1 answer
55 views

Tikz foreach draws lines from edge of nodes unexpectedly [duplicate]

Consider the following figure: \begin{tikzpicture}[ selected/.style={circle, draw=black, fill=yellow!60, very thick}, unselected/.style={circle, draw=black, very thick} ] \node[selected] ...
user avatar
  • 111
0 votes
0 answers
68 views

Pascal's triangle of binomial coefficient with modulo m

I tried to modify this answer to binomial coefficient with modulo 2 using \pgfmathparse{int(mod(, 2))} but it produced lots of errors. Package PGF Math Error: Unknown operator `=' or `=1' (in 'int(mod(...
user avatar
  • 169
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
2 votes
0 answers
38 views

TikZ: Why does my pgfmath macro cause errors when used within a node's label text?

I am trying to draw a graph with labels along the edges. To do this, I'm using two foreach loops like in the following code: \documentclass{article} \usepackage{tikz} \begin{document} \begin{...
user avatar
1 vote
1 answer
99 views

Having problems with drawing a modulus graph in LaTeX (overleaf)

Im asked to draw/plot the graph for the modulus function f(m) = m^7 modulo 137. I tried to do that in LaTeX with the package „pgfplots“ following the instructions from the official overleaf tutorial: ...
user avatar
  • 11
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
0 votes
0 answers
50 views

Variable argument number in pgfmath

I am trying to understand how to define a PGF function with a variable number of arguments. Here is a minimal working example of what I am trying to do: \documentclass{minimal} \usepackage{pgfmath} ...
user avatar
  • 133
1 vote
0 answers
72 views

Pgfmath numerical quaternion multiplication for 3D rotation

I need to rotate coordinates in a 3D space by a certain known angle around a given axis, in order to draw solids in tikz. One way to do this is to calculate the product p q p-1, where p is a ...
user avatar
  • 215
0 votes
0 answers
22 views

How to randomly and differently select questions from their bank each compilation? [duplicate]

Following this answer, the following document, many times, doesn't change the output each time I compile it. The output may change after three or four times I recompile the document. So, how to change ...
user avatar
  • 8,759
2 votes
1 answer
35 views

Rounding up to decimal pgfmath

I need to define a Roundup function that is "defined as the smallest number, specified to one decimal place, that is equal to or higher than its input." For example, Round up (4.02) is 4.1; ...
user avatar
  • 1,955
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
0 votes
1 answer
66 views

Evaluate user defined math function

I want to "plot" a simple line function, like f(x) = 3x+5. Actually, this is perfectly working: \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \...
user avatar
10 votes
0 answers
243 views

pgfplots: x vs \x

This question is a follow-up to this question ("pgfplots: Strange Bump in \tanh Function"). Stefan Pinnow, who knows a thing or two about pgfplots, provided an answer that distinguished ...
user avatar
23 votes
2 answers
926 views

pgfplots: Strange Bump in `\tanh` Function

Follow up question see pgfplots: x vs \x. I have a rather straightforward pgfplots diagram but I do not understand why there is a bump in my tanh function (should be smooth). The domain (and samples) ...
user avatar
1 vote
1 answer
59 views

Wrong computation with PGF math

all. I'm trying to draw an incircle to a regular pentagon. Here's my code: \documentclass[tikz,border=1.5mm]{standalone} \usetikzlibrary{calc, math} \begin{document} \begin{tikzpicture}[rotate=90] \...
user avatar
  • 1,359
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
1 vote
1 answer
443 views

Using math functions in a tikzmath coordinate

I am trying to execute the following code where I compute the coordinates using the TikZ math library and then I draw them in TikZ. Why does it output error ! Package pgf Error: No shape named '2*cos(...
user avatar
2 votes
2 answers
62 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
0 votes
0 answers
75 views

Electron Configuration (Madelung Scheme)

I have created an electron configuration (Madelung scheme, Aufbau principle, Hund's rule) with pgfmath. Does anyone have any suggestions for improvement or simplification? Note: currently not ...
user avatar
  • 6,217
2 votes
1 answer
27 views

TikZ / pgfmath: dim is now issuing something else

At my TikZ (TeXLive 2020) \documentclass[tikz]{standalone} \begin{document} \pgfmathprint{dim("gas")}, \pgfmathprint{dim("abcd")}, \pgfmathprint{dim("abcdefg")} \end{...
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
2 votes
2 answers
78 views

pgfmath function that puts out a question mark in some cases

I have a pgfmath-function here, that tests whether the \Phase is equal to 'gas', then the value \Density has to be multiplicated by 1000 (else not) and that's the DensityShowTest. That works so far. ...
user avatar
  • 6,217
4 votes
4 answers
184 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
6 votes
1 answer
183 views

expl3 cannot see declared functions

This question led to a new package: pgfmath-xfp I use tikzpicture with expl3 if floating-point computations exceed the TeX range. The problem is, expl3 cannot see declared functions, as illustrated ...
user avatar
  • 229
0 votes
1 answer
59 views

Scale X and Y differently

I want the following three functions to be displayed, with the constant A = [1,2,4] A*x^2*(1-x)^2 My initial MWE \documentclass[11pt, oneside,dvipsnames]{article} \usepackage{amsmath, amsthm, ...
user avatar
  • 43
3 votes
1 answer
56 views

Using pgfmath results in pgfkeys

I'm trying to create a simple variable system using pgfkeys, but I want to be able to create new "var" using other var, see this MWE where I have tried to use \pgfmathprintnumber. I thought ...
user avatar
1 vote
0 answers
49 views

Enforcing Order of Operations on Dimension Expressions?

I'm trying to make a tikz drawing using the component lengths as macros so I can easily adjust things and have changes propagate. That works, but when I try to use division to draw lines at even ...
user avatar
  • 11
1 vote
0 answers
69 views

Incomplete \iffalse; all text was ignored after line ... Fatal Error when replacing value by newcommand result using pgfmathparse

When I build the following code \documentclass{article} \newcommand{\halve}[1]{ \pgfmathparse{int(#1 / 2))} \pgfmathresult } \usepackage{tikz} \usepackage[paperwidth=100pt, paperheight=100pt, ...
user avatar
2 votes
1 answer
107 views

Which TeX graphics package is this?

I've been starting at LaTeX for a few months now and I'm learning to plot things there. I was using Tikz and GNUPlotTex to plot some things, but the end result is not what I would like it to be. I was ...
user avatar
  • 21
0 votes
1 answer
60 views

How to draw location line and width at half maximum line in tikz/pgfplots [duplicate]

I am attempting to draw a gaussian distribution using pgfplots in tikz. I would like to put a horizontal line illustrating the standard deviation, a horizontal line, in this example at x=0.5 - 1.5, y =...
user avatar
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

1
2 3 4 5
10