{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

1
vote
1answer
41 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 ...
3
votes
2answers
91 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} % ...
3
votes
1answer
32 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} ...
2
votes
1answer
42 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 ...
3
votes
2answers
93 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} } ...
2
votes
2answers
105 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 ...
12
votes
1answer
133 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 ...
4
votes
1answer
162 views

Is there a counter or variable that can be used to store numbers with decimals?

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 ...
6
votes
1answer
58 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 ...
3
votes
2answers
47 views

overloading functions of the fp package

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: ...
12
votes
2answers
302 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} ...
2
votes
3answers
99 views

Evaluate binomial coefficient with \pgfmathtruncatemacro

How is it possible to evaluate complex formulas like \binom{2^{4}-3}{2^3} with \pgfmathtruncatemacro ? I want this to evaluate to 1287. What already works: \begin{tikzpicture} \foreach \l ...
2
votes
2answers
72 views

Date Calculations (output should be the fixed day of the month)

I'm building a LaTeX document that already got the date from other files. The date showed as 23 November 2015 as the example (by \today). Then I need to output another date related to this original ...
8
votes
1answer
83 views

Struggle with floor- and ceiling-functions in pgfplots

Could anyone help me with this struggle? I don't get, why the floor- and ceil-functions in the axis-environment of pgfplots and in floating text differ from each other. Aren't they both processed by ...
4
votes
2answers
120 views

Calculation of an angle in tikz (fraction of light) including sin^-1

I want to calculate the deviation angle \beta with the law of Snellius in a tikzpicture. My code is \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{array} ...
9
votes
1answer
608 views

Resources For Calculating Average Sentence Length

I'm writing my masters thesis and my supervisor has picked up my sentence structure, in that they are too long. She commented that Microsoft Word has a feature to investigate 'large' sentences. How ...
3
votes
3answers
65 views

Getting the `\pageref` out from under `hyperref`

I thought I was pretty cool when I modified \ref to also print a page number when the referenced float was more than a few pages back. But I really want it to be a nice link using the hyperref package ...
13
votes
2answers
591 views

Factorial (or, even better, binomial coefficient) function

Is there a function in l3fp for calculating factorials or, even better, binomial coefficients directly?
3
votes
0answers
29 views

How to do math on overlay arguments using pgfkeys (handle numbers and ranges)

Context I'm trying to do some basic operations on arguments on pgfkeys, and got stuck while trying to do simple arithmetic on them. Thankfully, egreg gave a nice solution for handling the arithmetic ...
0
votes
2answers
81 views

Numerical calculations inside table environment

I am doing a coursework in mechanics and would like to write both the theory and calculations in LaTeX. However, as design is iterative process, I would like to escape the tedious cycle of: Select ...
4
votes
1answer
29 views

How to do math on pgfkeys arguments and asign them to other keys

