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
3
votes
1answer
66 views

Path joining in “to path” with non-integer scale factors

I am trying to debug a problem with an issue on circuitikz that I have been able to reduce to this MWE --- sorry if it's not so short... \documentclass[border=10pt]{standalone} \usepackage{tikz} \...
3
votes
1answer
87 views

Drawing perpendicular lines between a straight path and an arbitrary one

Before I go into too much detail on this question, the end result I want is something like this picture: I can draw all of it except the distributed force arrows running from the wobbly line w. ...
2
votes
1answer
51 views

\pgfmathparse/\pgfmathsetmacro produces a strange Incomplete \iffalse;

I'm trying to calculate things inside the \newcommand \documentclass[tikz]{standalone} \usepackage{tikz} \def\spradius{1} \newcommand*{\projectToSphere}[2]{% % calculate a reverse ...
0
votes
0answers
21 views

Tikzpicture Foreach loop curves not showing up and error in color change [duplicate]

In some stackexchange questions, some people posted code in making the code plot the curves iteratively. However, when I try mine, the orange curves do not show up. Here is the code: \begin{figure}[H]...
0
votes
1answer
31 views

pgfplots: How to overwrite macros in a loop for calculating domain-values

I want to draw several arcs (from percentages) in a loop. The following arc should connect to the previous one: 50% (Start=0, End=180°), then 25% (Start=180°, End=180°+90°),.... How do I do it ...
1
vote
1answer
25 views

How can I read the input to the pgfmathsetmacro command

I want to read the number from the external file into the \pgfmathsetmacro command, but it does not seem to work that way \documentclass[tikz]{standalone} \usepackage{tikz} \usetikzlibrary{arrows} \...
3
votes
1answer
78 views

Is a number an integer ? (with xfp or pgfmath or expl3 )

