# Tagged Questions

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

216 views

### How to add numbers occuring in a text?

How make LaTeX to remember some numbers and output the total sum by calling another command? Consider this example: \documentclass{article} \usepackage{lipsum} \begin{document} The price of the ...
1k views

### Reducing fractions automatically using LaTeX 3

Consider the following code: \documentclass{article} \begin{document} \noindent Can I make \LaTeX{} reduce a fraction automatically?\\[\baselineskip] For example, I would like the fraction \[ \frac{...
21 views

### How can I achieve textpos relative positioning in a document set to absolute positioning?

This is as close as I've got, but I can't work out how to do the calculation so that textblock accepts it: \documentclass[11pt]{article} \usepackage[paperheight=93.884mm,paperwidth=68.992mm,margin=...
30 views

### Calculations in TikZ [duplicate]

I need to draw two tangent circles with their common tangent. I drew the first circle centered at C radius CA, the tangent AB. Now I need to find the position of the center for the second circle on ...
189 views

### Sort Numbers After Their Values

Consider the numbers 2^4, 4^2, 3^2, and 5^2 Is it possible to make LaTeX calculate the values of these numbers and then arrange then automatically according to the values? That is, in this ...
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 ...
83 views

### How to calculate a square root of the area?

I am trying to tikz-euclide the following picture (it is made in Geogebra). Two solid circles are equal. To guarantee that, the length of the red segment should be \sqrt{S}, where S is the area of ...
142 views

### Tikz and variables

I have defined two variables \def\aa{3} \def\bb{1} \def\qq{\multiply\aa by \bb} but when I try to use \qq in a \matrix command like \matrix[matrix of math nodes]{12 & \qq\\}; ktikz says: ...
33 views

I come from this question: How can I automatically calculate sums in a LaTeX table? I want to do the same but with "timing" calculations. So my example would look like this: \documentclass{article} \...
58 views

### How to convert \textwidth to mm and use the number as a command?

I am trying to convert \textwidth to other units I want and do calculations with the number (without the unit). How does one do this?
83 views

### How to create a table with fixed-width cells and use cellcolor and multicolumn to create time bars? Or: How to substitute ganttbar with tabular?

Failing to combine a gantt chart with a table I now try to avoid the gantt chart by just using a tabular environment. However I like to keep some neat features of the pgfgantt-package and I'm facing ...
39 views

### Convert count into length

I want to decrease a length by a number (count). I tried some variations with \newlength{\temp} and \addtolength but I got problems there with the minus. I also tried variants with \dimexpr. The ...
39 views

### Output age on Birthday with Calendar \usepackage{montly}

I want to display the age of multiple people on my calendar. I can get the current year to come through with \the\year, but I can't figure out how to solve an equation in the option below (part of ...
277 views

### Multiply a label by 3 and print result

I would like to create a quiz for my students where the more parts I add to the question the more points it is worth. For each extra part, I want it to be 3 more points. In the following example, I ...
83 views

### Draw path if distance is below threshold

I want to draw an intersection graph and for this purpose I have an array with coordinates. Now I loop through them and calculate the distance between the coordinates and if it below the radius of ...
229 views

### Is there a counter or variable that can be used to store non-integers?

I'm working on an invoice document which has a 'Grand Total' at the end of the document after some rows of invoice items. As such, I need to keep a running count of the total for each row. Using the ...
52 views

### Number formatting, addtocounter and calc package

I have been having troubles with the following issue: I am making an invoice template in LaTeX. I use \addtocounter to calculate values like subtotal, tax and total. This works fine, until the value ...
72 views

### In-place calculation of color with tikz and calc

Is it possible to calculate a color value like this in-place with tikz and its calc library? \filldraw[fill=black!{50-95.7/2},draw=black] (1,0) rectangle (2,1); %Gives a 'Missing number, treated as ...
6k 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 illustrate....
37 views

### Mysterious summing: when calculator 's \ADD macro adds too much inside a table

Background: In my previous question, Robert Fuster taught me how to define a global variable using calculator package. I want to define a "counter" that also works with non-integers. I thus defined ...
50 views

### Using locally defined calculator commands inside tables (tabularx)

Inside a table, I want to draw rules. Their length equals the cell length times a predefined ratio (i.e. \rule{\ratio\linewidth}{1ex}). I use the \DIVIDE{A}{B}{\ratio} function of the calculator-...
53 views

### Positioning with current axis depending on limits?

I try to specify the x axis label position below the x axis arrow at the same baseline like the xticklabels. It works fine for most plots. However, when modifying the range of the y axis with ymin=...,...
36 views

### Show calculations to table cells

I have a table with a lot of financial data. I need to show the calculations behind each financial figure. I have considered to just use footnotes for each table cell, but I guess it's quite ugly to ...
5k views

### How to produce a list of prime numbers in LaTeX

I would like to write a LaTeX script that produces all the prime numbers between the numbers n and m, where n < m. How can I do this? I feel it should not be that hard, but I cannot seem to program ...
59 views

### pfg conditional addition of a number

I have coordinates stored in \xCoor and \yCoor, and and converting these into polar coordinates to express on paper. I'm wanting this done automatically, and have been able to define: \...
2k views

### Simplifying square roots

I want to create a command that, for a given integer n, type sets a simplified square root of n. For example, the output of \rsqrt{4} \rsqrt{8} \rsqrt{18} \rsqrt{7} would be the same as that of 2 ...
5k 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 ...
90 views

### A problem drawing arcs associated to angles

I need to draw arcs to denote angles inside an equilateral triangle. To do this, I am using the arc function in tikz with the help of the calc package. However, if I use an automatic solution which ...
38 views

### How can I calculate the correct offset for fancyhdr when using geometry to change layout?

I have a document with the following configuration: a custom layout is defined using geometry in the preamble; custom headers/footers are defined using fancyhdr in the preamble; an alternative ...
56 views

### Tikz macro with calculation error

I'm very new to this so bare with me. To get the hang of macros I wanted to write a simple command to draw a square in tikz. Now I know there are a lot of ways to do this, but I want to be able to ...
661 views

### Factorial (or, even better, binomial coefficient) function

Is there a function in l3fp for calculating factorials or, even better, binomial coefficients directly?
158 views

### Writing sequence terms

What would be the best way to write out the terms of a sequence, somehow like this, but preferably aligned? Is there a way to automatically generate the terms from an equation i.e. with n² for ...
41 views

### calc package and global lengths problem in tabularx

The output of the following code is affected whether calc package is included or not: \documentclass{article} \usepackage{tabularx} % \usepackage{calc} \newsavebox{\testbox} \newlength{\testlen} \...
49 views

### Use numbers stored in a command by spreadtab

My aim is to create a command to store numbers and calculated in the table. \begin{table}[h] \npthousandsep{,} \STautoround*{0} \begin{spreadtab}{{tabular}{| l | r | r | r |}} \hline ...
257 views

### How do I draw on images embedded with \includeimage in TikZ with pixel accuracy?

I want to draw on an image which I embedded using \includeimage: \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \node[anchor=south west,inner sep=0] (image) at (0,0) {\...
184 views

### serious scientific calculating with small numbers, using different methods

I got stuck in a problem with pgfmath module. When trying to calculate the following functions values the result that gets printed out is always zero. I guess the problem is an underflow of pgfmaths ...
57 views

### Sort array of words by length

I have a long array of words which I need to show in increasing order of length. I have tried to use the package arraysort and customize a comparator. My simplified code is: \documentclass{article} ...
101 views

### Creating a heatmap using calculations and tabular environment

I know there exists pgf, and many people uses this to create heatmaps. I however am not allowed to use this package. I therefore want to create a command that enables me to color the different cells. ...
48 views

### Checking a number with calculator package [duplicate]

I have a problem about calculator package, I need check if #1 is a number or not, could I use conditional command? ex: \def\CHECK#1{ % if #1 a number \if...? #1 is a number \else #1 is not a ...
151 views

### create node of own macro with tikz

i would like to draw a network of multiple queues. To build one node i would like to make a node out of this macro (DrawStation) and give it a name. \usepackage{tikz} \usetikzlibrary{positioning} % ...
40 views

### Perform math operation with values of \labels

I use \label to index the number of items in several environments. I wish to perform the sum of the quantities reported by those labels. Here is a working example: \documentclass{article} \usepackage{...
56 views

### Creating a Test-Template

after hours of searching and trying i want to ask my special question. I'am a teacher and want to create a template for my test-document. Therefore i need to add points in every task. To control the ...
141 views

### How to increment a variable in beamer slide?

I have this code: \documentclass{beamer} \mode<presentation> { \usetheme{Warsaw} } \usepackage{tikz} \AtBeginSection[] { \begin{frame} \tableofcontents[currentsection] \end{frame} } \begin{...
131 views

### Automated Creation of Questions and Solutions for a Worksheet/Exam

Overview My title is the not the best, and I will edit it if there are any better suggestions! In a nutshell, what I am trying to achieve is to randomly change numbers in a maths question and have a ...
164 views

### Understanding etoolbox macro \deflength

The etoolbox package documentation says about \deflength: This command may be used as a drop-in replacement for \setlength. I am having trouble getting it to work with the \minof macro from the ...
122 views

### Use floating point with calc

I wanted to use a pie chart in my document and tried this code example: http://www.texample.net/tikz/examples/pie-chart/ Now this seems to work perfectly with integer values but as for floating point ...
59 views

I have a document with several commands that store numeric variables inside an extra macro. This extra macro will highlight that text so I can track them in the printed document. Like so: \...
310 views

### Delete commas within numbers

To use package{calc} for calculation, number should not include any commas. So I tried to use \def\commatonone #1,#2.00 {#1#2} to get the number without commas. \documentclass{article} \usepackage{...