{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

8
votes
2answers
3k 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
880 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 ...
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
286 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
132 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
629 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
560 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.
19
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
829 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
475 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 = ...
5
votes
2answers
707 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
440 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".
16
votes
2answers
3k 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 ...
12
votes
3answers
1k 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" ...
9
votes
2answers
658 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
278 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
733 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
930 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
697 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 ...
33
votes
7answers
5k 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.
21
votes
2answers
28k 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} ...
21
votes
2answers
5k 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 ...
17
votes
2answers
4k 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
781 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
336 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 ...
29
votes
6answers
13k 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
363 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, ...
8
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
214 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
668 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
274 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
541 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
668 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
259 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
401 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 ...
13
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 ...
2
votes
1answer
285 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. ...
51
votes
3answers
12k 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 ...
9
votes
1answer
4k 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 ...
2
votes
1answer
4k views

TikZ Coordinate calculation - calculate coordinates separately

I'm trying to calculate coordinates based on existing coordinates but each coordinate individually. The first thing which is unclear to me is how to define scalar variables. I can define coordinates ...
12
votes
2answers
952 views

Where is the left-hand margin?

I'm working on the TikZ-from-TeX-SX package, specifically developing the code for putting equation numbering at places within a tikzpicture environment. To do this, I need to know where the text ...
6
votes
2answers
761 views

“Pretty-printing” numbers with significant figures

I like to use LaTeX to display data in figures and tables. I've used arrayjobx.sty and fp.sty to extremely good effect to handle data that comes out of, e.g., Excel or other Windoze-world data ...
2
votes
1answer
1k views

Calculating position in tikz

I'm trying to do calculation to be used in tikz. Here is my current code: \def\monthtabpos#1% {\ifthenelse{#1<7} {\dimexpr \numexpr -3*#1 \relax cm} {\dimexpr \numexpr -3*(#1-6) \relax ...
19
votes
4answers
4k 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 ...