6

I want a simple way to have:

\reverseit{abc defg \mycommand}

yield

\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...

einpoklum
  • 12,311

1 Answers1

11
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand\reverseit { m }
  { \tl_reverse:n { #1 } }
\ExplSyntaxOff

\begin{document}
\reverseit{abc defg \LaTeX}
\end{document}

This also honors spaces.

Azoun
  • 2,317
egreg
  • 1,121,712
  • 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. – Bruno Le Floch Jan 06 '12 at 12:25