{calculations} is about calculations in (La)TeX documents. A popular package is calc although may other also exist (fp, pgf, and LaTeX3 packages).

learn more… | top users | synonyms

34
votes
5answers
11k views

How can I automatically calculate sums in a LaTeX table?

Sometimes I would like LaTeX to automatically calculate sums (or other simple arithmetic) for me, eg. in a table. I would like to ensure that when I update the table, I don't accidentally forget to ...
17
votes
2answers
5k views

Is plotting exponential graphs a known source of bugs in TikZ?

I want to plot $y = 2^x$ over a small domain. Unfortunately, even though tikz (v 2.1) seems to be able to calculate 2^{negative numbers} it is not plotting them correctly. My minimal example is: ...
22
votes
2answers
6k views

Problems with TikZ calculations

When can I use functions and do calculations in TikZ? How do I make this work: \draw (0,0) arc(0:90:sqrt(15)); %not ok why is this working: \draw (0,0) arc(0:asin(1):5); %ok with ...
29
votes
6answers
3k views

How to use \pageref{foo} as a number?

What I want to do is to show a "progress bar" in the header to show how far you are in the document, by making a rule with width pagenumber divided by total pages times the paper width. This is what ...
5
votes
2answers
616 views

TikZ: Make node height span several others

How can I make the Z node span the total height of the ABCD column? My current code is: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc,positioning} \begin{document} ...
54
votes
3answers
14k 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 ...
52
votes
11answers
2k views

How can I define a mathematical function as a LaTeX macro?

I am attempting to create a usable function within LaTeX such that its inputs are transformed mathematically. However, I cannot find any documentation that can perform such mathematical function ...
22
votes
5answers
4k views

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 ...
8
votes
1answer
1k views

Computing value using pgfmath for use in coordinates?

Why can't I use the outcome of using pgfmath in a TikZ coordinate? Here is a (minimal) example that does not work: \documentclass[11pt]{article} \usepackage{tikz} \begin{document} ...
37
votes
5answers
2k views

Perform matrix operations (addition, product, transpose, etc.) in LaTeX?

I know the calc package can perform infix-notation arithmetic in LaTeX... but I want more! I'd like to perform (not necessarily infix-notation) linear-algebra operations such as scalar ...
33
votes
7answers
6k views

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.
17
votes
3answers
2k views

Doing maths with distance values in LaTeX source code

