1

I'm new to latex but would really like to use it to write my dissertation (chemistry, obviously). Labwork is nearly done, but that seems to be the lower hurdle right now :D

Right now, I'm trying to use the chemnum package to get nice labels for all compounds. Theoretically, it should replace "TMP"-markers (which are given in an external eps file created by the chemdraw software) with automated numberings. However, I fail to even get the example file running using TeXstudio:

https://de.overleaf.com/latex/templates/automatically-numbering-compounds-in-chemical-schemes/kybckmsxnshs

In my case, the markers are not replaced, but instead under all six exemplary compounds the text "TMP1" or "TMP2" is written. Also the font inside the pictures is screwed up in respect to the model pdf from above.

What am I doing wrong? And while we're at it: how do I make my own TMP-labels? is it fine to just write "TMP" as a textblock in chemdraw?

Thanks in advance!

6
  • Regarding: "is it fine to just write "TMP" as a textblock in chemdraw?": Yes, simply place a text box where you want the number to appear later and type TMP1, TMP2 and so on.
    – leandriis
    Mar 26 '20 at 16:59
  • Which compiler did you use to compile your .tex file? If you want to use PDFLaTeX, add \usepackage{auto-pst-pdf} to the preamble.
    – leandriis
    Mar 26 '20 at 17:04
  • \usepackage{auto-pst-pdf} gives different error messages and doesn't seem to be compatible with something I already use. Thanks anyway!
    – Shintaro
    Mar 26 '20 at 17:31
  • Did you use the exact same code from the link you added? Did you so some changes to the code (other than trying auto-pst-pdf)? What error message do you get? Did you create the .eps file yourself? If so, could you open the eps file using an text editor and see if you can find "TMP1" there?
    – leandriis
    Mar 26 '20 at 17:45
  • I used the exact code I liked, including the eps-file from the same source. The error message is "Package pdftex.def Error: File `Test-pics.pdf' not found: using draft setting. \includegraphics[width=\linewidth]{hexa}"
    – Shintaro
    Mar 26 '20 at 18:23
1

So, I got some additional clue: it may have to do with the compilation settings.

As stated earlier, the compilation does work online using the overleaf texmaker. Overleaf uses latex compilation, but when changed to pdflatex it fails to replate the TMP markers, however, the figure still looks correct. My setup already fails at depicting the picture (see screenshot below, note that random parts are missing/moved and the font was changed).

using the auto-pst-pdf command gives no picture at all.

enter\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}
\title{Automatically numbering compounds in chemical schemes}
%% Uncomment these lines if you get error about "too many \new..." 
% \let\tmp\newinsert
% \let\newinsert\newbox
\usepackage{chemstyle}
% \let\newinsert\tmp
\usepackage{chemnum}
% For positioning the scheme captions at the top.
\floatsetup[scheme]{position=top}

\begin{document}
\begin{scheme}
%% hexa.eps has "TMP1" and "TMP2" as the markers
%% in fact EVERY .eps should start with TMP1, TMP2 etc
%% for ease of use \replacecmpd{first:compound}  
%% automatically replace TMP1
\replacecmpd{DSV}  %% automatically replace TMP2
\includegraphics[width=\linewidth]{Picture}
\caption{This is something!}
\label{first:chem:scheme}
\end{scheme}
Compounds \refcmpd{first:compound} and \refcmpd{DSV} in \ref{first:chem:scheme}. Here's a reference to in-text creation of \cmpd{RareCompound} that we can later refer to.
\vfill
\end{document}

enter image description here

enter image description here

1

The issues you are describing are a common problem in the combination pdfLatex / chemnum / Texstudio / ChemDraw. The compound numbering is obviously very powerful in a chemistry thesis.

My answer bases on the answers to similar questions, see: Numbering/ChemDraw/Mac, EPS/ChemDraw/chemnum, correct Texstudio configuration,

I'll try to list in the following the most common sources of errors:

  1. Compilation: you need to use pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex in TexStudio

  2. Texstudio PATH: Depending on your operating system, Set your PATH to something like /usr/local/texlive/2019/bin/x86_64-darwin:/Library/TeX/texbin (you'll have to adapt depending on your OS).

  3. Auto-pst-pdf: you'll need to load \usepackage[crop=off,runs=2]{auto-pst-pdf} very early in your preamble.

  4. EPS: It needs to be made in a way that Text strings are clearly defined as such. ChemDraw on Windows does it fine (standard parameters for export), but not ChemDraw on a Mac. This is a bug and a former question looked into it. Since I could compile your MWE I think you're fine.

I don't know about the jobname comment previously, I didn't need it for TexStudio but that might be necessary for Overleaf?

This example worked for me using the above described settings, using TexStudio v3:

\documentclass{article}
%\def\jobname{main} %<-- your file name
\usepackage[
runs=2,
crop=off
]{auto-pst-pdf} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}

\title{Automatically numbering compounds in chemical schemes}


%% Uncomment these lines if you get error about "too many \new..." 
% \let\tmp\newinsert
% \let\newinsert\newbox
\usepackage{chemstyle}
% \let\newinsert\tmp
\usepackage{chemnum}

