[Tex/LaTex] Using `easybmat` and `beamer` together

beamertikz-pgf

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…)

Best Answer

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\advance\count1#1\@ne
    \global#3#5\allocationnumber
    \wlog{\string#5=\string#2\the\allocationnumber}%
  \else\ifnum#1<6
    \def\etex@dummy@definition{}% <-- code added
    \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}