I have a sty file with the command \newcommand{\foo}[1]{\noindent\kern#1} but I'd actually like to have something like \newcommand{\foo}[1]{\noindent\kern{#1 *0.5}} meaning that I'd like to have ...
16
votes
2answers
4k views

How can I compute the distance between two coordinates in TikZ?

Given two points (defined, for instance using nodes), I want to compute the distance between them. Is there some build in functionality in tikz to do this? If not, how can it be done using the ...
11
votes
2answers
955 views

Compute the x distance between two nodes

Is there a way to define a macro which would evaluate to the x part of the distance between two nodes? I know there are the point registers \p and the correspoding \x commands, but I find them rather ...
13
votes
4answers
864 views

Dividing dimensions to get a count

Is there a way to divide two dimens and get a count? For example, if I have a box that doesn't fit on a single page, and I want to know the number of pages I'd need for the box (i.e., \heightofbox / ...
38
votes
3answers
3k views

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.
24
votes
2answers
33k views

How to fit a large figure to page [duplicate]

Possible Duplicate: Best figure size adjustment when dealing with different image sizes Given: a large figure, whose height:width ratio is unknown. Todo: Include this fig in LaTeX, such ...
9
votes
1answer
828 views

Automatic calculation of error in pgfplots

When taking in data through a file (such as table[x index=0, y index=1, y error index=2]{plots/mydata.table};) is it possible to automatically calculate the error bars (instead of putting them in ...
9
votes
1answer
335 views

How to fit ellipse into another object - using intersections and calc library

I would like to ask, how to place ellipse into any object, so that the length of the main arm is defined by line1 (point A, B) in my code: calculate the coordinates of the ellipse midpoint rotation ...
6
votes
2answers
1k views

\widthof within tikzpicture

In this minimal example \documentclass{scrartcl} \usepackage{calc} \usepackage{tikz} \newlength{\TestLength} \begin{document} \setlength{\TestLength}{\widthof{\tikz \node {bla};}} ...
12
votes
3answers
6k views

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 ...
9
votes
1answer
1k views

Shrinking text to the width of a node within a tikzpicture

I would like to be able to scale text to the width of a TikZ node. Using \widthof within tikzpicture as a starting point, I've arrived at somewhat of a solution, except it has incorrect spacing, and ...
7
votes
5answers
2k views

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., \scalebox{<ratio>}. ...
30
votes
6answers
15k views

How can I sum two values and store the result in other variable?

In LaTeX2e,how can I sum two values and assign them to other variable? I want to compute something like: var=\textwidth - 1cm And if both were constants: var=1+1
25
votes
2answers
2k 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 ...
17
votes
4answers
774 views

Calculate prices

I want to calculate prices in a LaTex file. This means I want to add two numbers with exactly 2 decimal places and I want to multiply these values by an integer. An other thing is the output format. ...
14
votes
1answer
2k views

Determine height and depth of letters relative to the font size

I would like to scale graphical elements (like images, tikz and tikz-timing diagrams) relative to the font size, so that they have the same height as an normal uppercase letter (i.e. X or M; I noticed ...
12
votes
4answers
4k views

Why is this let expression not working in TikZ (calculating a midpoint)?

I have a rectangle in TikZ and the top left and bottom right corners are called (topleft) and (bottomright) respectively. I wanted to have a label midway down the left hand side of the rectangle, so I ...
15
votes
3answers
2k views

Why doesn't \settoheight of \parbox work?

Consider the following code: \documentclass[a4paper]{letter} \usepackage{calc} \usepackage{printlen} \newsavebox{\foobox} \newlength{\fooboxheight} \savebox{\foobox}{ ...
8
votes
4answers
345 views

Calculating the the exact width of the text and a lettrine

This is one question which technically could be broken into two minor questions. I am using a lettrine and some verse text, but the calculation to determine how much to indent the text does not ...
12
votes
3answers
1k views

How can I calculate the difference of 2 counters (pageref)?

How can I calculate the difference between 2 counters (like page numbers), so that pdfLateX outputs "3" in the last line of my example? and how could I calculate the difference between the "current" ...
8
votes
2answers
3k views

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} ...
22
votes
4answers
1k views

Get derivative of a function

I want to write a macro, which takes a mathematical function as argument and returns a plot using pgfplots of the function and of its derivative. I guess that this isn't possible using just LaTeX; ...
13
votes
2answers
484 views

Is there a better way to do intersections and calculations with relative coordinates in TikZ?

I've been doing many TikZ diagrams lately and every so often I encounter a situation where I am forced to use some temporary coordinate in a \path. In the following short example, the problem is ...
16
votes
3answers
1k views

PGF math engine imprecise?

The command \pgfmathparse{asin(1/\x)} yields for each \x in the range of 125 to 142 the same value, whereas \pgfmathparse{1/\x} yields the much more precise values for each \x. Is the ArcSin function ...
8
votes
1answer
255 views

How to define a macro that uses image width and height to define a variable for later use

Ok, the title might be a bit cryptic and my question is a bit lengthy, so please bear with me. What I want to do is: I have two images with different aspect ratios that I want to place next to each ...
17
votes
6answers
2k views

Checking if a number is a multiple of 4

Using etoolbox, ifthen, or another form of conditional checking, how can I check if a value is a multiple of 4? E.g. if the number is 4, 8, 12, 16, etc., then it returns "true".
15
votes
6answers
2k views

Sum of (example: 0+1+2+3 = 6 , 0+1+2+3+4+5+6+7 = 28 and so on)

Can anyone help please? I need to know how to make the sum of value S(n) = 0+1+2+3+4...+(n-1)+n (example: 0+1+2+3 = 6 , 0+1+2+3+4+5+6+7 = 28 and so on) on Latex
12
votes
2answers
1k views

Where is the left-hand margin?

I'm working on the TikZ-from-TeX-SX package, specifically developing the code for putting equation numbering at places within a tikzpicture environment. To do this, I need to know where the text ...
6
votes
2answers
2k views

Coordinates A, B: compute |B-A| and angle between +x and (B-A)

This question has two parts: why is the angle computed always 0 (should be 45) what is a straightforward way to compute distance between coordinates (there is How can I compute the distance between ...
2
votes
1answer
451 views

How to pass in a ratio in fraction form (as opposed to decimal form) to table column definition?

My scenario is to pass in a ratio (in fractional form as opposed to decimal form) to each table column definition. The following code cannot be compiled. \documentclass{article} \usepackage{pgf} ...
20
votes
3answers
2k views

Extract first & last characters of macro argument?

In LaTeX, how do I extract/isolate/determine the first and last characters of a macro argument? Specifically, in the case I'm dealing with, the argument happens to be a base-10 integer (call it N). ...
10
votes
2answers
641 views

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? ...
7
votes
2answers
217 views

Why a calc operation in width of beamercolorbox doesn't work?

Trying to answer How to add the footnote in the right down corner with the background color(only page)&change time background color I wanted to calculate beamercolorbox width as ...
6
votes
1answer
629 views

Extract coordinates from 3D point

How do I extract coordinates from a three-dimensional point defined when using tikz-3dplot? I would like to perform some calculations on these (more specifically a cross-product of two vectors), but ...
23
votes
1answer
2k views

References for \dimexpr \numexpr

I'm not really sure whether this is the right place to ask this question, but here I go.... Over the holiday I've been taking time to read through a lot of the Q&A here. I've been running across ...
9
votes
6answers
1k views

Parse simple arithmetics and return the result

I want a command \ca which takes a simple arithmetic calculation as an argument and returns the result with proper decimal places. Additionally I want an boolean argument which decides if only the ...
9
votes
2answers
2k views

How to enable use of minus and plus in tex documents?

I see many cls files using plus and minus operators to set lengths. How can I use these operators (or some equivalent macro(s)) to do something like the following? \setlength{\lengtha}{.5\textwidth} ...
8
votes
2answers
303 views

How can you make custom counter display types?

I'm a comp sci prof working on an exam for my students in LaTeX, using the exam class. I like to throw in a few in-jokes here and there. Unfortunately, the class breaks if you try to use 0-indexing on ...
5
votes
3answers
255 views

How to subtract both very large numbers and numbers smaller than one?

In the context of Scientific Notation Only For Large Numbers have we been looking for a way to handle large numbers, as pgfmathparse can't cope with these. The only package we could find was ...