Manuel Pégourié-Gonnard wrote: >> Remember, though, that *everything* xparse makes is \protected. So a >> function created with xparse will be trying to do \peek_<whatever> in an >> expansion situation. > > AFAIK, the beginning of a cell in an alignment is a expansion situation and the > \protected doesn't help here. A quick test confirms this (I'm nothing like an expert on \halign!) > Thinking of it, it's not only about peeking functions, but about the whole > parser, which should (optionally) work purely by expansion, so that no > unexpandable token appears before the development of the actual user macro, thus > allowing to define and effectively use macros involving \omit or \noalign. > > With current \newcommand, the "parser" has this property if there is no optional > argument (for the simple reason that there is no parser in this case) and could > have it if \@testopt were replaced with eg \FE@testopt from etextools in other > cases. > > My question is: is it doable/desirable to allow defining macros having this > property with xparse? It may involve a lot of changes in the implementation, > hence not be worth trying. However, I hope it was worth at least raising the > question. There is a bigger issue than simply \peek_<whatever> here. With \newcommand, it is only the first argument that is ever checked, so it is possible to do things in an expandable fashion. I assume that it is feasible to do the same for the first n arguments. However, with xparse there is the possibility to do: \DeclareDocumentCommand \foo { o m o m } % Or whatever syntax! which I don't see being easy (possible?) to do in an expandable way. You've then got to factor in the parallel question about post-processing: this would pretty certainly fail. (That is before you factor in other argument types.) I guess that using LuaTeX this type of thing becomes a lot easier. I wonder if this is a case where as Jonathan Fine suggests we are trying to do things TeX macros simply cannot do because of the nature of TeX (even with the various extensions). -- Joseph Wright