This is actually a follow-up / the real question of this previous question.
I would like to convert text start with >> into centered text.
The motivation for this seemingly silly purpose would be to add a new syntax to my package
jwjournal, so that lines like>> (some remark)would be converted into centered annotations.
Suppose that the string to be parsed has been stored into a token list \l_jwjournal_tmp_tl. The goal is to recognize >> and make the text after it centered. However, if multiple >> are found, the corresponding text should be centered separately. Thus for example, if the content of \l_jwjournal_tmp_tl is aaa>>bbb>>ccc, I would like bbb and ccc to be centered.
This previous question already addressed the main issue of parsing this token list properly. The problem for me now is that \l_jwjournal_tmp_tl shall be used later for further parsing and I would thus like the parsed result to directly overwrite \l_jwjournal_tmp_tl (just like \regex_replace_all:nnN which directly modifies the value of the given token list). How should I achieve this?
Below is a MWE.
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\newenvironment{JWJournalCompactCenter} % https://tex.stackexchange.com/a/98893
{\parskip=0pt\par\nopagebreak\centering}
{\par\noindent\ignorespacesafterend}
\NewDocumentCommand \JWJournalCompactCenterText { m }
{
\begin{JWJournalCompactCenter}
#1
\end{JWJournalCompactCenter}
}
\tl_new:N \l_jwjournal_tmp_tl
\tl_set:Nn \l_jwjournal_tmp_tl { aaa >>bbb >>ccc }
% \tl_new:N \l__mymodule_replace_head_tl
% \seq_new:N \l__mymodule_replace_tail_seq
% \cs_new_protected:Nn \mymodule_replace:n
% {
% \regex_split:nnN { >> } { #1 } \l__mymodule_replace_tail_seq
% \seq_pop_left:NN \l__mymodule_replace_tail_seq \l__mymodule_replace_head_tl
% \tl_use:N \l__mymodule_replace_head_tl
% \seq_map_function:NN \l__mymodule_replace_tail_seq \JWJournalCompactCenterText
% }
\tl_use:N \l_jwjournal_tmp_tl
\ExplSyntaxOff
\end{document}
l3regex... – Skillmon Aug 29 '23 at 04:25