{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
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
220 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
700 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
280 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
576 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
729 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
268 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
407 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 ...
14
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
289 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. ...
54
votes
3answers
13k 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
5k 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
5k 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
1k 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
790 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 ...
9
votes
1answer
1k views

Shrinking text to the width of a node within a tikzpicture

I would like to be able to scale text to the width of a TikZ node. Using \widthof within tikzpicture as a starting point, I've arrived at somewhat of a solution, except it has incorrect spacing, and ...
14
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 ...
5
votes
2answers
1k views

How can I nest coordinate calculations in TikZ?

Why does this not work? I'm not using LaTeX and TikZ very much; I don't see it. \begin{tikzpicture} \coordinate (Zero) at (0,0); \coordinate[label=below:cell a] (vertexA) at (0, 10); ...
12
votes
1answer
845 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 - ...
17
votes
2answers
682 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 ...
5
votes
2answers
634 views

Adding numerical values in a LaTeX tabular column [duplicate]

Possible Duplicate: How can I automatically calculate sums in a LaTeX table? Does anyone know if the is a TeX/LaTeX package which will make an ordinary tabular environment work as a simple ...
4
votes
2answers
1k views

Calculate maximum of lengths

How can I calculate a maximum of lengths? I am aware of pgfmath's function max(x_1,x_2,...) \documentclass[a4paper,draft]{article} \usepackage{tikz} \pgfmathparse{max(3,4)} \begin{document} ...
4
votes
1answer
2k views

Measuring height of fixed-width text box

Suppose some text is put inside a fixed width box. The text will then continue in vertical direction. How can you measure the total height of that text? Original text: text text text text text ...
15
votes
3answers
2k 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}{ ...
18
votes
2answers
867 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
3answers
2k 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 ...
4
votes
3answers
2k views

Can LaTeX perform simple math operations? [duplicate]

Possible Duplicate: How can I automatically calculate sums in a LaTeX table? Can LaTeX do simple math? I have a table with two columns and want to automatically add a third column which ...
6
votes
2answers
1k views

\widthof within tikzpicture

In this minimal example \documentclass{scrartcl} \usepackage{calc} \usepackage{tikz} \newlength{\TestLength} \begin{document} \setlength{\TestLength}{\widthof{\tikz \node {bla};}} ...
5
votes
2answers
1k views

How to use pgf-math inside an argument?

I response to xport's recent questions, I tried to do the following \usepackage{pgf} [...] \rule{\pgfmathdivide{4}{3}\pgfmathresult mm}{5mm} Unfortunately, this fails with the following error ...
2
votes
1answer
450 views

How to pass in a ratio in fraction form (as opposed to decimal form) to table column definition?

My scenario is to pass in a ratio (in fractional form as opposed to decimal form) to each table column definition. The following code cannot be compiled. \documentclass{article} \usepackage{pgf} ...
2
votes
3answers
931 views

How to pass in a ratio in fractional form?

How to pass in a ratio of 4/15 (instead of its approximated decimal form of 0.266) to table definition. Final solution can be seen here. I need one more vote to close this topic.
0
votes
1answer
175 views

Why did my exact calculation still produce small gaps on the most left and right table rules?

I have specified each tabular cell width exactly using formula ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth as shown in the following code snippet: \documentclass[dvips,dvipsnames,rgb]{book} ...
7
votes
5answers
2k views

How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ?

How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ? Actually I want to use the ratio for the \scalebox argument, e.g., \scalebox{<ratio>}. ...
8
votes
5answers
734 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 ...
25
votes
2answers
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 ...
29
votes
6answers
3k 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 ...
34
votes
5answers
11k 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 ...
11
votes
2answers
5k views

Performing basic arithmetic in custom commands

One thing annoying in sparklines is its verbosity and dependence on external arithmetics. For example, to depict a three bar graph of 16%, 53%, 31%, one has to write: \begin{sparkline}{4} ...
9
votes
1answer
460 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 ...
12
votes
4answers
4k 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 ...