9

I would like to use \insertshortpart (with some surrounding characters) in a Beamer theme, but only if a short part is actually available. However, if I try to check for emptiness with \ifx...\empty it turns out that this expression is never true.

Here is a minimal example:

\documentclass{beamer}
\begin{document}
\begin{frame}
\ifx\insertpart\empty
empty part
\else
non-empty part
\fi

\ifx\insertshortpart\empty
empty short part
\else
non-empty short part
\fi
\end{frame}
\end{document}

This results in "empty part" and "non-empty short part".

How can I check if the short part is actually empty?

I had a similar problem with \insertshortdate, \insertshorttitle and \insertshortsubtitle which I could solve by using \beamer@shortdate, \beamer@shorttitle and \beamer@shortsubtitle instead, respectively. For \insertshortpart, however, I couldn't find a replacement.

BTW, what's the difference between \empty and \@empty? In my style file both seem to work ...

1
4

The short part name is stored in \beamer@partnameshort, which however is undefined before a \part command is issued.

Here's a test for it:

\documentclass{beamer}

\makeatletter
\newcommand{\ifemptyshortpart}{%
  \@ifundefined{beamer@partnameshort}
    {\@firstoftwo}
    {\ifx\beamer@partnameshort\@empty
       \expandafter\@firstoftwo
     \else
       \expandafter\@secondoftwo
     \fi}}
\makeatother


\begin{document}

\ifemptyshortpart{\typeout{EMPTY}}{\typeout{NON EMPTY}}

\part[Short]{Long}
\ifemptyshortpart{\typeout{EMPTY}}{\typeout{NON EMPTY}}

\part[]{Long}
\ifemptyshortpart{\typeout{EMPTY}}{\typeout{NON EMPTY}}

\part{Long}
\ifemptyshortpart{\typeout{EMPTY}}{\typeout{NON EMPTY}}

\end{document}

The output on the terminal is

EMPTY
NON EMPTY
EMPTY
NON EMPTY

Note that you get empty only if no \part command has been issued or \part is issued with an explicit empty optional argument. Otherwise beamer stores in \beamer@partnameshort the long version.

The \ifemptyshortpart command should be followed by the "true" and "false" branches:

\ifemptyshortpart{short part is empty}{short part is non empty}
0
5

If you add

\show\insertshortpart

you will see its definition is

> \insertshortpart=macro:
->\@protected@testopt \insertshortpart \\insertshortpart {}.

which is not the same definition as \@empty even if it produces no text.

You can grab this definition at the start and use it in the test:

\documentclass{beamer}
\let\origiginsertshortpart\insertshortpart
\begin{document}
\begin{frame}
%\show\insertpart
\ifx\insertpart\empty
empty part
\else
non-empty part
\fi

%\show\insertshortpart
\ifx\insertshortpart\origiginsertshortpart
empty short part
\else
non-empty short part
\fi
\end{frame}
\end{document}
3
  • You should probably accept @egreg's answer but I'll let this one stand as it shows why your original \ifx test failed. Apr 1 '13 at 11:16
  • Thanks for the insight. Your suggestion works in my minimal example. However, when I actually define a part, it ceases to work. It seems that it always shows "empty short part".
    – Matthias
    Apr 2 '13 at 9:06
  • Yes that's right, I had (have) no idea what the command does so basically I was just explaining why the code in the question doesn't work. However I suspect that when you do use it the top level definition as seen by \ifx doesn't actually change. As I noted in the first comment above, I only left this answer rather than deleting it as it has the explanation of why your original code didn't work. Just do what @egreg says (he's sometimes right about TeX:-) Apr 2 '13 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.