myChemistry

chemistry, typesetting and LaTeX

A small exercise

| 2 Comments

By simulating section 3.2 of this paper[1] I will go through several topics:

  • customization of ChemFig
  • reaction scheme creation with ChemFig
  • advanced usage of chemnum

Before we start let’s take a look at what we want to achieve:

(click to enlarge)

There are several points we need to solve: there is a numbered scheme which is set in sans serif font and which is referred to in the text; there are compound labels with sublabels; more importantly there are ranges of sublabels. And there’s the actual reaction scheme, of course.

Now, the goal is to achieve this without generating any pictures with an external program. What we need are the following packages:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenx}
\usepackage[version=3]{mhchem}
\usepackage[multiple]{footmisc}
\usepackage{chemnum,chemfig,chemstyle,bpchem,caption
}

The next thing we do is setting up ChemFig.

\setbondstyle{semithick} % make bonds thicker than the default
\setdoublesep{2pt} % seperate double bonds a little bit more
\setcrambond{3pt}{0.5pt}{1pt} % not needed here
\setatomsep{1.6em} % make the default bond length shorter
\setarrowoffset{1em} % this is the distance between arrow and compound
\setcompoundsep{6em} % this is the (new default) distance between compounds
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % we want sans serif printed atoms

Let’s see what this setup does:

\documentclass{article}
\usepackage{chemfig}
\begin{document}

\begin{minipage}{.4\linewidth}
\chemname{\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}}{default settings}
\end{minipage}
\setbondstyle{semithick}
\setdoublesep{2pt}
\setatomsep{1.6em}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\begin{minipage}{.4\linewidth}
\chemname{\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}}{new settings}
\end{minipage}

\end{document
}

\begin{minipage}{.4\linewidth} \chemname{\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}}{default settings} \end{minipage} \setbondstyle{semithick} \setdoublesep{2pt} \setatomsep{1.6em} \renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} \begin{minipage}{.4\linewidth} \chemname{\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}}{new settings} \end{minipage}

This doesn’t look exactly like in the paper but it’s close enough. Now we can start to create the scheme. We will use chemstyle‘s scheme environment and set up the caption with the caption package. This way we can easily refer to the scheme using \label{} and \ref{}. Then we will create the actual scheme using ChemFig. Let’s start with the last part.

\schemestart
\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}
\arrow
\chemleft[
\chemfig{X-[:-30
](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y}
\chemright]
\arrow
\chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)
}
\schemestop

\setbondstyle{semithick} \setdoublesep{2pt} \setcrambond{3pt}{0.5pt}{1pt} \setatomsep{1.6em} \setarrowoffset{1em} \setcompoundsep{6em} \renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} \schemestart \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr} \arrow \chemleft[ \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y} \chemright] \arrow \chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)} \schemestop

This was easy enough. But wait: why did I draw an invisible bond in the second compound and not use \chembelow{}{}? True, the compound would have looked right but the square brackets would not have included the Ar. Using \Chembelow{}{} would solve that problem but then the bonds would have departed strangely from the N.

\chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]\chembelow{N}{Ar}-[:30]-[:-30]Y}\chemright]
\chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]\Chembelow{N}{Ar}-[:30]-[:-30]Y}\chemright]
\chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y
}\chemright]

\setbondstyle{semithick} \setdoublesep{2pt} \setcrambond{3pt}{0.5pt}{1pt} \setatomsep{1.6em} \setarrowoffset{1em} \setcompoundsep{6em} \renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} \chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]\chembelow{N}{Ar}-[:30]-[:-30]Y}\chemright] \chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]\Chembelow{N}{Ar}-[:30]-[:-30]Y}\chemright] \chemleft[\chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y}\chemright]

Now we need labels and a legend. We will use ChemFig’s possibilities, i.e. we will use invisible arrows with arrow type 0: \arrow{0}.

\begin{scheme}
\centering\sffamily\schemedebug{true}
\schemestart
 \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}
 \arrow
 \chemleft[
  \chemfig{X-[:-30
](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y}
 \chemright]
 \arrow
 \chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)}
 \arrow(@c1--label1){0}[-90,.38] hydrazine
 \arrow(@c2--){0}[-90,.3] TS
 \arrow(@c3--){0}[-90,.2] pyrazole
 \arrow(@label1--.north west[align=left]){0}[-60,.2]
 a, X $=$ CN; b, X $=$ \ce{CO2Me};\\
 c, X $=$ COMe; d, X $=$ \ce{CONH2}
\schemestop
\caption{}\label{scheme:example}
\end{scheme
}

