{calculations} is about calculations in (La)TeX documents. A popular package is calc.
4
votes
2answers
143 views
divide table cells by a certain amount
I made a mistake in the values that i put in the table. I need to divide all the values by 105. Is there a method where i can do it without having to replace this with a completely new table ?
% ...
1
vote
1answer
71 views
Counting lines and making calculations
This code snippet provides a way to highlight lines in a listings environment. If you consider the following line, though:
\emphline{1-6} {7} {8-15} {potencia.f95}
You'll notice how the #1 and the ...
8
votes
2answers
407 views
Compute the x distance between two nodes
Is there a way to define a macro which would evaluate to the x part of the distance between two nodes? I know there are the point registers \p and the correspoding \x commands, but I find them rather ...
5
votes
2answers
97 views
Can you add a constant value to a length macro?
I have a box that's the full width of the page. I would like to offset it back into the margin a little, but when I do that it no longer reaches the edge of the page. Is it possible to keep using a ...
3
votes
1answer
107 views
convert outcome of reference to regular number
Is it possible to transform the outcome of a reference (e.g., a line number) to a regular number that I can use in a calculation?
I have this (and works fine):
\FPeval{\result}{clip(5+6)} $\result$
...
20
votes
3answers
402 views
duodecimal page number
I would like to have page numbers in my document written in base 12. Here's an MWE
\documentclass[12pt]{article}
\usepackage[paperheight=1.8in, textheight=0.8in]{geometry}
...
4
votes
1answer
255 views
Can't get \fancyheadoffset to work
I have loaded the fancyhdr package and I want to make the headers and footers wider (clamp them to the margin), so I inserted the following line after the package has loaded:
...
2
votes
0answers
281 views
Project management tables (with cost “spread sheets”) using spreadtab [closed]
I'm trying to create a simple project management table detailing costs per task and milestone, using spreadtab:
The code for the latter is:
\begin{spreadtab}{{tabularx}{\textwidth}{lXllr}}
\toprule
...
5
votes
2answers
157 views
What is the easiest way to write dimensional expression?
I want to do the following arithmetic:
(x-y)*unit/s where x, y, s are rational constants and unit is in length unit.
\documentclass{article}
\usepackage{calc}
\newlength\unit
\unit=16pt
\def\x{0.5}
...
2
votes
1answer
139 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
393 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 ...
11
votes
2answers
1k 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{} ...
10
votes
2answers
301 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
214 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
...
7
votes
2answers
1k 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
416 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
...
5
votes
3answers
1k 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
257 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 ...
2
votes
1answer
585 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
109 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
294 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
352 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.
15
votes
3answers
846 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). ...
6
votes
3answers
1k 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
512 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
356 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
324 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 ...
4
votes
2answers
811 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
332 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
1k 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".
8
votes
2answers
2k 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 ...
10
votes
3answers
583 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
374 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
218 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
414 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}
...
8
votes
6answers
524 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 ...
15
votes
3answers
417 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 ...
22
votes
7answers
3k 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.
10
votes
2answers
10k 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 ...
8
votes
2answers
679 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}
...
17
votes
2answers
2k 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 ...
12
votes
2answers
2k 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
414 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
274 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 ...
15
votes
6answers
5k 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
295 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
1k 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
169 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}
...
1
vote
4answers
438 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
242 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}, ...

