1

Sorry, this must be a very beginner's thing, but I cannot figure out how to get the macro expanded in the loop. I tried expandafter, csname, but don't get it working.

\documentclass[]{minimal}
\usepackage{xkeyval}  
\usepackage{pgffor,pgfmath}                    
\makeatletter
\define@cmdkey[mini]{test}{keyA}       {}% 
\define@cmdkey[mini]{test}{keyB}       {}%
\define@cmdkey[mini]{test}{keyC}       {}%
\newcommand{\testMacro}[1][]  
{%
    \setkeys[mini]{test}{#1}%
    \cmdmini@test@keyA% these work ok
    \cmdmini@test@keyB%
    \cmdmini@test@keyC%
    \foreach \i in {A,B,C}{%
        \i :%
        \cmdmini@test@key{\i}% This is the line that goes wrong
    }            
}
\makeatother
\begin{document}
\testMacro[%
    keyA={this is key A},%
    keyB={this is key B},%
    keyC={this is key C},%
]
\end{document}
  • You need \csname cmdmini@test@key\i\endcsname. The \i is not an argument but part of the command name. – Ulrike Fischer Mar 17 '16 at 16:10
  • I would never have guessed that, but I understand more about (end)csname now. Thank you. – mauricev Mar 17 '16 at 16:31

Your Answer

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

Browse other questions tagged or ask your own question.