I need to replace all characters given as argument with other characters, doing some sort of transliteration.
This answer provides a solution that works nicely with XeLaTeX and Unicode. Unfortunately it cannot replace within arguments of commands that occur within the \myreplace
:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\myreplace}{m}
{
\tl_set:Nn \l__maxd_argument_tl { #1 }
\tl_replace_all:Nnn \l__maxd_argument_tl { e } { ẹ }
\tl_replace_all:Nnn \l__maxd_argument_tl { E } { Ẹ }
\tl_use:N \l__maxd_argument_tl
}
\tl_new:N \l__maxd_argument_tl
\ExplSyntaxOff
\begin{document}
\myreplace{Ee} \myreplace{E\emph{e}}
\end{document}
A general solution for all text-commands would be fantastic, but solving it for \emph
only would be fine for my purpose.
I'd also be interested to learn whether I could add some basic error-handling, e.g. by making the macro replace all characters other than the specified ones by something that's spotted easily, like "???".