{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

2
votes
1answer
188 views

Computing a simple maths calculation and use the result as page numbers in the Table of Contents

Following up this question here, I am looking for a way to compute a simple maths calculation inside the document and let the result of this calculation be the value that appears as page number in the ...
6
votes
1answer
696 views

Extract coordinates from 3D point

How do I extract coordinates from a three-dimensional point defined when using tikz-3dplot? I would like to perform some calculations on these (more specifically a cross-product of two vectors), but ...
12
votes
2answers
4k views

How to use \widthof as parameter to \kern

I sometimes encounter a problem when I attempt to use \widthof from the calc package, and don't know why. In the past I have just worked around it using a two step process of defining a \newdimen{} ...
14
votes
2answers
542 views

Is there a better way to do intersections and calculations with relative coordinates in TikZ?

I've been doing many TikZ diagrams lately and every so often I encounter a situation where I am forced to use some temporary coordinate in a \path. In the following short example, the problem is ...
8
votes
1answer
357 views

calc package incompatible with \setlength in \g@addto@macro?

I want to systematically have some indentation in \parboxes and minipage environments. To do this, I add the following code in the preambule of my LaTeX file: \makeatletter ...
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} ...
9
votes
2answers
1k views

“Arithmetic overflow” error

factorials up to 12 are handled.How can make it to compute beyond that? Error: “Arithmetic overflow \documentclass{article} \begin{document} \newcount\n \newcount\p \newcount\m ...
18
votes
9answers
2k views

fibonacci numbers

Hi I am trying to do Fibonacci below is the code but I am getting some error \newcount\n \newcount\np \newcount\npp \newcount\m \newcount\f \def\fibonacci#1{{\ifnum #1<3 1\else \np=1\npp=1\m=3 ...
7
votes
3answers
3k views

Line through two points with offset in TikZ

I could not find a native command in TikZ allowing to draw a line going through two specified points where an offset can be controlled. So far, I'm using the calc extension to perform what I need but ...
4
votes
2answers
292 views

Writing/Modifying Package

There is a package I'm trying to modify that essentially displays a grid. It uses counters to increment the distance. I want to change the distance each step instead of adding a constant value. In ...
4
votes
1answer
1k views

Can't find TikZ library calc

I've been googling for some time now, and can't find the manual for the TikZ library calc. All I see is people using it. Where can I find the manual or some info? Is it the same as the LaTeX package ...
5
votes
1answer
136 views

How to calculate with metadata in footer

I have footer that draws on a svn version data field (package: svn-multi). I would like to perform a simple calculation that subtracts a number from the reported version. The footer code is ...
1
vote
1answer
893 views

Sequent Calculus

What is sequent calculus? See wiki: http://en.wikipedia.org/wiki/Sequent_calculus So basicaly I'd like to produce something like this: Maybe using Tikz?
2
votes
2answers
684 views

Templates for generating timesheets

Are there templates for generating weekly time sheets in LaTeX? Ideally something that would minimize duplicate entries by computing totals and days-of-week.
20
votes
3answers
2k views

Extract first & last characters of macro argument?

In LaTeX, how do I extract/isolate/determine the first and last characters of a macro argument? Specifically, in the case I'm dealing with, the argument happens to be a base-10 integer (call it N). ...
7
votes
3answers
2k views

How to Intersect an arc with a line without calculating the angle

