eao@shape.mps.ohio-state.edu (Ed Overman) (11/22/90)
I want to do \let\A=3 \edef\B{\A} and have \B contain 3. This does not happen as can be seen from \let\A=3 \edef\B{\A} \let\A=9 \A where 9 will be printed out. The reason is that I want to search through a sequence of characters using \let\next= and then put the contents of \next into different control sequences depending on SOMETHING (for example, all letters go in \letters and all numbers go in \numbers). I must admit that I have never understood TeX's anatomy very well - which is why this has me confused (any references or good explanations would be greatly appreciated). The only solution I have found is to use \message\A since the third word in the output of this control squence, which is the character in question, can be grabbed and put into a control sequence. This does not seem a very elegant solution to me. Thanks, Ed Overman
marcel@cs.caltech.edu (Marcel van der Goot) (11/24/90)
In <1990Nov22.001531.7022@zaphod.mps.ohio-state.edu> and <1990Nov22.001733.7082@zaphod.mps.ohio-state.edu> Ed Overman (eao@shape.mps.ohio-state.edu) writes > I want to do > \let\A=3 \edef\B{\A} > and have \B contain 3. This does not happen [...] > [...] > (any references or good explanations would be greatly appreciated). I can explain why this doesn't work, but a solution is a different thing. * On p. 207 (TeXbook) it is explained that \A (on that page \zero) is not a macro, and therefore doesn't expand. * In the answer of exercise 20.14 Knuth does exactly what you do, precisely because \A is not expanded. * On p. 269 it is explained what \A is, namely an ``implicit character.'' * Answer 8.7 points out that \A is not a character token. Unfortunately, as far as I can tell, there are only three ways to get the current value of an implicit character: by using it as a command in horizontal mode (p. 286, 283) (i.e., by typesetting it), or by using \meaning, or by comparing it with something else using \if. > The only solution I have found is to use \meaning\A since the third word > in the output of this control squence, which is the character in question, > can be grabbed and put into a control sequence. This does not seem a very > elegant solution to me. It doesn't seem very elegant to me either, but apparently this sort of use of \meaning has occurred to Knuth (although he considers it ``obscure''), see answer 24.1. I think it is better not to use \let or \futurelet in the first place, but to use something with \def instead. First define \def\mylet#1=#2{\def#1{#2}} I don't quite know how you want to use it, but say #1 is a sequence of characters. Then \mylet\a=#1 has almost the same effect as \let\a=#1, except that \let\a=3 would have been changed to \def\a{3}, so that \edef\b{\a} has the required effect. Only the behavior with respect to spaces is different. Spaces may not be important in your case, otherwise you will have to do something complicated to test first whether #1 starts with a space. Marcel van der Goot marcel@vlsi.cs.caltech.edu
eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (11/24/90)
eao@shape.mps.ohio-state.edu (Ed Overman) writes: >I want to do > \let\A=3 \edef\B{\A} >and have \B contain 3. \let is a very strange thing. It makes a control sequence to a synonym for a token, which can be a control sequence token, or a character token. Note: a synonym, not a definition that has to be expanded. Thus in \edef\B{\A} the \A is not expanded, because there is nothing to expand; \A *is* already a charcter. For instance \if 3\A is true! However, you cannot get at for instance the Ascii code of the character that is \A: `\A is 65, which is Ascii for 'A'. >The only solution I have found is to use \meaning\A since the third word the output of \meaning\A is `the character 3'. I'm afraid I can't do any better than this. But do you need to do it this way? What is wrong with \def\GetOneLetter#1{ ... } ? This works at least for all letters and digits, tho' not for things like braces, and unfortunately also not for spaces. You can distinguish between a lot of tokens if you have \let\A, using \ifcat. For instance, '\ifcat a\A' will be true if \A has been let to a letter. Victor.