Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing an organic chemistry dissertation using (pdf)LaTeX. The content of the thesis contains a large amount of numbered chemical structures. The chemical structure drawings were generated using ChemDraw and exported to eps format. Since there are literally hundreds of numbered structures, I wrote a macro that uses a custom counter to keep track of the numbers:

\newcounter{compound}
\def\thecompound{\textbf{\thechapter.\arabic{compound}}}
\newcommand{\cmp}[1]{\refstepcounter{compound}\label{cmp:#1}\textsf{\scriptsize{\thecompound}}}

Each time I want to number a compound, I simply write the command (which automatically increments the counter):

\cmp{uniquestring}

The problem I am having is finding an efficient way to put the compound numbers on the structural drawings (eps figures). What I am using right now is a floating text block over the image that I have to manually align. Here is an example of one of my figures (I defined a custom float called a Scheme):

\begin{Scheme}[h]
  \centering \includegraphics[scale=0.8]{chp_diazobkg/images/shioiritwo}
   \begin{textblock}{1}(1.65,-0.8) \cmp{aax} \end{textblock}
  \begin{textblock}{1}(7,-1) \cmp{aay} \end{textblock}
  \begin{textblock}{1}(13,-1) \cmp{aaz} \end{textblock}
  \begin{textblock}{1}(17.5,-0.5) \cmp{aba} \end{textblock}
  \caption{Facile [1,3]-Brook rearrangement of $\alpha$-keto silane intermediate \ref{cmp:aay}.}
  \label{sch:shioiritwo}
\end{Scheme}

Ideally what I would like to be able to do is use a package like pstool/psfrag so that the unique identifiers could be built into the eps file and get replaced with the compound numbers. Using the pstool package, I am able to do text replacements in eps figures, but when I try to do a replacement with a counter psfrag chokes and can't generate the figure. The code below works fine for me so I know the package is installed correctly.

\psfragfig[scale=0.8]{test}{
  \psfrag{[aaa]}{testing}
}

However, when I try to do something like this no luck (in fact the whole package breaks and no image is generated):

\psfragfig[scale=0.8]{test}{
  \psfrag{[aaa]}{\cmp{xxx}}
}

Or even something simpler like this just gives ?? for the replaced text:

\psfragfig[scale=0.8]{test}{
      \psfrag{[aaa]}{\ref{somefigure}}
    }

Any suggestions would be greatly appreciated.

I have posted a minimal working example with EPS files at: https://sites.google.com/site/vrendina/latex

share|improve this question
1  
I guess it's too late now but there are packages like chemnum for this task. – cgnieder Jan 19 at 7:48
The approach taken by my own chemscheme package is not dissimilar to the one you outline (today I would also recommend chemnum, but that's a different issue). Could you provide a small MWE of your input (i.e a complete document), including an EPS somewhere we can get hold of for testing? – Joseph Wright Jan 19 at 8:23
Works for me, even with the same string [aaa]. The ?? might mean that the label somefigure is not defined. At this point, you really have to provide a MWE. – mafp Jan 19 at 10:11
Assuming you're using \psfragfig as defined by auto-pst-pdf then your syntax is wrong. The last argument is optional: \psfragfig[scale=0.8]{scheme}[\psfrag{TMP}{\cmp{xxx}}]. – cgnieder Jan 19 at 13:36
I think I chose not to use chemnum because I didn't want to have to maintain a list of 100+ compounds at the beginning of each chapter. If I moved a scheme from the end of the chapter to the beginning every number would change and I wanted that updated automatically. – Victor Rendina Jan 19 at 17:09
show 4 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.