I want to split a string into individual characters, transform each character individually, then join them back together.
Something like this:
\newcommand{\drawaboxaroundit}[1]{...}
\newcommand{\glue}{+}
\explodethenjoin{abcdef}{\drawaboxaroundit}{\glue}
Glossing over how \drawaboxaroundit
might work (it's just for illustration, it's not what I'm really doing), the result for this example would be something like this:
The intention is for \explodethenjoin{abc}{\drawaboxaroundit}{\glue}
will expand to
\drawaboxaroundit{a}\glue\drawaboxaroundit{b}\glue\drawaboxaroundit{c}
I nearly have a solution to my problem with this answer (although I know basically nothing about expl so I don't understand how it works) -- this processes each character individually but does not put glue between them.
One approach (which doesn't seem like good design to me) would be to make \drawaboxaroundit
aware of its position, i.e. the above abc
example would expand to
\drawaboxarounditwrapper{0}{\glue}{a}\drawaboxarounditwrapper{1}{\glue}{b}\drawaboxarounditwrapper{2}{\glue}{c}
with \drawaboxarounditwrapper
defined to be something like this
\newcommand{\drawaboxarounditwrapper}[2]{
\ifthenelse{\equal{#1}{0}}{}{\glue}
\drawaboxaroundit{#2}
}
Another option would be to split the string into head character and tail string. Something like this
\witheachcharacterinheadandtail{abcdef}{\drawaboxaroundit}{\glue\drawaboxaroundit}
Where \witheachcharacterinheadandtail{abcdef}{\foo}{\bar}
expands into
\foo{a}\bar{b}\bar{c}\bar{d}\bar{e}\bar{f}
This second approach seems to be better, but I don't know how to realize either of these approaches, or whether either is a good idea in the first place.
How can I explode-transform-join a string? We can assume the strings in question are ASCII and contain no latex commands, and all strings will contain at least two characters (a tail will always have nonzero length).
\scando
to do what you want instead of\spectrum
.