[NTG-pdftex] \expanded

Joseph Wright joseph.wright at morningstar2.co.uk
Thu May 17 10:35:00 CEST 2018

On 17/05/2018 07:30, Joseph Wright wrote:
> An \expanded primitive makes it much more convenient to create such 
> approaches, and matches the expansion carried out by e.g. \pdfstrcmp. 
> For the work of the team in expl3, this would significantly aid 
> consistency and allow more 'easy' expandable programming. The code 
> addition is also small compared with many other 'new' (post-e-TeX) 
> primitives, and \expanded is already present in LuaTeX. As such, we hope 
> that the request can be actioned: we will make similar requests for 
> XeTeX and (u)pTeX, such that all major engines have the functionality.

A 'toy' application is a very simple expandable case changer. I've used 
a bit of expl3 here purely to avoid having to re-work string comparison. 
The following currently runs only with LuaTeX as it uses \expanded:

\input expl3-generic %
% A string case switcher, for convenience
\cs_set_eq:NN \strcase \str_case:nnF
     % No match
     % No match

You *can* do the same without \expanded by arranging that each 'result' 
token is shuffled to the end of an internal auxiliary set up, but that 
means having to move tokens around. You can also deal with the nested 
macros by testing each token for being an expandable macro. But the 
result is much more 'pain', and that you have to be sure that everything 
is set up correctly. (See \tl_upper_case:n, etc., in expl3, for a real 
implementation that does all of these things.)

Having \expanded makes that all a lot easier, before you get on to 
places where 'shuffle the tokens' is not realistic.


More information about the ntg-pdftex mailing list