Questions tagged [calculations]

{calculations} is about calculations in (La)TeX documents. A popular package is calc, although others also exist (fp, pgf, and LaTeX3 packages, e.g `xfp`).

Filter by
Sorted by
Tagged with
1
vote
1answer
63 views

Add Rows to Table With Macro (calc fields result the same for each row)

I use as template macro from this articale: Add Rows to Table With Macro. All work fine if values in cells not to calculate. But othewise results of calculation is the same for each row. How to avoid ...
8
votes
3answers
1k views

Tikz: Calculate and store the Euclidian distance between two coordinates

Is there an easy way to store the Euclidian distance between two coordinates? I want to store the value 4 in a macro, so that I can use it to specify the width of a node. The easiest way I could ...
3
votes
1answer
288 views

How to specify a date and make calculations with it in datetime2?

I want to specify a date (and give it a name) in a master header TEX-file, then refer to that date in several independent daughter files. As this doesn't even work within a single file, this ...
9
votes
1answer
275 views

Accumulators in TikZ

I wanted to calculate something in TikZ. But, my TikZ code doesn't accumulate values to a variable. The following code is expected to output 1+2+...+10 = 55. However, it just shows 0. What should I ...
0
votes
1answer
143 views

Automation and variables

For school and exams, time is at a premium. Copying expressions and pasting them in a third party calculator is too time consuming. Not to mention if you discover that you have made a mistake, and ...
0
votes
1answer
308 views

How to add numbers with character?

how to add numbers which will automatically ignore non-numbers, file should be read from .csv file Eg.when A=10, B=20, C=NA --> here content of C contains some characters which is not a number so ...
2
votes
2answers
748 views

Math operations on lengths

