I'm on the process of migrating to the chemnum numbering system due to its advanced features (thank you!). For my purposes I need to input external files with the information (for each compound) stored as commands, and then applying those commands into a template (to "fill in" the information).
You can see the "minimal" code below (I have not cropped the packages that I'm using in the preamble just in case there's a conflict or order issue I'm unaware of). Basically there are three commands that store the information of the compound and a fourth command that inserts a new section and a EPS figure (with a label 'TMP1' to replace). When compiling, this label is OK in the second event but not in the first one (!!!?).
As the replacement occurs, I don't think is any problem with the psfrag part of it, but with the numbering of the compounds itself. If the "renewcommand" method is unsuitable for chemnum, is there any other alternative to introduce information from different files and apply consecutively the same template to them?
Thanks a lot!
\documentclass[a4paper,12pt,oneside]{article}
\usepackage{environ,fixltx2e}
\usepackage{titletoc}
\usepackage[linktocpage=true,hidelinks,unicode]{hyperref}
\usepackage{fullpage}
\usepackage[detect-all]{siunitx}
\usepackage{graphicx}
\usepackage[runs=2,crop=off]{auto-pst-pdf}
\usepackage{chemnum}
\usepackage[journal=rsc]{chemstyle}
\usepackage[version=3]{mhchem}
\usepackage{bm}
\usepackage{multicol}
\usepackage{etoolbox}
\newcommand{\compoundtag}{}
\newcommand{\nameofthecompound}{}
\newcommand{\descriptiontext}{}
\newcommand{\compoundDATA}{
\section{\nameofthecompound{} - \cmpdplain{\compoundtag}}
\begin{scheme}[H]
\replacecmpd[tag=TMP1]{\compoundtag}
\includegraphics{a.eps}
\end{scheme}
\descriptiontext
}
\begin{document}
Main text mentioning \cmpd{A} and \cmpd{B}
%This data comes from a different file through an input event.
\renewcommand{\compoundtag}{A}
\renewcommand{\nameofthecompound}{Name of compound A}
\renewcommand{\descriptiontext}{Text of the compound A}
\compoundDATA
%This data comes from a different file through a second input event.
\renewcommand{\compoundtag}{B}
\renewcommand{\nameofthecompound}{Name of compound B}
\renewcommand{\descriptiontext}{Text of the compound B}
\compoundDATA
\end{document}

\noexpandin front of\replacecmpd, because it's defined with\NewDocumentCommand, so it's not expanded in\edef. – egreg Jul 20 '14 at 22:33