Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
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 8 '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 S-Z Jan 8 '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 8 '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 8 '11 at 22:07
show 2 more comments

1 Answer

up vote 10 down vote accepted

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!

share|improve this answer
    
Yeah, hence my use of the word expand in quotes. I suspected this might be the case, though! Cheers :-) –  Will Robertson Oct 5 '10 at 12:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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