# Problem of having \begin…\end inside \ifdefined…\fi clause

I am using beamer, and have a LaTeX code as below.

\ifdefined\VAR
\begin{itemize}
\item blahblab
\end{itemize}
\fi


this does not compile, throwing an error: ! Incomplete \ifx; all text was ignored after line 61.

Line 61 is on end{itemize}. If I remove the itemize clause, as below. it works (of course)... Does anyone here have the same error before?

\ifdefined\VAR
blahblab
\fi


UPDATE: If I put a separate frame inside the \ifdefined...\fi clause, then it does not complain anything. Maybe this tells something..

\ifdefined\VAR
\begin{frame}
\begin{itemize}
\item blahblab
\end{itemize}
\end{frame}
\fi


UPDATE2: A self-contained example code for reproducing the error...

\documentclass[]{beamer}
\usepackage{beamerthemesplit}

\begin{document}
\begin{frame}
\ifdefined\VAR
\begin{itemize}
\item blahblab
\end{itemize}
\fi
\end{frame}
\end{document}

• I have added a full example code... though it's mostly duplication of the one in OP. – Richard Aug 3 '13 at 12:55
• Put \begin{itemize} ... \end{itemize} in braces -> {\begin{itemize} ... \end{itemize}} – karlkoeller Aug 3 '13 at 13:01
• @karlkoeller, this is working... if you make it an answer, I will accept it.. – Richard Aug 3 '13 at 15:28

It suffices putting \begin{itemize} ... \end{itemize} in braces and it will work.

\documentclass[]{beamer}
\usepackage{beamerthemesplit}

\begin{document}
\begin{frame}
\ifdefined\VAR
{
\begin{itemize}
\item blahblab
\end{itemize}
}
\fi
\end{frame}
\end{document}

• Putting the environment in braces also works for the structure \ifCustomBoolean ... \else ... \fi, which triggered the same error, when an environment was enframed with ifCustomBoolean and \fi. Thanks :-) – hardmooth Jul 3 '14 at 13:50

With beamer, frame is a peculiar environment which is processed in a nonstandard way. So the \end in \end{itemize} causes a bad pairing of conditionals (the error you get is Incomplete \ifx).

You can solve the issue by not making LaTeX “see” the conditional (or hiding \end in braces as suggested by karlkoeller).

\documentclass[]{beamer}
\usepackage{beamerthemesplit}

\makeatletter
\ifdefined#1
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi}
\makeatother

%\def\VAR{} % try also uncommenting this line

\begin{document}
\begin{frame}