16

Consider the following:

\let\1=X
\edef\2{\1}
\show\1 \show\2

The result is

> \1=the letter X.

> \2=macro:
->\1.

Is it possible to ‘expand’ the meaning of \1 so that \2 contains just X? The only solution I can think of is to use \meaning on \1 and cut out the prefix, but that doesn't seem very elegant.

(Context: I'm writing a scanning function that looks ahead at the next token and then either adds it to a scratch variable or terminates the scanning. Can't add it to the scratch variable without expanding it first, though! But it's not the context that I care about, since I can do the loop in another way; I'm interested in this particular question.)

lockstep
  • 250,273
  • Maybe we should ask Taco to add such a function to the token library. – Philipp Dec 24 '10 at 12:21
  • 1
    Please make this site more user friendly! I wanted to comment (actually ask a question) on Joseph's answer, but I couldn't. – Ahmed Musa Jan 08 '11 at 22:07
  • @Pluto: Welcome to TeX.SX! This site limits what you can do by how much reputation you have, as explained in the FAQ. To leave comments, you need to get 50 reputation. If you have questions about how this site works, please ask over on meta, and use answers just for something which answers the question. (Deleting this one would probably be a good idea.) I hope you stick around here :) – Antal Spector-Zabusky Jan 08 '11 at 22:07
  • @Pluto: I think Antal S-Z forgot to mention the most important point: If you've got a question, don't ask it in a comment. Please ask a new question, using "Ask Question", and link to this one if you need to refer to it. – Hendrik Vogt Jan 08 '11 at 22:07
  • @Antal: Before you welcome a user to our site, have a look at his user profile. He could have welcomed you! – Hendrik Vogt Jan 08 '11 at 22:07
  • @Antal: As a new user, he cannot post on meta. I think it's a pretty silly restriction. Can't comment, can't post on meta to complain that he can't comment. sigh – TH. Jan 08 '11 at 22:07
  • @Pluto: Just a note to confirm Antal and Hendrik's comments, if you have a question then ask a fresh question; this gives you the best chance of it being answered. You can link back to this one if it is a follow-up question. – Andrew Stacey Jan 08 '11 at 22:07

1 Answers1

10

You can't expand a token which has been defined using \let (unless of course we are taking about something \let to another macro). As you say, \meaning is the only way that is going to work. Sorry if this is something of a non-answer!

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036