I want a simple way to have:

\reverseit{abc defg \mycommand}


\mycommand gfed cba


(Yes, the original motivation is related to Hebrew and RTL languages, but that can sort of be solved using \beginR ... \endR/\beginL ... \endL where necessary without changing the language. So I'm asking the general question.)

Edit: The solution in this question is acceptable as a non-LaTeX-3 solution...


1 Answer 1

\NewDocumentCommand\reverseit { m }
  { \tl_reverse:n { #1 } }

\reverseit{abc defg \LaTeX}

This also honors spaces.

  • For completeness, mention \tl_reverse_items:n, which does not honor spaces, and puts braces around every item, but is much faster (100 times?). --- Sorry, didn't see that there were spaces in Eyal's example. Jan 6, 2012 at 12:25

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.