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
0
votes
1answer
68 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{...
1
vote
1answer
73 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, ...
1
vote
1answer
41 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 ...
5
votes
1answer
1k views

Insert negative of \widthof into \hspace without defining a newlength [duplicate]

Following MWE does not work: \documentclass{article} \usepackage{calc} \newlength{\charwidth} \setlength{\charwidth}{\widthof{$-$}} \begin{document} \centering $\infty$ \centering \hspace{-\...
0
votes
0answers
128 views

what does calc.sty missing from the foler mean

This error suddenly appeared in my file! It was not before what should I do? File `calc.sty' not found. \RequirePackage
2
votes
1answer
39 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 (...
8
votes
2answers
253 views

Is there a sane way to visualize a division in “german style”

I need to visualize divisions in "german style". I managed to do it with TikZ, but it's a hard job! \documentclass[parskip=half]{scrreprt} \usepackage{tikz} \usetikzlibrary{chains} \begin{document} \...
1
vote
0answers
34 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" ...
0
votes
0answers
62 views

Precision Tikzmath

I have the implementation of Bissection method in tikzmath environment below: \documentclass[tikz,border=5mm]{standalone} \usepackage{etoolbox} \usepackage{tikz} \usepackage{fp} \usepackage{xfp} \...
0
votes
0answers
49 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.
1
vote
0answers
29 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}...
0
votes
0answers
38 views

Problem with Tikz - Math (Looping)

I have the following code in TikzMath to generate approximations for a initial problem of system of differential equations (rule of medium point). The algorithm is given below: \documentclass[tikz,...
4
votes
1answer
108 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}\...
2
votes
2answers
36 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 ...
0
votes
1answer
84 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 ...
0
votes
0answers
45 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 ...
2
votes
1answer
102 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 ...
4
votes
3answers
370 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.
8
votes
2answers
594 views

Tikz wrong calculation draw exponential function

Thanks for your help in advance:) I have a problem with tikz calculating/printing the values of my function wrong. The function is f(x) = (ax³+bx²+cx)*e^(dx) with a=-3.01718 b=11.8804 c=0.753323 d=-0....
2
votes
2answers
102 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,...
1
vote
1answer
55 views

Dynamic table : setting the column number after the table

I would like to create a dynamic table with \N columns at the beginning of the page, in which \N is the number of sections in the whole document, so the value of \N is set after the table. When I set ...
1
vote
1answer
54 views

Add days to a specific date in datetime2 in a for loop / foreach loop

I want to calculate the beginning and ending date of a week (first day is Monday, last is Sunday). This is working fine for a single date. Now I want to calculate the start and end of multiple weeks ...
-1
votes
1answer
32 views

How to set horizontal alignment inside a custom environment, based on one of the parameters

So with this code using xparse : \NewDocumentEnvironment{figwcommentary}{O{0.45} m m} { \adjustbox{valign=t} {\begin{minipage}{#1\textwidth} #2 \end{minipage} } } { \adjustbox{valign=t,right=0.5\...
6
votes
2answers
354 views

How to divide in LaTeX without it rounding or truncating?

I'm working on a diagram and I'm pretty new to LaTeX, so I've decided to try to do it using math instead of statically assigned values. I have come up with the following: \newcommand\qoffset{14} \...
1
vote
1answer
27 views

Cutting text to a given length

I want to put text on the header of my document (I'm using fancyhdr), but if the text surpass certain length it overlaps with other elements. For example, if I want to put "A very long text to ...
2
votes
2answers
33 views

Latex3 sum of array terms

I have used expl3 to sum the terms of a given array, however as you can see the procedure is quite cumbersome. Is there a more elegant way to do the same thing? \documentclass{article} \usepackage{...
4
votes
2answers
201 views

Why is there an arithmetic overflow in the progress bar with more than 44 frames?

I am trying to implement a progress bar into my beamer theme, but as soon as I hit 45 frames, I get the error message ! Arithmetic overflow. \progressbar@progressbar ...progressbar@tmpcounta \divide \...
169
votes
4answers
62k views

Get width of a given text as length

Is there a TeX command that returns the width of a given text as length value, so that I can use the result directly as a length argument of another command? I mean, I would like to have a command \...
1
vote
0answers
35 views

TikZ - “Calculate” the numeric suffix of the name of a node

Relaxing answer Symbol gives the answer in his comment below. Change \def\secondnode{T22} \coordinate (M) at ($(T2#1)!.5!(\secondnode)$); to \coordinate (M) at ($(T2#1)!.5!(T2\the\numexpr#1+1\relax)$...
6
votes
2answers
556 views

How to make text appear in the middle of a phantom in math mode?

I want to make a part of an equation to appear in the center of a (horizontal) phantom. This would be awesome for example for making bra-kets that are all of the same width and still look natural. ...
5
votes
2answers
184 views

How to round numbers to hundreds, i.e., to the nearest multiple of 100

I want to round numbers to hundreds. I note Rounding a number to its hundred. However, the question asks about rounding 2,386.0 down to 2,300.0 -- and I would want it to be rounded up to 2,400.0, and ...
3
votes
2answers
65 views

Convert \input to number

I'm reading several txt-files from disk and I want to do some simple calculations on them and be able to print them on the page. Basically I have: \newcommand\getinput[2]{ \immediate\write18{do-...
2
votes
0answers
55 views

A mask for conversion degrees to radians and viceversa for my students of an high school

Starting from this code: \documentclass[a4paper,12pt]{article} \usepackage{calculator} \usepackage{amsmath,amssymb} \begin{document} \DEGtoRAD{60}{\sola} Result in radian without the use $\pi$: \sola ...
0
votes
1answer
156 views

How to write a math parser in TeX?

TeX is not really good in calculating, so some packages and LuaTeX were developed. But none of these solutions offers symbolic/exact mathematics, so I have tried something like this: % Plain TeX \...
20
votes
2answers
7k views

Rotate a path around a point

I have a named path (a triangle). How do I rotate it around point A in various angles without recalculating points B & C? Here's my code. I want to create the red and green triangles by simply ...
3
votes
1answer
79 views

Approximation of module gsl or Asymptote own calculation is the best?

Example: import graph; import gsl; size(12cm,false); defaultpen(linewidth(.7bp)); real f(real x){return x^2;} real g(real x){return 2^x;} draw(graph(f,-1.5,5),red); draw(graph(g,-1.5,5),blue); draw(...
0
votes
1answer
69 views

Multiplication and division with counters while also formatting

See the code that follows. The user gives some pairs of numbers. Each time they happen also to be displayed. Finally they are added up in a specific way. \documentclass{article} %\def\Result... \...
1
vote
1answer
42 views

Not able to draw arrows parallel to line

I am trying to draw a region. I am not able to draw arrows parallel to line connecting inner region to outer region. This is what I have and this is what I want The code I have so far is below. ...
7
votes
2answers
249 views

Modeling randomly generated inscribed triangles

The problem I am modeling: Three points are randomly chosen on a circle. What is the probability that the triangle formed by these three points contains the center of the circle? Conceptual ...
3
votes
1answer
178 views

NFSS: Can I scale fonts using fractions (more accurate) instead of decimals?

I would like to be able to pass a fraction expression to s*[<number>] in a \DeclareFontShape. The ultimate goal is to instruct LaTeX2e’s New Font Selection Scheme (NFSS) to perform more ...
2
votes
1answer
78 views

xsim: How to calculate points of the sections

Is there a simple way to calculate the points a section includes? \documentclass{scrartcl} \usepackage[no-files]{xsim} \xsimsetup{ exercise/the-counter = \thesection.\arabic{exercise}, exercise/...
0
votes
1answer
47 views

use \IfEqCase output as a numeric value

How can i use the output as a number \documentclass{article} \usepackage{xstring} \newcommand{\CableType}{N2XSY} \newcommand{\Ksc}{ \IfEqCase{\CableType}{ ...
31
votes
5answers
3k views

Reducing fractions automatically using LaTeX 3

Consider the following code: \documentclass{article} \begin{document} \noindent Can I make \LaTeX{} reduce a fraction automatically?\\[\baselineskip] For example, I would like the fraction \[ \frac{...
2
votes
2answers
104 views

tikz rectangle that fits exacly into linewidth including boundary

I had this code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \newcommand{\mywidth}{\linewidth} \begin{figure}[p] \begin{tikzpicture} \draw[ultra thick]...
34
votes
3answers
6k views

Date calculations

I'm building a LaTeX document that helps me to formulate quotations for my customers. Since I decided to offer monthly recurring payments I'd like to have payment dates calculated automatically ...
3
votes
2answers
93 views

Help recalling a package which automatically calculates derivative orders

I distinctly recall stumbling upon a package which typeset derivatives nicely, and moreover automatically calculated some of the indices involved in partial differentiation. Unfortunately, I can't ...
10
votes
2answers
752 views

Inaccurate Calculations By pgfplots

In graphing a certain function using pgfplots (link here) I noticed a distortion in the curve that at first I assumed must have been a point of inflexion - but on investigating the maths, found that ...
2
votes
1answer
213 views

Can I write once, publish in HTML(blog) and PDF?

I'm going to write an article. It will have math equations, images, and tables. My article frequently contains repeated content with slight modifications. For instance my article may have If the ...
14
votes
4answers
840 views

How to get the sum, difference, product, and quotient from a macro in ConTeXt or Plain TeX?

I want to create a set of macros like this: \addnumbers{2}{5} \subtractnumbers{3}{5} \multiplynumbers{2}{-2} \dividenumbers{2}{8} The first will display the number 7, adding #1 and #2. The ...
0
votes
0answers
88 views

LaTeX set and add durations as in primary school

I'm looking for a package, or even a macro that allows me to simply write duration calculations for young students. Like for example this (Lebossé-Hemery 1957 classe de sixième): Please note that ...

1
2 3 4 5
11