{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

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
911 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
288 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
245 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
189 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
175 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
176 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
755 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
141 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
824 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
393 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
203 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
85 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
227 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
242 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
562 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
229 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} ...
13
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
927 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
193 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} ...
20
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
5k 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
688 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
763 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
2k 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
501 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 ...
11
votes
3answers
428 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
197 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
196 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
155 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
87 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
318 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.
10
votes
2answers
596 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? ...
5
votes
1answer
114 views

How to calculate the number of cells per line

Assume I have a table with a dynamic number of rows and columns, and I want to fill the table with n elements. Assume an element has the constant length x, and I want to say make floor(linewitdth/x) ...
2
votes
1answer
1k views

\dimexpr \numexpr & calc package

Why doesn't this work? I use Windows, TeX Live 2012 and pdfLaTeX \documentclass{article} \usepackage{calc} \newlength{\perclenght} \setlength{\perclenght}{% \dimexpr% ...
4
votes
1answer
1k views

Calculate parbox width to make it meet the page border?

I'm using the program package to typeset my algorithms. I want my comments to have a light gray background, therefore I'm using colorbox with a parbox inside (for multi-line comments). Now the ...
12
votes
3answers
321 views

Arithmetic in arguments to the geometry package

I'd like to use the geometry package to auto-crop the output of my LaTeX (so that it looks bigger on-screen as I'm editing). I have found a way to remove the margins completely and brutally: ...
4
votes
2answers
228 views

divide table cells by a certain amount

I made a mistake in the values that i put in the table. I need to divide all the values by 105. Is there a method where i can do it without having to replace this with a completely new table ? % ...
2
votes
1answer
108 views

Counting lines and making calculations

This code snippet provides a way to highlight lines in a listings environment. If you consider the following line, though: \emphline{1-6} {7} {8-15} {potencia.f95} You'll notice how the #1 and the ...
11
votes
2answers
894 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 ...
5
votes
2answers
134 views

Can you add a constant value to a length macro?

I have a box that's the full width of the page. I would like to offset it back into the margin a little, but when I do that it no longer reaches the edge of the page. Is it possible to keep using a ...
3
votes
1answer
319 views

convert outcome of reference to regular number

Is it possible to transform the outcome of a reference (e.g., a line number) to a regular number that I can use in a calculation? I have this (and works fine): \FPeval{\result}{clip(5+6)} $\result$ ...
24
votes
4answers
607 views

duodecimal page number

I would like to have page numbers in my document written in base 12. Here's an MWE \documentclass[12pt]{article} \usepackage[paperheight=1.8in, textheight=0.8in]{geometry} ...
4
votes
1answer
632 views

Can't get \fancyheadoffset to work

I have loaded the fancyhdr package and I want to make the headers and footers wider (clamp them to the margin), so I inserted the following line after the package has loaded: ...