I want to print the Bibliography slide only if there were any citations in the presentation.
To that end I have redefined the \cite command to include the toggling of a boolean.
I tried multiple versions to redefine the command as well as different ways to define booleans.
The redefined version of the command contains a \typeout for debugging purposes and that's triggered as shown by pdflatex' log.
Nevertheless the MWE below does print showbib false and I am probably missing something obvious but can't figure it out. :(
If I toggle the boolean manually in the text with \showbibtrue it actually works.
Why doesn't \showbibtrue work within \cite?
FWIW, I have tested it to be not related to beamer (feel free to test/provide a solution with article instead).
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{bib.bib}
@misc{foo,
author="foo bar",
title="getting things done",
}
\end{filecontents*}
\let\oldcite\cite
\newif\ifshowbib
\showbibfalse
\renewcommand{\cite}{\showbibtrue\typeout{within cite}\oldcite}
\begin{document}
\begin{frame}{sigh}
\cite{foo}
\end{frame}
\ifshowbib
\begin{frame}[c,allowframebreaks]{Bibliography}
\typeout{showbib true}
showbib true
\bibliography{bib}
\end{frame}
\else
\typeout{showbib false}
showbib false
\fi
\end{document}