# Numbering of compounds in the order it appears in the schemes (bpchem or similar)

I am using chemstyle and bpchem to number my compounds. I save my chemdraw drawings as eps and use TMP and TMP2 as markers that will replaced by the compound numbers. As long as \CNlabel is used before the scheme is inserted, it works fine, but if the text is below the picture as in the following example, the labeling in the text is different from the labeling in the schemes.

\documentclass{article}
\usepackage[runs=2]{auto-pst-pdf}
\usepackage{bpchem}
\usepackage[journal=rsc, tracking=bpchem]{chemstyle}
\usepackage[version=3]{mhchem}

\begin{document}

\begin{scheme}
\begin{center}
\schemeref[TMP]{1}
\schemeref[TMP2]{2}
\includegraphics{Reactions_MSC/I010}
\end{center}
\end{scheme}

\begin{scheme}
\begin{center}
\schemeref[TMP]{3}
\schemeref[TMP2]{4}
\includegraphics{Reactions_MSC/I012}
\end{center}
\end{scheme}

Text where I mention the compounds in a different order than in the schemes: \CNlabel{2}, \CNlabel{3}, \CNlabel{4}, \CNlabel{1}

\end{document}


Additionally, I would prefer to have the numbering in the order the compounds appear in the schemes instead of in the order they appear in the text. Is there a good solution to do this? One possible workaround I can think of would be to add a list like this in the beginning of the document:

\CNlabelnoref{1}
\CNlabelnoref{2}
\CNlabelnoref{3}
\CNlabelnoref{4}


To do this manually, however, would be quite tedious. Is there a way I could generate such a list automatically?

-
Although I'm the author of chemstyle, I'd suggest using the chemnum package instead for numbering in schemes. It's newer, and over all cleaner. I can't just drop chemstyle as it has been used by quite a lot of people, but there are some flaws :-( –  Joseph Wright Apr 14 '12 at 19:51

Try adding the following to your document preamble, after loading chemstyle:

\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\LetLtxMacro\oldschemeref\schemeref
\DeclareRobustCommand{\schemeref}[2][]{%
\CNlabelnoref{#2}%
\oldschemeref[#1]{#2}%
}


It's difficult to test without actual PDF images.

-