{calculations} is about calculations in (La)TeX documents. A popular package is calc.
34
votes
3answers
1k views
Can LaTeX perform calculation like Excel formula table?
I wonder if this feature is available in TeX system? For example, given a formula within a table, it can apply the formula and display data after the calculation.
27
votes
4answers
508 views
Perform matrix operations (addition, product, transpose, etc.) in LaTeX?
I know the calc package can perform infix-notation arithmetic in LaTeX... but I want more!
I'd like to perform (not necessarily infix-notation) linear-algebra operations such as scalar ...
25
votes
3answers
5k 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 ...
25
votes
5answers
7k views
How can I automatically calculate sums in a LaTeX table?
Sometimes I would like LaTeX to automatically calculate sums (or other simple arithmetic) for me, eg. in a table. I would like to ensure that when I update the table, I don't accidentally forget to ...
23
votes
2answers
859 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 ...
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.
22
votes
5answers
2k 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 ...
20
votes
4answers
772 views
Get derivative of a function
I want to write a macro, which takes a mathematical function as argument and returns a plot using pgfplots of the function and of its derivative.
I guess that this isn't possible using just LaTeX; ...
20
votes
3answers
401 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}
...
18
votes
2answers
516 views
Automated age calculation
How can I calculate my age at compile-time in LaTeX?
Something like:
I'm \myage{day}{month}{year} years old.
would be most awesome.
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".
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 ...
17
votes
2answers
566 views
Handling different time zones
I'm looking for a way to handle date/times with different time zones. For example in svn-multi and filemod a date and time with a timezone is returned. I like to be able to compare times in different ...
17
votes
1answer
293 views
Setting TikZ curve control points and preserve area of closed curve
I would like to reproduce the shown periodic table, with more correct areas.
http://www.meta-synthesis.com/webbook/35_pt/relative_abundance.jpg
I would appreciate any ideas to how this can be ...
16
votes
1answer
114 views
Using \fontdimen as an array to store data
Reading through pi.tex, I discovered the trick of using \fontdimen as an array of dimensions (which is equivalent to storing integers between ±(2^31-1)sp). Namely,
\font\x=cmr10 at 1sp % or whatever ...
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
15
votes
3answers
844 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). ...
15
votes
3answers
416 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 ...
15
votes
4answers
2k 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 ...
14
votes
3answers
1k views
Doing maths with distance values in LaTeX source code
I have a sty file with the command
\newcommand{\foo}[1]{\noindent\kern#1}
but I'd actually like to have something like
\newcommand{\foo}[1]{\noindent\kern{#1 *0.5}}
meaning that I'd like to have ...
14
votes
2answers
281 views
square root of number in counter
I would like to get the square root of a number which I have stored into a counter. I have been using the calc package for summation and multiplication operations, but I cannot find anything like
...
13
votes
6answers
1k views
Calculating right angle triangle side inside LaTeX
I'd like compute the width of a screen from it's diagonal and its aspect ratio inside a LaTeX document. The formula is easy to get from the Pythagorean theorem, but needs square roots.
I currently ...
13
votes
3answers
443 views
PGF math engine imprecise?
The command \pgfmathparse{asin(1/\x)} yields for each \x in the range of 125 to 142 the same value, whereas \pgfmathparse{1/\x} yields the much more precise values for each \x. Is the ArcSin function ...
13
votes
5answers
276 views
Autocalculate result in math-mode
Are there any available programs/software/etc. that allow you to autocalculate and then autocomplete TeX equations? It would be great if for example, I were doing really long messy equations like
120 ...
13
votes
1answer
150 views
References for \dimexpr \numexpr
I'm not really sure whether this is the right place to ask this question, but here I go....
Over the holiday I've been taking time to read through a lot of the Q&A here. I've been running across ...
12
votes
3answers
1k views
Why doesn't \settoheight of \parbox work?
Consider the following code:
\documentclass[a4paper]{letter}
\usepackage{calc}
\usepackage{printlen}
\newsavebox{\foobox}
\newlength{\fooboxheight}
\savebox{\foobox}{
...
12
votes
2answers
590 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 ...
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:
...
12
votes
1answer
164 views
How to implicitly specify column width (in a columns-like environment)?
I am using the columns environment in Beamer-documents like this:
\begin{columns}
\begin{column}{0.8\textwidth}
%%
\end{column}
\begin{column}{0.2\textwidth}
%%
...
11
votes
3answers
172 views
Arithmetic in arguments to the geometry package
I'd like to use the geometry package to auto-crop the output of my LaTeX (so that it looks bigger on-screen as I'm editing). I have found a way to remove the margins completely and brutally:
...
11
votes
3answers
372 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 ...
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{} ...
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 = ...
10
votes
4answers
3k views
Why is this let expression not working in TikZ (calculating a midpoint)?
I have a rectangle in TikZ and the top left and bottom right corners are called (topleft) and (bottomright) respectively. I wanted to have a label midway down the left hand side of the rectangle, so I ...
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 ...
10
votes
3answers
193 views
How to set a counter to double the value of another counter?
The title says it. Lets have to counters:
\newcounter{myCount}
\newcounter{anotherCount}
I set myCount to some value for example 10
\setcounter{myCount}{10}
How do I set counter anotherCount to ...
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 ...
10
votes
3answers
577 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
1answer
558 views
Difference between two dates
Is there a macro that calculates the year and months from a given start date and the current date.
So let's say I have 05/02/2010 (the start date), then it should do the following: Today - ...
9
votes
4answers
186 views
Dividing dimensions to get a count
Is there a way to divide two dimens and get a count? For example, if I have a box that doesn't fit on a single page, and I want to know the number of pages I'd need for the box (i.e., \heightofbox / ...
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
...
9
votes
3answers
285 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 ...
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 ...
9
votes
2answers
118 views
Set variable with mathematical expression
I need to do something like the following,
\includegraphics[width=(\textwidth - 50mm)/2]{myfig.eps}
What keywords can I use to search for doing this operation? Everything I've searched for was ...
9
votes
1answer
183 views
How to fit ellipse into another object - using intersections and calc library
I would like to ask, how to place ellipse into any object, so that the length of the main arm is defined by line1 (point A, B) in my code:
calculate the coordinates of the ellipse midpoint
rotation ...
9
votes
1answer
366 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 ...
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 ...
8
votes
2answers
674 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}
...
8
votes
5answers
685 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. Thanks, \real!
I've been ...
8
votes
2answers
138 views
TikZ grouping expressions in calculations
I had to do some calculations like:
\node (A) {A};
\node (b) at (x,y) {B};
((A) + (B))*2
However I could not figure out how to group it in a calc statement, I tried ($((A)+(B))*2$) and ...
