I am trying to define a command that changes the color of every letter in the whole document to a specified color. I already tried different approaches from this thread, but I was not able to color every letter with any of those.
My best approach looks like this:
\documentclass{article}
\usepackage{xparse,l3regex}
\usepackage{xcolor}
\definecolor{color1}{HTML}{FF0000} %for A and a
\definecolor{color2}{HTML}{00FF00} %for B and b
\ExplSyntaxOn
\NewDocumentCommand{\colorsyn}{ m }
{
\colorsyn:nn { #1 }
}
%defining a new tocken list
\tl_new:N \l_syn_tl
\cs_new_protected:Npn \colorsyn:nn #1
{
%setting l_syn_tl to the string-argument
\tl_set:Nn \l_syn_tl { #1 }
%Coloring A and a by replacing them in the string and overriding l_syn_tl with the new string
\regex_replace_all:nnN { ([A+a]) } { \c{textcolor}\cB\{color1\cE\}\cB\{\1\cE\} } \l_syn_tl
%Coloring B and b and overriding l_syn_tl again
\regex_replace_all:nnN { ([B+b]) } { \c{textcolor}\cB\{color2\cE\}\cB\{\1\cE\} } \l_syn_tl
%Using \l_syn_tl as output
\tl_use:N \l_syn_tl
}
\ExplSyntaxOff
\begin{document}
\colorsyn{A Baby}
\end{document}
It works unless I try to change the color of more than two letter pairs, by simply adding:
\regex_replace_all:nnN { ([C+c]) } { \c{textcolor}\cB\{color3\cE\}\cB\{\1\cE\} } \l_syn_tl
to the code.
I hope anyone of you guys can help me with that problem or give me an new approach to work with.
Btw, that is what it should look like:


c, which also replaces\textcolor{color1}to\textcolor{\textcolor{color3}{c}olor}. If you define\cs_new_protected_nopar:Npn \__color_three:n { \textcolor{color3} }then it would probably work with the regex replace\c{__color_three:n}\cB\{\1\cE\}. – Manuel Nov 22 '14 at 14:46