Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [calculations]

{calculations} is about calculations in (La)TeX documents. A popular package is calc, although others also exist (fp, pgf, and LaTeX3 packages, e.g `xfp`).

Filter by
Sorted by
Tagged with
2 votes
1 answer
70 views

Latex3 floating point calculations in longtblr (tabularray)

I'm learning LaTeX3 and trying to do simple calculations on floats in a longtblr environment. Trouble is that I cannot manage to dynamically compute sub-totals per row. The global total is working ...
user avatar
3 votes
1 answer
46 views

Changing the default length unit in tikz

Is there a way to change the default length unit in tikz to the ex unit? I have trouble while calculating complicated coordinates in tikz when I'm using the ex unit (I always get an error or a wrong ...
user avatar
14 votes
1 answer
552 views

Animate mass-spring-damper TikZ

I've create a TikZ of a mass-spring-damper system that is described by the following ODEs dx1/dt = x2 dx2/dt = -w0^2*x1 -2*zeta*w0*x2 + u y = K*w0*x1 + 2*zeta*w0*x2 wherein u is the input and y is ...
user avatar
  • 297
5 votes
2 answers
850 views

tikz Math Library: Why does this operation "755 / 100" produce 7.54999 and not 7.55?

Here is a code example. \tikzmath{ \x = 755; \x = \x / 100; } Output: \x I expect my value stored in \x to be 7.55, but it is instead 7.54999. Is there some setting to make the result be ...
user avatar
  • 53
0 votes
0 answers
27 views

Using datatool and xkeyval for calculating sums in tables

I want to build a nice and easy to use interface for users to fill a table with information. Therefor I use xkevval and pass its values to datatool for a proper processing. Now I have a table for ...
user avatar
0 votes
1 answer
44 views

Placing symbols into spreadtab

I am quite new for the spreadtab package. I have prepared a MWE for my issues as: \documentclass[handout]{beamer} \usepackage{spreadtab} %\input{diagrams} \newcommand\dollarsign{\$} \begin{document} \...
user avatar
  • 160
2 votes
1 answer
60 views

Floating point calculations LaTeX without printing result in pdf

I'm writing a package and I need LaTeX to perform calculations involving floats and fractional parts without them appearing on the pdf, like how you would define a variable in Python without having it ...
user avatar
0 votes
2 answers
50 views

How can I convert automatically a calculated angle in degrees minutes and seconds [duplicate]

I want to make a batterie of exercises for a part of geometry. In this document I can change the length of the triangle. It calculates the angle. But I want the angle in Degrees minutes and seconds. ...
user avatar
3 votes
1 answer
111 views

Use command argument in foreach

When I define a new command to draw an axis I want to use one argument to calculate the step size of the tick numbers. I tried this but it didn't work: \newcommand{\axistest}[2]{ \draw[->,color=...
user avatar
3 votes
2 answers
312 views

How to write Pascal's Triangle modulo 2

I am writing a document and would love to write Pascal's triangle modulo 2. That is each binomial coefficient modulo 2, "the remainder" when dividing by 2. I found these links (Pascal) of ...
user avatar
4 votes
0 answers
99 views

What are the available macros for algebra and calculus?

