{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

7
votes
2answers
370 views

Rounding up decimal number using LaTeX 3

I would like to use LaTeX 3 to round up decimal numbers; I want something like the following: If I type \RoundingUpFunction{2.7} it should return 3 as output. Unfortunately, I haven't taken the ...
4
votes
1answer
955 views

Calculate numerical value for node text in TikZ

I am using a tikzpicture environment to draw a Temperature v composition plot. I do not have exact data so am only mimicking it. I am aware that I could/should use pgfplots but the issue could be ...
11
votes
2answers
196 views

What is the best practice for arithmetic operations specially for package/class writing?

There are some possibilities to execute arithmetic operations inside a package or class. TeX TeX supports \advance, \multiply or \divide to execute arithmetic operations. However the syntax is more ...
10
votes
2answers
915 views

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] ...
2
votes
1answer
411 views

Modulo calculation in PGFplots tick label

I am printing a diagram and want to use a_[0...3] as tick labels on the x-axis. Right now I have a[0...7] as labels and look for a way to print a[\tick mod 4] (i.e. a_0, a_1, a_2, a_3, a_0, a_1, a_2, ...
17
votes
4answers
756 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. ...
15
votes
2answers
1k views

Golden ratio typography in TeX

Chris Pearson makes a number of claims in his article Secret Symphony: The Ultimate Guide to Readable Web Typography, which I find fascinating, and I would like to know: are the formulas he proposes ...
2
votes
2answers
264 views

Calc and \settocdepth break \tikzexternalize

This might well be the strangest TeX behaviour I've ever seen and that's saying a lot. The following really is a MWE as far as the header is concerned: \documentclass{memoir} \settocdepth{subsection} ...
5
votes
1answer
594 views

Right Angle Symbol Alignment with TikZ/Calc

I used a solution from @Jake from this post Insertion of Perpendicular Symbol at Intersection of Two Lines, but the alignment is not quite right. I have my suspicions why, but I don't understand the ...
7
votes
1answer
222 views

How to perform arithmetic within siunitx?

I often put comments in my documents to remind me where a number comes from: \SI{39.68}{\milli\metre} deep % 0.31 * 128 I'd like LaTeX to calculate the product by itself. I wrote a function to do ...
4
votes
2answers
318 views

Different Results for distance by sqrt and veclen

I'm trying a simple task of drawing a tangent to a circle. While I already succeded with the tangent cs option, I also want to use the library calc for the exact intersection points. I simply start ...
5
votes
3answers
250 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 ...
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 ...
8
votes
1answer
997 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} ...
10
votes
3answers
293 views

What is the most convenient way to do general-arithmetic calculations involving lengths?

I know LaTeX can store at least two types of numbers: Dimensionless quantities (i.e. 1, pi, etc.) and lengths (i.e. 1pt, \textwidth, etc.). Is there some convenient, general way to do calculations, ...
6
votes
3answers
256 views

How can I calculate the length of the longest word in a node?

I would like to create an inline brace command \inline{} for xelatex using TikZ. The difficult part is calculating the text width for the node without hardcoding it into the tikzpicture environment. ...
3
votes
1answer
191 views

Calculating the minimum height for a node based on the size of other nodes

