# Is it permitted to have arguments (i.e. value in key-value) including \par in the xkeyval package?

I wish to use the xkeyval package to overide the 9 arguments limit and to clarifiy the different arguments (compulsory or optional). In my arguments/parameters, I have complete paragraphs possibly including \par or \\\\. I know that some macros accepts \par, others don't, to avoid hidden problematic nestings I understand. It seems that the prefix \long allows to have \par within arguments. In the implementation part of the doc, I see plenty of these \long macros.

Does that guarantee I can use \par in the arguments/value within the package xkeyval?

• Welcome to TeX.SX! Did you try it? ;-) – user31729 May 31 '15 at 9:38
• @ChristianHupfer I am trying ! But, since I don't know how to use xkeyval, if one says "no way, it won't work" I would try something else :) – user1771398 May 31 '15 at 10:28
• @user1771398: Well, it works, as shown in my answer ;-) – user31729 May 31 '15 at 10:30

\newline or \\ after an empty line would be an error anyway, but otherwise it's ok (if really necessary ;-)). \par or empty lines will do in a key as well.


If you want to be on the safe side, use \NewDocumentCommand{\foocmd}{+o+m}{...} from the xparse package, the + character allows explicitly \par etc. in the argument then.

Some background

TeX's \def command does not allow arguments with a parbreak etc, unless the \def usage is preceeded with \long (see the example below).


\documentclass{article}

\usepackage{xkeyval}

\makeatletter

\define@key{foofamily}{foo}{%
\def\KVfookey{#1}%
}

\def\foodef[#1]#2{%
\setkeys{foofamily}{#1}%

\ifdefined\KVfookey
The key had the value \KVfookey
\fi

Mandatory argument was #2
}

\long\def\foodeflong[#1]#2{%
\setkeys{foofamily}{#1}%

\ifdefined\KVfookey
The key had the value \KVfookey
\fi

Mandatory argument was #2
}

\makeatother

\newcommand*{\fooother}[2][foo={A long

key
}]{%
\setkeys{foofamily}{#1}%
Arg was #2%
}

\newcommand{\foocmd}[2][foo={A long

Arg

}]{%
\setkeys{foofamily}{#1}%
The key was \KVfookey

And this is the 2nd argument: #2%
}

\begin{document}

% Won't work, since arg isn't long
%\foodef[foo={Some

%key}]{Hello World again}

% Won't work, since defined with \newcommand* .. i.e not \long\def...
%\fooother{Hello World}

\begin{itemize}
\item Using a \verb+\long\def+ command -- works
\foodeflong[foo={Some

key}]{Hello World again}

\item Using a \verb+\newcommand+ command -- works

\foocmd{Hello World}

\foocmd[foo={A very long command  \newline\newline

\par
\parskip=5cm

key}]{... which is absolutely useless}

\end{itemize}

\end{document}