% For positioning the scheme captions at the top.
%\floatsetup[scheme]{position=top}

    \begin{document}
    
    \begin{scheme}
    %% hexa.eps has "TMP1" and "TMP2" as the markers
    %% in fact EVERY .eps should start with TMP1, TMP2 etc
    %% for ease of use
    \replacecmpd{first:compound}  %% automatically replace TMP1
    \replacecmpd{second:compound}  %% automatically replace TMP2
    \includegraphics[width=\linewidth]{hexa}
    \caption{This is something!}
    \label{first:chem:scheme}
    \end{scheme}
    
    Compounds \refcmpd{first:compound} and \refcmpd{second:compound} in \ref{first:chem:scheme}. Here's a reference to in-text creation of  \cmpd{RareCompound} that we can later refer to.
    
    \vfill
    
    \begin{scheme}
    \replacecmpd{next:compound} %% automatically replace TMP1 BUT the autonumbering counter updates to 3!
    \replacecmpd{last:compound} %% automatically replace TMP2
    \includegraphics[width=\linewidth]{hexa}
    \caption{This is something else!}
    \label{second:chem:scheme}
    \end{scheme}
    
    Compounds \refcmpd{next:compound} and \refcmpd{last:compound} in \ref{second:chem:scheme}. Hey remember \cmpd{RareCompound}? \texttt{chemnum} still remembers it correctly, \emph{and} see how the compound numbering continues throughout the scheme diagrams!
    
    \vfill
    
    %% MANUAL UPDATING THE COMPOUND COUNTER; make sure you know what you're doing!
    \setcounter{cmpdmain}{8} 
    
    \begin{scheme}
    \replacecmpd{jumped:compound} %% automatically replace TMP1 BUT the autonumbering counter updates to 9!
    \replacecmpd{nextjumped:compound} %% automatically replace TMP2
    \includegraphics[width=\linewidth]{hexa}
    \caption{This is again something else!}
    \label{third:chem:scheme}
    \end{scheme}
    
    Compounds \refcmpd{jumped:compound} and \refcmpd{nextjumped:compound} in \ref{third:chem:scheme}. (Yes we manually modified the compound numbering counter after \ref{second:chem:scheme}).
    \end{document}

enter image description here

1
  • I can get it almost done with Simons answer. The only numbers missing are the ones in the scheme. In the text the numbering works fine, but the molecules themselves are not numbered. Do you have to put the TMP's yourself, or is that done automatically?
    – David
    Jun 16 at 8:18
0

I do not have the reputation to comment your answer. If you still want to use pdflatex as compiler, i would suggest to rename the `\jobname´ like Ulrike Fischer did in here answer here.

Using the overleaf example you cited and adding the line to rename the \jobname and the {auto-pst-pdf} package works for me.

\documentclass{article}
\def\jobname{main} %<-- your file name
\usepackage[
%runs=2,
%crop=off
]{auto-pst-pdf} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}

\title{Automatically numbering compounds in chemical schemes}


%% Uncomment these lines if you get error about "too many \new..." 
% \let\tmp\newinsert
% \let\newinsert\newbox
\usepackage{chemstyle}
% \let\newinsert\tmp
\usepackage{chemnum}

% For positioning the scheme captions at the top.
%\floatsetup[scheme]{position=top}

\begin{document}

\begin{scheme}
%% hexa.eps has "TMP1" and "TMP2" as the markers
%% in fact EVERY .eps should start with TMP1, TMP2 etc
%% for ease of use
\replacecmpd{first:compound}  %% automatically replace TMP1
\replacecmpd{second:compound}  %% automatically replace TMP2
\includegraphics[width=\linewidth]{hexa}
\caption{This is something!}
\label{first:chem:scheme}
\end{scheme}

Compounds \refcmpd{first:compound} and \refcmpd{second:compound} in \ref{first:chem:scheme}. Here's a reference to in-text creation of  \cmpd{RareCompound} that we can later refer to.

\vfill

\begin{scheme}
\replacecmpd{next:compound} %% automatically replace TMP1 BUT the autonumbering counter updates to 3!
\replacecmpd{last:compound} %% automatically replace TMP2
\includegraphics[width=\linewidth]{hexa}
\caption{This is something else!}
\label{second:chem:scheme}
\end{scheme}

Compounds \refcmpd{next:compound} and \refcmpd{last:compound} in \ref{second:chem:scheme}. Hey remember \cmpd{RareCompound}? \texttt{chemnum} still remembers it correctly, \emph{and} see how the compound numbering continues throughout the scheme diagrams!

\vfill

%% MANUAL UPDATING THE COMPOUND COUNTER; make sure you know what you're doing!
\setcounter{cmpdmain}{8} 

\begin{scheme}
\replacecmpd{jumped:compound} %% automatically replace TMP1 BUT the autonumbering counter updates to 9!
\replacecmpd{nextjumped:compound} %% automatically replace TMP2
\includegraphics[width=\linewidth]{hexa}
\caption{This is again something else!}
\label{third:chem:scheme}
\end{scheme}

Compounds \refcmpd{jumped:compound} and \refcmpd{nextjumped:compound} in \ref{third:chem:scheme}. (Yes we manually modified the compound numbering counter after \ref{second:chem:scheme}).
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.