I am writing a chemistry report and I have a few graphs that I need to insert. As the series labels I want to have the compound number (assigned by chemstyle) + some more text. I use ggplot2 to generate the plots and save as .eps. If the label is just the space holder (e.g. "TMP"), the substitution by chemstyle works fine. However, if the label is for example "TMP + compound A", the substitution no longer works. I also tried adding the extra text to the eps-file in incscape, but when I open it in inkscape and save it, the substitution no longer works either.

Here is an example:

\documentclass[11pt, titlepage]{article}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[runs=2]{auto-pst-pdf}

\usepackage{bpchem}
\usepackage[journal=rsc, tracking=bpchem]{chemstyle}

%%% compound labels declared when scheme is put in %%%
\usepackage{letltxmacro}
\LetLtxMacro\oldschemeref\schemeref
\DeclareRobustCommand{\schemeref}[2][]{
\CNlabelnoref{#2}
\oldschemeref[#1]{#2}
}

\begin{document}

\begin{scheme}
\begin{center}
\schemeref[TMP1]{1}
\schemeref[TMP2]{2}
\includegraphics[width=1\textwidth]{Chemdraw_Report/triazole_CD}
\caption{\small{CD spectrum of \CNref{1} and \CNref{2}.}}
\label{fig:triazole_CD}
\end{center}
\end{scheme}

\end{document}


The eps file that works, but without the wanted additional text can be found here. An example of what it looks like after adding text in inkscape, but where the text substitution no longer works can be found here.

How can I circumvent this problem? Are there better solutions that don't mean I have to add the compound labels by hand?

• If you open your first EPS in a text editor you can find the string TMP. If you open the second one you can't find the string. So it looks like your Inkscape text isn't actually saved as text. However, the psfrag package (that is used internally by chemstyle) needs to find a text string in order to the the text replacement. – clemens Mar 6 '14 at 21:23

The chemstyle package uses the psfrag package to replace labels in eps graphics. According to section 8.1 of the psfrag package documentation:

When adding a piece of text (a tag) in a figure for PSfrag to replace, use a single word, containing only unaccented letters and numbers.

This is the way that PSfrag is intended to be used; doing so will almost guarantee that PSfrag works as advertised.

Sometimes you will get away with labels that contain spaces, but note that

The tag supplied to the \psfrag command must be typed exactly as it appears in the EPS file's *show command, without the surrounding parentheses.

This is probably the cause of your first problem.

The second version of your file does not contain the text (try opening it with your favourite text editor and searching for "TMP" to see what I mean). It appears that Inkscape has 'drawn' the labels, forming each character from a combination of lines and curves. Because of this there are no show directives for psfrag to intercept.

EDIT

One way to solve your problem is to use \psfrag*, which appends extra material to a replacement. Again, quoting from the manual:

If a replacement for {tag} already exists, the unstarred command \psfrag will replace it without warning. The starred version \psfrag*, however, will add the new replacement to a list. Using the starred command, a single piece of PostScript text could trigger several replacements. I can’t think of a reason why most users would use the starred version, ...

You will need to play around with spacing (and adjust the size of the coloured background area), but something like this should work.

\documentclass[11pt, titlepage]{article}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[runs=2]{auto-pst-pdf}

\usepackage{bpchem}
\usepackage[journal=rsc, tracking=bpchem]{chemstyle}

%%% compound labels declared when scheme is put in %%%
\usepackage{letltxmacro}
\LetLtxMacro\oldschemeref\schemeref
\DeclareRobustCommand{\schemeref}[2][]{
\CNlabelnoref{#2}
\oldschemeref[#1]{#2}
}

\begin{document}

\begin{scheme}
\begin{center}
\schemeref[TMP1]{1}
\schemeref[TMP2]{2}
\psfrag*{TMP1}[l][l]{\qquad MORE TEXT!!!} % <--- New
\includegraphics[width=1\textwidth]{triazole_CD}
\caption{\small{CD spectrum of \CNref{1} and \CNref{2}.}}
\label{fig:triazole_CD}
\end{center}
\end{scheme}

\end{document}


Admittedly, I didn't even know about \psfrag* until now; if I could upvote your question again, I would do so.

• I see the problem, but do you have any suggestion for solutions? I know that maybe this is not a latex problem, more a eps editing problem, but I don't know where else to ask. – Helen Mar 7 '14 at 4:36
• @Helen --- I have edited my answer to offer a potential solution. – Ian Thompson Mar 7 '14 at 10:54