# Questions tagged [arithmetic]

The tag has no usage guidance.

58 questions
Filter by
Sorted by
Tagged with
47 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 ...
57 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 ...
212 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 ...
58 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 ...
118 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 ...
107 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 ...
88 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 ...
1 vote
86 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 ...
212 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 ...
1 vote
92 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{...
1 vote
65 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}{ \piccaption{\small #1} \parpic(#2cm,0pt){\...
1 vote
60 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 ...
1 vote
295 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}{% Here is the ...
575 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.
1 vote
109 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 ...
522 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. \...
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}...
534 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 ...
1 vote
45 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 ...
118 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 ...
81 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 ...
1 vote
109 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} ...
102 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 ...
77 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 ...
1 vote
74 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{...
1 vote
926 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 ...
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 ...
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{\... 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 = ...
363 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 ...
391 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 ...
980 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{...
506 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 ...
998 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{...
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 ...
864 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 ...
1 vote
22 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 ...
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 ...
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{...
953 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)...
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}...
357 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 ...
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 ...
1 vote
114 views

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 ...
232 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 ...
1 vote
517 views

### Typesetting long division with tabular and overlining repeating part

I used some of the solution proposed in this post: How to present a vertical multiplication/addition and my code is as follows: \documentclass{standalone} \begin{document} \begin{tabular}{c*{11}{@{...
1 vote
156 views

### Separate Pages for Questions & Solutions

I am making basic arithmetic worksheets with random numbers. I want to separate the questions from the answer page. Not sure how to do that. Ideally, it would look something like this, but with more ...
435 views

### Use arithmetic of counters inside \cline

I have a custom counter \myCounter set to, say 3. I need to produce such a table: The following code does not work: \documentclass{article} \newcounter{myCounter} \setcounter{myCounter}{3} \begin{...