# Chemfig package compatibility

Looking for help on the following problem:

I am trying to use chemfig package in my document, however after initial insertion had the following error:

!No room for a new \dimen.


I found No room for a new \dimen and added:

\usepackage{etex}
\reserveinserts{28}


but now I have another error:

!You can't use a prefix  with \begingroup


the answer to which I cannot seem to find online. Any help on this matter is greatly appreciated.

Here is the minimum working example:

\documentclass[12pt,doublespacing,letterpaper]{report}
\usepackage{etex}
\reserveinserts{28}
\usepackage{chemfig}

\usepackage{cite}
\usepackage{morehelp}
\usepackage{setspace}
\usepackage{easytable}
\usepackage{longtable}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{dcolumn}

\begin{document}

\chapter{}

\chemfig {*6(-=-(- M{(}OH{)}_2)=-=)}

\end{document}

-
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). –  adn May 6 '13 at 2:18
Thank you guys for the answers and explanations! It worked great! –  chemist May 7 '13 at 3:02

There seems to be some problem with chemfig and easytable; loading chemfig after easytable solves the problem (I commented out the line loading the morehelp package, since my LaTeX system doesn't have it):

\documentclass[12pt,doublespacing,letterpaper]{report}
\usepackage{etex}
\usepackage{cite}
%\usepackage{morehelp}
\usepackage{setspace}
\usepackage{easytable}
\usepackage{chemfig}
\usepackage{longtable}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{dcolumn}

\begin{document}

\chapter{Test}

\chemfig {*6(-=-(- M{(}OH{)}_2)=-=)}

\end{document}


-

## Solution

Reordering the load order will solve this issue: Gonzalo's answer demonstrates this nicely.

## Underlying cause

The underlying problem here is how the file easy.sty does its allocation of registers:

%
% define dimens for internal computation.
%
\@tempcnta=30\relax
\@whilenum\@tempcnta>\z@\do{%
\expandafter\global\expandafter\newdimen\csname @easy@hsize\romannumeral\@tempcnta\endcsname%
\expandafter\global\expandafter\newdimen\csname @easy@vsize\romannumeral\@tempcnta\endcsname%

This looks dense to the non-expert, but the key thing is that the \newdimen is being prefixed by \global. This is not necessary (dimensions are allocated globally by LaTeX), but is normally harmless.
The error arises if \global\newdimen occurs at the 'wrong' time. Classical TeX had only 256 dimens available, while e-TeX made many more (64k) accessible. However, the LaTeX \newdimen command is set up to only use the 256 classical ones, and so to actually use the 'extended pool' you have to alter part of the kernel. This is what the etex package does. However, it is set up to first use the 256 'standard pool' registers before altering how allocation is done for the 'extended pool'. That is all fine and usually is transparent. It goes wrong, however, if the switch happens when \newdimen is prefixed by \global, as the \global ends up 'in front' of an internal \begingroup, and that gives an error. (The error doesn't actually break the document, but no-one wants an error on every compile.)
Reordering loading will almost certainly skip the issue as it moves when the switch happens, hopefully away from the \global\newdimen use. A 'better' solution would be to alter easy.sty to not use \global, but as this file is 12 years old at time of writing I would not hold my breath on that. Perhaps the best solution would be to change etex to allow for an deal with the use of \global here: tricky and again a change in a file that has been unchanged for a long time.
I'm asking why \global is used there to begin with, because it ends in front of \alloc@ that already begins with \global. –  egreg May 6 '13 at 9:04
@egreg As I indicate in my answer, this is not required, and I'm not sure why people put a \global in (I came across this issue with some code Will Robertson wrote ages ago, and changed when it was pointed out it was not needed). –  Joseph Wright May 6 '13 at 9:20