\setbondstyle{semithick} \setdoublesep{2pt} \setcrambond{3pt}{0.5pt}{1pt} \setatomsep{1.6em} \setarrowoffset{1em} \setcompoundsep{6em} \renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} \sffamily\schemedebug{true} \schemestart \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr} \arrow \chemleft[ \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y} \chemright] \arrow \chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)} \arrow(@c1--label1){0}[-90,.38] hydrazine \arrow(@c2--){0}[-90,.3] TS \arrow(@c3--){0}[-90,.2] pyrazole \arrow(@label1--.north west[align=left]){0}[-60,.2] a, X $=$ CN; b, X $=$ \ce{CO2Me};\\ c, X $=$ COMe; d, X $=$ \ce{CONH2} \schemestop

The right label numbers are missing, of course, but we’ll get there. You might have noticed the placement of the labels via \arrow(@c1--label1){0}[-90,.38]. This tells us we’re starting from the (already set) compound named c1 (as \schemedebug{true} tells us) and we call the new compound label1. (In a scheme in the chemfig sense everything before and after an arrow is a compound.) We’re going down (-90), 90 degrees clockwise from the horizontal direction) and shorten the arrow by the factor .38.

  \arrow(@label1--.north west[align=left]){0}[-60,.2]
  a, X $=$ CN; b, X $=$ \ce{CO2Me};\\
  c, X $=$ COMe; d, X $=$ \ce{CONH2
}

This uses the label1 to place the legend in an angle of 60 degrees clockwise. Here the upper left corner of the legend will start as indicated by the anchor .north west. Then we’re using the TikZ key align to modify the node within which we are going to place the legend in.

As you can see ChemFig provides various possibilities placing and customizing compounds. We only scratched at the surface, as the general syntax[2] of the \arrow command may indicate:

\arrow(from.anchor[<tikz>]--to.anchor[<tikz>]){<type>[<above>][<below>]}[<angle>,<length>,<tikz>]

Now we add labels for the compounds to our preamble using chemnum’s \cmpdinit to ensure the right order of the labels:

\cmpdsetup{sub-marker=!}\cmpdreset[75]
\cmpdinit{
  hydrazine!CN,
  hydrazine!CO2Me,
  hydrazine!COMe,
  hydrazine!CONH2,
  TS!CN,
  TS!CO2Me,
  TS!COMe,
  TS!CONH2,
  pyrazole!CN,
  pyrazole!CO2Me,
  pyrazole!COMe,
  pyrazole!CONH2
}

This will initialize and declare the compound labels and the sublabels for the corresponding variants. We have to ensure, that we declare the sublabels in the same order for each compound. Otherwise 1a and 2a might not refer to the same group for X.

Edit 2011/12/10: from v0.4 on, this can be done easier.

If we to change the scheme to

\begin{scheme}
\centering\sffamily
\schemestart
 \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}
 \arrow
 \chemleft[
  \chemfig{X-[:-30
](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y}
 \chemright]
 \arrow
 \chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)}
 \arrow(@c1--label1){0}[-90,.38] \cmpd[cmpd-all]{hydrazine}
 \arrow(@c2--label2){0}[-90,.3] \cmpd[cmpd-all]{TS}
 \arrow(@c3--label3){0}[-90,.2] \cmpd[cmpd-all]{pyrazole}
 \arrow(@label1--.north west[align=left]){0}[-60,.2]
 \cmpd[sub-only]{pyrazole!CN}, X $=$ CN; \cmpd[sub-only]{pyrazole!CO2Me}, X $=$ \ce{CO2Me};\\
 \cmpd[sub-only]{pyrazole!COMe}, X $=$ COMe; \cmpd[sub-only]{pyrazole!CONH2}, X $=$ \ce{CONH2}
\schemestop
\caption{}\label{scheme:example}
\end{scheme
}

we will now get the following (this needs at least two latex runs):

Rendered by QuickLaTeX.com

This will only work with the newest version of chemnum, i.e. v0.3b. You can get it here.

That’s it for the scheme. The text will be easier.

This synthesis has recently been developed initially by Goncalves \etal\footnotemark[58]
who reported that \IUPAC{meso\|xalo\|nitrile aryl\|hydrazones} \cmpd{hydrazine!CN} reacted with functionally
substituted hydrazines in \IUPAC{tri\|ethyl\|amine} solutions to yield \IUPAC{4\-amino\|pyrazole\-5\-carbo\|nitriles}
\cmpd{pyrazole!CN}. Subsequently, Elnagdi \etal\footnotemark[59]\footnotemark[60]\footnotemark[61] have extended this
approach and could show that it is a general one of application for a variety of
\IUPAC{2\-aryl\|hydrazono\|nitriles} \cmpd[sub-list={CO2Me..CONH2}]{hydrazine} (\ref{scheme:example
}). Elnagdi \etal
have recently reviewed achievements in this direction\footnotemark[62].

I use \footnotemark[], because I don’t want this example to be too complicated. What we should use here is biblatex if we want real citations. Then I use bpchem‘s \IUPAC{} to ensure the right hyphenation of the compound names, chemstyle’s \etal, and of course chemnum’s \cmpd{} for the compound labels.

Rendered by QuickLaTeX.com

