# What is the difference between \number and \the?

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 .
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

\begin{document}

\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

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

\end{document}

• 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. Commented Nov 9, 2014 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 ? Commented Nov 9, 2014 at 18:39
• Regarding the performance: when followed by \numexpr, \the is faster. tex core - The difference between \the\numexpr and \number\numexpr - TeX - LaTeX Stack Exchange Commented Jun 12, 2022 at 12:15

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

\the\dimen0


or

\the\everypar


or

 \the\font


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.