Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sum two numbers in Latex with my own command?

Tags:

sum

latex

I have to sum two numbers (integers) in LaTeX. I also have to "print" the process of sum. So it would look like 5+2=7 in text. Any ideas? My code so far:

\newcommand{\Sum}
{\newcounter{cnt}
\setcountter{cnt}{1+1}
}
like image 265
FatTommy Avatar asked Mar 20 '18 20:03

FatTommy


People also ask

How do you add two numbers in LaTeX?

In school, we use the symbol + to denote the sum between two numbers or, more in general, between two algebraic quantities (like x + y).

Can you do calculations with LaTeX?

The calculator package allows us to use LATEX as a calculator, with which we can perform many of the common scientific calculations (with the limita- tion in accuracy imposed by the TEX arithmetic). The calculus package uses calculator to compute simultaneously a function and its derivative.

How to enter limit in LaTeX?

Limit expression can be added using the \lim_{lower} command.

How do you write greater than in LaTeX?

Greater than (or equal) Symbol in LaTeX Commands In Latex you use the key “>” inside math mode to represent greater than. You don't need extra packages (yet). Now for the greater than or equal symbol, you use the command \geq or \ge, no value as an argument.


1 Answers

In LaTeX, first you have to define a counter with:

\newcounter{countername}

Then you can put a value in this counter with:

\setcounter{countername}{<value>}

where <value> is an integer. Or you can add one to this counter with:

\stepcounter{countername}

or you can add some arbitrary value to this counter with:

\addtocounter{countername}{<value>}

Then, to access this counter you use:

\value{countername}

so you can, for example, make calculations with this counter:

\setcounter{anothercounter}{%
  \numexpr\value{countername}+10\relax%
}

Then, when you need to print the value of this counter to the pdf file, you can you the mighty \the:

\the\value{countername}

or you can use one of these:

\arabic{countername}
\roman{countername}
\Roman{countername}
\alph{countername}
\Alph{countername}
like image 97
Phelype Oleinik Avatar answered Sep 22 '22 09:09

Phelype Oleinik