1

I defined the following latex command:

\NewDocumentCommand{\invokeWithCSV}{m>{\SplitList{,}}m}{#1#2}

It takes as input the name of a command and a list of comma separated arguments and invokes the command using those arguments. Then I create the command:

\newcommand{\sample}[3]{sample text}

Now if I try to create a glossary entry with either

\newglossaryentry{entry}{
      name=\sample{1}{2}{3},
      description={desc}}

or

\newglossaryentry{entry}{
      name=\invokeWithCSV{\sample}{1,2,3},
      description={desc}}

then the second option fails. Could you explain this and offer a solution for it. The exact command to be invoked and the number of its arguments are unknown beforehand.

A minimal working example with the first option:

\documentclass{article}
\usepackage{xparse,pgffor}
\usepackage{glossaries}
\makeglossaries

\begin{document}
% \NewDocumentCommand{\invokeWithCSV}{m>{\SplitList{,}}m}{#1#2}
\newcommand{\sample}[3]{sample text}

\newglossaryentry{entry}{
    name=\sample{1}{2}{3},
    description={desc}}

\gls{entry}    
\printglossaries
\end{document}

A minimal NON-working example, just by changing the name field:

\documentclass{article}
\usepackage{xparse,pgffor}
\usepackage{glossaries}
\makeglossaries

\begin{document}
\NewDocumentCommand{\invokeWithCSV}{m>{\SplitList{,}}m}{#1#2}
\newcommand{\sample}[3]{sample text}

\newglossaryentry{entry}{
    name=\invokeWithCSV{\sample}{1,2,3},
    description={desc}}

\gls{entry}    
\printglossaries
\end{document}
2
  • Welcome! Can you expand your code to provide a minimal working example which compiles or a minimal non-working example, if you get an error?
    – cfr
    Jan 21 at 0:26
  • I changed accordingly. Thanks.
    – atti6j
    Jan 21 at 10:30

1 Answer 1

0

I found a way to circumvent the above issuse:

\NewDocumentCommand{\newentrywithargs}{m >{\SplitList{,}}m}{
    \newglossaryentry{entry}{
        name={#1#2},
        description={desc}
    }
}

\newentrywithargs{\sample}{1,2,3}
\gls{entry}

With this command I can create entries whose names are generated by macros with arbitrary number of parameters.

This solution, mind you, doesn't answer the question why my original approach throw an error.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .