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
.