I'm trying to reduce the work load of applying some overlays over and over with different numbers. However, I need to compute for a given frame the next or previous one, thus needing to do simple ...
27
votes
5answers
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 \[ ...
79
votes
3answers
22k views

Get width of a given text as length

Is there a TeX command that returns the width of a given text as length value, so that I can use the result directly as a length argument of another command? I mean, I would like to have a command ...
11
votes
4answers
602 views

Using LaTeX as calculator [duplicate]

I know that exist several packages, like fp that allow to make all kinds of computations. But I do not understand the correct way to use them. I need some simple examples of multiplication and ...
4
votes
1answer
105 views

Problem with calculutor, calculus

MWE \documentclass[a4paper,11pt]{report} \usepackage[turkish]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage{calculator} % 2014/02/20 v.2.0 ...
4
votes
3answers
371 views

Perform spreadsheet-like calculations and display formula and result

Currently I am performing calculations using excel and manually formatting them for printing using an online LaTeX equation editor. The end result looks something like this: As you may imagine this ...
3
votes
1answer
109 views

Using a macro inside a Tikz coordinate calculation

I am trying to create a general macro that prints a particular custom character, based on an answer to a previous question of mine. Here is a minimal (non-)working example: %!TEX encoding = UTF-8 ...
2
votes
3answers
59 views

How can one number be divided by another number to give a real number result (not an integer)? [duplicate]

How could a function a bit like basiceval be written to give a real number result as opposed to an integer, making the third calculation here more accurate? \documentclass[american, a4paper]{report} ...
6
votes
1answer
84 views

calc breaks assoccnt? [closed]

I want to use totcount to get the number of parts and chapters in my document. To get the correct number of chapters in the presence of appendices, I use assoccnt (see totcount gives wrong chapter ...
4
votes
2answers
141 views

Tikz: Math with coordinates

I need to extract the coordinates of a node into a variable. I've tried \pgfextractx \documentclass[11pt]{article} \usepackage{fp} \usepackage{tikz} \usetikzlibrary{calc} ...
3
votes
2answers
66 views

Show variable name, measurement unit and value in a single command invocation

I am using the fp package to write a coursework in mechanics and calculate the numerical values on the fly. Here is some example code: \documentclass{article} \usepackage[nomessages]{fp} % ...
2
votes
1answer
101 views

TikZ Dimension too large Matrix Transform [closed]

I'm working on some matrix transformation code, and I keep getting ! Dimension too large. I traced it down to the following simple example. The problem does not occur when 2e-17 is replaced with ...
2
votes
1answer
64 views

Calculation in a TeX function. How to do it?

I don't know anything of TeX but would like to improve a function. Here is the initial function: \newcommand{\setnewvsize}[1]{% \global\paperheight\dimexpr#1+\initialVerticalInset\relax% ...
3
votes
2answers
95 views

identify pieces of text automatically generated from input and new command

I have a document where many of its values are defined in a separate file via \newcommand, and added to the main document using \input in the preamble. The file being included is the output of a ...
13
votes
3answers
578 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 ...
6
votes
4answers
262 views

Error using \widthof inside tikzpicture

\documentclass{article} \usepackage{tikz} \usepackage{calc} \begin{document} \begin{tikzpicture} \newlength{\TextWidth} \setlength{\TextWidth}{\widthof{Text}} %\node[draw,text ...
3
votes
1answer
107 views

Determine width of a milticolumn cell

I am attempting to draw a rectangle within a multicolumn, and would like it to span the width of the cell and be consistant with a similar rectangle drawn in a standard cell. I am struggling to ...
4
votes
1answer
323 views

Why do modern TeX variants not support floating point arithmetic?

I understand that, at the time when TeX was devised, no single standard for floating point calculations was available. But, these days there is IEEE 754. Why doesn't any TeX variant support it? ...
1
vote
0answers
92 views

Insert negative of \widthof into \hspace without defining a newlength

Following MWE does not work: \documentclass{article} \usepackage{calc} \newlength{\charwidth} \setlength{\charwidth}{\widthof{$-$}} \begin{document} \centering $\infty$ \centering ...
5
votes
2answers
270 views

Enumerate every third item

Is there a way to have a enumerate environment that increment the counter every three item? I already see this question: Enumerate pattern: 1, 1, 2, 2, 3, 3, ... , etc but I'm looking for something ...
22
votes
2answers
627 views

Sum of finite series using LaTeX 3

Is it possible to calculate the value of a finite series, say, using LaTeX 3?
12
votes
3answers
386 views

Drawing the three altitudes of a triangle with TikZ; incorrect orthocenter

You probably know that if you draw all three altitudes of a triangle, they will meet at a single point, the orthocenter. I'm trying to draw a picture that shows the intersecting altitudes with TikZ ...
4
votes
1answer
56 views

Calculator package and Math Times Pro 2

When I try to use the calculator the mtpro2 package at the same time I get an error message. Recently I found out that this issue has something to do with the \SQRT command. ...
15
votes
2answers
8k views

simple arithmetic on index of foreach statement in tikz

Is foreach really a tikz statement or is derived from some other package? I would like to draw a horizontal axis with 7 ticks spaced 1 cm apart. I'd like to place a label under each tick that is the ...
5
votes
3answers
159 views

Comparing calculated real numbers

"\ifdimless" can compare two real numbers. But, how can we feed the result of a calculation to this function ? \documentclass[]{article} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{etoolbox} ...
3
votes
1answer
73 views

Using a variable to calculate the tax on an invoice

I've customized a class to obtain the tax value and also the total amount in an invoice. This is the portion I need to modify: { \hline\hline\hline {Valor venta} & & & {S/. \total{cost}} ...
4
votes
1answer
69 views

Length operation within a newtcblisting

Consider the following code: \documentclass[10pt,letterpaper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{calc} \usepackage{tikz} ...
17
votes
4answers
12k 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 ...
1
vote
1answer
20 views

Unable to make crop work with dynamic length and width from calc

I am using using XeTeX, Version 3.1415926-2.4-0.9998 (TeX Live 2012/W32TeX) to design a book cover. I thought of writing a generic document with customizable sizes of book width, height, bleed and ...
2
votes
1answer
21 views

Package that receives a number #1 and return #1-1

I'm working with a counter but I'm having some problems with the index. This is my problem: I'm using a command with \arabic{#1} with some input #1. But I need to print \arabic{#1-1}. I would like ...