I need to produce a variable-sized string consisting of even number of Latin letters, each pair being of the format a\textrightarrow A;
. Each pair separated from the other pairs by some empty space (here 1cm for example). For this I define a command \midarrow
and use \regex_replace
of expl3
to modify the argument of \midarrow
.
I want \midarrow
to convert
"a,A;b,B;c,C" to "(a->A); (b->B); (c->C)"
"a,A;b,B;c,C;d,D" to "(a->A); (b->B); (c->C); (d->D)"
"->" above should be actual arrows produced by
\textrightarrow
The MWE is as follows:
\documentclass[a4paper,11pt]{article}
\usepackage{expl3,xparse}
\usepackage{textcomp}
\ExplSyntaxOn
\NewDocumentCommand{\midarrow}{m}
{
\tl_set:Nn \l_tmpa_tl { (#1) }
\regex_replace_all:nnN { , } { \textrightarrow } \l_tmpa_tl
\regex_replace_all:nnN { ; } { );\hspace{1cm}( } \l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
\begin{document}
\midarrow{a,A;b,B;c,C}
\end{document}
However I get garbage as result. How do I make sure that the result of \regex_replace_all
should be compiled by pdfLaTeX and produce the desired output?
PS: I am not proficient in latex3. I have just reused and modified code I found on this site to suit my purposes.
\tl_replace_all:Nnn \l_tmpa_tl { , } { \textrightarrow }
and\tl_replace_all:Nnn \l_tmpa_tl { ; } { );\hspace{1cm}( }
instead of regular expressions.