I am trying to learn more about macro programming - if that's the right word - in TeX and LaTeX. I began by defining a quantity I called Sum : \newcount\Sum. I then wrote \Sum=0. Then I did some arithmetical operations on Sum, by using \multiply . . . by . . . and \advance . . . by . . ..

Finally I wanted to print out (in the document) the value of Sum. For that I used the line

 The Sum equals **\number**\Sum , 

and it worked as expected ! But later on, I discovered that I might just as well have written

The Sum equals **\the**\Sum ". 

And now I wonder which of the two is the preferred way to write out a numerical value. Are they equivalent ? Or are they intended for different purposes - even if the results overlap in my example ?

Here is an MWE:

%% Here is the example tex-file that illustrates use of \number and \the .   

\usepackage[paperwidth=4in, paperheight=0.8in]{geometry}


\newcount\a  \newcount\b  \newcount\Sum

\a=1   \b=5  \Sum=0
\advance\Sum by \a  \multiply\Sum by \b
\advance\Sum by \a  \multiply\Sum by \b

The Sum equals \number\Sum  \quad;\quad I used ``number''.
\par \vskip 10pt \noindent
The Sum equals \the\Sum     \quad;\quad I used ``the''.

  • Instead of describing the problem, It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem, and perhaps added the description as comments. – Peter Grill Nov 9 '14 at 18:35
  • A related question is why I was not allowed to define variables, or counters, by giving them names such as x1, x2, . . . It seemed as if the names I wanted to use were not allowed to contain numbers -- only letters were allowed. Is there a way around this ? – user35145 Nov 9 '14 at 18:39
  • You should ask about this as a separate question. – Ian Thompson Nov 9 '14 at 18:51

\number and \the are similar on a count register. \the may be applied to more types, such as






Using \number on those cases is either an error or (in the first case) casts the dimen to a number, taking its value is sp units.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.