I'd like to draw an optics-related figure, for which I need to draw several beams with varying opening angles, which will need to be labeled. What I've come up at the moment (boiled down to a minimal ...
3
votes
1answer
1k views

Multiplying a length by a factor

I am trying to create a package that will use grid typesetting (in the humanities, so not much of a problem) but that should allow the user to freely set the \baselinestretch. I am using the memoir ...
11
votes
3answers
554 views

Calculating checksum

I would like to calculate a checksum in LaTeX. My problem is that I don't know how to get the numeric value of a char. Here is the pseudo code of the algorithm: var input = "123456789"; car output = ...
7
votes
2answers
952 views

Add two lengths in raisebox argument, without the calc package

I've seen people use such constructs as \raisebox{-\height+\baselineskip}{...}, which works well using the calcpackage. What equivalent would you use to achieve the same behaviour without the calc ...
6
votes
2answers
2k views

Coordinates A, B: compute |B-A| and angle between +x and (B-A)

This question has two parts: why is the angle computed always 0 (should be 45) what is a straightforward way to compute distance between coordinates (there is How can I compute the distance between ...
4
votes
1answer
470 views

Prevent tikz to calculate

I just played with an answer to a question I asked here some time ago: Divide a rectangle into n times k equal cells. I wanted to be able to generate the list of points in a separate macro, however ...
17
votes
6answers
2k views

Checking if a number is a multiple of 4

Using etoolbox, ifthen, or another form of conditional checking, how can I check if a value is a multiple of 4? E.g. if the number is 4, 8, 12, 16, etc., then it returns "true".
19
votes
2answers
4k views

How can I compute the distance between two coordinates in TikZ?

Given two points (defined, for instance using nodes), I want to compute the distance between them. Is there some build in functionality in tikz to do this? If not, how can it be done using the ...
13
votes
3answers
2k views

How can I calculate the difference of 2 counters (pageref)?

How can I calculate the difference between 2 counters (like page numbers), so that pdfLateX outputs "3" in the last line of my example? and how could I calculate the difference between the "current" ...
10
votes
2answers
795 views

Calculating percentage

I have tried to use the calc package to write a macro which prints a percentage based on two numbers. E.g.: \printpercent{100}{200} should display 50% as 100 is the half-way point of 200. I have tried ...
4
votes
1answer
296 views

Why don't modern TeX variants support floating point?

I understand that, at the time when TeX was devised, no single standard for floating-point calculations was available. But these days, there's IEEE 754. Why doesn't any TeX variant support it? ...
5
votes
2answers
860 views

Anomalies and a question regarding a line-filling rule

I've created a command for filling a line with a black rectangle. It's called \fullrule, you can find it in the code below. I have several questions regarding this MWE: \documentclass[10pt]{article} ...
9
votes
6answers
1k views

Parse simple arithmetics and return the result

I want a command \ca which takes a simple arithmetic calculation as an argument and returns the result with proper decimal places. Additionally I want an boolean argument which decides if only the ...
16
votes
3answers
880 views

Using command to compute sum?

I must admit this sounds like an easy question. I'm creating a grading model for a homework assignment, and I'm adding the maximum amount of points to each question. Is there a way to have LaTeX ...
35
votes
7answers
6k views

How do I calculate n modulo 3 in LaTeX?

I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
27
votes
2answers
41k views

How to fit a large figure to page [duplicate]

Possible Duplicate: Best figure size adjustment when dealing with different image sizes Given: a large figure, whose height:width ratio is unknown. Todo: Include this fig in LaTeX, such ...
9
votes
2answers
2k views

How to enable use of minus and plus in tex documents?

I see many cls files using plus and minus operators to set lengths. How can I use these operators (or some equivalent macro(s)) to do something like the following? \setlength{\lengtha}{.5\textwidth} ...
23
votes
2answers
7k views

Problems with TikZ calculations

When can I use functions and do calculations in TikZ? How do I make this work: \draw (0,0) arc(0:90:sqrt(15)); %not ok why is this working: \draw (0,0) arc(0:asin(1):5); %ok with ...
19
votes
2answers
6k views

Is plotting exponential graphs a known source of bugs in TikZ?

I want to plot $y = 2^x$ over a small domain. Unfortunately, even though tikz (v 2.1) seems to be able to calculate 2^{negative numbers} it is not plotting them correctly. My minimal example is: ...
5
votes
1answer
1k views

Insert relative date and time specifications?

How can I specify a relative date and let LaTeX insert the resulting absolute one? For example like this: \somedatecommand{next thursday} Which should result in: Thursday, 20.10.2011 Or: ...
8
votes
4answers
357 views

Calculating the the exact width of the text and a lettrine

This is one question which technically could be broken into two minor questions. I am using a lettrine and some verse text, but the calculation to determine how much to indent the text does not ...
35
votes
6answers
19k views

How can I sum two values and store the result in other variable?

In LaTeX2e,how can I sum two values and assign them to other variable? I want to compute something like: var=\textwidth - 1cm And if both were constants: var=1+1
7
votes
3answers
388 views

Convert hour to decimal number

I'm trying to make a command for converting an hour (ex: "14:17") to a decimal value (hour + min/60 = 14.28333333333) for use in a TikZ schedule : \creneau[day=1, start=13.5, ...
9
votes
2answers
2k views

How can I show base-2 long division?

I am writing a report in Latex and need to represent the CRC computation. So basically, I need to show the Paper-n-Pencil Method of Long Division in LaTeX. Any idea how I can approach this problem ? ...
0
votes
1answer
228 views

How should I express my length calculation to minimize rounding errors?

I have an input file as follows. % Test.tex \documentclass{article} \usepackage{pstricks} \psset { linewidth=0.01 } \newcommand\All{0.1} \newcommand\Left{-\All} \newcommand\Right{\All} ...
2
votes
4answers
741 views

Is there a simpler way to do arithmetic in PSTricks?

I want to animate PSTricks diagram, so looping is intensively used. I have 3 global variables \START, \STOP, \DELTA that should be declared in the preamble. The remaining variables in the body will ...
3
votes
4answers
285 views

What is the TeX equivalent for the following C# nested loop?

I need a nested loop to animate PSTricks diagrams. In C# or C or C++, I usually write as follows. int N=6; for(int x=0; x<N; x++) for(int y=x+1; y<N; y++) Console.WriteLine("({0}, ...
6
votes
1answer
633 views

How to divide a length-valued macro by a dimensionless-valued macro?

I have attempted to do as follows, but it does not work. \documentclass{minimal} \usepackage{pstricks-add} \psset { xunit=\dimexpr1cm/\psPi\relax, yunit=1cm } \begin{document} ...
1
vote
2answers
785 views

What is the correct syntax to do arithmetic for length and dimensionless macros?

I want to set papersize based on PSTricks settings. The PSTricks settings may be a value without dimension and/or a value with dimension. Honestly I have not read the TeXBook because of my laziness. ...
3
votes
1answer
283 views

How to translate this scenario to LaTeX looping macro?

I want to slice an image into 8 parts, i.e., 2 rows by 4 columns. Each part is on a single page as follows. The gray frame is the Acrobat Reader background, so don't think it is a part of the output I ...
2
votes
1answer
425 views

How to improve accuracy when working with PSTricks?

I have tried this with TikZ that produces the same issue, you can try Leo's solution here. In other words, this issue is NOT specific to PSTricks. The hidden idea is to avoid cropping with pdfcrop ...
15
votes
1answer
2k views

Determine height and depth of letters relative to the font size

I would like to scale graphical elements (like images, tikz and tikz-timing diagrams) relative to the font size, so that they have the same height as an normal uppercase letter (i.e. X or M; I noticed ...
6
votes
3answers
1k views

Having trouble dividing lengths with calc package

What I want is something like \resizebox but which I can give a maximum height and width to, it will make it fit into those bounds, and not distort the image. (\resizebox, of course, always makes it ...
3
votes
1answer
294 views

How does spreadtab know it is a number?

Using spreadtab with glossaries I define a glossary entry A with a field user1=12. Now, if I call this field in a spreadtab table with \glsentryuseri{A}, spreadtab does not recognize it as a number. ...
61
votes
3answers
17k 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 ...