# Replace tag inbetween parentheses in eps with psfrag/chemnum

## Question

Is it possible to replace the TMP1 inbetween some parentheses (or other symbols and text) with chemnum?

## Examples

The following shows the input (eps; left), and the output (compiled file; right):

Maybe also used like this, as often seen in journals:

• If it works with psfrag then it works with chemnum. So the question rather is: is it possible with psfrag to replace a substring in a postscript or EPS file? – cgnieder Jun 2 '14 at 17:57
• I don't think substring replacements are possible with psfrag. Why not just replace the whole string, brackets included (i.e. \psfrag{(TMP1)}{(1)} and likewise for the second case)? – Ian Thompson Jun 2 '14 at 19:29
• @Ian: Someone could than maybe use replacecmpd{...} (chemnum), to replace the isolated TMP1 through a number, and then use psfrag to replace the obtained substituted string. The only problem is, that you never really know, which number will be in there (since there might be compounds added before in the work of progress) I will give it a try - maybe it can be done with \replacecmpd{\cmpd{CAS:532-27-4}} and a consecutive \psfrag{\cmpd{CAS:532-27-4}}{(\cmpd{CAS:532-27-4})}, if there is the isolated TMP1 in the eps. I will post the results of this experiment later on. – lcnittl Jun 3 '14 at 9:33
• @lcnittl \replacecmpd{foo} internally at some time does the equivalent of \psfrag{TMP1}{\cmpd{foo}}. (\replacecmpd{\cmpd{CAS:532-27-4}} will certainly not work...) – cgnieder Jun 3 '14 at 10:15
• @cgnieder You were totally right - It didn't work. But I came up with another solution - Not really nice, and everything else than automatic, but at least a workaround: {\psfrag{(TMP1)}{(\cmpd{a})}\includegraphics{./test.eps}} (so an adopted version of what chemnum does) – lcnittl Jun 3 '14 at 12:18

It doen't seem to be possibly in a native way, since psfrag (used by chemnum to replace the tags) is not supporting this kind of replacements, as can be read in the psfrag manual (page 10 at the very bottom), where it says:

And PSfrag can only replace entire strings, not just parts of one. So if your EPS file contains

(I want to replace the XXX here) show


then the \psfrag command will fail if you supply just the XXX.

## Approaches to still acquire the replacement

For the purpose of the following examples, this main code

\documentclass{article}

\usepackage[runs=2,crop=off]{auto-pst-pdf}
\usepackage{chemnum}
\usepackage{chemstyle} %Needed for scheme environment

\begin{document}
\input{code}
\end{document}


applies, where \input{code} would insert the code snippets from below.

The used graphic (EPS.eps) can be any .eps file containing the phrase (TMS1).
Note: Of course also TMP1 instead of (TMP1) will work, thus there's the danger, that this tag gets automatically substituted by chemnum (as this is the standard tag, and the normally desired behaviour), if one is not working carefully.

### A silver lining

Altough, I came up with a small workaround to solve this problem. I have to admit, that this solution is not really considered to be beautiful, but as there's no other solution (or at least I couldn't find one), someone in the need of this replacement has to accept to work with it.

The code

\psfrag{(TMP1)}{(\cmpd{a})}
\includegraphics{./EPS.eps}


does the job. This is an adoption of what \replacecmpd{foo} of chemnum is doing at some point.

This could also be packed inside a figure or scheme (as provided by chemstyle package) environment

\begin{scheme}
\centering
\caption{Caption}
\psfrag{(TMP1)}{(\cmpd{a})}
\includegraphics{./EPS.eps}
\label{schm:label}
\end{scheme}


what I believe would be the standard usage.

### A failed approach

I also tried to use

\begin{scheme}
\centering
\caption{Caption}
\psfrag{\cmpd+{a}}{(\cmpd+{a})}
\includegraphics{
\replacecmpd[tag=(TMP1)]{a}
\includegraphics{./chemnum_question.eps}
}
\label{schm:label}
\end{scheme}


to make a double replacement ((TMP1) > 1 (in this example) and in a second step 1 > (1)). The nested \includegraphics command is used in psfrag manual (page 9 in the middle), where:

\includegraphics[width=3.5in]{\includegraphics{example.eps}}

is used to scale the image and the replaced strings.

But using this technique failes, as it entails an error (TeX capacity exceeded, sorry [input stack size=5000]).