# Tag Info

## Hot answers tagged expansion

12

At the very beginning you said: When TeX first tokenized \cmd | but that's wrong. TeX is a well-behaved gentleman and doesn't get ahead of itself scanning a  and a | before knowing what \cmd is supposed to do. As far as TeX is concerned, the space and the | and whatever other character could all mean the same thing, and could change in meaning, so pre-...

11

When TeX is expanding tokens and finds a macro, it replaces it with the macro’s replacement text, after having absorbed the arguments, if so specified by the macro. Then it restarts from the first token in the replacement text. Thus the steps with your code are \c\a \b\a \def\a{2}\a <do the assignment> \a 2 To complement the above description, ...

6

I believe what happens is as follows: \verb is first tokenized (the space character, which has catcode 10 just before \verb is tokenized, marks the end of this control word but is not discarded). TeX will go into state S, since \verb is a control word (control sequence whose name is made of “letters” only), but it doesn't skip blanks yet. \verb is ...

6

You can achieve this by testing whether the argument contains exactly 3 braced groups or tokens and if so whether the first of those tokens is \setcol. If that is the case output the special case, else use the normal output. The following uses expl3 to achieve this (because it already contains everything we need for those tests). \documentclass[]{article} \...

6

Expansion is depth first, that is, \c will be completely expanded before \a is expanded, so it will go like this: \c\a ==> \b\a ==> \def\a{2}\a ==> 2

4

\seq_if_in:Nn(TF) is not expandable because the tokens in the sequence might have different catcodes: \exp_args:NNx \seq_set_from_clist:Nn \l_tmpa_seq { \token_to_str:N : } \seq_show:N \l_tmpa_seq \seq_if_in:NnTF \l_tmpa_seq { : } { \show\T } { \show\F } and you can't (reasonably) test that expandably. Property lists, on the other hand, have the key ...

4

That is expected, yes. x is \edef under the hood, and \edef as a definition command expects that a # is either followed by a valid parameter number, or by another #. And, as you observed yourself: If \example:x { #1 . } is changed to \example:x { ##1 . }, it behaves exactly as \example:e { #1 . }. In “The LaTeX3 Programming Language” (expl3.pdf) it says (...

3

I presume you are using pdfTeX, otherwise you wouldn't have issues with Unicode. There are a few options, depending on what precisely you want to do. If you don't want the argument to expand at all, then you can use \exp_not:n {#1} to prevent \write from messing up the active UTF-8 tokens: \NewDocumentCommand { \writetofile } { m } { \iow_now:Nx \...

1

Although it is explicitly not asked for a test it may be worth mentioning that a test for the expandability of a token can be based on the circumstance that with expandable tokens and undefined tokens the test \expandafter\ifx\noexpand⟨token⟩⟨token⟩⟨token not expandable⟩\else⟨token expandable or undefined⟩\fi delivers the tokens of the \else-branch/delivers ...

Only top voted, non community-wiki answers of a minimum length are eligible