{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

4
votes
4answers
116 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
84 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 ...
2
votes
1answer
91 views

TikZ Dimension too large Matrix Transform

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 ...
4
votes
1answer
313 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
36 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
244 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
588 views

Sum of finite series using LaTeX 3

Is it possible to calculate the value of a finite series, say, using LaTeX 3?
23
votes
5answers
1k views

Reducing fraction using LaTeX 3

Consider the following: \documentclass{article} \begin{document} \noindent Can I make \LaTeX{} reduce a fraction automatically?\\[\baselineskip] For example, I would like the fraction \[ ...
12
votes
3answers
281 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
39 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. ...
14
votes
2answers
6k 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
115 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
40 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
47 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} ...
11
votes
4answers
451 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 ...
17
votes
4answers
9k 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
14 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
16 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 ...
3
votes
1answer
26 views

Computation of size in titlespacing

Consider the following example: \documentclass[11pt,a4paper]{book} \usepackage{lipsum} \usepackage{titlesec} \newlength{\textsize} \makeatletter \setlength{\textsize}{\f@size pt} \makeatother ...
7
votes
2answers
351 views

Length plus minus other length?

Consider the following example: \newlength{\textsize} \makeatletter \setlength{\textsize}{\f@size pt} \makeatother \setlength{\parskip}{12pt plus 1pt} % WORKS \setlength{\parskip}{\textsize plus ...
1
vote
1answer
34 views

Inline calculation gives `Could not parse input` error in PGFplots

The inline calculation exp(\tick) in PGFplots gives me a Could not parse input error when compiling the code \documentclass[margin=1cm]{standalone} \usepackage{pgfplots} \begin{document} ...
2
votes
1answer
127 views

Tikz coordinate calculations inside foreach

As part of a drawing that will go with an explanation of diffraction, I want to draw the "outer rays" of a beam of light and draw several rays in between. An MWE of how I'm going about this is shown ...
1
vote
0answers
24 views

Convert decimal to integer in Visual TeX IDE [duplicate]

I want to convert decimal number to integer in latex program with Visual Tex IDE. I found this function \pgfmathparse{ceil(2.7)} which requires installing the package pgfmath and pgfkeys. And after ...
2
votes
3answers
46 views

Using reference labels in mathematical calculations

EDIT: This answer points to a good solution. I wanted to use reference labels in mathematical calculations and was under the impression that if I use the calc package, it will be rather ...
2
votes
1answer
52 views

Make \droptotalpoints look like \droppoints (exam documentclass)

To save typing, I have \newcommand{\q}{\question[1]} defined in my exam documentclass. Then, after the question, I use \droppoints to get [1 pt] printed in the right margin. But sometimes, my ...
5
votes
2answers
149 views

Missing number, treated as zero with amsmath and calc

This simple code produces "Missing number, treated as zero" \documentclass{article} \newcounter{test} \newcounter{testtwo} \usepackage{calc} \usepackage{amsmath} \begin{document} ...
5
votes
1answer
273 views

Simple arithmetic in an exam

How can I do some simple calculations in LaTeX? Specifically, I want to divide \numpoints (part of the exam package) by 1.10. That is, I want to do something like this: Grade: ...
53
votes
11answers
3k views

How can I define a mathematical function as a LaTeX macro?

I am attempting to create a usable function within LaTeX such that its inputs are transformed mathematically. However, I cannot find any documentation that can perform such mathematical function ...
1
vote
3answers
101 views

Multirow and rotated column headers

I want to typeset a table with rotatetd column headers (so far it works) stretching over multiple rows. The problem seems to be that multirow does not adjust the tables row heights, thus I have to do ...
2
votes
1answer
55 views

Why is \glueexpr used in etoolbox's \deflength instead of \dimexpr

Consider the following snippet from etoolbox: \newrobustcmd*{\deflength}[2]{% \ifundef{#1} {\etb@noglobal\etb@err@nolen{#1}}% {#1\glueexpr#2\relax}} Maybe I do not understand the ...
4
votes
1answer
45 views

TikZ: Move points towards center

I want to move a set of points towards the center of my figure, but I want the distance to depend inversely on the relative distance to the center. Thus, for instance move a point at (-2,-3) to ( -2 - ...
26
votes
3answers
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 ...
6
votes
1answer
96 views

Modifying the equation number with simple calculation

I am trying to modify the equation numbering as follows \renewcommand{\theequation}{FFF(\arabic{SomeCounter}).\arabic{equation}}, where SomeCounter is a counter defined as \newcounter{SomeCounter} ...
4
votes
0answers
68 views

guess a number proportional to another [closed]

This is a challenging question. I am not sure how to begin coding it, or whether it is easily possible in TeX. I wish to define a command that takes in input of a simple formula such as Z = X x N + ...
9
votes
4answers
424 views

Chain addition mod 10

Is it possible in LaTeX create a table-like structure that represents successive modulo-10 addition of the individual units modulo 10 with wrap-around? This is referred to as chain-addition. For ...
5
votes
1answer
138 views

Calculations in PGFplots \addplot3 inline table

Plotting a rectangular patch with the code \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \addplot3[patch,patch ...
5
votes
1answer
96 views

Calculate quartiles of data set

Comment: The following code is taken from egreg's answer here. Code: \documentclass{beamer} \usepackage{lmodern} \usepackage{booktabs} \usepackage{siunitx} \usepackage{xparse} \ExplSyntaxOn ...
2
votes
1answer
189 views

Calculating a point in TikZ that completes a right trangle?

I am trying to draw an incline plane free body diagram for my Physics class ( a little like the one pictured here): Currently, my code looks like this (using TikZ, tkz-euclide, TiKz libraries calc ...
6
votes
1answer
132 views

Calculate axis limits depending on depicted data

In a pgfplots axis environment, I want to make the axis limits dependent on the depicted data or some other data. Consider the minimum working example \documentclass{standalone} ...
1
vote
3answers
297 views

How to calculate a percentage and use result in progressbar?

With the progressbar package, I want to show bars on pages depending on a counter. Progressbar works like: \progressbar{0.7} I use the calc package anyway, so I thought it should be easy to ...
30
votes
7answers
4k views

How to use \pageref{foo} as a number?

What I want to do is to show a "progress bar" in the header to show how far you are in the document, by making a rule with width pagenumber divided by total pages times the paper width. This is what ...
3
votes
1answer
72 views

Parse numerical value from glossaries variable

Can I parse the text returned from \gls*{...} and get latex to recognize it as a numerical variable so that I can use it in a calculation? This calculation could be done using calculator, fp, calc or ...
2
votes
1answer
154 views

Tikz 3d trimetric view coordinate calculation bug

I'm trying to draw a line in the x-y-plane and circles in the y-z-plane at constant x position. Problem is, that the circle is far out of position (x-coordinate of center point of the circle is ...
1
vote
1answer
51 views

How to print a past value of a counter [duplicate]

I have this counter which I have defined using \newcounter{myCounter}. Printing the value of myCounter can be easily done via \arabic{myCounter}. How can I print the value of (myCounter - 2)?
5
votes
1answer
117 views

Does anyone have an explanation of the algorithm for calculating weeknumber by Taco Hoekwater?

Taco Hoekwater wrote an algorithm in 2006 calculating the weeknumber. The algorithm mostly computes the weeknumber correctly, but apparantly misses out for the first 4 days of 2015. Without an ...
4
votes
1answer
165 views

Is it possible to use the width of one TikZ node to calculate the width of another?

Question Is it possible to store the variable width of a node and use that width to calculate the text width of another node in TikZ? Example I have a list of similar nodes side-by-side (inline, ...
8
votes
4answers
772 views

ConTeXt / e-TeX Real Numbers?

I've been using LaTeX for about 6 years and the calc package for a long time. Therefore, not being able to use real / floating point numbers was never really a problem. I've been pouring over the ...
8
votes
3answers
597 views

What is the best way to do math inside LaTeX macros?

I'm interested in writing a little personal package (or sharing it if it's actually useful) to speed up typesetting Trigonometry. I'd like commands like ...
4
votes
1answer
79 views

How can I calculate the distance added between a title and a titlerule?

Question How can I calculate the distance after a title such that I can place a node where the title rule would go? Example I would like a bar to drop from the top righthand corner of the page down ...
8
votes
3answers
4k views

Multiply the value by decimal number in latex?

I used the following construct quite often: \includegraphics[width=\textwidth/2]{pic.png} But when I try to adjust the size a small bit, like this: \includegraphics[width=\textwidth*0.45]{pic.png} ...