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.

5
  • What are you trying to do with the \Fakeframe macro? May 28 at 14:04
  • Actually I want to define a \Fakeframe in both beamer and article. In the beamer, it should be a frame. But in the article, it will be just a normal text. @samcarter_is_at_topanswers.xyz
    – Ngiap
    May 28 at 14:08
  • 1
    Fundamentally your code is wrong because because \input{thequest.tex} is not fully expandable while \ifthenelse's argument require it to be fully expandable. But do you want to check if #1 itself is empty, or the file content is empty?
    – user202729
    May 28 at 14:09
  • @Ngiap Can you add a bit more background what the purpose of this macro is? Your question sounds very much like an x-y-problem. Maybe using the beamerarticle package would be easier than making fake frames? May 28 at 14:11

1 Answer 1

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.

2
  • WONDERFUL! Love u~
    – Ngiap
    May 28 at 14:20
  • @Ngiap Look at the addition.
    – egreg
    May 28 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .