{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

5
votes
1answer
281 views

How to preserve lenghts to use with \includegraphics scaling, when calculating them with pgf

This question is related to my earlier question here: How to define a macro that uses image width and height to define a variable for later use . There you can find a full MWE of the problematic code. ...
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 ...
23
votes
4answers
571 views

Day of the year

I'm using the day of the year a lot in my documents and I wonder if I can have LaTex calculating it for me? Example: 2013178 where 2013 is (surprise) the current year (which I know could be achieved ...
0
votes
1answer
117 views

Autosum Table contents in LaTeX

I am trying to add the contents of a latex table, having something like this in mind: How can I automatically calculate sums in a LaTeX table? But this solution does not work for me... Is there any ...
3
votes
0answers
32 views

Integer operations on cross references [duplicate]

I would like to perform integer operations on a cross reference. \documentclass{article} \usepackage{etoolbox} \begin{document} hello \label{here} \ifnumequal{\pageref{here}}{1}{You are on the 1st ...
3
votes
1answer
238 views

Calculating coordinates with postscript [duplicate]

I want to calculate coordinates for some lines using pstricks. How can I do this? Example: I want something like (0.5*cos(45) + 8, 0.5*sin(45) + 8) and use coordinate pairs like this one to ...
8
votes
2answers
425 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
1k 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
199 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
961 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
432 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
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. ...
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
270 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
617 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
325 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
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 ...
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
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} ...
10
votes
3answers
295 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
259 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
195 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
191 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
186 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
826 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
148 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
897 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
452 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
211 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
87 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
243 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
254 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
592 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
250 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
1k 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
202 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} ...
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 ...
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 ...
17
votes
3answers
749 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
863 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
519 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
441 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
203 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
158 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 ...