This question is basically a follow-up of two older questions I posted a year ago, but actually is a consequence of trying to find a solution to this question:
Use toggles in biblatex `printbibliography`
I want to use a command with a key-value setup with an \if statement (pseudocode)
\somekeycommand[\ifdisplay somekey=A \else someotherkey=B]
such that some specific key is set according to the state of the variable \ifdisplay.
Unfortunately none of the various approaches work, not even the \begingroup\edef\x{\endgroup\noexpand....}\x - trick is successful.
Please note, that I don't want to use
\ifdisplay
\somekeycommand[somekey=A]
\else
\somekeycommand[someotherkey=B]
\fi
The actual \somekeycommand is some code from a package, the macro uses \setkeys
Here is the failing MWE
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{xkeyval}
\makeatletter
\define@key{myfam}{somekey}{%
\def\somekeyvalue{#1}%
}
\define@key{myfam}{someotherkey}{%
\def\somekeyothervalue{#1}%
}
\makeatother
\NewDocumentCommand{\somekeycommand}{+O{}}{%
\begingroup
\setkeys{myfam}{#1}%
\ifdef{\somekeyvalue}{%
Key was \somekeyvalue%
}{%
}%
\endgroup
}%
\newif\ifdisplay
\displayfalse
\begin{document}
\somekeycommand[somekey=A]
\edef\x{%
\expandafter\noexpand\csname ifdisplay\endcsname%
somekey=A%
\noexpand\else%
someotherkey=B%
\noexpand\fi%
}%
\somekeycommand[\x] % fails
\somekeycommand\expandafter[\x] % fails --> expands to [ \expanded value ]
\somekeycommand[\expandafter\begingroup\edef\x{%
\ifdisplay
somekey=A%
\else%
someotherkey=B%
\fi%
}\x] %% -> fails, prints someotherkey=B,
\expandafter\somekeycommand[\begingroup\edef\x{%
\noexpand\ifdisplay
somekey=A%
\noexpand\else%
someotherkey=B%
\noexpand\fi%
}\x] %% -> fails, prints someotherkey=B,
\end{document}

Here are the older questions of mine:

\setkeysdoesn't expand its second argument. I don't really understand what you're after. – egreg Feb 15 '15 at 22:12\ifdisplayis evaluated to be true or to be false. The keys are different – Feb 15 '15 at 22:22