# Using easybmat and beamer together

I've written an article using the easybmat package and now it is time to create the beamer slides....however, as you can see here, in order to load both the easybmat and tikz (or pgf?) one needs to first load the etex package. This I do not know how to do in the beamer documentclass where the most minimal example fails:

\documentclass[beamer]{beamer}

\usepackage{easybmat} % I get different errors depending
\usepackage{etex}     % on the order of these two lines

\begin{document}
test
\end{document}


Do I need to resort to \LoadClass solutions? (I so, I need help...)

-

I've already encountered this bug once. Here are two solutions to solve the problem; the first is quick and easy to put in place, while the second needs to look at where the problem occurs.

SOLUTION 1. It is possible to load packages before \documentclass by using \RequirePackage instead of \usepackage. This allows to get both etex and easybmat loaded before tikz and makes the problem disappear:

\RequirePackage{etex}
\RequirePackage{easybmat}
\documentclass[beamer]{beamer}
\begin{document}
test
\end{document}


SOLUTION 2. Loading easybmat first and then etex cannot work because there won't be enough dimen registers available for easybmat. So you must load etex first and easybmat second. The error message becomes You can't use a prefix with '\begingroup'. The reason for this error is due to both easybmat.sty and etex.sty. The problem with easybmat.sty is that it calls the package easy.sty which declares some new dimensions with \global\newdimen. Putting a \global before \newdimen is not necessary but is usually harmless. Here, however, it is not harmless because etex.sty is loaded and (the two conditions must be met) the \newdimen with the \global occurs when etex.sty switches between the vanilla TeX registers and the extended eTeX engine ones. The reason can be found in the code of the \alloc@ macro from etex.sty which has a \begingroup in it. What happens is that the \global before \newdimen gets applied to this \begingroup, thus triggering the error. A (not very elegant) way to solve the problem is to put a dummy definition just before the \begingroup. It should not (I hope) have any side effects.

\documentclass[beamer]{beamer}

\usepackage{etex}
\makeatletter
\def\alloc@#1#2#3#4#5%
{\ifnum\count1#1<#4% make sure there's still room
\allocationnumber\count1#1
\global#3#5\allocationnumber
\wlog{\string#5=\string#2\the\allocationnumber}%
\else\ifnum#1<6
\begingroup \escapechar\m@ne
\expandafter\alloc@@\expandafter{\string#2}#5%
\else\errmessage{No room for a new #2}\fi\fi
}
\makeatother
\usepackage{easybmat}

\begin{document}
test
\end{document}

-
This works!! Thanks. Is this a bug? In what package? are you going to report it with you nifty workaround? –  Yossi Farjoun Nov 26 '10 at 12:46
@Philippe: Your second solution looks really nice! Maybe you can edit your answer to give this easy solution first? I think this would be very helpful! –  Hendrik Vogt Nov 26 '10 at 17:20
@ Hendrik: I've put the easiest solution first as well as expanded a little the explanations of the second. @Yossi: It might be considered a bug in etex, but the problem is really with easybmat which should not use \global before \newdimen. I'll try to report the problem, but I'm not sure the easybmat package is still actively maintained or that a hack as a dummy definition would be acceptable in a common package like etex. –  Philippe Goutet Nov 26 '10 at 21:22
There's been some discussion of this issue on the LaTeX-L list in the context of the etex package. –  Joseph Wright Nov 26 '10 at 22:10
@Philippe: +1, great, looks much better now. (By the way, I didn't get notified of your comment due to the space after "@". But only this way Yossi was notified: You can only notify one user with "@".) –  Hendrik Vogt Nov 26 '10 at 22:48