6

I'm working on a beamer theme in which each of the title page elements is optional; for example, I don't want defining an empty date to produce a large empty space on the title slide. I figured I could do this by wrapping the layout for each element in a conditional like so:

\ifx\insertdate\empty%
\else
   ...
   \insertdate
   \vskip{1em}
   ...
\fi

And this pattern works as expected... except for the author. For whatever reason, \ifx\insertauthor\empty never seems to evaluate to true, unlike the other title page elements:

\documentclass{beamer}
\author{}
\date{}
\begin{document}
  \ifx\insertauthor\empty
    empty
  \else
    nonempty
  \fi
  % outputs "nonempty"

  \ifx\insertdate\empty
    empty
  \else
    nonempty
  \fi
  % outputs "empty"
\end{document}

Why is this? Is there any workaround that would let me test for an empty author?

2 Answers 2

4

The definition text of \insertauthor is not empty, which is quite obvious, because the macro is meant to do something with data that should already have been given.

From beamerbasetitle.sty, line 149 and following:

% The \author command
%
%
\def\author{\@dblarg\beamer@author}
\long\def\beamer@author[#1]#2{%
  \def\insertauthor{\def\inst{\beamer@insttitle}\def\and{\beamer@andtitle}#2}%
  \def\beamer@shortauthor{#1}%
  \ifbeamer@autopdfinfo%
    \def\beamer@andstripped{}%
    \beamer@stripands#2 \and\relax
    {\let\inst=\@gobble\let\thanks=\@gobble\def\and{, }\hypersetup{pdfauthor={\beamer@andstripped}}}
  \fi%
}

So when you specify \author (with or without the optional argument), \insertauthor is defined (and not empty). Since on line 173 we find

\author{}

we deduce that \insertauthor is initialized and is never empty at the start of a beamer job.

You're probably better served by testing \beamer@shortauthor, which will be indeed empty at the start of a job, until another \author command appears.

\documentclass{beamer}
\author{}
\date{}
\begin{document}

\makeatletter
\ifx\beamer@shortauthor\empty
  empty
\else
  nonempty
\fi
\makeatother

\end{document}
0

You could take some inspiration from beamer, e.g. from https://github.com/josephwright/beamer/blob/1b04c51a596a51530adeff278ca2c43aa963c9b1/base/themes/inner/beamerinnerthemeinmargin.sty#L68-L74 and replicate this test. This has the advantage that the author names will be printed on the title page even if your users choose an empty short author:

\documentclass{beamer}
\author[]{test}
\date{}
\begin{document}

\makeatletter
\expandafter\ifblank\expandafter{\beamer@andstripped}{
  empty
}{%
  nonempty
}
\makeatother

  \ifx\insertdate\empty
    empty
  \else
    nonempty
  \fi
  % outputs "empty"
\end{document}

(there was an issue for users of the usepdftitle=false class option, this is already fixed in the beamer dev version and should be included in beamer v3.72 or newer)

You must log in to answer this question.

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