The difference is in the time at which the ‘right hand side’ is evaluated.
Thus \let\foo\bar
defines \foo
to have the value that \bar
had at the point of definition. On the other hand, \def\foo{\bar}
in effect defines \foo
to have the value that \bar
has at the point of use.
Consider:
\def\bar{hello}
\let\fooi\bar
\def\fooii{\bar}
\fooi +\fooii
\def\bar{goodbye}
\fooi +\fooii
This produces
hello+hello
hello+goodbye
This is a simple process.
However it's also a subtle one, so it might be worth highlighting a few key points:
When TeX encounters control sequences such as \fooi
, it evaluates them; if these are macros (that is, they have been defined by \def
, or \let
equal to something which was defined by \def
), then the result is that they will expand to other tokens, which TeX will then examine in turn, and so on, recursively, until what's left is either ‘primitive’ control sequences or letters (I'm simplifying a little bit).
\fooi
expands directly to the characters hello
(because \bar
initially did, and \fooi
was defined to have the same value).
\fooii
, in contrast, expands to \bar
, which is then immediately reexamined and reexpanded. In the first case, \bar
expands to hello
and in the second case to goodbye
. The definition of \fooii
hasn't changed, but \bar
has been redefined in between.
Getting a clear idea of the process of this recursive expansion is very helpful when learning how to develop and debug TeX macros.
\the\value{MyCounter}
is just a slightly faster way to say \arabic{MyCounter}
, as the former expands successively to
\the\csname c@MyCounter\endcsname
\the\c@MyCounter
and the latter to
\expandafter\@arabic\csname c@MyCounter\endcsname
\@arabic\c@MyCounter
\number\c@MyCounter
TeX rules say that \the
is essentially equivalent to \number
. I don't think that the difference in execution time can be significant in a normal document. It's usually better to stick to "official" macros, when they exist, in order to be sure that the result will be stable over time.
Usage of \theMyCount
may be improper when we are not sure what kind of representation is associated to the counter MyCount
.
On the other hand, \theMyCount
should not be used in contexts when we are interested in the "abstract" value stored in the counter, so putting in a macro
\ifnum\value{MyCounter}>0
is correct, while
\ifnum\theMyCounter>0
is dangerous, because the user might have changed the representation of MyCounter
when the macro is used.
Best Answer
\thecounter
typesets the result of the counter, be it in arabic, roman, etc, while\value{counter}
provides an integer value in return. In many, but not all, instances, the difference will go unnoticed.The rule is, if you are looking for a character, use
\the...
; if you are looking for an integer, use\value{...}
.Here's an example where it matters. By typesetting the page number in roman (via
\pagenumbering{roman}
), the option of\romannumeral\thepage
is no longer an option, since it would be attempting\romannumeral i
, whereas\romannumeral\value{page}
works fine.Here's another example...you cannot typeset
\value
The difference can also affect comparisons, since
\if
compares tokens, not integers:The above example would show a match, were the
\if
s changed to\ifnum
s, since\ifnum
will interpret/convert the character2
into an integer. However, even that can get you into trouble for more complex cases.Here, I can combine
\theQ
with3
to represent23
. The same does not apply for\value{Q}3
.Now this last one is quite unusual. That of using
\value
to try to provide the numerical part of a length specification. It works as expected if you merely specify\value{Q} pt
. However, if you try2\value{Q} pt
, it takes the2
as a multiplier and\value{Q}
as a length specified insp
machine units! The trailingpt
becomes an extraneous residual, not even part of the length.This behavior occurs because, deep down in TeX, lengths are actually stored as integer counts in machine units. What value TeX uses as its minimal unit