# Numbering equations within dynblocks environment

I'm trying to number an equation inside an environment created for customed blocks with equations like those contained in how to adjust the latex beamer block width to the size of its content?. But I receive an error when inserting an \align{} environment. Any suggestions?

-

The errors are my fault with the code. But we should distinguish:

• the numbering problem;
• the align problem.

For what concern the numbering problem it could be easily solved: at the moment equations are not numbered due to the call

\opaqueblock<#1>[\wd\mybox]{$\BODY$}


Of course, replacing $\BODY$ with

\opaqueblock<#1>[\wd\mybox]{$$\BODY$$}


is of help, but we still missing the fact that we previously measure the width of $\BODY$ without numbers, so the width of the box is wrong. A workaround is:

\NewEnviron{cdyn}[1]{%
\sbox{\mybox}{$$$\BODY$$ \qquad (1)$}%
\begin{center}
\begin{dynblock}
\opaqueblock<#1>[\wd\mybox]{$$\BODY$$}
\end{dynblock}
\end{center}
}{}%


A complete example:

\documentclass[t]{beamer}
\usepackage{lmodern}
% setting the block body color
\usebeamercolor{block body}
\definecolor{my block body}{named}{bg}
\setbordercolor{my block body}
\setblockcolor{my block body}

% new enviroment always centered

\usepackage{environ}
\newsavebox\mybox
% new environment cdyn: #1 => overlay specification

\NewEnviron{cdyn}[1]{%
\sbox{\mybox}{$$$\BODY$$ \qquad (1)$}%
\begin{center}
\begin{dynblock}
\opaqueblock<#1>[\wd\mybox]{$$\BODY$$}
\end{dynblock}
\end{center}
}{}%

\begin{document}

\begin{frame}{Test}
\abovedisplayskip=0pt

\begin{cdyn}{1-}
c^2=a^2+b^2
\end{cdyn}

\begin{cdyn}{2-}
x+y=400
\end{cdyn}

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}+
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}

\begin{cdyn}{4-}
\begin{cases}
\end{cases}
\end{cdyn}

\only<4->{I'm referring to \eqref{eq:sum}.}

\end{frame}

\end{document}


The result:

For the other problem, inserting an align environment, unfortunately I don't have a solution. Indeed, just changing

\opaqueblock<#1>[\wd\mybox]{$$\BODY$$}


with

\opaqueblock<#1>[\wd\mybox]{\begin{align}\BODY\end{align}}


is not sufficient. Actually, it works with the example provided above, but if you change

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}+
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}


into

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}


! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.54 \end{frame}

Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Missing $inserted. <inserted text>$
l.54 \end{frame}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.54 \end{frame}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

! Missing $inserted. <inserted text>$
l.54 \end{frame}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.


The problem here is how the box is measured:

\sbox{\mybox}{$\BODY + \qquad (1)$}%


does not work with environments that break the line (I suppose) and I don't know how to push something like that in a box and measure its width. Of course, you could always do it manually:

\begin{center}
\begin{dynblock}
\opaqueblock<3->[0.8\textwidth]{%
\begin{align}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{align}
}
\end{dynblock}
\end{center}


A mwe for completeness:

\documentclass[t]{beamer}
\usepackage{lmodern}
% setting the block body color
\usebeamercolor{block body}
\definecolor{my block body}{named}{bg}
\setbordercolor{my block body}
\setblockcolor{my block body}

% new enviroment always centered

\usepackage{environ}
\newsavebox\mybox
% new environment cdyn: #1 => overlay specification

\NewEnviron{cdyn}[1]{%
\sbox{\mybox}{$$$\BODY$$ \qquad (1)$}%
\begin{center}
\begin{dynblock}
\opaqueblock<#1>[\wd\mybox]{$$\BODY$$}
\end{dynblock}
\end{center}
}{}%

\begin{document}

\begin{frame}{Test}
\abovedisplayskip=0pt

\begin{cdyn}{1-}
c^2=a^2+b^2
\end{cdyn}

\begin{cdyn}{2-}
x+y=400
\end{cdyn}

\begin{center}
\begin{dynblock}
\opaqueblock<3->[0.35\textwidth]{%
\begin{align}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{align}
}
\end{dynblock}
\end{center}

\begin{cdyn}{4-}
\begin{cases}