I want to define a macro in a group in LaTeX3 so that it stays defined after the group, but without using global variables. For now I do:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentEnvironment{test}{}{}{
\str_clear_new:N \mytest
\str_put_right:Nx \mytest {I ~ like ~}
\str_gset_eq:NN \dummyvar \mytest
\group_insert_after:N \str_set_eq:NN
\group_insert_after:N \mytest
\group_insert_after:N \dummyvar
}
\ExplSyntaxOff
\begin{document}
\def\mytest{chocolate.}
{
\begin{test}
I’d like mytest to be defined at the end of the group without using global variables.
\end{test}
\mytest
}
\mytest
\end{document}
It works, but it seems really dirty, like I need to introduce a global dummy var etc… I tried to do:
\group_insert_after:N \str_set_eq:NN
\group_insert_after:N \mytest
\expandafter \group_insert_after:N \mytest
But funnily, the string is written backward now!! I also tried to generate a variant of \group_insert_after:V but it is forbidden.
\exp_args:NNNNNV \group_insert_after:N \str_set_eq:NN \group_insert_after:N \mytest \group_insert_after:N \mytest(you'll probably have to generate\exp_args:NNNNNVthough). – gusbrs Jul 09 '23 at 23:49\exp_args_generate:n {NNNNV}, but can’t make it work, not sure if I’m doing something stupid…Could you provide a full example by any chance? – tobiasBora Jul 09 '23 at 23:59\str_clear_new:N \mytestinside the environment, since it may be used multiple times). – gusbrs Jul 10 '23 at 00:14