Skip to main content

Questions tagged [arithmetic]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
3 answers
269 views

List of numbers in an arithmetic progression

I need to generate a list of numbers in an arithmetic progression. For example 3,7,11,15,19. I was hopeful there was a way to achieve this by specifying the first term (a), the common difference (d) ...
Wendy Taylor's user avatar
2 votes
2 answers
89 views

Misunderstanding yunit in pstricks, or a bug, or extreme imprecision?

Feeding latex with \documentclass{article} \pagestyle{empty} \usepackage{pstricks} \begin{document} {1: \begin{pspicture}(-.1,-1)(.1,5) \psline(0,0)(0,5) \end{pspicture}} {$10^{-4}$: \psset{yunit=....
AlMa1r's user avatar
  • 541
2 votes
2 answers
439 views

TeX variables become local within list environments?

Apparently, when the value of a TeX counter is modified inside an enumerate environment (and no doubt many other contexts), it acts like a local variable, so that any modifications to it are local to ...
Mars's user avatar
  • 1,108
4 votes
1 answer
168 views

Is it possible to perform arithmetic on the entries in a table?

I want LaTeX to automatically sum the entries in a certain table column. I know these entries will always be integers, but I can't think of a way to 'grab' their values. My first thought was something ...
Ian Thompson's user avatar
  • 44.1k
0 votes
1 answer
38 views

pgfmathsetcounter to unprecise

I want to use the following commman \newcommand{\Gewicht}[2]{ \pgfkeys{/pgf/number format/.cd, precision=8} Volumen des Bauteils nach CAD: \SI{#1}{\cm^3}\\ Dichte: \SI{#2}{\kg\per\cm^3}\\ ...
FN-2187's user avatar
0 votes
1 answer
68 views

How to multiply all the components of a skip length by the same number?

I am looking for a way to simply multiply all the components in a skip expression ( the natural length plus the plus-length minus the minus-length ) by the same number. I've tried some examples in my ...
User23456234's user avatar
  • 1,890
3 votes
1 answer
64 views

Asinh scale in pgfplots with small parameters

I have recently asked a question about introducing an asinh scale in pgfplots. While the solution given in there does implement an asinh scale, when I tried to implement it in my particular case I've ...
Níckolas Alves's user avatar
2 votes
2 answers
221 views

Simplify arithmetics +-, -+, --, 1x, -1x

I made some command \pcoef and \mcoef that simplifies +- and -+ to -, and -- to + in arithmetic expressions, and a \coef that simplifies 1x and -1x to x and -x respectively. They are not really ...
mathteacher's user avatar
2 votes
1 answer
65 views

How do I correctly align, center, and number a multi-step arithmetic problem?

As indicated in the picture, I would like to have several things: Numbered steps (if possible, on the left side) Aligned and centered properly, so it looks professional. The summation in step #2 ...
anon's user avatar
  • 35
0 votes
2 answers
157 views

Looking for an alternative to \numexpr: an intuitive interface for LaTeX numeric expressions

The xparse package makes writing commands easier and more flexible. The ifthen package does the same to conditionals. Is there a similar package for numeric expressions? Even better if it interacts ...
Evan Aad's user avatar
  • 11.1k
0 votes
1 answer
210 views

Multiply length using \expr

I have a length that I wish to scale, however I am not sure of how to do it, and none of the answers i have found online have been helpful. The function I attempted to derive this from is: % #1 is the ...
cdickstein's user avatar
2 votes
1 answer
143 views

Calculate ratio between lengths/scale

I would like to calculate the the ratio between two lengths in order to automatically get the scale for a map included using the mercatormap package. For instance, I want the map to show 1km in the ...
Ninoett's user avatar
  • 179
1 vote
1 answer
99 views

Turning this addition code into subtraction

\documentclass{article} \usepackage{xintexpr}[2018/05/18]% because we use randrange() \newcommand{\BaseTenAddition}{% % temporarily make definitions have global scope, because % xint creation of ...
Paul A's user avatar
  • 1,117
0 votes
1 answer
265 views

How to use dynamic numerical variables in tikzpicture?

I am currently creating technical documentation that depicts through a tikzpicture the data flow across something called the I2C bus (example-like graphic). I initially started doing this by hand with ...
Code Doggo's user avatar
1 vote
1 answer
141 views

Multiplying length values

I am trying to make a macro \scalelen that scales an existing length value \len by the input value. However, \len is actually a string containing a unit. I made a code: \documentclass{article} \begin{...
Hermis14's user avatar
  • 423
1 vote
1 answer
67 views

New command: Arithmetic-based image width

Theoretically, I think this command should create an environment which is slightly wider than the image it is meant to house: \newcommand{\ListedFig}[3]{ \piccaption{\small #1} \parpic(#2cm,0pt){\...
kiwi's user avatar
  • 13
1 vote
3 answers
68 views

To emulate lookahead for variable evaluation, run a macro laden block of text twice. How to suppress text output in the first pass?

I'm writing a little supplement for my friends, we use the GURPS tabletop role playing game system. This system uses a points pool to buy aspects of characters. I would like to have the point total of ...
Worm of Love's user avatar
1 vote
1 answer
503 views

Adding a number to command parameter and outputting it

I have a command that takes a single parameter. I want to add a constant number to that parameter and include it in the output. Something like (pseudo-code): \newcommand*{\label}[1]{% Here is the ...
me--'s user avatar
  • 377
4 votes
3 answers
619 views

Calculation summations in Latex

Anyone can help me please? I need to calculate the sum 1+1/2+1/3+...1/n (n given) by using only Latex commands. I have no idea how can I do this. Many thanks.
Angelo Aliano Filho's user avatar
1 vote
1 answer
131 views

pgffor loop with arithmetic expression

I've grown fond of this xintexpr package for its nice syntax. I'd like to repeat a command M times and another one 5-M = N times. I'm getting an error due to the arithmetic expression of the latter ...
likethevegetable's user avatar
0 votes
1 answer
656 views

Tikz \def arithmetic division

This is, I hope, a trivial question, but one that has cost me a lot of time. I am drawing a simple TikZ picture. I define some variables which specify the coordinates of the lines, nodes and so on. \...
Mike Tanner's user avatar
0 votes
0 answers
28 views

The tikz variable resets before the loop finishes [duplicate]

In tikz, I define a variable outside \foreach loop, and use \pgfmathtruncatemacro command to increase it inside the loop. Below is my MWE. \documentclass{article} \usepackage{pgfplots,tikz,tikz-3dplot}...
padawan's user avatar
  • 1,562
4 votes
3 answers
653 views

\numexpr with parentheses / order of operations

I feel very silly. Basically I want to divide the result of an addition with \numexpr, such as: (10 + 5) / 3 The problem is that if I put parentheses there, like \numexpr (10+5)/3 \relax my online ...
Gaspa79's user avatar
  • 143
1 vote
2 answers
51 views

command which creates a variable number of spaces

Basically my problem is that I want to treat the argument to a command as a number (and perform arithmetic operations on it), but I can only get it to be treated as a string. In particular, I want my ...
push33n's user avatar
  • 115
0 votes
0 answers
122 views

Random Arithmetic overflow with Tikz

\documentclass [11pt,a4paper]{article} \usepackage{pgfplots} % per i plot \tikzstyle{mybox} = [draw=black, thick, rectangle, rounded corners, inner ysep=5pt, inner xsep=5pt]%per riquadrare una parte ...
Tommaso Iaquinta's user avatar
2 votes
1 answer
89 views

Have MetaFont read an arithmetic expression from a file

I know this is a question that possibly does not belong to pure TeX, as MetaFont is part of a project to which TeX relates, ie as part of building TeX. My question is as follows: I call MetaFont from ...
Yaacov NNNNM's user avatar
1 vote
1 answer
120 views

tikz:arithmetic in calculating coordinates

Consider this example: \documentclass[margin=5pt]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \def\xstart{-1} % \def\xstart{-0.2-0.8} ...
Viesturs's user avatar
  • 8,095
4 votes
1 answer
113 views

Shortening lengths in LaTeX

I'm trying to create a a bipartite object that has the \textwidth at most, and doesn't overflow from the right, but has the width of the separator given as an argument. I attempted to achieve this ...
Alex Petrosyan's user avatar
0 votes
1 answer
81 views

Is typesetting of elementary arithmetic exercises without tables or TikZ possible?

Is there a way to avoid using TikZ or tables typesetting elementary arithmetic exercises like these: I would like to have a some kind of a placeholder character and the distance between numbers have ...
georgmierau's user avatar
  • 1,608
1 vote
0 answers
81 views

How to do long division of an angle in degrees

Is there a way to display the basic operations with angles in degrees, just like xlop does with integers? For example, with integers we use: \documentclass{article} \usepackage{xlop} \begin{...
Ulysses's user avatar
  • 197
1 vote
1 answer
989 views

How to calculate factorial with xfp package

I'm trying to calculate the factorial with the xfp package. In the documentation (http://ctan.cs.uu.nl/macros/latex/contrib/l3packages/xfp.pdf), I have found the function name to be fact. My code ...
Carl's user avatar
  • 11
3 votes
2 answers
1k views

Modulo 2 binary long division in European notation [duplicate]

I need to represent binary modulo 2 long division in my tex document. Notation needed is same as https://en.wikipedia.org/wiki/Long_division#Eurasia under Austria, Germany, etc. I know about ...
TexUser's user avatar
  • 31
15 votes
4 answers
2k views

7.0pt ≠ x⋅10.0pt for all x

Consider the following input: \documentclass{article} \begin{document} \newlength{\smallertopskip} \setlength{\smallertopskip}{.700004577636718749999999999999999999999999999999\topskip} \newlength{\...
user avatar
5 votes
3 answers
1k views

What is wrong with the use of `isodd` of `xifthen`?

The white/black board can be drawn by testing the parity of node positions as follows: \documentclass[tikz]{standalone} \usepackage{xifthen} \begin{document} \begin{tikzpicture}[every node/.style = ...
hengxin's user avatar
  • 2,391
12 votes
2 answers
414 views

known benchmarks for floating point calculations?

I frequently have the problem that I have to perform some simplistic calculations, mostly products and sums of two or three quantities. I used to use the fp package for it, but it does look somewhat ...
John Frazer's user avatar
2 votes
1 answer
409 views

Doing math with a value from readarray

I have some numbers that have been read in from a file, using the readarray package. But now I need to add two of these numbers together and output their sum into the file. Is there a way to do this ...
Draconis's user avatar
  • 922
7 votes
2 answers
986 views

Bamboozling Arithmetic!

While creating some pgfmathsetmacro arithmetic macros, I stumbled upon a very perplexing result. Take the following example: \documentclass{article} \usepackage{tikz} \usepackage{xstring} \begin{...
Code Doggo's user avatar
2 votes
1 answer
575 views

How to do arithmetic and get a string version of an integer expression?

How, in the context of a Tex macro, do I do arithmetic on integers and also capture the string representation of the value of an expression so that it can be displayed? Addition and subtraction would ...
Rosie F's user avatar
  • 444
2 votes
2 answers
1k views

How to do arithmetic with variables used in for loop?

How can I use arithmetic inside a node's curly brackets? I have this, and it prints for example "0+1" in a circle. I would like to have circles that show the sum of their coordinates. \begin{...
user3435407's user avatar
2 votes
1 answer
2k views

Next step in formatting long division

I have posted this and this later item on long division. I thought what appears below worked perfectly. But only today I tried it with an example that has several digits before the decimal point in ...
Michael Hardy's user avatar
3 votes
2 answers
908 views

How to do arithmetic without assignment?

I have known that I can use "advance...by..." to do arithmetic on number in TeX, but is there any way to do arithmetic without changing the value of number? For example, if I want to determine whether ...
Evian's user avatar
  • 211
1 vote
0 answers
23 views

How to dynamically refer to nodes within tikz environment? [duplicate]

Here is my code with two tikzpictures. I was expecting both to produce similar output. \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node[rectangle,draw,minimum ...
Lone Learner's user avatar
  • 3,256
4 votes
2 answers
3k views

More on formatting of long division

Among the several proposals for formatting long division in LaTeX, the one that has worked best for my purposes is the one for which the code appears below. It is necessary for me: to stop the process ...
Michael Hardy's user avatar
6 votes
0 answers
1k views

Arithmetic overflow in TiKZ/pgfmath

I am writing some material on the trinomial theorem and Pascal's pyramid, and I'm trying to typeset a single layer. Here is my code so far: \documentclass{article} \usepackage{tikz} \begin{...
Alasdair's user avatar
  • 5,267
4 votes
1 answer
989 views

Arithmetic operation in tikz

Consider the following MWE \documentclass{article} \usepackage{tikz} \usepackage{amsmath} \begin{document} \begin{tikzpicture} \path[black] (0,-1) node{$N=0$} (-1,0) node{$g=0$}; \path[black] (1,-1)...
Larara's user avatar
  • 303
11 votes
2 answers
4k views

Divide two lengths

How do I divide two lengths and get a length out? \documentclass{article} \newlength\A \newlength\B \newlength\C \setlength\A{10pt} \setlength\B{5pt} \setlength\C{\dimexpr\A/\B\relax} \begin{document}...
Carucel's user avatar
  • 1,055
4 votes
3 answers
362 views

Arithmetic temporaries in tex

Can i call macros something like this \StrMid{\mystring}{\X}{\X+2}\par So, i would like to have running window of length 3. And for this end i would like to be able to use temporary unnamed local ...
Yola's user avatar
  • 481
3 votes
1 answer
76 views

Forming totals in cell of tabular environment. Macro expansion or inline eval possible for simple arithmetic?

I have a tabular environment with a dozen or so itemized lines, each with a numeric integer cost. I would like to display a total in the last row. I've edited items in the table several times over a ...
init_js's user avatar
  • 257
1 vote
1 answer
117 views

Breaking numbers Simple addition

I want to make something like the following (I made it in photoshop). Basically I want to make questions for my students to do but without the numbers in the boxes. I don't mind if there is no ...
Matthew Tang's user avatar
2 votes
2 answers
244 views

Single-Digit xlop exercises

I am creating worksheets for young children in which they'll be doing single digit operations vertically. How do I set them up vertically so that there is: An exercise worksheet with no answers. A ...
WeCanLearnAnything's user avatar