Now we only need to add the right numbers in order to make the simulation complete, add the heading, and format the caption of the scheme:

% format of the caption
\DeclareCaptionFormat{scheme}{\textbf{#1}#3\par}
\captionsetup{format=scheme,singlelinecheck=off
}
% start with compound number 75, in preamble _before_ \cmpdinit
\cmpdreset[75]
% set counters so we get subsection 3.2 and scheme 23
\setcounter{section}{3} \setcounter{subsection}{1} \setcounter{scheme}{22}

The complete code is this:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenx}
\usepackage[version=3]{mhchem}
\usepackage[multiple]{footmisc}
\usepackage{chemnum,chemfig,chemstyle,bpchem,caption}

\DeclareCaptionFormat{scheme}{\textbf{#1}#3\par}
\captionsetup{format=scheme,singlelinecheck=off
}

% Setup ChemFig:
\setbondstyle{semithick}
\setdoublesep{2pt}
\setcrambond{3pt}{0.5pt}{1pt}
\setatomsep{1.6em}
\setarrowoffset{1em}
\setcompoundsep{6em}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}
}

% setup chemnum, initialize compound labels:
\cmpdsetup{sub-marker=!}\cmpdreset[75]
\cmpdinit{
  hydrazine!CN,
  hydrazine!CO2Me,
  hydrazine!COMe,
  hydrazine!CONH2,
  TS!CN,
  TS!CO2Me,
  TS!COMe,
  TS!CONH2,
  pyrazole!CN,
  pyrazole!CO2Me,
  pyrazole!COMe,
  pyrazole!CONH2
}

\setcounter{section}{3} \setcounter{subsection}{1} \setcounter{scheme}{22}
\begin{document}
\subsection{Reaction of arylhydrazononitrile with functionally\\substituted alkylhalides}
This synthesis has recently been developed initially by Goncalves \etal\footnotemark[58]
who reported that \IUPAC{meso\|xalo\|nitrile aryl\|hydrazones} \cmpd{hydrazine!CN} reacted with functionally
substituted hydrazines in \IUPAC{tri\|ethyl\|amine} solutions to yield \IUPAC{4\-amino\|pyrazole\-5\-carbo\|nitriles}
\cmpd{pyrazole!CN}. Subsequently, Elnagdi \etal\footnotemark[59]\footnotemark[60]\footnotemark[61] have extended this
approach and could show that it is a general one of application for a variety of
\IUPAC{2\-aryl\|hydrazono\|nitriles} \cmpd[sub-list={CO2Me..CONH2}]{hydrazine} (\ref{scheme:example}). Elnagdi \etal
have recently reviewed achievements in this direction\footnotemark[62].

\begin{scheme}
 \centering\sffamily
 \schemestart
  \chemfig{X-[:-30](-[:30]CN)=^[6]N-[:-30]NHAr}
  \arrow
  \chemleft[
    \chemfig{X-[:-30
](-[:30]CN)=^[6]N-[:-30]N(-[6,.5,,,draw=none]Ar)-[:30]-[:-30]Y}
  \chemright]
  \arrow
  \chemfig{Ar-[2]N*5(-(-Y)=(-NH_2)-(-X)=N-)}
  \arrow(@c1--label1){0}[-90,.38] \cmpd[cmpd-all]{hydrazine}
  \arrow(@c2--label2){0}[-90,.3] \cmpd[cmpd-all]{TS}
  \arrow(@c3--label3){0}[-90,.2] \cmpd[cmpd-all]{pyrazole}
  \arrow(@label1--.north west[align=left]){0}[-60,.2]
    \cmpd[sub-only]{pyrazole!CN}, X $=$ CN; \cmpd[sub-only]{pyrazole!CO2Me}, X $=$ \ce{CO2Me};\\
    \cmpd[sub-only]{pyrazole!COMe}, X $=$ COMe; \cmpd[sub-only]{pyrazole!CONH2}, X $=$ \ce{CONH2}
 \schemestop
 \caption{}\label{scheme:example}
\end{scheme}

\end{document
}

Rendered by QuickLaTeX.com

  1. [1] I chose it for two reasons: 1) the paper is free, 2) it shows an example for advanced usage of chemnum.
  2. [2] It may depend on the arrow type.

2 Comments

  1. since chemnum v0.4 option names changed (see chemnum documentation). option sub-marker was renamed to sub-input-sep and option sub-list no longer exists. Therefore the following changes need to be made to the above code example to work with chemnum versions large to v0.3.

    change \cmpdsetup{sub-marker=!}\cmpdreset[75] to \cmpdsetup{sub-input-sep=!}\cmpdreset[75]

    and \cmpd[sub-list={CO2Me..CONH2}]{hydrazine} to \cmpd{hydrazine!{CO2Me..CONH2}}

    • Thanks for this! This is a problem with posts in the internet: they easily outdate… which is kind of embarrassing since chemnum is one of mine after all…

Leave a Reply

Required fields are marked *.