The polynom package can provide all the steps of a long division of polynomials if I just provide the polynomials: \documentclass{article} \usepackage{polynom} \begin{document} \polylongdiv{x^4-3x^3-...
user avatar
  • 189
3 votes
3 answers
173 views

pgfplots: Dimension too large with no obvious large numbers

The following MWE results in the error Dimension too large. Changing the upper limit of the domain to a smaller value like 120 gets makes this error disappear. \documentclass{article} \usepackage{...
user avatar
  • 12.5k
0 votes
1 answer
41 views

How to use decimal computations inside parentheses to compute the height of an image?

I have the following LaTeX file which does not compile: \documentclass{report} \usepackage{calc} \usepackage{graphicx} \newcommand\AFiveHeight{210mm} \newcommand\BodyToLayoutRatio{0.7} \newcommand\...
user avatar
  • 125
3 votes
1 answer
61 views

Automatic calculation of check number for ISBN-13

Here is a simple example. If I have the first 12 digits of ISBN-13 number. \documentclass[12pt]{report} \parskip=12pt \def\ISBNnumber{978-618-5645-08} \pagestyle{empty} \begin{document} ...
user avatar
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
4 votes
3 answers
182 views

Adding to number

I want to check if the value of the parameter is negative. If the parameter is negative, I want to substract 0.5 and if it is positive, I want to add 0.5. The best I could do is define new variable ...
user avatar
  • 5,473
0 votes
0 answers
39 views

One to one function, how to draw in LaTeX? [duplicate]

Here are both set of one to one function. How to make LaTeX coding in figure type: (x)=0,2,3 (y)=a,b,c
user avatar
3 votes
8 answers
722 views

How do I print an increasing value with iteration in LaTeX?

For example, I want to print all values x + 1 with n repetition In Python it would be: def arithmetic_add_1_(n,x): for k in range(n): print(x) x = x+1 print(x) with n -> repetitions ...
user avatar
  • 49
3 votes
1 answer
48 views

StrGobble doesn't work with \numexpr

I made the following function which strips left, right or both (if present) brackets and it seems to work as intended when used in the document, i.e. \stripp{1}, \strip{(1)}, \strip{1)} and \strip{(1)}...
user avatar
  • 538
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,935
2 votes
1 answer
83 views

How to draw \hrule based on text width?

I have a \divider command where it draws a thick hrule and a thin hrule to achieve the style I want: \newcommand{\divider}[1]{% \vskip-2pt % {% \color{black}% \hrule% }% ...
user avatar
13 votes
3 answers
408 views

I encountered the following problems when using foreach:

\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x in{0,0.1,...,0.5}{ \node[] at (20*\x,0) {\x}; } \end{tikzpicture} \end{document} ...
user avatar
0 votes
3 answers
54 views

arithmetic in tex when the data type is not an integer

Use case. I am drafting a contract where I would specify in the beginning an hourly rate using \newcommand{\monthlyrate}{\$10000} And in the following command, I would like to specify a penalty that ...
user avatar
  • 1,023
3 votes
1 answer
156 views

Calculate the lengths of rules (in LaTeX3?)

I don't think this hard to do but I 'am a real noob with calculations and dimensions. In the code above I would like to calculate automatically the dimensions of the left and right rules such as ...
user avatar
  • 11.4k
1 vote
1 answer
46 views

Problem with \tikzdeclarecoordinatesystem

I create a new coordinate system with \tikzdeclarecoordinatesystem. Compiles true when scale=1 and false otherwise. Why? Can you help me? Thanks alot. This is my code. \documentclass[tikz, border=2mm]{...
user avatar
4 votes
1 answer
66 views

Expandable set of divisors with xfp?

I wrote some code to print the set of divisors but it is not expandable. \input expl3-generic.tex \def\divisors#1{% \def\L{1}% \def\M{#1}% \def\x{2}% \loop \ifnum \fpeval{floor(#1/...
user avatar
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
4 votes
1 answer
103 views

Is there an interface to define functions in xfp?

Some functions are defined in xfp. Example: You can write something like \fpeval{max(1, 2, 3, 4)} and get 4 as the result. I would like to define functions like crbt(x) = x^(1/3) or the greatest ...
user avatar
1 vote
2 answers
119 views

Sum variables and process sign expressions in ConTeXt

I try to generate random exercises: \setvariables[parametres][a=-4, b=2, c=4] \starttext Solve: \startformula \getvariable{parametres}{c} x + (\getvariable{parametres}{a}+2) x = 5 \stopformula \...
user avatar
6 votes
2 answers
241 views

Mathematical manipulation of a pgf macro

I am trying to draw a TikZ diagram that I would like to start counting from zero instead of one. I have adapted this answer for my needs. \documentclass[tikz,border=3mm]{standalone} \usetikzlibrary{...
user avatar
  • 195
0 votes
2 answers
77 views

Is it possible to evaluate an integral using the xfp package?

I am curious if it is possible to evaluate an integral using the xfp package using tex language? \fpeval{\int_{-1}^{1}\frac{1}{\sqrt{1 - x^2}}dx}} Just throwing out the idea. I know I can easily do ...
user avatar
2 votes
2 answers
277 views

Use command for node position in TikZ

I have a command setup to calculate the transformed location of a nodes point, because I want to center these nodes on top of rectangles which have been rotated. So instead of manually calculating the ...
user avatar
0 votes
2 answers
41 views

Use number as argument for command

I am unable to use a number as a parameter for a command that I have defined. The command takes 5 numerical inputs and returns a single number. \documentclass{standalone} \usepackage{tikz} \...
user avatar
1 vote
1 answer
40 views

Problem with calculation of y values horizontal line

I have a problem with the calculation of the y-values in pgfplots. In my MWE, there seems to be a problem in the calculation of these values. \documentclass[border=5pt,tikz]{standalone} \usepackage{...
user avatar
  • 2,130
1 vote
1 answer
57 views

Calculator to return current year plus one

I am trying to use the package calculator to return current year plus one. I have tried the following but it does not seem to work. Any suggestions? \documentclass{article} \usepackage[utf8]{inputenc} ...
user avatar
  • 25
1 vote
1 answer
92 views

Simple calculations inside Tikz matrix

I have this rather complicated matrix and it would be great to do some calculations directly in LaTeX as I need to generate several iterations for each problem I prepare. The calculations are simple, ...
user avatar
1 vote
1 answer
102 views

tikz or tikzmath messing up units?

I would like to work on variable using different kinds of latex unit of length. I'm declaring variables including the units, but it's making a big mess. If a unit is given in a calculation, the length ...
user avatar
1 vote
1 answer
4k views

what does calc.sty missing from the foler mean [closed]

This error suddenly appeared in my file! It was not before what should I do? File `calc.sty' not found. \RequirePackage
user avatar
2 votes
1 answer
107 views

Latex long calculation error: "Missing number, treated as zero"

Why do I get the error "Missing number, treated as zero." for case A, while other cases are working? And how to avoid it? \documentclass{report} \begin{document} \newlength\newLen % Case A (...
user avatar
1 vote
0 answers
40 views

Tikz plots. I need to draw the intersection coordinates [duplicate]

I have this plot with the intersections of the functions f(x) & g(x) marked as P1, P2 and P3. How can I write its coordinates instead of the texts "P1", "P2" and "P3" ...
user avatar
0 votes
0 answers
64 views

Matrix operations on tikz math

Is possible I define a matrix A a vector x and compute the product b = A*x using tikzmath environment? Many thanks.
user avatar
1 vote
0 answers
35 views

exam/geometry: First footer is shifted below when setting geometry using \AtBeginDocument

This answer does the job for placing the header right. However, the first footer is unknowingly shifted way much down. So, why does \AtBeginDocument{\settototalheight\headerTotalHeight{\headerContents}...
user avatar
  • 8,759
4 votes
1 answer
174 views

tcolorbox: error with \settototalheight when calculating the header height before passing it to the geometry package

Following up this answer, I would like to know why the following doesn't compile and gives this error ! Undefined control sequence. \tcb@startbox ...x }{\tcb@w@upper }\tcb@lua@color {tcbcolupper}\...
user avatar
  • 8,759
2 votes
2 answers
39 views

Replacing length registers in expressions

I have some understanding on how to use length registers for calculations. However, I always end up requiring way too many length registers for tasks which could probably be solved better by ...
user avatar
1 vote
1 answer
94 views

Calculating recursive terms of a sequence

I want to calculate resursive terms of a sequence. The following code do this task with fibonacci sequence (sure, could be other sequence). \documentclass[varwidth,border=5]{standalone} \usepackage{...
user avatar
0 votes
1 answer
173 views

Using Tikz package to extracting length, coordinates and assigning them to variables

The code below is extracted from: "\internalforces" command in stanli package (code exam1b - The second coding set in this example) and Using reference points in "Stanli" Is there ...
user avatar
  • 733
0 votes
0 answers
49 views

Variable declaration, substitution and automated calculations with luatex in math environment [duplicate]

I am trying to perform automated calculations with latex using lualatex. I need to be able to printout calculations like "M = a+b" while maintaining all functionalities and options wihtin ...
user avatar
  • 733
2 votes
1 answer
593 views

Rounding a value from a function

Is possible I define a mathematical function f(x), for example, f(x) = sqrt(x), evaluate this function in a given point p=2 and round the result with 4 decimal places? I prefer use this code inside a ...
user avatar
4 votes
3 answers
471 views

Calculation summations in Latex

Anyone can help me please? I need to calculate the sum 1+1/2+1/3+...1/n (n given) by using only Latex commands. I have no idea how can I do this. Many thanks.
user avatar
2 votes
2 answers
109 views

Inaccuracy in floating number computation with fpu library

So I am trying to do some a bit involved computations with LaTeX, and it kept spitting out a nonsense answer. I am trying to compute number of layers you could cover a ball with, given some conditions,...
user avatar

1
2 3 4 5
12