代码如下:
\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}
这段小代码使 pdflatex 变为 outout(仅最后几行):
! 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!
有什么办法可以修复这个问题吗?或者我应该放弃使用 \newif?
答案1
Beamer 对其输入进行了大量“有趣”的重新排列,您可以[fragile]
在框架上使用该选项,以便它使用更安全、更慢的机制:
\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}
答案2
使用
\begin{frame}
\ifok
Hello
{\begin{tabular}{c}
ok \\
\end{tabular}}
\fi
\end{frame}