LaTeX forum ⇒ GeneralArgument expansion within NewDocumentCommand

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

Argument expansion within NewDocumentCommand

Postby pippipalma » Tue May 24, 2016 3:24 pm

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:

  1. \documentclass{article}
  2. \usepackage{xparse}
  3.  
  4. \newcommand{\addConjug}[1]{#1.\par}
  5. \NewDocumentCommand{\verbum}{>{\SplitList{;}}m}
  6. {\ProcessList{#1}{\addConjug}}
  7.  
  8. \newcommand{\addVoice}[1]{#1;}
  9. \NewDocumentCommand{\regVerbum}{>{\SplitList{,}}m}
  10. {The input: \ProcessList{#1}{\addVoice}\par
  11. The output: \verbum{\ProcessList{#1}{\addVoice}}}
  12.  
  13. \begin{document}
  14. \regVerbum{a,b,c,d,e,f,g}
  15.  
  16. The input: a;b;c;d;e;f;g;\par
  17. The output: \verbum{a;b;c;d;e;f;g;}
  18. \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!

Tags:

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Thu May 26, 2016 12:44 pm

This works in at least for your example code:

  1. \documentclass{article}
  2. \usepackage{xparse}
  3.  
  4. \newcommand{\addConjug}[1]{#1.\par}
  5.  
  6. \NewDocumentCommand{\verbum}{>{\SplitList{;}}m}
  7. {\ProcessList{#1}{\addConjug}}
  8.  
  9. \newcommand{\addVoice}[1]{#1;}
  10.  
  11. \NewDocumentCommand{\regVerbum}{>{\SplitList{,}}m}
  12. {%
  13. The input: \ProcessList{#1}{\addVoice}\par
  14. % this only works because \addVoice is expandable; it might or might not
  15. % work in your real case
  16. \edef\regVerbumAux{\ProcessList{#1}{\addVoice}}%
  17. The output: \expandafter\verbum\expandafter{\regVerbumAux}%
  18. }
  19.  
  20. \begin{document}
  21.  
  22. \regVerbum{a,b,c,d,e,f,g}
  23.  
  24. The input: a;b;c;d;e;f;g;\par
  25. The output: \verbum{a;b;c;d;e;f;g;}
  26.  
  27. \end{document}


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

pippipalma
Posts: 22
Joined: Mon Aug 20, 2012 5:12 pm

Postby pippipalma » Sun May 29, 2016 12:31 pm

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:

  1. \documentclass{article}
  2. \usepackage[polutonikogreek,italian]{babel}
  3. \usepackage[latin1]{inputenc}
  4. \usepackage{hanging}
  5. \usepackage{type1ec}
  6. \usepackage{etoolbox}
  7. \usepackage{xparse}
  8. \usepackage{mfirstuc}
  9.  
  10. % counters declarations
  11. \newcounter{formlist}
  12. \newcounter{meaninglist}
  13. \newcounter{verblist}
  14. \newcounter{rvlist}
  15.  
  16. % general definitions
  17. \newcommand{\gr}[1]{\begin{otherlanguage*}{greek}#1\end{otherlanguage*}}
  18. \newcommand{\aum}[2]{#1\ifstrempty{#1}{\`e#2}{\`#2}}
  19.  
  20. % definitions for command \entry
  21. \newcommand{\addForm}[1]{\stepcounter{formlist}\ifnumequal{\theformlist}{1}{\markboth{#1}{#1}}{, }#1}
  22. \newcommand{\addMeaning}[1]{\stepcounter{meaninglist}\ifnumequal{\themeaninglist}{1}{}{. }\makefirstuc{#1}}
  23. \NewDocumentCommand{\entry}{>{\SplitList{;}}m m >{\SplitList{;}}m m}%
  24. {\setcounter{formlist}{0}\hangpara{2em}{1}\textbf{\ProcessList{#1}{\addForm}}\ifstrempty{#4}{}{ [#4]} \emph{#2}\ \setcounter{meaninglist}{0}\ProcessList{#3}{\addMeaning}\par}
  25.  
  26. % definitions for command \verbo
  27. \newcommand{\iv}[1]{%
  28. \ifnumequal{\theverblist}{1}{; \emph{txt1.\ \emph{#1}}}{}%
  29. \ifnumequal{\theverblist}{2}{; \emph{txt2.\ \emph{#1}}}{}%
  30. \ifnumequal{\theverblist}{3}{; \emph{txt3.\ \emph{#1}}}{}%
  31. \ifnumequal{\theverblist}{4}{; \emph{txt4.\ \emph{#1}}}{}%
  32. \ifnumequal{\theverblist}{5}{; \emph{txt5.\ \emph{#1}}}{}%
  33. \ifnumequal{\theverblist}{6}{; \emph{txt6.\ \emph{#1}}}{}%
  34. \ifnumequal{\theverblist}{7}{, #1}{}%
  35. \ifnumequal{\theverblist}{8}{; \emph{txt7.\ \emph{#1}}}{}%
  36. \ifnumequal{\theverblist}{9}{; \emph{txt8.\ \emph{#1}}}{}%
  37. \ifnumequal{\theverblist}{10}{; \emph{txt9.\ \emph{#1}}}{}%
  38. \ifnumequal{\theverblist}{11}{; \emph{txt10.\ \emph{#1}}}{}%
  39. \ifnumequal{\theverblist}{12}{; \emph{txt11.\ \emph{#1}}}{}%
  40. \ifnumequal{\theverblist}{13}{; \emph{txt12.\ \emph{#1}}}{}%
  41. \ifnumequal{\theverblist}{14}{; \emph{txt13.\ \emph{#1}}}{}%
  42. \ifnumequal{\theverblist}{15}{; \emph{txt14.\ \emph{#1}}}{}%
  43. \ifnumequal{\theverblist}{16}{; \emph{txt15.\ \emph{#1}}}{}%
  44. \ifnumequal{\theverblist}{17}{, #1}{}%
  45. \ifnumequal{\theverblist}{18}{; \emph{txt16.\ \emph{#1}}}{}%
  46. \ifnumequal{\theverblist}{19}{; \emph{txt17.\ \emph{#1}}}{}%
  47. \ifnumequal{\theverblist}{20}{; \emph{txt18.\ \emph{#1}}}{}%
  48. }
  49. \newcommand{\addConjug}[1]{\stepcounter{verblist}\ifstrempty{#1}{}{\iv{#1}}}
  50. \NewDocumentCommand{\verbo}{>{\SplitList{;}}m m m m m}%
  51. {\setcounter{verblist}{0}%
  52. \entry{#2}{\ifdefequal{#3}{1}{v.\ tr.}{v.\ intr.}\ProcessList{#1}{\addConjug}}{#4}{#5}}
  53.  
  54. % definitions for command \verboreg
  55. \newcommand{\rva}{}
  56. \newcommand{\rvb}{}
  57. \newcommand{\rvt}{}
  58. \newcommand{\rv}[1]{%
  59. \ifnumequal{\thervlist}{1}{\aum{\rva}{\rvb}#1}{}%
  60. \ifnumequal{\thervlist}{2}{xxx \rva\rvb#1}{}%
  61. \ifnumequal{\thervlist}{3}{\aum{\rva}{\rvb}#1}{}%
  62. \ifnumequal{\thervlist}{4}{yyy \rva\rvb#1}{}%
  63. \ifnumequal{\thervlist}{5}{zzz \rva\rvb#1}{}%
  64. \ifnumequal{\thervlist}{6}{\rva\rvb#1}{}%
  65. \ifnumequal{\thervlist}{7}{\rva\rvb#1}{}%
  66. \ifnumequal{\thervlist}{8}{\rva\rvb#1}{}%
  67. \ifnumequal{\thervlist}{9}{\rva\rvb#1}{}%
  68. \ifnumequal{\thervlist}{10}{\rva\rvb#1}{}%
  69. %\ifdefequal{\rvt}{1}{%
  70. \ifnumequal{\thervlist}{11}{\rva\rvb#1}{}%
  71. \ifnumequal{\thervlist}{12}{\rva\rvb#1}{}%
  72. \ifnumequal{\thervlist}{13}{\rva\rvb#1}{}%
  73. \ifnumequal{\thervlist}{14}{\rva\rvb#1}{}%
  74. \ifnumequal{\thervlist}{15}{\rva\rvb#1}{}%
  75. \ifnumequal{\thervlist}{16}{\rva\rvb#1}{}%
  76. \ifnumequal{\thervlist}{17}{\rva\rvb#1}{}%
  77. \ifnumequal{\thervlist}{18}{\rva\rvb#1}{}%
  78. \ifnumequal{\thervlist}{19}{\rva\rvb#1}{}%
  79. %}{}%
  80. \ifnumequal{\thervlist}{20}{\rva\rvb#1}{;}%
  81. }
  82. \newcommand{\addDes}[1]{\stepcounter{rvlist}\ifstrempty{#1}{}{\rv{#1}}}
  83. \NewDocumentCommand{\verboreg}{m m m m m m >{\SplitList{;}}m}%
  84. {\setcounter{rvlist}{0}%
  85. \renewcommand{\rva}{#1}%
  86. \renewcommand{\rvb}{#2}%
  87. \renewcommand{\rvt}{#4}%
  88. \edef\verboregAux{\ProcessList{#7}{\addDes}}%
  89. \expandafter\verbo\expandafter{\verboregAux}{#1#2#3}{#4}{#5}{#6}}
  90.  
  91. % definition of end_user command \anno
  92. \newcommand{\anno}[6]%
  93. {\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}}
  94.  
  95.  
  96. \begin{document}
  97. text
  98. \anno{aaa}{bbb}{ccc}{1}{Some recent text.}{\gr{some ancient text}}
  99.  
  100. \end{document}


Would you have any idea on how to solve that problem?

Best,
Giuseppe

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun May 29, 2016 1:03 pm

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.
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 8 guests