# Context

This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if

# Problem

The problem is that complex content (for example, itemize on the content of the argument) is not handled well when the conditional is set to true.

# Emulation

To emulate and show the problem, I created the following MWE

\documentclass{article}

\newif\ifdetails
\detailstrue
%\detailsfalse

\makeatletter
\newcommand{\test}[1]{-#1-}
\newcommand{\wrapper}[1]{%
\test{%
\begingroup
\protected@edef\x{\endgroup
\noexpand\long\noexpand\def\noexpand\argseven{#1}}\x
\if\relax\detokenize\expandafter{\romannumeral-\Q\argseven}\relax
\else{#1}\fi}}
\makeatother

\begin{document}

\wrapper{%
\ifdetails
I would like all this stuff to be raggedright, however. The "year-year" is not important.
\fi
}

\wrapper{%
\ifdetails
I would like all this stuff to be raggedright, however.
% This more complex content breaks existing solutions
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\fi%
}

\end{document}


When one executes that with \detailsfalse the code works. However, with \detailstrue there is an error:

! Undefined control sequence. \itemize ...nce \@itemdepth \@ne \edef \@itemitem {labelitem\romannumeral \t...

# Question

Thus, what is the correct way of handling the argument, so that the \if inside can be evaluated, as well as the complex content on it. (Like the problem of the question Spurious space on moderncv \cventry using \if)

• \begin and \item are fragile, so they don't survive \protected@edef. – egreg May 10 '16 at 16:06

I admit I don't fully understand what you're trying to do here, but as egreg notes, \begin and \item are fragile which is what's causing the problem. It's easy enough to "fix" this particular example

\newcommand{\wrapper}[1]{%
\test{%
\begingroup
\let\begin\relax
\let\item\relax
\let\end\relax
\protected@edef\x{%
\endgroup
\noexpand\long\noexpand\def\noexpand\argseven{#1}%
}%
\x
\if\relax\detokenize\expandafter{\romannumeral-\Q\argseven}\relax\else
#1%
\fi
}%
}


I don't understand what the point of that conditional is (and I removed the braces around #1).

Since you're using \detokenize, you're relying on e-TeX, so you can use

\usepackage{etoolbox}
\robustify\begin
\robustify\end
\robustify\item


to make those robust. And assuming that the conditional is to check if \argseven is blank, you can use \ifblank{#1}{true branch}{false branch} from etoolbox.