I am trying to make a command with named (key-value) parameters to produce a table row. The reason is that table has more than 9 columns (command parameters) that will have position changed, be deleted or added. So it is hard to keep it with regular command (both because positions and limited number of args).
I tried to make it work with xkeyval package, but something gets broken inside table. Here is MWE:
\documentclass{article}
\usepackage{xkeyval}
\begin{document}
\makeatletter
\define@key{myrowkey}{name}{\def\MyRowName{#1}}
\define@key{myrowkey}{num}{\def\MyRowNum{#1}}
\makeatother
\newcommand\myrow[1]{
\setkeys{myrowkey}{#1}
\MyRowName, \MyRowNum & \\ \hline
}
\newcommand\myrowb[1]{
\setkeys{myrowkey}{#1}
\MyRowName & \MyRowNum \\ \hline
}
\begin{table}
\begin{tabular}{|c|c|}\hline
A & B \\ \hline
\myrow{name=Abc,num=2000}
\myrow{name=Def,num=2000}
\end{tabular}
\end{table}
\end{document}
Command \myrow works as I'd like it to, while \myrowb does not, i.e., it produces an error. If I replace \def\MyRowName{...} with \newcommand\MyRowName{} and then \renewcommand\MyRowName{#1} there is no error any more, but an empty cell instead of the value (num).



\setkeyscommand within\myrowb:\setkeys{name={},num={},#1}. – Werner Sep 19 '13 at 18:01keyresetcommand for this. – Ivan Sep 20 '13 at 08:50