# Unexpected error when combining beamer + tabular + newif

The code is below:

\documentclass[a4paper]{beamer}
\usepackage[utf8]{inputenc}
\title{Ok}
\author{Me}
\date{\today}

\newif\ifok
\oktrue

\begin{document}

\maketitle

\begin{frame}
\ifok
Hello
\begin{tabular}{c}
ok \\
\end{tabular}
\fi
\end{frame}

\end{document}


This small code piece makes pdflatex to outout (only last lines):

! Incomplete \ifx; all text was ignored after line 19.
<inserted text>
\fi
<*> ok.tex

?
! Emergency stop.
<inserted text>
\fi
<*> ok.tex

!  ==> Fatal error occurred, no output PDF file produced!


Any idea to fix this or should I throw out the use of \newif?

Beamer does lots of "interesting" re-arrangements of its inputs, you can use the [fragile] option on a frame so it uses a safer, slower, mechanism:

\documentclass[a4paper]{beamer}
\usepackage[utf8]{inputenc}
\title{Ok}
\author{Me}
\date{\today}

\newif\ifok
\oktrue

\begin{document}

\maketitle

\begin{frame}[fragile]

\ifok
Hello
\begin{tabular}{c}
ok \\
\end{tabular}
\fi

\end{frame}

\end{document}

• Thank your very much. Maybe, a rule of thumb could be: if doesn't work as expected, use "fragile". – Cassé Hugues Jan 10 '19 at 9:06
• @CasséHugues that's the rule I used here:-) – David Carlisle Jan 10 '19 at 9:19

Use

\begin{frame}
\ifok
Hello
{\begin{tabular}{c}
ok \\
\end{tabular}}
\fi
\end{frame}