I have already seen the related page macros - What is the difference between \let and \edef?, but I'm afraid it still doesn't expain to me the following MWE:
\documentclass{minimal}
\begin{document}
\let\tmpa=Hello
\edef\tmpb{A\tmpa}
\tmpb % typesets "ello AH"
\typeout{\tmpa} % writes "\tmpa" in terminal
\typeout{\tmpb} % writes "A\tmpa" in terminal
\end{document}
This is how I understand it:
\let\tmpa=sees first character ofHello,H- it sees it as a single token and gets assigned to it (that is,\let\tmpa=H)- The remaining characters ("ello") from
\let\tmpa=Hello"fall through" and get typeset (the "ello" in "ello AH") \edef\tmpb{A\tmpa}runs => since\tmpa=H, then\tmpbshould expand to "AH"\tmpbruns => as expected, "AH" is typesed after the previous "ello"
And the confusion comes from \typeout{\tmpa} - from the typeset output, I'm pretty sure \tmpa=H; so I expect \typeout{\tmpa} to result with H, but it doesn't - and instead it writes again \tmpa! Same thing if I try to expand it via \edef and throw it in another command (\tmpb), and then I try to \typeout that command.
Why does \typeout in this case not show the "expanded" value of \tmpa? How can I get \typeout to show the expanded value of \tmpa?
Ah well, I asked this question; then I asked myself for it to be closed, given that Showing expanded \let command with \typeout generally provides an answer; in the meantime I came up with an answer I wanted to document - but now I cannot anymore, because it's closed :/ So I posted the answer in macros - How do I ‘expand’ a control sequence \let to a character?; but that answer simply doesn't belong there.
Then finally I realized I can edit my question post, even if it is closed (I just cannot add an answer) - so better to delete the answer from the other question, and move it here I guess (although now that it is here, it would have been better it's an answer :/ Ah nevermind).
So, not to nag the mods to reopen and reclose again, I'll post that answer here:
Basically, to \typeout the contents of that example:
- Use
\meaningto convert\tmpato "The letter H" - Use a "parser" macro, to extract the third word from a set of three words
So finally we have the corrected MWE, that can print the content of \tmpa (given here we explicitly expect it to be one letter) to terminal:
\documentclass{minimal}
\begin{document}
\def\wordIIIofIII #1 #2 #3{#3}
\let\tmpa=Hello
\edef\tmpb{A\tmpa}
\tmpb % typesets "ello AH"
\typeout{\tmpa} % writes "\tmpa" in terminal
\typeout{\tmpb} % writes "A\tmpa" in terminal
\edef\tmpc{\meaning\tmpa}
\typeout{\tmpc} % writes "the letter H" in terminal
\edef\tmpd{\expandafter\wordIIIofIII\tmpc}
\typeout{\tmpd} % writes "H" in terminal
\typeout{\the\catcode`H} % 11
% \typeout{\the\catcode`\tmpd} % "! Improper alphabetic constant."
\typeout{\the\catcode\expandafter`\tmpd} %11
\end{document}
\letmust be followed by a control sequence (or an active character), an optional=and one token! Other tokens following the first won't belong to the\letinstruction. – egreg May 28 '12 at 08:33