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).

is about calculations in (La)TeX documents. A popular package is calc that redefines most length- and counter-setting macros (like \setcounter, \addtocounter, \setlength and \addtolength) to allow expression-style input.

Regular mathematical calculations are possible via the fp package, which provides infix or RPN notation for calculations. The powerful pgf package provides a similar and more extended functionality, as does LaTeX3's l3fp.

Please note that the features of l3fp can be used outside of LaTeX3 code with \fpeval by loading the xfp package.

590 questions
54
votes
3 answers

Can LaTeX perform calculation like Excel formula table?

I wonder if this feature is available in TeX system? For example, given a formula within a table, it can apply the formula and display data after the calculation.
roxrook
  • 9,907
50
votes
8 answers

How do I calculate n modulo 3 in LaTeX?

I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
mcandre
  • 911
34
votes
7 answers

Floating point calculations in LaTeX?

I am looking for a method to do minimal floating point / integer calculations in LaTeX, not for the purpose of package writing, but for the production of actual text. Here is an example to illustrate. Given the following input text The experiment…
Yossi Gil
  • 15,951
25
votes
4 answers

How to do simple calculation in LaTeX?

Consider the following macro: \newcommand{\sxfigure}[4]{ \includegraphics[width=#1*#3 cm, height=#2*#3 cm]{#4} } #1 and #2 is some value to determine the width and height of the figure, #3 is to control the zoom ratio. However, the above code…
Xing Shi
  • 375
25
votes
5 answers

Simplifying square roots

I want to create a command that, for a given integer n, type sets a simplified square root of n. For example, the output of \rsqrt{4} \rsqrt{8} \rsqrt{18} \rsqrt{7} would be the same as that of 2 2\sqrt{2} 3\sqrt{2} \sqrt{7} where \rsqrt{} is the…
21
votes
3 answers

Multiply the value by decimal number in latex?

I used the following construct quite often: \includegraphics[width=\textwidth/2]{pic.png} But when I try to adjust the size a small bit, like this: \includegraphics[width=\textwidth*0.45]{pic.png} I get ! Package calc Error: `.' invalid at this…
Rogach
  • 3,088
19
votes
3 answers

Simple way to multiply two values

I have a macro to define the scale of my figures: \newcommand{\myscale}{0.35} Now I have a figure that needs to be scaled twice as big, so I tried to use something like this: \begin{figure}[hbt] \includegraphics[scale=2\myscale]{my-image} …
Veger
  • 2,037
15
votes
7 answers

Calculating right angle triangle side inside LaTeX

I'd like compute the width of a screen from it's diagonal and its aspect ratio inside a LaTeX document. The formula is easy to get from the Pythagorean theorem, but needs square roots. I currently compute this using the calc package to compute the…
13
votes
3 answers

Total number of points

I'm looking for a simple answer, as I'm not a programmer. Everything I've found online about this is way too dense for my knowledge level. I teach calculus, and every year the points for each question on the test varies a little. We have multiple…
12
votes
2 answers

Multiplication with dimexpr?

(This post bases on: lstaddons: Dynamic linewidth calculation) Hey everyone, is there a way to do this with a multiplication instead of two additions? \dimexpr\linewidth+\lst@linebgrdsep+\lst@linebgrdsep\relax Thank you in advance :)
tollo
  • 263
  • 1
  • 8
12
votes
4 answers

Calculating checksum

I would like to calculate a checksum in LaTeX. My problem is that I don't know how to get the numeric value of a char. Here is the pseudo code of the algorithm: var input = "123456789"; car output = ""; var checksum = 0; var weight =…
rekire
  • 1,454
10
votes
5 answers

How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ?

How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ? Actually I want to use the ratio for the \scalebox argument, e.g.,…
Display Name
  • 46,933
9
votes
2 answers

Why do modern TeX variants not support floating point arithmetic?

I understand that, at the time when TeX was devised, no single standard for floating point calculations was available. But, these days there is IEEE 754. Why doesn't any TeX variant support it? Granted, there's LuaTeX, but IEEE 754 was popular long…
9
votes
2 answers

How to add numbers occuring in a text?

How make LaTeX to remember some numbers and output the total sum by calling another command? Consider this example: \documentclass{article} \usepackage{lipsum} \begin{document} The price of the first item is \pr{10.23}, that of the second item…
student
  • 29,003
8
votes
1 answer

How can I show radius of this circle exactly?

I want to show radius of this circle. The correct result of radius is 7/sqrt(3). My code. \documentclass[border = 1mm]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{intersections,calc,backgrounds,fpu}…
1
2 3 4