I'd like to apply a function to capitals only so that:
Preferably without using too many packages (I already use
NOTES: I use XeLaTeX (as it's bidi support seems best).
Ok, here is an other approach dedicated to LuaLaTeX fans (and future fans of LuaLaTeX). I think it is a good example to show how easy it is to write a few (easy to understand) lines of Lua code. In the provided Lua code one can check the input string for every char and format any LaTeX string you need without cryptic TeX commands.
It is good practice to write the lua functions in a separate file with the extension .lua. For this MWE I use the
Edit: After the great comment from Khaled Hosny I want to provide a very straight solution. It shows again the power of Lua ;-). The new function replaces all (thats what the
I got this answer from
I use it in my document to format transliterations from semitic/arab languages. (instead of the
An approach using LaTeX3: the important command is
Of course, spaces are preserved, as are any formatting commands within the argument (here I put
Alternatively, you could use the replacement
I changed the regex to match any number of consecutive uppercase letters, and I changed the replacement text to add braces around the argument to
Consider rather writing a macro for this type of issue. For example you can create a command for your example as follows:
The advantage of this, is that also your mark-up can be more meaningful.
As per request and a bit of a different approach to egreg's solution.
This assumes that your input contains only normal letters (no accents). The result is really ugly.