[Tex/LaTex] Define numeric variables

macrospackages

I would like to define some variables in a tex document. For example, I write in .tex something similar as: Our tool succeeds to validate x samples by Method A, and y samples by Method B. Thus its score is z. Where z is defined as x+y, and x (resp. y) is instanced somewhere else by a number, eg., 30 (resp. 50). As a result, after the compilation the text turns out to be Our tool succeeds to validate 30 samples by Method A, and 50 samples by Method B. Thus its score is 80.

The advantage of this, is that I just need to change the value of some variables, to change all the numbers in the text…

Does anyone know how to achieve this?

Best Answer

\documentclass{article}

\newcommand\x{30}
\newcommand\y{50}
\begin{document}

 I would like to define some variables in a tex document. For example,
 I write in .tex something similar as: Our tool succeeds to validate \x\
 samples by Method A, and \y\ samples by Method B. Thus its score is
 \the\numexpr\x+\y\relax. 

\end{document}

output-

enter image description here

Related Question