4

I recently needed to cover some over- and underbrace and found a solution here: Beamer: Uncover underbrace

However, I was not 100% satisfied with the offered solutions, in particular, my goal was to create commands \underbrace<>{}_{} and \overbrace<>{}^{} that should just work like you'd expect, with no additional restrictions on overlay specifications or content. I succeeded doing this for underbrace [A], although I do not know exactly why my solution works (I was very surprised it did!) However, to my even bigger surprise, it does not work with overbrace! However, it turned out it would again with a slight modification - which again I do not understand why it works at all in one case but not the other. The crucial part of the code is:

% underbrace version A
\onslide<#1>\underbrace{\onslide<1->#2}_{#3}\onslide
% underbrace version B
\underbrace{#2\onslide<#1>}_{#3}\onslide
% overbrace version A
\onslide<#1>\overbrace{\onslide<1->#2}^{#3}\onslide
% overbrace version B
\overbrace{#2\onslide<#1>}^{#3}\onslide

The only combination that works as intended is underbrace version B and overbrace version A. But why? EDIT: I just noted, for \overset and \underset one has to do it the other way round! Full MWE:

\documentclass{beamer}
\setbeamercovered{transparent}
\usepackage{xparse}

\DeclareDocumentCommand{\ubraceA}{d<> m e{}}{% \IfValueTF{#1}{% IF <overlay-specification> given \onslide<#1>\underbrace{\onslide<1->#2}{#3}\onslide }{% ELSE \underbrace{#2}_{#3} }% }%

\DeclareDocumentCommand{\ubraceB}{d<> m e{}}{% \IfValueTF{#1}{% IF <overlay-specification> given \underbrace{#2\onslide<#1>}{#3}\onslide }{% ELSE \underbrace{#2}_{#3} }% }%

\DeclareDocumentCommand{\obraceA}{d<> m e{^}}{% \IfValueTF{#1}{% IF <overlay-specification> given \onslide<#1>\overbrace{\onslide<1->#2}^{#3}\onslide }{% ELSE \overbrace{#2}^{#3} }% }%

\DeclareDocumentCommand{\obraceB}{d<> m e{^}}{% \IfValueTF{#1}{% IF <overlay-specification> given \overbrace{#2\onslide<#1>}^{#3}\onslide }{% ELSE \overbrace{#2}^{#3} }% }%

\begin{document} \begin{frame}{underA, overA} \begin{align} \ubraceA<5->{p(x\mid y)}{\text{posterior}} = \frac{\obraceA<2->{p(y\mid x)}^{\text{likelihood}} ,\obraceA<3->{p(x)}^{\text{prior}} }{\ubraceA<4->{p(y)}{\text{evidence}}} \end{align} \end{frame} % \begin{frame}{underA, overB} \begin{align} \ubraceA<5->{p(x\mid y)}{\text{posterior}} = \frac{\obraceB<2->{p(y\mid x)}^{\text{likelihood}} ,\obraceB<3->{p(x)}^{\text{prior}} }{\ubraceA<4->{p(y)}{\text{evidence}}} \end{align} \end{frame} % \begin{frame}{underB, overA} \begin{align} \ubraceB<5->{p(x\mid y)}{\text{posterior}} = \frac{\obraceA<2->{p(y\mid x)}^{\text{likelihood}} ,\obraceA<3->{p(x)}^{\text{prior}} }{\ubraceB<4->{p(y)}{\text{evidence}}} \end{align} \end{frame} % \begin{frame}{underB, overB} \begin{align} \ubraceB<5->{p(x\mid y)}{\text{posterior}} = \frac{ \obraceB<2->{p(y\mid x)}^{\text{likelihood}} ,\obraceB<3->{p(x)}^{\text{prior}} }{\ubraceB<4->{p(y)}{\text{evidence}}} \end{align} \end{frame} \end{document}

  • For overbrace option a, I got good result with \onslide<#1>\overbrace{\onslide a}^{b}for option A. This avoids using <1-> – Laurent Jacques Jan 27 '23 at 16:48
  • beamer's documentation mentions that \pause (which uses \onslide internally) doesn't work in align, p 78 (probably related to its multiple processing of the environment due to measuring). So, I assume, \onslide therefore may cause difficulty within align. – Werner Jan 27 '23 at 19:01

0 Answers0