I continue to test the transition from fp to xfp. The results are good but two macros resist: \FPifint and\FPClip. I did not find how to replace them in xfp. I have numbers (decimal numbers [+,-,0,...,...
2
votes
2answers
46 views

how to use a substitute function of veclen temporarily

The question comes from this question : here \documentclass{standalone} \usepackage{tkz-euclide,xfp} \usetkzobj{all} % with version 1.16 not necessary with 2.5xx (soon) \input{mynewmacro} \begin{...
2
votes
1answer
214 views

tikz Plotting the complex logarithm

I would like to plot the complex logarithm (imaginary part) which is defined as follows: ln(z) = ln(r) + i * arg(z) This should look like this. However, I have no experience with 3 dimensional/...
1
vote
1answer
53 views

pgfmath: How to create a '10^n sep' like '1000 sep'?

We know, there is a command 1000 sep={...}. Is it possible, to create a command like 10^11 sep={\\}? \documentclass{article} \usepackage{tikz} \begin{document} \pgfmathprintnumber[fixed, 1000 sep={\...
1
vote
2answers
46 views

How to print number with predefined exponent base (pgf)?

How can I print a number with some predefined base of power of 10 (exponent base) using \pgfmathprintnumber \documentclass[border=1cm]{standalone} \usepackage{pgf} \usepgflibrary{fpu} \begin{...
0
votes
1answer
41 views

How can I colour-fill a plotted shape?

I have the following code \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{decorations.markings} \usetikzlibrary{arrows.meta} \usetikzlibrary{decorations.pathreplacing} \usetikzlibrary{...
3
votes
1answer
53 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}% \...
1
vote
2answers
168 views

How to pass a variable to a command in LaTeX?

I am trying to make a tax calculator for an invoice template and the idea is to pass the variable subcost to the command \taxcalc. \newcommand*{\taxcalc}[2]{% \pgfmathparse{#1/(1.0-#2)-#1}% \...
1
vote
1answer
105 views

Why does pgf calculate arc sine incorrectly (by a lot)?

Reasonable imprecision is OK, but diverging from a calculator by entire 10 degrees is unacceptable. \documentclass[border=5mm]{standalone} \usepackage{tikz} \usetikzlibrary{math} \tikzmath { \angle=...
2
votes
2answers
97 views

pgfmath in graph library giving compilation errors

I want to represent a graph where the labels for each node are obtained computing a modulo computation. The first and easy way to do it is as follow : \documentclass[tikz]{standalone} \usetikzlibrary{...
3
votes
1answer
47 views

Change the text color in table cells based on the value criterion

I have a confusion matrix ranges from 0.0 to 1.0. In which the value beyond 0.70 is bad. Therefore, I am coloring them as red. I am following the example presented here to color my confusion table. ...
1
vote
1answer
28 views

How to get mantissa and exponent of a number from within pgf/fpu?

I need to get mantissa and exponent of a number from within pgf/fpu. I found @egreg's solution from here, but this solution does not work inside fpu. \documentclass[]{article} \usepackage{pgf, tikz} \...
1
vote
1answer
67 views

animateinline problems

I have a couple of problems regarding an animation in latex 1) The animation flicker while it runs 2) The animation is shown as a sliding window, I would like to keep the already played ...
2
votes
3answers
66 views

Result of pgmathsetmacro is lost in loop iterations

Consider the following code. %!TEX program = lualatex \documentclass[tikz]{standalone} \begin{document} \pgfmathsetmacro{\sumk}{0} \foreach \k in {1,2,...,10}{ \pgfmathsetmacro{\sumk}{\k+\sumk} ...
0
votes
1answer
64 views

A PGFplots linear regression problem

I'm having problems with the linear regression function in PGFplots. The eq given by the package has the signs changed. \documentclass[12pt,letterpaper]{article} \usepackage[letterpaper, margin = 1 ...
0
votes
1answer
31 views

A problem with pgfcalendar and fpu

I'm trying to define a macro that will determine two dates (in weeks of 7 days), calculated from a given date (defined by \setmovedate below. For brevity the code below uses only #2 from \movetasks: \...
5
votes
2answers
206 views

How to “add” units to results of \pgfmathsetmacro?

This question is inspired by Jake's answer to this question. The problem is illustrated by this MWE: \documentclass{standalone} \usepackage{tikz} \begin{document} \def\ri{1.0cm} % define inner ...
0
votes
1answer
32 views

Treat number using pgfmath

I have the MWE below. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{arrows} \begin{document} \begin{tikzpicture}[{x=(1mm,0)},{y=(0,1mm)}] \small \def\...
5
votes
1answer
123 views

TikZ angle calculation and rotation with transformed coordinates

Please consider the following MWE: \documentclass[]{article} \usepackage{tikz} \begin{document} \typeout{Using internal functions} \begin{tikzpicture}[ color=green!50!black] \draw[thin, ...
3
votes
1answer
121 views

Binomial distribution in table

Here you can find how to calculate and print table for the binomial distribution. I would like to get rid of those lines that are all empty due to too small probabilities (<=0.0000). I used the ...
1
vote
1answer
37 views

Using the maximum value of two equations from a mathematical expression in a pgf plot

Good afternoon everyone, currently, I am making a graph to insert it into another document later on. It is a regression line in a dot cloud. (The dot cloud is represented by four coordinates in the ...
3
votes
4answers
141 views

pgfmath / gnuplot: How to use gnuplot for complicated calculations?

Is there a way to use gnuplot for complicated calculations? For \pgfmathsetmacro{\x}{0.02} \pgfmathsetmacro{\y}{2*11000*(1 - 1.40576 - cos(\x) + sqrt(1.40576^2 - sin(\x)^2))} for example I get '...
2
votes
4answers
79 views

How to find the length of a PGF array even if it's in a macro?

One of the answers to a question about how to calculate the length of a PGF array provided a function that increments a counter for each step of the iteration on the array provided as its argument. ...
3
votes
1answer
58 views

Dynamic bar plot from file

I need to draw a bar chart based on the data from the file. The data looks something like this \begin{filecontents*}{tls.dat} Name Abbreviation percentage Bod-Kin LS1 60 Intraper LS2 40 ...
2
votes
2answers
140 views

Superlattice in Tikz

I'm trying to work out how to plot two (hexagonal) lattices stacked on top of each other at a relative twist angle on tikz -- see the attached examples. I know how to plot a lattice using a for loop, ...
1
vote
1answer
89 views

Precision difference between \pgfmathsetmacro and \pgfplotsretval

I am currently working on some datasets with pgfplots and pgfplotstable. At some point, I need to store some cell values for mutiple uses so I use a \pgfmathsetmacro{\somevar}{\pgfplotsretval} call. ...
9
votes
2answers
281 views

Best practice for printing and evaluating formulas with the minimal coding

Can the following MWE be reduced by creating a command that can accept a formula then print and evaluate it without the need to write it twice in two different forms for both evaluating and printing ...
1
vote
1answer
44 views

How can I use `\pgfmathresult` as x-coordinate?

I need to use \pgfmathparse{floor(\textwidth/2)} as one of x-coordinates of a path but I get an error. \documentclass[margin=5mm,varwidth=100mm]{standalone} \usepackage{tikz} \begin{document} \...
1
vote
1answer
25 views

Tikz error for large values with \pgfmathsetmacro

I have the following MWE \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[{x=(1mm, 0)},{y=(0,1mm)}] %-> DEFINITIONS \def\plthgt{50} % plot ...
0
votes
1answer
31 views

Random compile-time document style

I am trying to create a document class with random style attributes, determined at compilation time. Random attributes would ideally include: Margins Line spacing Font selection For my particular ...
3
votes
1answer
66 views

Problem on coloring nodes with [fill=black!\pgfmathresult] in tikz

I tried to use tikz to fill nodes with colors according to values in an array file, but I failed to fill nodes with right color when fixing node position by [at (a,b)]: \begin{document} The data in ...
3
votes
3answers
59 views

dimension too large in pgfmathsetmacro

This works for \test{500} but not for let say \test{50000} \documentclass[10pt,german]{article} \usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage[utf8]{inputenc} \...
1
vote
2answers
75 views

foreach / pgfmath: create a list of specific values

I would need a list, possibly an array (for later use in a foreach loop / TikZ graphic), which contains the following values ​​(a_n) in order (n = 1,2,3, ...): 45,135,225,270,315, 45,45,90,135,135,...
2
votes
1answer
67 views

Use \ifthenelse{\equal{ on a number called from reference

I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice ...
3
votes
0answers
62 views

Using conditionals inside mcexam

I want to write exams where the questions and answers are randomized, and mcexam lets me do almost everything I want. However, I would also like each question to be picked randomly from a group of ...
1
vote
1answer
48 views

Problem with using rnd function in Tikz polar coordinates

I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this ...
2
votes
1answer
91 views

Define a new math function

I want to use an angle (say a) in tikzpicture, which is calculated from other parameters: \def\d{1} \def\D{2} \def\H{5} a=90+0.5*asin(2(\D-\d)/\H) This angle a I then use in a tikzpicture ...
2
votes
0answers
31 views

In tikzmath the “random” puts “.0.0” if want negative random number [duplicate]

Here is a MWE: \documentclass{article} \usepackage{pgf} \usepackage{pgfplots} \usetikzlibrary{math} \begin{document} \tikzmath{ int \foo; \foo = random(-16,10); print {Foo value: \foo.}; } \...
1
vote
2answers
261 views

variant of scientific notation on pgf

I use scientific notation on pgf to display numbers. My present code as follows: \documentclass{article} \usepackage{pgf} \begin{document} \pgfkeys{ /pgf/number format/.cd, sci, sci generic={...
1
vote
1answer
22 views

How can I manipulate a part of a text depending of the sign of a parameter or the parameter itself (automated calculation solution quadratic function)

I want to make a complete solution sheet with the whole context for my students. My code is this (with the answer I changed my problem) to this: \documentclass{article} \usepackage{pgfplots} \...
2
votes
1answer
64 views

pgfplotstable: highlight entire rows and columns

This is a follow-up on this question. With pgfplotstable, I would like to create a style to highlight an entire row and/or column. Zarko's answer at the linked question shows how to bolden an entire ...
2
votes
3answers
60 views

How to prepend extra 0s unto calculated binary digits

So I'm suppose to make an omega network that connects 0010 to 1000 and I have pretty much done it, however I would like to display my binary with extra zeros. \documentclass{standalone} \usepackage{...
2
votes
1answer
155 views

How do I display only certain rows in a table using pgfplotstable?

I have a table, read from a file, and I would like to display only rows which have a specific value in a given column. The specific value is a string (e.g. Agricultural). I am able to do it using the ...
3
votes
3answers
126 views

Check whether String represents valid number for PGF

I am searching for a reliable way to determine whether a String can be fed into \pgfmathprintnumber. I used to use the \IfDecimal from the xstring package which works fine for things like 3.14 and ...

1 2 3 4 5 8