I have a table with three columns and I want the table to be distributed on \textwidth of the page. I tried: \documentclass{article} \usepackage{tabularx} \begin{document} \begin{tabularx}{\...
3
votes
2answers
211 views

Problems with numerical stability [closed]

In a macro that is supposed to calculate the value of the third derivative, I used the following formula: (f (x + 3 * delta) -3 * f (x + 2 * delta) + 3 * f (x + delta) -f (x)) / (delta) ^ 3 Because ...
3
votes
1answer
583 views

pgfplots: drawing multiple vectors with corresponding unit vectors

Suppose you have a couple of 3D-vectors given by their start and endpoints. Now you want to define a command that draws one of these vectors together with its respective unit vector from the same ...
0
votes
0answers
43 views

Evaluate combinations of page dimensions [duplicate]

For any given class and its specified page layout, I'd like to be able to combine (sum or subtract) a subset of the page dimensions, to obtain a length to work with, without specifying absolute values....
3
votes
1answer
91 views

Is there a preferred way to switch between units?

I'm working on a recipe book. Some of my recipes are in British Imperial units, some in American, some in metric. I want to avoid manual conversion as that can produce errors, but I want the book to ...
0
votes
1answer
305 views

Strange behaviour of \FPeval

I have a piece of code, which sometimes compiled correctly, other times it gives an error. Is it possible that the package fp is unstable? Or might another package conflict with fp? How could I fix ...
0
votes
1answer
94 views

How to cumulate computed durations?

My current code generates a result as shown in the image below. My problem is: how to cumulate the "Car" durations?. When the line 95 % \global\let\routeCarTotalDuration\tempd% is uncommented, ...
0
votes
1answer
1k views

subtract leftskip from textwidth inside a expression

If I do: \includegraphics[width=\textwidth-\leftskip]{image.png} I don't get the same picture size as if I subtract its values of 483pt-60pt = 423pt. But if i do: \includegraphics[width=\textwidth-...
1
vote
2answers
150 views

Using a sequence for the x values in a functiontable

In a previous question about the automatic creation of a functiontable I got a very good answer from @egreg here. I have reduced this example, see code below. I thought I could calculate the x-values ...
5
votes
2answers
1k views

n-base to decimal calculations in LaTeX

I have to make an assignment about converting base-n notation to decimal and vice versa. We are allowed to make it on paper, and send it in digitally by scanning. However, I'd like to send it in ...
3
votes
2answers
498 views

How to calculate and display percent of screen that has no content

In this example, I want to insert the percentage of the page that isn't blank including the strikeouts and the percentage itself. I tried doing both a Google search and a TeX.SE search but nothing ...
2
votes
1answer
517 views

Automated solution of a quadratic equation with non approximated solution

How to get the roots automatically not in an approximate way but with square roots in Output format for text and math with macro not correct ? (editor's update) I.e., I need a LaTeX macro \quadSol ...
2
votes
2answers
147 views

Probably just another gdef-expansion problem

In continuation of the post, I try to make the following (simplified) code to work. \timedelta uses 2 arguments. Using a \gdef as the first argument is Ok. Using a \gdef as the second argument is Nok....
2
votes
2answers
102 views

Probably a gdef-expansion problem, but how to solve?

Trying to integrate the answer of this post it into my real code, I face the error Argument of \timedelta@i has an extra } when calling the proposed method. Upto now, I've not been able to fix it. ...
3
votes
1answer
103 views

How to do math with numbers and units in a command

I want to create a 2-column wide table, that can change the width of the individual cells each row (in 5mm increments). My Problem: I'm trying to multiply a length (5mm) by an argument number. Also ...
8
votes
5answers
611 views

A \def syntax problem

I want to compute a time difference. For example: 22:44 - 22:50 -> 00:06 23:00 - 00:10 -> 01:10 In the second case, the time is implicitly about the following day. My idea is: Convert the times ...
4
votes
3answers
192 views

Simple float-point calculations with comparison inside own macro

I currently have the command \aeq{} to easily print the equivalents used in a chemical reaction in my experimental section. I use numbers rounded to one decimal place. However, in some reactions, I ...
7
votes
2answers
518 views

How to transcript codes from HP 50G in LaTeX

I have a code from HP 48/50G series, as shown in the image below. The closest that I did, using [lstlisting] is shown in the code snippet below. \begin{lstlisting} << SWAP DUP SIZE HEAD 1 - -&...
3
votes
1answer
278 views

Create fillable pdfs that can do calculations

I am interested in create a fillable PDF, for which I found This question which tells to use hyperref. But I am curious that if I have 2 number fields, A and B, and I want a third field to be a number ...
4
votes
2answers
425 views

How to prevent loss of precision for operations on length values?

Value \MM is equal to 1mm and is internally stored as 2.84526pt. Value \MMQUARTER is equal to 0.25mm and is supposed to be stored as 0.711315pt (2.84526/4 = 0.711315) but is stored as 0.7113pt. I need ...
5
votes
2answers
912 views

How to calculate the width of a space?

Using the questions: Get width of a given text as length Lengths and when to use them enumitem package and description lists For the inline enumerate: controlling the item spacing Customizing inline ...
6
votes
4answers
879 views

How to declare “newcommand” value as a sum of some number (with units) and another command so that it can be used in coordinate arithmetic?

I suspect that arithmetic I put inside newcommand is not processed as I would expect. What is the value of \FMARGIN after declaring it as \newcommand{\FWIDTH}{2mm} \newcommand{\FMARGIN}{10mm+\FWIDTH}...
3
votes
1answer
193 views

tikz change color based on argument

I'm trying to produce a periodic table where the color of the elements changes based on their electronegativity, like here. Thanks to this answer, I can create the table (first two rows) like this: \...
5
votes
1answer
124 views

Make a CV auto updating

I would like to create a code to insert in my CV that make it auto update. The hypotetic sentence is this one: "Engineer with twenty experience years", where twenty is generated by, e.g., \startyear{...
5
votes
1answer
159 views

Why the empty space size is increasing each call to my calculate listing header command?

I learned how to create a list of codes on my thesis on the question Setting Entries of List of Listings in LaTeX. Package Listings and I put that command on another file with english tiles as \...
3
votes
1answer
129 views

Arithmetic of composite counter

How do I calculate and display an incremented value of a numeric composite counter, such as \thesubsection? Do I try to extract and increment the "decimal" part separately and then glue the result ...
1
vote
1answer
779 views

How to compute two checkbox values of form and present on Adobe?

I want to show the computation of two values in the questionaire where the user choose one option per question. Many measure proprietary sources of research have PDF documents such as ...
1
vote
2answers
1k views

Convert hexadecimal string into (La)TeX number

How can I convert a user-supplied hexadecimal string like 14b or 14B into something which (La)TeX will recognise as a number? I suppose that a package like xcolor can do it, but I have not been able ...
2
votes
1answer
216 views

tcolorbox problems with asymmetric page layout

Using tcolorbox for chapter headings I never had a problem, except when I changed to asymmetric layout. Usually tcolorbox's option spread sidewards works just fine in a chapter's heading (you can ...
4
votes
2answers
693 views

How to get numeric value from array

I'm struggling to get the numeric value out from arrays using the arrayjobx package. My goal is to store a list of values in several arrays, then when display them in a table be able to show the sum (...
20
votes
3answers
2k views

Longest Collatz sequence calculated with LaTeX

Recently, I started to experimenting with expl3 programming language. I found it very powerful for solving problems not only related with typesetting, but also with problems the other programming ...
2
votes
1answer
334 views

Counting the number of occurrences of specific words in latex

I have defined \GreenCircle, \AmberCircle and \RedCircle to display a green or an amber or a red circle before the beginning of the paragraph depending on the content of the paragraph. Would it be ...
-1
votes
2answers
100 views

Package for adding to start time to make an event “running sheet”? [duplicate]

I'd like to form a "running sheet" for an event that is likely to change, so I'd like LaTeX to keep track of the calculations for me if the programme changes. I imagined storing a "start" time, ...
6
votes
2answers
1k views

How to calculate age on a particular date in Years, months, days format?

Lets say my D.O.B is 10/02/1989 and i want to calculate my age on 1st May, 2017, then 28 years, 2 months, and 21 days will be my age on this particular date, How to get in this format 28 years, 2 ...
7
votes
2answers
997 views

How to count the occurence of M and F in a particular column , No. of male and female deaths?

how to command LaTeX to count occurence of M and F in a particular column of a table from first row to last row of a particular column? And also the number of Male Deaths and Number of Female Deaths, ...
4
votes
3answers
208 views

How to create multipage tables of binary arithmetical problems (and associated answers) involving pseudo-random numbers?

Consider the following example: \documentclass[ a4paper, landscape, 12pt ]{article} \usepackage[sc]{mathpazo} \usepackage[ hmargin = 4cm, tmargin = 1.5cm ]{geometry} \usepackage{fancyhdr} \...
4
votes
1answer
696 views

How to sum two non-integer numbers in LaTeX? [duplicate]

Here is the sample format of non-integers number 12.5+13.8=26.3
6
votes
1answer
695 views

LuaLaTeX: Calculate length in Lua

I apologize if this a rookie question, but I find it extremely hard to find a solution to my Lua problem using online searches and browsing reference manuals. I would like to calculate a length: ...
2
votes
2answers
386 views

Drawing intersecting line

I'm currently trying to reproduce a chalk drawing in tikz. Currently, I'm trying to draw intersecting lines without manually typing in the coordinates as I currently have. Does anyone know how this ...
6
votes
1answer
312 views

ConTeXt: Calculate Page Number as Percentage of Page Count

Background Looking to draw a horizontal "progress bar" along the bottom of each page. The first page should have no line above the page number (or very, very short) and the last page should have a ...
0
votes
2answers
1k views

Measuring the height of a box

Solution in Edit 3. It works well, but seems to need an optimization. :) MWE: \documentclass{scrartcl} \usepackage{calc} \usepackage{mathptmx} \usepackage{anyfontsize} \newcommand{\Title}[1]{ \...
4
votes
2answers
1k views

Multiplying lengths by a factor

I am trying to create a pspicture where some lengths are calculated in dependency of the size of the pspicture and an included graphic but I am getting the following error message Illegal unit of ...
1
vote
1answer
812 views

Many errors given by the calc package

I know that the title is not clear at all; the issue is that I'm trying to use the calc package to compute the value of a certain counter, and I receive two different error messages, according to some ...
1
vote
0answers
75 views

Working with variables in Tikz [duplicate]

Background I'm fairly new to tikz, and I am currently trying to create a figure with variables to easily change dimensions when needed. I am however having some troubles when attempting to apply ...

1 2
3
4 5
11