{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
182 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
4answers
286 views

Sum of values spread across tables in document? (like in Word)

My document is structured as follows: * Bla bla bla Quantity | Item | Price per item | Total price ---------+----------+----------------+------------ 5 | Sandwich | 5.00 | ...
1
vote
1answer
218 views

Can I calculate a square or square root to include as coordinates in a tikz picture?

I am trying to draw the folding lines of a paper plane. This as a template for my kids to learn how to fold a paper plane. I came as far as: % based on ...
6
votes
4answers
239 views

Is there a better way to check divisibility in LaTeX?

I want to draw a trimmed ruler, for example, from 2.3cm to 3.9cm where the distance between two consecutive marks is 1mm. I have difficulty to efficiently check whether or not the counter is a ...
6
votes
2answers
135 views

Delayed expression evaluation giving wrong result

I have made my own lists. I want to refer to them outside the lists. If I do a calculation using counters at a certain point in my list hierarchy, say \alph{listcounter}, how do I freeze that result ...
0
votes
0answers
137 views

Spread tab and Calculation in Table

I tried the following, \documentclass[a4paper,12pt]{article} \usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry} \usepackage{multirow} \usepackage{spreadtab} ...
7
votes
2answers
105 views

Numerical calculations using PSTricks

Assume I have defined a constant \valueA as \def\valueA{25 2 sqrt sqrt mul } I would like to devide this value by the square root of 2, so I tried \pstFPdiv\valueB{\valueA}{2 sqrt} but this is ...
22
votes
4answers
840 views

How to add, subtract, multiply, and divide in plain TeX?

I find many cases where I need to calculate many numbers, using adding, subtracting, multiplying, and dividing, but it would save much time if TeX could simply compute these for me. This is a sample ...
1
vote
1answer
201 views

Using multicolumn and multirow together with spreadtab

I tried this piece down \documentclass[a4paper,12pt]{article} \usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry} \usepackage{multirow} \usepackage{spreadtab} ...
3
votes
1answer
336 views

Calculations in Table using spreadtab

When I use this piece, \documentclass[a4paper,12pt]{report} \usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry} \usepackage{multirow} \usepackage{spreadtab} \usepackage{url} ...
3
votes
1answer
508 views

Tikz: Scale coordinates perhaps using the calc package

I've drawn a rectangle like this: \draw[color=orange, fill=orange, opacity=0.1] (Q3term1) rectangle (Q3term2); and essentially, what I want is to do is stretch the rectangle by 10% horizontally and ...
10
votes
2answers
269 views

Lua calculation fails with a negative number

The macro runs except when the real b is negative. Why ? \documentclass[a4paper,12pt]{article} \usepackage[upright]{fourier} \usepackage[no-math]{fontspec} \usepackage{luacode,luatextra,luaotfload} ...
13
votes
1answer
170 views

Using calc-like (calc Package) Commands within LaTeX3/expl3

In my pursue to switch as much as possible from LaTeX2e code to LaTeX3/expl3, I got stuck with the usage of some of the calc package facilities. I've read of the l3calc package, but it seems it is ...
2
votes
0answers
103 views

Use input inside a spreadtab environment with calculations

My aim is to create a command for inserting tables, which will format the table, and add calculations on its values, given a file containing the raw data of the rows only. ...
6
votes
1answer
372 views

dimexpr: multiplication with constant real factor from macro

I want to multiply a constant from a macro with a deimension using dimexpr. When using real numbers the decimal point and the decimal digits are typeset behind the result and the result is a ...
8
votes
2answers
306 views

Fixed Point Arithmetic: Why does the fp work sometimes but others it errors?

Why does fixed point arithmetic like to error on parts of the code that aren't doing any math? I am using the package to improve the calculation of some angles I have it printing out, but it is ...
5
votes
1answer
113 views

How to cherry pick from datatool DB and calculate totals

I have a CSV file with current prices/item. These prices are updated regularly. I have loaded a DB with datatool. I would like to use these prices to calculate totals according to quantities I have ...
8
votes
2answers
235 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 ...
1
vote
3answers
609 views

How can I draw tikz arrows on a calculated triangle?

I am going to need a lot of vector triangles and would like to do them with TikZ. My TikZ experience is close to not existing. Therefore I would like to ask you, if there is a possibility to draw ...
5
votes
2answers
494 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} ...
5
votes
1answer
214 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
212 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 ...
22
votes
4answers
548 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
111 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 ...
2
votes
1answer
181 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 ...
7
votes
2answers
313 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 ...
3
votes
1answer
597 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
180 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
678 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
302 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, ...
16
votes
4answers
663 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 ...
1
vote
2answers
219 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
489 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
184 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
269 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
225 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 ...
36
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 ...
7
votes
1answer
761 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
273 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
198 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
177 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
154 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
157 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
649 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
78 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
130 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
701 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
342 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 ...