Consider the following example: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{xcolor} \begin{document} \def\mydist{1mm} \begin{tikzpicture}[ mystyle/.style={ ...
4
votes
1answer
187 views

Adding constant to function (vspace) argument?

How can I get Latex to add a constant to a value as part of a \vspace argument? Here's my minimal example: \documentclass{article} \usepackage{calc} \begin{document} ab %\vspace{20mm+10mm} ...
5
votes
2answers
182 views

Floating Point multiplication in custom commands

I'd like to create a custom command which creates an underscore of a given length. However, this length should be the argument of the command multiplied be a floating point constant. How can I ...
9
votes
1answer
798 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 ...
2
votes
1answer
80 views

Store a ratio value in command and then use it to recalculate a length?

I want to store a ratio value in a command, e.g. \newcommand{\ratio}{0.7}, and then use it in recalculating a length, e.g. \setlength{\somelength}{\ratio*\width}. Using lengths to store the ratio ...
2
votes
0answers
146 views

Generating pdf files that are “viewing-time” or current system-time dependent [closed]

The \FpEval{}{} function which can be used to do computations, and store the result in a variable, in latex. For details, kindly see How can I sum two values and store the result in other variable? . ...
6
votes
1answer
868 views

tikz label coordinates using mathematical expression from foreach variables

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x [count=\xi from 1] in {-3.0,-2.8,...,1.8} \draw[thin] (0,0) ++(\x,2) rectangle ++(0.2, 0.2) ...
4
votes
1answer
435 views

sum two numbers in \ifnum

I would like to implement a command in LaTeX which would sum two numbers before comparing them to a third number as follows: \ifnum #1+45>0 above \else left \fi where #1 is an angle in ...
2
votes
0answers
58 views

Storing and manipulating real numbers [duplicate]

Is there any way to store real numbers (e.g. 4.5) as variable / macro / counter / whatever in standard LaTeX (no direct Lua code) and perform the 4 basic mathematical operations with them? I need to ...
8
votes
2answers
210 views

TikZ grouping expressions in calculations

I had to do some calculations like: \node (A) {A}; \node (b) at (x,y) {B}; ((A) + (B))*2 However I could not figure out how to group it in a calc statement, I tried ($((A)+(B))*2$) and ...
7
votes
2answers
86 views

Using calc and \year to get the years from a start date automatically in text?

I would like to say, "I have played piano for 23 years" -- but this document will have to be changed every year so I remember to make it 23, then 24, then 25. Is there a way to do something like: I ...
4
votes
1answer
241 views

Manipulating arguments in newcommand

I'd like to manipulate the arguments in \newcommand. More explicitly, I'd like something like that: \newcommand{\X}[1]{ #1+1 } And if I call \X{0}, I want it to return 1 and not 0+1. Thank you :-) ...
20
votes
1answer
250 views

Using \fontdimen as an array to store data

Reading through pi.tex, I discovered the trick of using \fontdimen as an array of dimensions (which is equivalent to storing integers between ±(2^31-1)sp). Namely, \font\x=cmr10 at 1sp % or whatever ...
13
votes
5answers
588 views

Autocalculate result in math-mode

Are there any available programs/software/etc. that allow you to autocalculate and then autocomplete TeX equations? It would be great if for example, I were doing really long messy equations like 120 ...
4
votes
2answers
243 views

settototalheight issue with empty lines

I am using \settototalheight to calculate the height of the text in order to use needspace correctly. This is the code i am using : \documentclass[12pt]{article} \usepackage{graphicx} ...
14
votes
3answers
1k views

How to set a counter to double the value of another counter?

The title says it. Lets have to counters: \newcounter{myCount} \newcounter{anotherCount} I set myCount to some value for example 10 \setcounter{myCount}{10} How do I set counter anotherCount to ...
8
votes
1answer
990 views

Using let command in TikZ but want to have reference to new point later as well

I'm beginning to use TikZ and am having some issues understanding the proper way to reference my data points without specifying the precise absolute positions for all of them. An example of the simple ...
6
votes
4answers
200 views

How can I calculate within style values?

Is it possible to calculate (addition etc.) in style values? I wanted to do the following: \documentclass{article} \usepackage{tikz} \usetikzlibrary{positioning,fit,chains} ...
22
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 ...
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 ...
16
votes
3answers
719 views

square root of number in counter

I would like to get the square root of a number which I have stored into a counter. I have been using the calc package for summation and multiplication operations, but I cannot find anything like ...
13
votes
4answers
822 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 / ...
7
votes
2answers
3k views

Create a table with calculations of binomial and poisson distribution

Well, I was looking for some tables on the internet about the binomial and poisson distribution (not the cumulative ones) in LaTeX format. But I've only found the code of the cumulative distributions, ...
17
votes
1answer
510 views

Setting TikZ curve control points and preserve area of closed curve

I would like to reproduce the shown periodic table, with more correct areas. http://www.meta-synthesis.com/webbook/35_pt/relative_abundance.jpg I would appreciate any ideas to how this can be ...
12
votes
3answers
438 views

How to ensure document total page numbers is a multiple of four?

I'm producing a document (book class) that will ultimately be produced using offset lithography. It's therefore useful to ensure the total number of pages is a multiple of four by adding as many blank ...
3
votes
2answers
200 views

Undesired equal sign in beamer using \dimexpr

I'm using the following script in beamer to locate our logo at the right-most corner of all pages in the presentation, \begin{textblock}{5}(10.0, \dimexpr 0.5\headheight - 7.5pt ) ...
9
votes
2answers
200 views

Set variable with mathematical expression

I need to do something like the following, \includegraphics[width=(\textwidth - 50mm)/2]{myfig.eps} What keywords can I use to search for doing this operation? Everything I've searched for was ...
4
votes
1answer
157 views

How to get vertical size of table captions?

I found that the tabularht package, which allows to give a fixed vertical size for a tabular, does not take into account the vertical space taken up by a table's caption. It stands to reason, the ...
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 ...
1
vote
1answer
90 views

Adjust typeblocksize in light of paper size

I'm trying to figure out how to adjust the typeblocksize in memoir in light of the ratio of \paperheight to \paperwidth. Right now, I have \settypeblocksize{*}{\lxvchars}{1.414} to adjust the ...
9
votes
1answer
329 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 ...
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; ...
12
votes
1answer
1k views

How to implicitly specify column width (in a columns-like environment)?

I am using the columns environment in Beamer-documents like this: \begin{columns} \begin{column}{0.8\textwidth} %% \end{column} \begin{column}{0.2\textwidth} %% ...
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.