Using (first of all) xparse I want to create a command like this:

\DeclareDocumentCommand{\c}{ s > { \SplitList { ; } } r""}
% do something

It basically should just do the following:

  • convert "f;g;h;..." to f » g » h » ..., if s is false (no star is given)
  • convert "f;g;h;..." to fgh..., if s is true (a star is given)

The whole purpose is being able to redefine the command to basically reverse the order, that is:

  • convert "f;g;h;..." to ... « h « g « f, if s is false (no star is given)
  • convert "f;g;h;..." to ...hgf, if s is true (a star is given)

How can I nicely do this using "high-level functions"? I am already using xparse, xstring and I am thinking etoolbox or something similar might help. I do not really want to deal with "low-level" TeX programming, if that makes any sense.

  • Is there any particular reason for using a delimited argument instead of the standard braces? – egreg Jan 18 '16 at 20:48
  • @egreg Not particularly. I guess it looks better and it is little bit easier to type. Oh, it also may improve readibility, when you have nested commands (when you use multiple kinds of delimiters). – Stefan Perko Jan 18 '16 at 21:31

Not really 'high-level' but since xparse is used anyway and SplitList is expl3 anyway:

The \convert command uses the first starred argument for the f>g>h splitting and the third argument is for reversal of the order.

It uses a \seq_... variable and splits the input by ; into tokens and glues them together (or replaces effectively ; by >) and eventually reverses the order.



  \seq_set_split:Nnn \l_tmpa_seq {;} {#2}
  \IfBooleanT{ #3 }{%
    \seq_reverse:N \l_tmpa_seq 
    \seq_use:Nn \l_tmpa_seq {}%
    \seq_use:Nn \l_tmpa_seq {$>$} 





enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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