0

I have a problem with foreach loop. When I pass parameters as list with '/' used as separator it works really well. However when any element in that list is defined with \def the separator seems to not work and the strings are concatenated.

\newcommand{\testme}[1]{
\foreach \aa/\bb in {#1} { 
    |\aa| |\bb| \newline
    }
}

\def\testmedef{{xyz}/{XYZ}}

\testme{ {abc}/{CDE}, \testmedef% }

Result:

|abc|CDE|
|xyz/XYZ|xyz/XYZ|

Thank you for your kind help!

goki
  • 103

1 Answers1

1

you can call:

\newcommand{\testme}[1]{
\foreach \aa/\bb in {#1} { 
    |\aa| |\bb| \newline
    }
}

\def\testmedef{{xyz}/{XYZ}}

\ExplSyntaxOn \cs_set_eq:NN \expandx \exp_args:Nx \ExplSyntaxOff \def\testmedef{{xyz}/{XYZ}} \expandx\testme{abc/CDE,\testmedef}

ljguo
  • 1,213
  • 1
  • 4
  • 12