# smashoperator seems to break beamer transparency

I am using beamer and smashoperator as follows:

\documentclass[xcolor={rgb}]{beamer}
\setbeamercovered{transparent}
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage{mathtools}
\usepackage{bm}
\newcommand{\var}[1]{\operatorname{var}{#1}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\begin{document}
\begin{frame}[t]
\begin{align*}
\onslide<2->{&= \E\Bigl( g(a)^2 \smashoperator{\sum_{j\in[n]\backslash\{a\}}} f^2_j Y^2_j + \smashoperator{\sum_{\substack{j\in[n]\setminus\{a\}\\i\ne j}}} f_i f_j g(i) g(j) Y_i B_j\Bigr) -{}\\}
\onslide<3->{&= \sum_{j\in[n]\backslash\{a\}} \frac{f^2_j}{k} + 0 - 0\\[\jot]}
\end{align*}
\end{frame}
\end{document}


However this gives an odd result.

Is there any way to fix this?

It actually works if you add

\everymath{\def\sbox#1#2{\setbox#1\hbox{{#2}}}}


although that isn't a real fix.

\sbox in addition to the \setbox primitive pushes and pops the current color but the light grey transparent effect isn't set up for that.....

This takes a slightly sledgehammer approach and removes the colour push/pop for all sbox in math mode.

Your \onslide starts with &. That means it starts in one tabular/align cell, and continues in the next. Tabular cells build groups, and while beamer contains code to allow color mixins to survive groups, it fails here in part as there are two group levels. This affects \smashoperator as it contains a \sbox command, which issues a color command, but now with the wrong color.

I doubt that a real solution is possible. Work-arounds are:

• move the & outside the \onslide, so that it no longer covers more than one group
• issue a \color{.} to reset the color
\documentclass[]{beamer}
\setbeamercovered{transparent}
\newsavebox\testbox

\begin{document}
\begin{frame}[plain,t]

\begingroup\begingroup
\onslide<2->{\sbox\testbox{111}\usebox\testbox\endgroup %works
\sbox\testbox{222}\usebox\testbox\endgroup %still works
\sbox\testbox{333}\usebox\testbox}         %fails

\begingroup\begingroup
\onslide<2->{\sbox\testbox{111}\usebox\testbox\endgroup
\sbox\testbox{222}\usebox\testbox\endgroup
\color{.}\sbox\testbox{333}\usebox\testbox} %work around

\end{frame}
\end{document}


I can't explain what may be going wrong with \smashoperator, but I can suggest a viable alternative: applying \mathclap to the underset argument of \sum.

Slide 1:

Slide 2:

Slide 3:

\documentclass[xcolor={rgb}]{beamer}
\setbeamercovered{transparent}
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]

\usepackage{mathtools,bm}
\newcommand{\var}[1]{\operatorname{var}{#1}}
\DeclareMathOperator{\E}{\mathbb{E}}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}
\begin{frame}[t]
\begin{align*}
\onslide<1->{&= \E\Bigl( g(a)^2
\sum_{\mathclap{j\in[n]\setminus\{a\}}} f^2_j Y^2_j +
\sum_{\mathclap{\substack{j\in[n]\setminus\{a\}\\i\ne j}}} f_i f_j g(i) g(j) Y_i B_j\Bigr) \\}
\onslide<2->{&\kern1.5cm -\Bigl(\,
\sum_{\mathclap{j\in[n]\textminus\{a\}}} f_j \E[g(a)g(j)Y_j]\Bigr)^2 \\[\jot]}
\onslide<3->{&=
\sum_{\mathclap{j\in[n]\setminus\{a\}}} f^2_j/k + 0 - 0 \,.\\[\jot]}
\end{align*}
\end{frame}
\end{document}

• Thank you. It seems to be a bug in mathtools/smashoperator which has now been reported. Sep 16 '20 at 10:00