2

I need to split comma-separed string from variable (actually data file) for further procesing.

There is MWE:

\documentclass{article}
\usepackage{csvsimple}
\usepackage{xparse}
\usepackage{filecontents}

\begin{filecontents*}{sample.csv}  
colA;  
A,B,C;  
\end{filecontents*}

\NewDocumentCommand{\myfunc}{ >{\SplitList{,}} m }{\ProcessList{#1}{\func}}
\NewDocumentCommand{\func}{m}{\fbox{#1}}

\newcommand{\textA}{a,b,c}

\begin{document}
\parindent=0pt

(1) \myfunc{a,b,c}\\  % OK
(2) \myfunc{\textA}\\ % Wrong
(3) \expandafter\myfunc\expandafter{\textA}\\ % OK

\csvreader[
head to column names,
separator=semicolon
]{sample.csv}{}%
{
(4) \expandafter\myfunc\expandafter{\colA} % Wrong (how to correct?)
}
\end{document}

What is the correct way to expand argument in case (4) in the same way as (1) or (3)??

Thank you very much in advance for any help or suggestion!

Best regards,

Lubos

3

This has not much to do with xparse, rather with the fact that \csvreader sets \colA to a macro containing what you're after, so it needs to be expanded twice. One way is to do

\expandafter\expandafter\expandafter\myfunc
\expandafter\expandafter\expandafter{\colA}

instead of only two \expandafter.

  • You are exactly right, thats work as expected! Thanks for explanation (and sorry for possible confusion). BTW: (just curious) any way to use any "shotcut" commands (and again sorry, I love TeX but I'm not Tex guru...)? – Luboš Kejzlar Aug 9 '16 at 13:56
  • I would probably use expl3: for instance (between \ExplSyntaxOn and \ExplSyntaxOff) one could do (4) ~ \exp_args:Nf \myfunc { \colA } to fully expand \colA on the left. (Note I used ~ for the space after (4).) – Bruno Le Floch Aug 9 '16 at 18:05
  • @LubošKejzlar You have already asked several questions here, and most of them seem to have reasonable answers. Please consider to accept answers if they worked for you (you can accept at most one answer per question) and/or to upvote them (you can upvote all answers that you appreciate). Maybe spare two minutes to take the tour. – gernot Mar 30 '17 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.