GeneralArgument expansion within NewDocumentCommand

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
pippipalma
Posts: 23
Joined: Mon Aug 20, 2012 5:12 pm

Argument expansion within NewDocumentCommand

Post by pippipalma »

Hello,
I'm trying to call the macro \verbum (defined via \NewDocumentCommand) from the other macro \regVerbum, but it seems that the mandatory argument taken by the \Splitlist processor in \verbum command has not been expanded.

Here it is a minimal working example:

Code: Select all

\documentclass{article}
\usepackage{xparse}

\newcommand{\addConjug}[1]{#1.\par}
\NewDocumentCommand{\verbum}{>{\SplitList{;}}m}
{\ProcessList{#1}{\addConjug}}

\newcommand{\addVoice}[1]{#1;}
\NewDocumentCommand{\regVerbum}{>{\SplitList{,}}m}
{The input: \ProcessList{#1}{\addVoice}\par
The output: \verbum{\ProcessList{#1}{\addVoice}}}

\begin{document}
\regVerbum{a,b,c,d,e,f,g}

The input: a;b;c;d;e;f;g;\par
The output: \verbum{a;b;c;d;e;f;g;}
\end{document}
Could you please suggest a way to obtain by \regVerbum{a,b,c,d,e,f,g} what I obtain by \verbum{a;b;c;d;e;f;g;}?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Argument expansion within NewDocumentCommand

Post by cgnieder »

This works in at least for your example code:

Code: Select all

\documentclass{article}
\usepackage{xparse}

\newcommand{\addConjug}[1]{#1.\par}

\NewDocumentCommand{\verbum}{>{\SplitList{;}}m}
  {\ProcessList{#1}{\addConjug}}

\newcommand{\addVoice}[1]{#1;}

\NewDocumentCommand{\regVerbum}{>{\SplitList{,}}m}
  {%
    The input: \ProcessList{#1}{\addVoice}\par
    % this only works because \addVoice is expandable; it might or might not
    % work in your real case
    \edef\regVerbumAux{\ProcessList{#1}{\addVoice}}%
    The output: \expandafter\verbum\expandafter{\regVerbumAux}%
  }

\begin{document}

\regVerbum{a,b,c,d,e,f,g}

The input: a;b;c;d;e;f;g;\par
The output: \verbum{a;b;c;d;e;f;g;}

\end{document}
Regards
site moderator & package author
pippipalma
Posts: 23
Joined: Mon Aug 20, 2012 5:12 pm

Argument expansion within NewDocumentCommand

Post by pippipalma »

Thank you, Clemens, for your help. Unfortunately, it seems that, in my actual document, the command \addDes (which is the analogue of \addVoice in the MWE) is not expandable:

Code: Select all

\documentclass{article}
\usepackage[polutonikogreek,italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage{hanging}
\usepackage{type1ec}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{mfirstuc}

% counters declarations
\newcounter{formlist}
\newcounter{meaninglist}
\newcounter{verblist}
\newcounter{rvlist}

% general definitions
\newcommand{\gr}[1]{\begin{otherlanguage*}{greek}#1\end{otherlanguage*}}
\newcommand{\aum}[2]{#1\ifstrempty{#1}{\`e#2}{\`#2}}

% definitions for command \entry
\newcommand{\addForm}[1]{\stepcounter{formlist}\ifnumequal{\theformlist}{1}{\markboth{#1}{#1}}{, }#1}
\newcommand{\addMeaning}[1]{\stepcounter{meaninglist}\ifnumequal{\themeaninglist}{1}{}{. }\makefirstuc{#1}}
\NewDocumentCommand{\entry}{>{\SplitList{;}}m m >{\SplitList{;}}m m}%
{\setcounter{formlist}{0}\hangpara{2em}{1}\textbf{\ProcessList{#1}{\addForm}}\ifstrempty{#4}{}{ [#4]} \emph{#2}\ \setcounter{meaninglist}{0}\ProcessList{#3}{\addMeaning}\par}

% definitions for command \verbo
\newcommand{\iv}[1]{%
\ifnumequal{\theverblist}{1}{; \emph{txt1.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{2}{; \emph{txt2.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{3}{; \emph{txt3.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{4}{; \emph{txt4.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{5}{; \emph{txt5.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{6}{; \emph{txt6.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{7}{, #1}{}%
\ifnumequal{\theverblist}{8}{; \emph{txt7.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{9}{; \emph{txt8.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{10}{; \emph{txt9.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{11}{; \emph{txt10.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{12}{; \emph{txt11.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{13}{; \emph{txt12.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{14}{; \emph{txt13.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{15}{; \emph{txt14.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{16}{; \emph{txt15.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{17}{, #1}{}%
\ifnumequal{\theverblist}{18}{; \emph{txt16.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{19}{; \emph{txt17.\ \emph{#1}}}{}%
\ifnumequal{\theverblist}{20}{; \emph{txt18.\ \emph{#1}}}{}%
}
\newcommand{\addConjug}[1]{\stepcounter{verblist}\ifstrempty{#1}{}{\iv{#1}}}
\NewDocumentCommand{\verbo}{>{\SplitList{;}}m m m m m}%
{\setcounter{verblist}{0}%
\entry{#2}{\ifdefequal{#3}{1}{v.\ tr.}{v.\ intr.}\ProcessList{#1}{\addConjug}}{#4}{#5}}

% definitions for command \verboreg
\newcommand{\rva}{}
\newcommand{\rvb}{}
\newcommand{\rvt}{}
\newcommand{\rv}[1]{%
\ifnumequal{\thervlist}{1}{\aum{\rva}{\rvb}#1}{}%
\ifnumequal{\thervlist}{2}{xxx \rva\rvb#1}{}%
\ifnumequal{\thervlist}{3}{\aum{\rva}{\rvb}#1}{}%
\ifnumequal{\thervlist}{4}{yyy \rva\rvb#1}{}%
\ifnumequal{\thervlist}{5}{zzz \rva\rvb#1}{}%
\ifnumequal{\thervlist}{6}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{7}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{8}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{9}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{10}{\rva\rvb#1}{}%
%\ifdefequal{\rvt}{1}{%
\ifnumequal{\thervlist}{11}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{12}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{13}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{14}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{15}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{16}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{17}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{18}{\rva\rvb#1}{}%
\ifnumequal{\thervlist}{19}{\rva\rvb#1}{}%
%}{}%
\ifnumequal{\thervlist}{20}{\rva\rvb#1}{;}%
}
\newcommand{\addDes}[1]{\stepcounter{rvlist}\ifstrempty{#1}{}{\rv{#1}}}
\NewDocumentCommand{\verboreg}{m m m m m m >{\SplitList{;}}m}%
{\setcounter{rvlist}{0}%
\renewcommand{\rva}{#1}%
\renewcommand{\rvb}{#2}%
\renewcommand{\rvt}{#4}%
\edef\verboregAux{\ProcessList{#7}{\addDes}}%
\expandafter\verbo\expandafter{\verboregAux}{#1#2#3}{#4}{#5}{#6}}

% definition of end_user command \anno
\newcommand{\anno}[6]%
{\verboreg{#1}{#2}{#3}{#4}{#5}{#6}{bla1;bla2;bla3;blà4;bla5;bla6;bla7;bla8;bla9;bla10;bla11;bla12;bla13;bla14;blò15;bla16;bla17;bla18;blù19;bla20}}


\begin{document}
text
\anno{aaa}{bbb}{ccc}{1}{Some recent text.}{\gr{some ancient text}}

\end{document}
Would you have any idea on how to solve that problem?

Best,
Giuseppe
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Argument expansion within NewDocumentCommand

Post by cgnieder »

Indeed it isn't expandable: you have a \stepcounter in there which does an assignment (it assigns a value to a counter) and assignments never are expandable.
site moderator & package author
Post Reply