In my attempt to learn expl3 programming, I've hacked together a function to fake "smallcaps" by looping through a token list and enlarging any tokens that are capital letters. The code currently "works", but I know I have jumped through more hoops than I needed to. My question is: how can I rewrite the code to better use what expl3 has to offer?
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_if_eq:nnTF { VV }
\cs_generate_variant:Nn \tl_to_str:n { e }
\DeclareDocumentCommand\fakesmallcaps{m} {
\tl_new:N \__orig_tl
\tl_new:N \__modified_tl
\tl_set:Nn \__orig_tl {#1}
% Put all the spaces in groups so they don't get filtered out when we map over them.
\tl_replace_all:Nnn \__orig_tl { ~ } { {~} }
\tl_set:Nn \__modified_tl {
\tl_map_inline:Nn \__orig_tl {
\tl_set:Nn \__current_tl {##1}
\tl_set:NV \__uppercasecurrent_tl {\tl_upper_case:n {##1}}
\str_set:Nx \__orig_str {\tl_to_str:e {\__current_tl}}
\str_set:Nx \__uppercasecurrent_str {\tl_to_str:e {\__uppercasecurrent_tl}}
\tl_if_eq:VVTF {\__orig_str} {\__uppercasecurrent_str} {
{\Large \__orig_str}
}{
\__uppercasecurrent_str
}
}
}
\tl_use:N \__modified_tl
}
\ExplSyntaxOff
\fakesmallcaps{This Is Cool}
I am aware of solutions using regular expressions here, but I really want to "loop through the tokens". I have also tried and failed to create an \bool__iscapital:n function macro that can be used inside of \bool_if:nTF, so guidance on that would be appreciated! It would also be a huge plus if I could do something like \fakesmallcaps{{\color{blue}The} Windy Road} and have the color preserved.
