2

First I write a tex named thequest like:

\begin{quest}
Just a problem.
\end{quest}

Then in the main tex, I write

\newtheorem{quest}{Question}
\newcommand{\Fakeframe}[1]{\ifthenelse{\equal{#1}{}}{}{
    \begin{frame}[t]
       #1
    \end{frame}
    }}
\FakeFrame{\input{thequest.tex}}

Then xelatex. There will be "Argument of \reserved@a has an extra }." and "Paragraph ended before \reserved@a was complete." But the pdf is correct.

Why????? If I don't use the ifthenelse, or just not use the input, everything will be OK. But if I use the newcommand with a ifthenelse, and that input, there must have two errors.

That's so weird.

Ngiap
  • 89

1 Answers1

4

I'm not sure what this would be useful for: it makes little sense to check for emptiness of the argument, in that case just don't use \FakeFrame{}.

Anyway, \equal tries to expand its argument and with \input this fails. Use xifthen and \isempty.

\begin{filecontents*}{\jobname-quest}
\begin{quest}
Just a problem.
\end{quest}
\end{filecontents*}

\documentclass{beamer} \usepackage{xifthen}

\newtheorem{quest}{Question} \newcommand{\FakeFrame}[1]{\ifthenelse{\isempty{#1}}{}{% \begin{frame}[t] #1 \end{frame} }}

\begin{document}

\FakeFrame{\input{\jobname-quest.tex}}

\end{document}

If you want to load the file only if it's not empty, then use a different strategy.

\begin{filecontents*}{\jobname-quest}
\begin{quest}
Just a problem.
\end{quest}
\end{filecontents*}

\begin{filecontents*}{\jobname-empty}

\end{filecontents*}

\documentclass{beamer}

\newtheorem{quest}{Question}

\ExplSyntaxOn

\NewDocumentCommand{\FakeFrameInput}{m} {% #1 = filename \file_get:nnN { #1 } { } \l_tmpa_tl \tl_remove_all:Nn \l_tmpa_tl { \par } \tl_if_blank:VF \l_tmpa_tl { \begin{frame}[t] \input{#1} \end{frame} } }

\ExplSyntaxOff

\begin{document}

\FakeFrameInput{\jobname-quest.tex} \FakeFrameInput{\jobname-empty.tex}

\end{document}

This will only produce one frame. The file is read into a token list variable in which we remove all \par tokens (generated by empty lines). If nothing remains (or just spaces), the file is considered empty.

egreg
  • 1,121,712