Chemfig Doc en
Chemfig Doc en
v1.0h
Christian Tellechea
CH3
OH
HO
OH
CH3
O
CH3
HN
CH3
O
OH
O
O
O
CH3
Taxotere
OH
N
OH2
N
H
R
H2 O
R
2
6
6
6
4
R0
R0
3
7
7
7
5
OH2
H2 O
R0
OH
H
R0
R0
N
N
H
ChemFig
CONTENTS
Contents
I
Introduction
1 Foreword
2 Presenting ChemFig
II
Operation of ChemFig
1 Groups of atoms
3 Bond angle
3.1 Predened angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Absolute angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Relative angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
7
7
8
4 Length of a bond
6 Customization of bonds
10
7 Default values
10
8 Branches
11
8.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
8.2 Nesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
8.3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
9 Connecting distant atoms
10 Rings
10.1 Syntax . . . . . . . . . . .
10.2 Angular position . . . . . .
10.2.1 At the start . . . .
10.2.2 After a bond . . . .
10.3 Branches on a ring . . . . .
10.4 Nested rings . . . . . . . .
10.5 Rings and groups of atoms
12
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
14
14
15
15
15
16
17
17
20
III
23
Advanced usage
1 Separating atoms
23
2 Displaying atoms
23
3 Optional arguments
24
ChemFig
CONTENTS
4 Vertical alignment
25
26
27
7 Saving a sub-molecule
27
8 Decorations
28
8.1 Lewis diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.2 Stacking characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.3 Chemical reactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
9 Using \chemfig in the tikzpicture environment
32
10 Beyond chemistry
32
11 Annotated examples
11.1 Ethanal . . . . . . . . . . . . .
11.2 2-amino-4-oxohexanoic acid .
11.2.1 Absolute angles . . . .
11.2.2 Relative angles . . . .
11.2.3 Ring . . . . . . . . . .
11.2.4 Nested rings . . . . . .
11.3 Glucose . . . . . . . . . . . . .
11.3.1 Skeleton diagram . . .
11.3.2 Fisher projection . . .
11.3.3 Chair representation
11.3.4 Haworth projection . .
11.4 Adrenaline . . . . . . . . . . .
11.4.1 Using one ring . . . .
11.4.2 Using two rings . . . .
11.5 Guanine . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
33
33
34
34
34
35
35
35
36
36
37
37
38
38
39
40
12 How to . . .
12.1 Write a colored atom . . . . . . . . . . . . .
12.2 Add a superscript without modifying a bond
12.3 Draw a curve bond . . . . . . . . . . . . . .
12.4 Modify the size of a molecule . . . . . . . . .
12.5 Draw a ploymer element . . . . . . . . . . .
12.6 Draw the symmetrical of a molecule . . . . .
12.7 Add text above bonds and arc to angles . . .
12.8 Schma de Lewis langle prs . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
41
41
41
42
42
43
44
44
45
IV
Reaction schemes
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
47
1 Overview
47
2 Arrow types
48
3 Arrows features
48
4 Compounds names
49
5 Anchoring
49
6 Compounds style
51
7 Branching
52
ChemFig
FOREWORD
8 Subscheme
52
55
10 Arrows customization
57
10.1 First arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.2 Curved arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
11 The \merge command
59
12 The + sign
61
64
VI
List of commands
Gallery
66
Index
82
PART I
Introduction
1
Foreword
This package has seen the light of day thanks to the assistance of Christophe C, who had the idea after
being confronted with the complexity of the syntax of the ppchtex package.
Throughout the writing of the code, he helped me nd interesting features. He always encouraged me to write
more advanced features even though I was sometimes (nearly always?) reluctant; if ChemFig has the features it
does, it is in large part thanks to him. I thank him as well for his testing of beta versions of this package, and for
his contributions to the writing of this manual.
Experience shows that is it has been dicult to combine drawing of molecules with the typographic
quality of a program like LATEX, leaving little choice for the user who wishes to have a vector format
for these drawings. After having abandoned the ppchtex package (developed for conTEXt and available
under LATEX) because of the complexity of its syntax, I turned to the world of programs outside LATEX.
The diculty in this case is nding a compromise between quality and price. After many unsuccessful
attempts I found the only option was a new package, and I would like to thank Christian T for
bringing it to life. To meet my requirements, ChemFig needed to be easy to use but still have advanced
features, something well nigh impossible. Yet he was able to put together a very exible TEX code which
makes it a pleasure for me to write my molecules. I hope it will be the same for you readers looking for a
package useful in the eld of chemistry.
Christophe C
Finally, I wish to warmly thank Theo H and more recently Nikola C for oering to translate this
manual into English.
LATEXed by Christian T, the November 27, 2013.
ChemFig
PRESENTING ChemFig
Presenting ChemFig
To use this package, start by adding the following code to the preamble:
\input chemfig.tex with "TEX;
\usepackage{chemfig} with LATEX;
\usemodule[chemfig] with ConTEXt.
In all cases, the tikz package, if not loaded before, is loaded by ChemFig.
The most important command for drawing molecules is \chemfig{<code>}. The argument code is a set of
characters describing the structure of the molecule according to the rules which are described in this manual.
Care has been taken to make it possible to draw the greatest possible number of molecular congurations, while
maintaining a simple, exible, and intuitive syntax. Despite this, the <code> which describes the 2D structure of
the molecule increases in complexity in proportion to that of the molecule being drawn.
The command \chemfig draws a molecule using the commands provided by the tikz package, placed inside a
tikzpicture environment. The choice of tikz implies that:
the user has a choice of compilation method: pdfLATEX can be used equally well in dvi mode (tex !
dvi ! ps ! pdf) or in pdf mode (tex ! pdf). In eect tikz, via the underlying pgf, gives identical
graphical results in the two modes;
the bounding box is automatically calculated by tikz and the user need not worry about any overlap with
the text. However, care must be taken with alignment when the molecule is drawn in a paragraph. In the
O
following example, we have drawn the bounding box for the molecule: H3 C
always places the rst atom of the molecule on the baseline of the preceding code.
. ChemFig
C
OH
ChemFig
PART II
Operation of ChemFig
This part is devoted to describing the most common features of ChemFig. The user will nd here explanations
sucient to draw most molecules. The presentation of features is done from a theoretical angle, and the goal of
this part is not to draw real molecules but to give the user a formal description of the functionality of ChemFig.
The Advanced usage, page 23, will be more practical and will illustrate advanced features for the most demanding
uses. It will also highlight methods of building real molecules, page 33. Finally, the last part will give examples of
molecules and the code used to draw them.
Groups of atoms
Drawing a molecule consists inherently of connecting groups of atoms with lines. Thus, in the molecule O
there are two groups of atoms, each consisting of a single atom O.
O,
OH
there are four groups of atoms: H3 C, C, O and OH. For reasons which we shall see later, ChemFig splits
each group into single atoms. Each atom extends up to the next capital letter or one of these special characters: = ~ ( ! * < > @ . ChemFig ignores all characters inside braces when splitting groups into atoms.
Therefore the rst group of atoms H3 C is split into two atoms: H3 and C . In terms of chemistry, of course,
these are not real atoms; H3 , for example, consists of three hydrogen atoms. In what follows the word atom refers
to ChemFigs denition. Thus ChemFig sees the preceding molecule as follows:
O
H3 C
C
OH
For ChemFig, bonds between two atoms are one of nine types, represented by the characters - , = , ~ , > , < , >: ,
<: , >| and <| :
Bond #
1
2
3
4
5
6
7
8
9
LATEXed by Christian T, the November 27, 2013.
Code
\chemfig{A-B}
\chemfig{A=B}
\chemfig{A~B}
\chemfig{A>B}
\chemfig{A<B}
\chemfig{A>:B}
\chemfig{A<:B}
\chemfig{A>|B}
\chemfig{A<|B}
Result
A
B
A
B
A
B
A
B
A
B
A
B
A
B
A
B
A
B
Bond type
Single
Double
Triple
right Cram, plain
left Cram, plain
right Cram, dashed
left Cram, dashed
right Cram, hollow
left Cram, hollow
5
ChemFig
The command \setdoublesep{<dim>} adjusts the spacing between the lines in double or triple bonds. This
spacing is 2pt by default.
We must understand that when a bond is made between two atoms, these atoms are contained within invisible
rectangular boxes. The centres of these two rectangles are separated by an adjustable distance called the
interatomic distance. Furthermore, bonds do not connect to the exact edges of the rectangles: a length , also
adjustable, separates the edges of the rectangles and the beginning and end of the bond line. The rectangular
boxes are made visible in the diagram below to help understanding.
The macro \setatomsep{<dimension>} adjusts the interatomic distance . If the <dimension> is empty, it takes
the default value of 3em. This command, like all other settings commands, aects all the following molecules.
Interatomic distance
\setatomsep{2em}\chemfig{A-B}\par
\setatomsep{50pt}\chemfig{A-B}
A
A
B
B
<dimension>
Trimming bonds
\setbondoffset{0pt}\chemfig{A-B}\par
\setbondoffset{5pt}\chemfig{A-B}
A
A
B
B
If one bond is followed immediately by another, then ChemFig inserts an empty group {}. Around this empty
group the separation is zero:
Empty groups
\chemfig{A-B=-=C}
The \setbondstyle{<tikz code>} command sets the style for all the bonds drawn thereafter. The <tikz code>
is empty by default. To custom a single bond, see page 10.
Style of bonds
\setbondstyle{line width=1pt,red}
\chemfig{A-B=C>|D<E>:F}
The spacing for just one bond can be specied with the character #. This character must be placed immediately
after the bond symbol and has one required argument between parentheses of the form #(<dim1>,<dim2>),
where <dim1> is the spacing at the beginning of the bond and <dim2> is the that at the end. If <dim2> is omitted,
the spacing at the end of the bond takes the value of in eect at that time. One can see in the example how the
shortening, set to 4pt to be more visible, is nullied for the bond arriving at B, then for the one leaving B, and
nally for both:
Fine adjustment of bond shortening
\setbondoffset{4pt}
\chemfig{A-B-C}\par
\chemfig{A-#(,0pt)B-C}\par
\chemfig{A-B-#(0pt)C}\par
\chemfig{A-#(,0pt)B-#(0pt)C}
A
A
A
A
B
B
B
B
C
C
C
C
By default, all atoms within groups of atoms are typeset in math mode (spaces are ignored). They may therefore
contain math mode specic commands such as subscripts or superscripts1 :
Math mode
\chemfig{A_1B^2-C _ 3 ^ 4}
1 There
A 1 B2
C43
is a problem with the placement of groups of atoms containing exponents or subscripts. See page 25.
ChemFig
BOND ANGLE
There are settings specically for Cram bonds. This syntax is used:
\setcrambond{<dim1>}{<dim2>}{<dim3>}
Any empty argument takes its default value. The three arguments are:
<dim1> is the size of the base of the triangle, and is 1.5pt by default;
<dim2> is the thickness of the dots, and is 1pt by default;
<dim3> is the spacing between the dots, and is 2pt by default.
Here is an example where the three dimensions are changed:
Modified Cram bonds
\setcrambond{10pt}{0.4pt}{1pt}
\chemfig{A>B>:C>|D}
Bond angle
Each bond takes an optional argument in brackets. This optional argument can adjust every aspect of a bond,
and consists of ve optional elds separated by commas. The rst of these elds denes the bond angle. Angles
increase counterclockwise, and are relative to the horizontal. If the angle eld is empty, the angle takes its default
value of 0 . We will see later how to change this default.
There are several ways of specifying the bond angle.
\chemfig{A-B-[1]C-[3]-D-[7]E-[6]F}
These angles remain valid if the atoms are empty, and this is the case for all the features we will see below:
Predefined angles with empty groups
\chemfig{--[1]-[3]--[7]-[6]}
A
C
ChemFig
LENGTH OF A BOND
C
\chemfig{A-[:-5]-[::+20]-[::20]B-[::+20]-[::20]C-[::20]}
B
A
One can break a chain of relative angles by putting an absolute or predened angle where desired. Here, atom
B is followed by a bond at an absolute angle of 315 .
Result of relative angles followed by absolute
B
\chemfig{A-[:-5]-[::20]-[::20]B-[7]-[::20]C-[::20]}
A
C
Length of a bond
Rather than speaking of length of a bond, we should use the term interatomic spacing. If eect, only the interatomic
spacing is adjustable with \setatomsep as we have seen on page 6. Once this parameter is set, the length of a
bond depends on the content of atoms and, to a lesser extent, the angle the bond makes with the horizontal. It
should be obvious that two slimmer atoms will have larger edge separations than two which are larger. This can
be seen easily in the following example where an I atom is narrower than an M atom, which means that the
bond between the I atoms is longer than that between the M atoms:
Influence of the size of atoms
\chemfig{I-I}\par
\chemfig{M-M}
I
M
I
M
This aspect of the size of atoms becomes particularly acute when the atom involves subscripts or superscripts. In
this example, the bond is extremely short, to the point of confusion with a negative sign :
Too-short bond
A++
2
\chemfig{A^{++}_{2}-B^{-}_3}
B3
It is important to note that the exponent - is put inside braces. If this were not done, ChemFig would stop the
atom on this character, which is a bond character. The atom would then be B^, which would lead to unexpected
results.
We see in the example above that is it sometimes necessary to increase (or perhaps reduce) the interatomic distance
associated with a bond. For this, the optional argument to bonds is actually made up of several comma-separated
elds. As we have seen, the rst eld species the angle. The second eld, if it is not empty, is a coecient which
multiplies the default interatomic distance . Thus, writing -[,2] asks that this bond have the default angle (rst
eld is empty) and that the atoms it connects be separated by twice the default distance.
Modified bond length
\chemfig{A^{++}_{2}-[,2]B^{-}_3}\par
\chemfig{A-B-[,2]C=[,0.5]D}\par
\chemfig{-=[,1.5]-[,0.75]=[:-20,2]}
A++
2
A
B
B3
C D
ChemFig
We can change the size of molecules by altering the font size or the argument of \setatomsep, possibly on both 2 ,
being careful to conne these changes within a group if we want to limit the scope:
How to modify the size of molecule
O
H
\normalsize
\chemfig{H-[:30]O-[:-30]H}\par
\setatomsep{2.5em}\chemfig{H-[:30]O-[:-30]H}\par
\small
\chemfig{H-[:30]O-[:-30]H}\par
\footnotesize
\chemfig{H-[:30]O-[:-30]H}\par
\scriptsize
\chemfig{H-[:30]O-[:-30]H}\par
\tiny
\chemfig{H-[:30]O-[:-30]H}
H
H
A group of atoms can contain several atoms. Suppose we want to connect the group ABCD to the group
EFG with a bond. ChemFig calculates which atom of the rst group and which of the second group are to be
connected by looking at the angle of bond relative to the horizontal. If the angle is between (but not including)
90 and 90 (modulo 360 ) then the bond is made between the last atom of the rst group and the rst atom of
the second group. In all other cases, the bond is made between the rst atom of the rst group and the last atom
of the second group.
Here are some examples where the bond is in the interval ( 90, 90), and where the bond is made between D and
E:
Default atom connections
EFG
\chemfig{ABCD-[:75]EFG}\quad
\chemfig{ABCD-[:-85]EFG}\quad
\chemfig{ABCD-[1]EFG}
ABCD
EFG
ABCD
ABCD
EFG
In the following examples, the angles are in the interval [90, 270] and so the bond is made between A and G:
Default atom connections
E FG
\chemfig{ABCD-[:100]EFG}\quad
\chemfig{ABCD-[:-110]EFG}\quad
\chemfig{ABCD-[5]EFG}
ABCD
ABCD
ABCD
E FG
E FG
One may sometimes want the bond partners to be atoms other than those determined by ChemFig. The departure
and arrival atoms can be set with the optional bond argument by writing:
[,,<integer 1>,<integer 2>]
where <integer 1> and <integer 2> are the numbers of the desired departure and arrival atoms. These atoms
must exist, otherwise an error message will be given.
Specified atom connections
\chemfig{ABCD-[:75,,2,3]EFG}\qquad
\chemfig{ABCD-[:75,,,2]EFG}\qquad
\chemfig{ABCD-[:75,,3,2]EFG}
2 You
EFG
ABCD
EFG
ABCD
EFG
ABCD
can also use the second optional argument of \chemfig, see page 24.
ChemFig
DEFAULT VALUES
Customization of bonds
There is a fth and last optional argument for bonds which is found after the fourth comma:
[,,,,<tikz code>]
This <tikz code> is passed directly to tikz when the bond is drawn. There one can put characteristics such as
colour (red), dash type (dash pattern=on 2pt off 2pt), thickness (line width=2pt), or even decoration if the
tikz decoration library has been loaded. A bond can be made invisible by writing draw=none. To set several
attributes, the syntax of tikz is used, separating them by a comma:
Passing tikz code
\chemfig{A-[,,,,red]B}\par
\chemfig{A-[,,,,dash pattern=on 2pt off 2pt]B}\par
\chemfig{A-[,,,,line width=2pt]B}\par
\chemfig{A-[,,,,red,line width=2pt]B}
A
A
A
A
B
B
B
B
Numerous tikz decoration libraries are available. For example, one can use the pathmorphing library by putting
in the preamble in order to draw wavy bonds:
\usetikzlibrary{decorations.pathmorphing}
Wavy bonds
\chemfig{A-[,3,,,decorate,decoration=snake]B}
Default values
At the beginning of each molecule, the default values for the optional arguments are initialized. They are:
0 for the bond angle;
1 for the length multiplication coecient;
<empty> for the numbers of the departure and arrival atoms, which lets ChemFig calculate these based
on the bond angle;
<empty> for the parameters passed to tikz.
These default values can be changed for the whole molecule by beginning the molecule code with
[<angle>,<coeff>,<n1>,<n2>,<tikz code]
Thus, if the code of a molecule begins with [:20,1.5], then all the bonds will be at angle of 20 by default, and
the interatomic distances will have a length 1.5 times the default length. These default values can be overridden at
any time by giving an optional argument, such as for the bond which follows atom C in this example:
Overriding default values
F
C
\chemfig{[:20,1.5]A-B-C-[:-80,0.7]D-E-F}
If something odd like [1,1.5,2,2,red,thick] is written, then unless otherwise indicated all the bonds will have
an angle of 45 , the interatomic distances will be 1.5 times the default distance, the bonds will begin and end on
the second atom of each group, and the bonds will be red and thick:
Default values
GHI
\chemfig{[1,1.5,2,2,red,thick]ABC-DEF=GHI}
DEF
ABC
10
ChemFig
BRANCHES
Branches
8.1 Principle
Up to now, all the molecules have been linear, which is rare. A sub-molecule can be attached to an atom by
following the atom with <code> in parentheses. This <code> is the code of the submolecule which will be attached
to the atom.
In this example, the sub-molecule -[1]W-X will be attached to atom B:
A branch
W
\chemfig{A-B(-[1]W-X)-C}
There can be several sub-molecules which are to be attached to the same atom. Just have several parentheses
containing the code for each sub-molecule:
Multiple branches
W
A
\chemfig{A-B(-[1]W-X)(-[6]Y-[7]Z)-C}
Y
Z
The code of each sub-molecule can dene its own default values, which will be valid throughout the whole
sub-molecule. Here a sub-molecule [:60]-D-E is attached to atom B, with a default angle of 60 absolute. A
second sub-molecule [::-60,1.5]-X-Y is attached to B with a default bond angle 60 less than that of the
preceding bond (which will be the one between A and B) and with an interatomic distance 1.5 times the default
value:
Default values in branches
E
D
\chemfig{A-B([:60]-D-E)([::-30,1.5]-X-Y)-C}
C
X
Y
Observe what happens if, at the beginning of the main molecule, one writes [:-45]:
Effect of the default bond angle
E
D
A
B
\chemfig{[:-45]A-B([:60]-D-E)([::-30,1.5]-X-Y)-C}
C
X
We see that the angle between the bond B-C and the bond B-X stays at 30 because it is a relative angle for the
sub-molecule -X-Y. By contrast, the branch -D-E stays inclined at 60 to the horizontal, and does not follow
the rotation given by the 45 angle at the beginning; this is expected because -D-E has an absolute angle. It is
essential that all the angles be relative in order to rotate the whole molecule.
11
ChemFig
8.2 Nesting
Sub-molecules may be nested, and the rules seen in the preceding paragraphs stay in force:
Nested branches
Z
\chemfig{A-B([1]-X([2]-Z)-Y)(-[7]D)-C}
C
D
8.3 Method
O
Suppose now that we want to draw an acid anhydride molecule: R
C
O
O
The best way to get this is to nd the longest chain. Here, for example, we can draw the chain R-C-O-C-R taking
into account angles and using only relative angles:
Acid anhydride structure
R
\chemfig{R-C-[::-60]O-[::-60]C-[::-60]R}
O
R
To this structure we just have to add two =O sub-molecules to each of the carbon atoms:
Acid anhydride
O
R
\chemfig{R-C(=[::+60]O)-[::-60]O-[::-60]C(=[::+60]O)-[::-60]R}
O
R
C
O
Because we used only relative angles, we can rotate this molecule by giving a default angle of e.g. 75 :
Rotation of a molecule
O
C
\chemfig{[:75]R-C(=[::+60]O)-[::-60]O-[::-60]C(=[::+60]O)-[::-60]R}
O
C
R
R
We have seen how to connect atoms which are adjacent in the code. It is often necessary to connect atoms which
are not next to each other in the code. Lets call these particular bonds distant bonds.
Lets take this molecule:
LATEXed by Christian T, the November 27, 2013.
12
ChemFig
Branched structure
W
\chemfig{A-B(-[1]W-X)(-[7]Y-Z)-C}
C
Y
and suppose that we want to connect the atoms X and C. In this case, ChemFig allows a hook to be placed
immediately after the atom of interest. The character used for a hook is ? because of its similarity to a hook. So,
if one writes X? then the atom X will have a hook. Later in the code, all atoms followed by a ? will be connected to
X:
Distant bond
W
\chemfig{A-B(-[1]W-X?)(-[7]Y-Z)-C?}
C
Y
We could connect other atoms to X by following them with ?. Here its the atoms C and Z:
Several distant bonds
W
\chemfig{A-B(-[1]W-X?)(-[7]Y-Z?)-C?}
C
Y
Now imagine if we were to leave the distant bonds X-C and X-Zwhile adding another: A-W. We must therefore ask
for two dierent hooks, one on A and the other on X. Fortunately the character ? has an optional argument:
?[<name>,<bond>,<tikz>]
\chemfig{A?[a]-B(-[1]W?[a]-X?[b])(-[7]Y-Z?[b])-C?[b]}\par\medskip
\chemfig{A?[a]-B(-[1]W?[a,2,red]-X?[b])(-[7]YZ?[b,1,{line width=2pt}])-C?[b,{>},blue]}
C
Y
Several dierent hooks can be written after an atom. Suppose that in this unnished pentagon, we wish to connect
and E-C:
A-E, A-C
An incomplete ring
E
\chemfig{A-[:-72]B-C-[:72]D-[:144]E}
D
B
is not exactly right. Actually all the characters that can be put between \csname...\endcsname are allowed.
13
ChemFig
10
RINGS
D
B
10 Rings
The preceding example shows how to draw a regular polygon, but the method used is tedious because the angles
depend on the number of sides of the polygon.
10.1
Syntax
ChemFig can easily draw regular polygons. The idea is to attach a ring to an <atom> outside the ring with this
syntax:
<atom>*<n>(<code>)
is the number of sides of the polygon and the <code> describes the bonds and groups of atoms which make
up its edges and vertices. This code must begin with a bond because the atom is outside the ring.
<n>
\chemfig{A*5(-B=C-D-E=)}
C
A
A ring can also be drawn with one, several, or all the groups of atoms empty, as is the case for diagrams outside
rings:
5-ring with empty groups
\chemfig{*5(-=--=)}
C
B
If a ring has a code which contains too many bonds and atom groups for the given number of vertices, all the
bonds and groups over the maximum allowed are ignored:
Truncated 5-ring
E
\chemfig{A*5(-B=C-D-E=F-G=H-I)}
C
A
It is possible to draw a circle or an arc in the inside of a ring. To do so, the following syntax is used:
<atom>**[<angle 1>,<angle 2>,<tikz>]<n>(<code>)
where each eld of the optional argument takes its default value if it is empty:
LATEXed by Christian T, the November 27, 2013.
14
ChemFig
10
RINGS
<angle 1> and <angle 2> are the absolute angles of the start and nish of the arc. These default to 0 and
360 respectively so that a circle is drawn by default;
<tikz> is the code that will be passed to tikz for drawing the arc.
Rings and arcs
\chemfig{**6(------)}\quad
\chemfig{**[30,330]5(-----)}\quad
\chemfig{**[0,270,dash pattern=on 2pt off 2pt]4(----)}
10.2
Angular position
10.2.1
At the start
As can be seen in the examples above, the rule is that the attachment atom A is always at the south-west of the
ring. Furthermore, the ring is always constructed counterclockwise, and the last bond descends vertically onto
the attachment atom:
Angular position of rings
\chemfig{A*4(-B-C-D-)}\qquad\chemfig{A*6(------)}
If this angular position is not convenient, it is possible to specify another angle using the optional argument at
the beginning of the molecule. Here is a 6-cycle which has been rotated by +30 , by 30 , and lastly by +60 :
Rotation of rings
\chemfig{[:30]A*6(------)}\qquad
\chemfig{[:-30]A*6(------)}\qquad
\chemfig{[:60]A*6(------)}
10.2.2
After a bond
When a ring does not begin a molecule and one or more bonds have already been drawn, the default angular
position changes: the ring is drawn is such a way that the bond ending on the attachment atom bisects the angle
formed by the rst and last sides of the ring.
Here is a simple case:
Bond ending on a ring
F
\chemfig{A-B*5(-C-D-E-F-)}
B
C
The rule remains valid, whatever the angle of the preceding bond:
Bonds ending on a ring
B
A
\chemfig{A-[:25]B*4(----)}\vskip5pt
\chemfig{A=[:-30]*6(=-=-=-)}
15
ChemFig
10.3
10
RINGS
Branches on a ring
To have branches attached to the vertices of a ring, we use the syntax we have already seen:
<atom>(<code>)
where the <code> is that of the sub-molecule and the <atom> is at the vertex. Unique to rings, the default angle of
the sub-molecule is not 0 but is calculated so that it will bisect the sides leaving the vertex:
Branch on a ring
C
B
A
\chemfig{X*6(-=-(-A-B=C)=-=-)}
A sub-molecule can be attached to the rst vertex of a ring, just like the other vertices:
Ring and branches
F
G
\chemfig{*5((-A=B-C)-(-D-E)-(=)-(-F)-(-G=)-)}
A
B
C
E
If one wants the bond leaving a vertex not to be the bisector of its sides, one can tinker with the optional global
parameter or the optional bond parameter:
Branches at specified angles
B
A
\chemfig{*5(---([:90]-A-B)--)}\qquad
\chemfig{*5(---(-[:90]A-B)--)}\qquad
\chemfig{*5(---([::+0]-A-B)--)}
B
A
B
A
It is worth noting that in the third example, where a relative angle of 0 was given, the bonds of the branch are
drawn in line with the preceding bond in the ring. This is the rule on page 8 which specied that the reference
angle was that of the bond last drawn.
We can now connect together rings with bonds:
Connected rings
\chemfig{*6(--(-*5(----(-*4(----))-))----)}
16
ChemFig
10.4
10
RINGS
Nested rings
To glue two rings together, the syntax is only slightly dierent: the vertex is specied where the other ring
is going to start. Simply follow this vertex by the usual syntax for a ring. Here for example is a 5-ring which is
attached to the second vertex of a 6-ring:
Nested rings
\chemfig{A*6(-B*5(----)=-=-=)}
A
B
Note that the ring which is going to be attached to the main ring has an angular position such that two of the
rings sides coincide. In addition, the 5-ring has only four bonds ----. In eect, the fth will be useless because
it is the second side of the 6-ring, which has already been drawn.
It is quite possible to glue multiple rings together:
Multiple nested rings
\chemfig{*5(--*6(-*4(-*5(----)--)----)---)}
There is a case where a trick must be used. It can be seen in this example that the fourth side of the second 5-ring
just passes through the centre of atom E.
Flawed drawing
F
\chemfig{A-B*5(-C-D*5(-X-Y-Z-)-E-F-)}
Y
C
This is normal because the second 5-ring (which is attached to atom D) is drawn before ChemFig knows about
atom E. In this case, it is necessary to use two hooks to draw the bond Z-E:
Distant bond and ring
F
\chemfig{A-B*5(-C-D*5(-X-Y-Z?)-E?-F-)}
Y
C
Y
C
10.5
E
D
Some care must be taken with rings when one or more vertices are made up of groups of atoms:
17
ChemFig
11
GH
\chemfig{AB*5(-CDE-F-GH-I-)}
F
AB
CDE
In order for the ring to have a regular shape, it is necessary to override the ChemFig mechanism which
automatically calculates the departure and arrival atoms of bonds. Here, C-F and F-G must be connected by using
the optional argument of these bonds:
Forced departure and arrival atoms
I
\chemfig{AB*5(-CDE-[,,1]F-[,,,1]GH-I-)}
GH
F
AB
CDE
The optional argument <opt> of the \chemmove command will be added to the argument of the tikzpicture
environment in which the links between the nodes will be drawn. The <tikz opt> and <tikz link> instructions
are describe in detail in the documentation of the tikz package.
11.1
Mesomeric eects
To make these concepts concrete, lets take the example of a mesomeric eect involving a double bond and
non-bonding lone pair conjugate. Lets begin with the possible delocalization of electrons from the double bond.
We will place a node named db (double bond) in the middle of the double bond and a node named a1 on the
end of the double bond.
Mesomeric effect 1
\chemfig{@{a1}=_[@{db}::30]-[::-60]\lewis{2,X}}
\chemrel{<->}
\chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
\chemabove{X}{\scriptstyle\oplus}}
\chemmove{\draw[->](db).. controls +(80:8mm) and +(145:8mm)..
4 Actually,
(a1);}
the \chemmove command puts its argument in a tikzpicture environment with the options remember picture, overlay.
18
ChemFig
11
As noted above, there is no comma after the node placed in the optional arguments of a bond; we write
=_[@{db}::30] and not =_[@{db},::30] as one might be tempted to do.
To link the nodes db and a1 we have used the following syntax:
\chemmove{\draw[->](db)..controls +(80:8mm) and +(145:8mm)..(a1);}
In this example we ask for an arrow ([->]) and we use two control points5 . These will be located using polar
coordinates at 80 and 8 mm from db for the rst and at 145 and 8 mm from a1 for the second. Though this
syntax may seem complicated at rst reading, one need not be alarmed because its use will usually be a matter of
copying and pasting. Only the names and coordinates of the control points need be changed, as can be veried
from the example below, where an arrow has been added from the lone pair (node dnl to the single bond (node
sb).
Mesomeric effect 2
\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}}
\chemrel{<->}
\chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
\chemabove{X}{\scriptstyle\oplus}}
\chemmove{
\draw[->](db)..controls +(100:5mm) and +(145:5mm)..(a1);
\draw[->](dnl)..controls +(90:4mm) and +(45:4mm)..(sb);}
For our new arrow we have set the control points as follows: 4 mm at an angle of 90 from dnl and 4 mm at an
angle of 45 from sb. But we are not completely satised, since we would like the arrow not to touch the line
segment representing the lone pair. To do this we will add some options to our arrow.
Mesomeric effect 3
\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}}
\chemrel{<->}
\chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
\chemabove{X}{\scriptstyle\oplus}}
\chemmove[->]{
\draw(db).. controls +(100:5mm) and +(145:5mm).. (a1);
\draw[shorten <=3pt,shorten >=1pt](dnl) .. controls +(90:4mm)
and +(45:4mm) .. (sb);}
The option shorten <=3pt indicates that the tail of the arrow is to be shortened by 3 pt just as shorten >=2pt
means that the head of the arrow is shortened by 2 pt.
We can use all the power of tikz instructions to modify the style of the arrow. Here we change the head of the
arrow leaving the double bound, writing -stealth instead of ->, and we draw the arrow with a ne dashed
red line. We also add the letter above the middle of the arrow:
Mesomeric effect 4
\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}}
\chemrel{<->}
\chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
\chemabove{X}{\scriptstyle\oplus}}
\chemmove{
\draw[-stealth,thin,dash pattern= on 2pt off 2pt,red]
(db).. controls +(100:5mm) and +(145:5mm)..
node[sloped,above] {$\pi$} (a1);
\draw[->, shorten <=3pt, shorten >= 1pt]
(dnl).. controls +(90:4mm) and +(45:4mm).. (sb);}
In the following example, well see how to indicate the position of the departure or arrival anchor points of the
arrow. If we write
Departure or arrival anchor point 1
\chemfig{@{x1}\lewis{1:,X}}
\hspace{2cm}
\chemfig{@{x2}\lewis{2|,X}}
\chemmove{\draw[->,shorten >=4pt]
(x1).. controls +(90:1cm) and +(90:1cm)..
5 To
(x2);}
nd all the ways of connecting two nodes with tikz, read the documentation for that package.
19
ChemFig
12
Note that the tail of the arrow does not leave correctly from our electrons; it leaves from the middle of the upper
edge of the node. Indeed, we chose a departure angle of 90 and so tikz makes the arrow leave from the anchor
x1.90 which corresponds to the intersection of the ray leaving from the centre of node x1 at a 90 angle relative
to the horizontal and of the edge of the rectangular node. To get the arrow departure angle that we want, we
must specify its position. After some trial and error, it is x1.57:
Departure or arrival anchor point 2
\chemfig{@{x1}\lewis{1:,X}}
\hspace{2cm}
\chemfig{@{x2}\lewis{2|,X}}
\chemmove{\draw[->,shorten <=4pt,shorten >=4pt]
(x1.57).. controls +(60:1cm) and +(120:1cm)..
(x2);}
In some cases it will be easier to use Cartesian coordinated for the control points. Here we use just one control
point placed 1 cm to the right of and 1.5 cm above x1:
A single control point
\chemfig{@{x1}\lewis{1:,X}}
\hspace{2cm}
\chemfig{@{x2}\lewis{2|,X}}
\chemmove{\draw[->,shorten <=4pt,shorten >=4pt]
(x1.57).. controls +(1cm,1.5cm).. (x2);}
All the graphics drawn by means of the command \chemmove are superimposed and will not be included in the
bounding boxes. We can see this in the preceding example.
11.2
Reaction mechanisms
Thanks to the option remenber picture which is passed to all the tikzpicture environments we can easily draw
arrows indicating reaction mechanisms. Lets take for example the rst step of the esterication reaction.
Esterification: step 1
\setatomsep{7mm}
\setchemrel{}{}{5mm}
\chemfig{R-@{dnl}\lewis{26,O}-H}
\chemsign{+}
\chemfig{R-@{atoc}C([6]-OH)=[@{db}]O}
\chemrel[\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}]{<>}
\chemmove[->,shorten <=2pt]{
\draw[shorten >=2pt](dnl)..controls +(90:1cm)and+(north:1cm)..(atoc);
\draw[shorten >=6pt](db)..controls +(north:5mm)and+(100:1cm)..(atoh);}
H + R
H
C
OH
The use of the \chemabove{<code>}{<materiel>} command does not change the dimensions of the bounding
box of <code>. For this reason we can run into some diculty in pointing to the symbol representing the charge
carried ( or ). In the example above the solution is to create a control point with an angle of 110 at 1 cm from
atoh and to shorten the arrow by 6pt. In the following example, the second step of the esterication reaction, we
can see that the arrow can take more complicated forms without complicating the code.
Esterification: step 2
\setatomsep{7mm}
\setchemrel{}{}{5mm}
\chemfig{R-O-C(-[2]R)(-[6]OH)-@{dnl}\lewis{26,O}H}\hspace{1cm}
\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}
\chemmove{
\draw[->,shorten <=2pt, shorten >=7pt]
(dnl).. controls +(south:1cm) and +(north:1.5cm).. (atoh);}
R
R
OH
OH
20
ChemFig
12
The <dim>, which is 1.5ex by default, will be inserted between the baseline of the molecule and the top of the
letters of the <name>. The <name> will be centred relative to the molecule, but the <name> may not contain multiple
paragraphs. As we see in this example: H
O
H, the <name> which is displayed under the molecule is
The water molecule: H2 O
taken into account only for the vertical size of the bounding box. The horizontal size of <name> is always zero.
Here is a reaction with the names under the molecules:
Displaying names of molecules
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
\chemsign{+}
\chemname{\chemfig{ROH}}{Alcohol}
\chemrel{->}
\chemname{\chemfig{R-C(-[:-30]OR)=[:30]O}}{Ester}
\chemsign{+}
\chemname{\chemfig{H_2O}}{Water}
O
R
O
+ R0 OH
OH
Carboxylic acid
+ H2 O
C
OR0
Ester
Alcohol
Water
There are some limitations to this command. Suppose we switch the acid and the alcohol on the left side:
Name alignment 1
\chemname{\chemfig{ROH}}{Alcohol}
\chemsign{+}
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
\chemrel{->}
\chemname{\chemfig{R-C(-[:-30]OR)=[:30]O}}{Ester}
\chemsign{+}
\chemname{\chemfig{H_2O}}{Water}
O
R0 OH + R
Alcohol
O
R
OH
Carboxylic acid
+ H2 O
C
OR0
Ester
Water
In fact, to draw the <name> the command \chemname inserts 1.5ex + the largest of the depths6 of the molecules
thus far below the baseline of each molecule (light grey for the examples in this manual). The command
\chenameinit{<stuff>} initializes this largest depth with the <stuff>. Therefore one should:
write \chemnameinit{<deepest molecule>} before using the \chemname command in a reaction, unless
the reaction begins with the deepest molecule;
write \chemnameinit{} after having written all the names in a chemical reaction lest the greatest depth in
this reaction interfere with a future reaction.
Thus the correct code uses \chemnameinit before and after the reaction:
Name alignment 2
\chemnameinit{\chemfig{R-C(-[:-30]OH)=[:30]O}}
\chemname{\chemfig{ROH}}{Alcohol}
\chemsign{+}
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
\chemrel{->}
\chemname{\chemfig{R-C(-[:-30]OR)=[:30]O}}{Ester}
\chemsign{+}
\chemname{\chemfig{H_2O}}{Water}
\chemnameinit{}
O
R0 OH + R
Alcohol
OH
Carboxylic acid
O
R
+ H2 O
C
Ester
OR0
Water
Finally, to write a name on multiple lines, the command \\ encountered in a <name> causes a line break7 :
6 In
TEX terms, the depth is the dimension which extends vertically below the baseline.
the command \par is forbidden and causes a compilation error.
7 Conversely,
21
ChemFig
12
Name on 2 lines
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic\\acid}
\chemsign{+}
\chemname{\chemfig{ROH}}{Alcohol}
\chemrel{->}
\chemname{\chemfig{R-C(-[:-30]OR)=[:30]O}}{Ester}
\chemsign{+}
\chemname{\chemfig{H_2O}}{Water}
\chemnameinit{}
O
R
C
OH
Carboxylic
acid
O
+ R0 OH
Alcohol
+ H2 O
C
Ester
OR0
Water
If \chemname*{<nom>} is written, the macro does not take into account the previous names.
22
ChemFig
DISPLAYING ATOMS
PART III
Advanced usage
1
Separating atoms
The separating atom mechanism described previously extends each atom until the next capital letter or one of the
characters - = ~ ( ! * < > @
In certain cases this automatic separation produces incorrect atoms which can translate into an imperfect diagram.
Consider this example molecule, noting that the ( character is placed between braces so that ChemFig doesnt
incorrectly create a branch:
Alkene
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C{(}CH_3{)}_3}
C(CH3 )3
CH3 CH2
C
H3 C
We nd that the bond which arrives at the carbon atom in the upper right is too short. This happens because,
if we apply the ChemFig rules for separating atoms to the upper right group, the atoms are split in this way:
C{(}, C, H_3{)}_3. We now realize that the rst atom contains a parenthesis and thus has too great a depth in
math mode; we can see this by making the bounding boxes visible:
C(CH3 )3
CH3 CH2
C
H3 C
The character | forces splitting of the atom when it is encountered. Thus we can write C|{(CH_3)_3} to ensure
that ChemFig separates just two atoms here: C and {(CH_3)_3}. The problem of the too-short bond is thus
solved:
Alkene
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C|{(CH_3)_3}}
CH3 CH2
C
H3 C
C(CH3 )3
C
H
Displaying atoms
Once a molecule has been split into atoms, the macro \printatom is called internally by ChemFig in order to
display each atom. Its sole argument is the code of the atom to be displayed (e.g. H_3). By default, this macro
enters math mode and displays its argument with the math font family rm. It is dened by the following code:
\newcommand*\printatom[1]{\ensuremath{\mathrm{#1}}}
LATEXed by Christian T, the November 27, 2013.
ChemFig
\def\printatom#1{\ifmmode\rm#1\else$\rm#1$\fi}
OPTIONAL ARGUMENTS
One can modify the code of this macro to customize how atoms are displayed. In the following example, we
redene \printatom so that each atom will be enclosed in a rectangular box:
Redefinition of \printatom
\fboxsep=1pt
\renewcommand*\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}}
\chemfig{H_3C-C(=[:30]O)(-[:-30]OH)}
O
H3 C
C
OH
O
H3 C
C
OH
Optional arguments
The \chemfig command takes two optional arguments; their syntax is as follows:
\chemfig[<opt1>][<opt2>]{<molecule code>}
The rst optional argument <opt1> contains tikz instructions which will be passed to the tikzpicture environment
in which the molecule is drawn. The second optional argument <opt2> contains tikz instructions which will be
executed when each node8 is drawn.
With the use of the rst optional argument one can, for example, choose the global colour or thickness of lines:
Style choice
C
A
B
C
\chemfig{A-B-[2]C}\par\medskip
\chemfig[line width=1.5pt]{A-B-[2]C}\par\medskip
\chemfig[red]{A-B-[2]C}
B
C
With the second optional argument, one can choose the colour of nodes drawn by tikz, change the angle of the
drawing or its scale:
Style choices
C
A
B
C
\chemfig{A-B-[2]C}\par\medskip
\chemfig[][red]{A-B-[2]C}\par\medskip
\chemfig[dash pattern=on 1pt off 2pt][red]{A-B-[2]C}\par\medskip
\chemfig[][rotate=20]{A-B-[2]C}\par\medskip
\chemfig[][scale=0.5]{A-B-[2]C}
B
C
C
B
A
C
A
8 These instructions are added to the end of the argument of every node/.style{<argument>}. This argument contains by default the
following instructions: anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt.
24
ChemFig
VERTICAL ALIGNMENT
Vertical alignment
In some cases with condensed structural diagram of molecules having horizontal bonds, the placement of groups
of atoms is incorrect.
Careful study of the following example shows that the groups of atoms are not correctly aligned on the baseline:
Vertical placement
\Huge\setatomsep{2em}
\chemfig{A^1-B-C-D}\qquad
\chemfig{E_1-F-G-H}
A1
E1
Surprisingly, the second atom is correctly aligned while the last two undergo a vertical shift which seems to be
the results of the dierent height of the bounding box of the atoms A^1 and E_1.
In order to understand this phenomenon, we need to consider how ChemFig places groups of atoms relative to
each other. Let us limit ourselves to the case of horizontal bonds in order to simplify terminology, although the
algorithm is the same for other bonds. A horizontal bond leaves from the middle of the right side of the bounding
box of the departure atom of this bond. The arrival atom is positioned in such a way that the middle of the left side
of its bounding box is at the end of the bond. It follows that the vertical placement of the arrival atom depends on
the height of the departure atom. To limit this phenomenon, ChemFig adds to each arrival atom the \vphantom
of the departure atom, but does not include it in the contents of the arrival atom; this \vphantom is not intended
to aect the following atoms. The atoms remaining in each group are aligned so that their baseline coincides with
the baseline of the preceding atom.
The defective alignment can thus be explained. The atoms B and F are aligned correctly as they reect
the height of the atoms before them because of their \vphantom. For the atoms C and F, the heights of the
immediately preceding atoms are taken into account, but those of the atoms A^1 and E_1 are ignored! It
follows that these atoms are a little too high or too low, depending on the height of these bonds.
We can show this by making visible the bounding boxes of the atoms; one sees clearly that the atoms B and F
have bounding boxes that reect the heights of the immediately preceding atoms:
Vertical placement and bounding boxes
\Huge\setatomsep{2em}
\fboxsep=0pt
\renewcommand\printatom[1]{\fbox{\ensuremath{\mathrm#1}}}
\chemfig{A^1-B-C-D}\qquad
\chemfig{E_1-F-G-H}
A1
E1
Since there is no satisfactory manual solution, this problem can be worked around manually by putting inside the
third atom a \vphantom having the same height as the rst, so that the height aects the following atoms:
Vertical placement workaround
\Huge\setatomsep{2em}
\chemfig{A^1-B-{\vphantom{A^1}C}-D}\qquad
\chemfig{E_1-F-{\vphantom{E_1}G}-H}
A1
E1
For any group of atoms it is possible to temporarily deactivate the alignment adjustment mechanism and thus
neutralize the \vphantom. Simply place the \chemskipalign command in the group of atoms; the alignment will
resume in the following group of atoms as if the group of atoms containing \chemskipalign had never existed.
The following example shows the eects of this instruction: the reference point of the box containing the rst
atom is placed at the level of the bond which arrives from the left. The bounding boxes of the atoms are drawn in
the second line.
25
ChemFig
This command is to be used with caution lest the alignment of atoms in the next group be disrupted. In general,
all will be well if the group of atoms featuring \chemskipalign contains a single atom whose height and depth
are less than those of the preceding and following atoms, and if the preceding and following atoms have identical
heights and depths. Here is an example of the mess that results when the group of atoms contains two atoms,
here \chemskipalign. and B:
Consequence of the \chemskipaligncommand
\large
\fboxsep=0pt
\renewcommand\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}}
\chemfig{A-\chemskipalign.B-C}
.B
This feature can sometimes be useful. Suppose we want to draw the following molecule
A
We can dene commands which will draw the empty and full disks with tikz. To ensure that these disks are at the
right height, namely the height of the bond arriving at them, we will use the command \chemskipalign. In the
second line below the bonds are stuck to the disks by using the ability to change the bond shortening with the
# character, a feature seen on page 6.
Use of \chemskipalign and #
\begingroup
\def\emptydisk{\chemskipalign\tikz\draw(0,0)circle(2pt);}
\def\fulldisk{\chemskipalign\tikz\fill(0,0)circle(2pt);}
\chemfig{A-\emptydisk-\fulldisk-B}\par
\chemfig{A-#(,0pt)\emptydisk-#(0pt,0pt)\fulldisk-#(0pt)B}
\endgroup
A
A
B
B
All double bonds are made up of two line segments, and these segments are drawn on either side of the imaginary
line along which a single bond would be drawn. It is possible to shift a double bond so that one of the line segments
lies on the imaginary line. The other segment is then shifted above or below the bond. Actually, it is more correct
to say left or right of the imaginary line, as the bond is traversed in the direction of drawing.
To shift the bond to the left, write =^ and to shift it to the right, write =_:
Shifted double bonds
\chemfig{A-=-B}\par
\chemfig{A-=^-B}\par
\chemfig{A-=_-B}
A
A
A
B
B
B
In rings, double bonds are automatically shifted to the left. However, they can be shifted to the right by specifying
it with =_:
Shifted double bonds and rings
\chemfig{*6(-=-=-=)}\qquad
\chemfig{*6(-=_-=_-=_)}
Shifted bonds are particularly useful in drawing skeleton diagrams of molecules consisting of carbon chains with
double bonds. They give a continuous zig-zag path, whereas the path will be broken with regular double bonds:
LATEXed by Christian T, the November 27, 2013.
26
ChemFig
SAVING A SUB-MOLECULE
It is sometimes necessary to draw a double bond so that one line segment is dashed while the other is solid9 . This
feature is not hard-coded into ChemFig; instead tikz, its decorations library and its programmable styles make
it possible.
First of all, after having loaded the decorations library by putting \usetikzlibrary{decorations} in the
preamble, a decoration named ddbond (for Dashed Double Bond) is dened (lines 1 to 14) and then two tikz
styles called lddbond and rddbond (lines 15 and 16). For the former, the dashed line segment is on the left
of the solid middle segment; for the latter it is on the right. These styles can be called with the fth optional
argument of bonds:
Custom decorations
\pgfdeclaredecoration{ddbond}{initial}
{
\state{initial}[width=4pt]
{
\pgfpathlineto{\pgfpoint{4pt}{0pt}}
\pgfpathmoveto{\pgfpoint{2pt}{2pt}}
\pgfpathlineto{\pgfpoint{4pt}{2pt}}
\pgfpathmoveto{\pgfpoint{4pt}{0pt}}
}
\state{final}
{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\tikzset{lddbond/.style={decorate,decoration=ddbond}}
\tikzset{rddbond/.style={decorate,decoration={ddbond,mirror}}}
\setatomsep{4em}
\chemfig{[:-30]R-C-[::60]C(-[::60,,,,rddbond]O)-[,,,,lddbond]N(-[::-60]H)-[::60]C-R}
C
C
C
N
Saving a sub-molecule
ChemFig is capable of saving a <code> as an alias for reuse in a more compact form in the code of a molecule.
This is particularly useful when the <code> appears several times.
To do this, one gives the command
\definesubmol{<name>}{<code>}
which saves the <code> for recall in the code of the molecule via the shortcut !{name}. This <name> can be:
a sequence of characters: all the alphanumeric characters able to be between \csname and \endcsname are
accepted;
9 Thanks
to Andreas B who suggested this feature and who gave me the solution to this problem.
27
ChemFig
DECORATIONS
a control sequence.
In all cases, if the alias is already dened you should not overwrite it with a new denition using \definesubmol.
A warning will be issued to the user that the old alias will be overwritten by the new one. To override the denition
of an alias made previously, use:
\redefinesubmol{<name>}{<code>}
Here is a code which draws the pentane molecule. An alias xy was dened beforehand for the code CH_2:
Pentane
\definesubmol{xy}{CH_2}
\chemfig{H_3C-!{xy}-!{xy}-!{xy}-CH_3}
H3 C
CH2
CH2
CH2
CH3
In this case the technique is not very interesting because !{xy} is just as long to type as the code it replaces.
But in certain cases, this feature saves a lot of space in the code of the molecule and increases readability. In the
following example, we draw the complete structural diagram of butane. We will dene an alias with the control
sequence \xx for the sub-molecule CH2 . If we use only relative angles, it is possible to rotate the entire molecule
to any given angle by using the optional global angle parameter which species the default bond angle of the
main molecule. It is set to 15 here:
Butane
\definesubmol\xx{C(-[::+90]H)(-[::-90]H)}
\chemfig{[:15]H-!\xx-!\xx-!\xx-!\xx-H}
C
H
C
H
C
H
When the optional argument is present, the alias !<name> will be replaced by <code1> if the bond which arrives
at the alias comes from the right, i.e., if the angle which the arriving bond makes is between but is not equal to
90 and 270 . For all the other cases where the bond arrives from the left of vertically, the alias will be replaced by
<code2>.
We will dene a control sequence \Me pour methyl so that the alias !\Me will be replaced by H_3C when the
bond arrives from the right and by CH_3 when it arrives from the left. We can observe in the example that with
this alias we need no longer worry about the angle:
Dual alias
CH3
H3 C
CH3
H3 C
CH3
\definesubmol\Me[H_3C]{CH_3}
\chemfig{*6((-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-)}
CH3
Decorations
28
ChemFig
DECORATIONS
where the <n1>. . . <ni> represent the desired positions (in multiples of 45 ) around the <atom>. These whole
numbers must be between 0 and 7.
This command can also be used inside the argument of \chemfig:
The \lewis macro
A
B
\lewis{0246,A}\par\medskip
\lewis{1357,B}\par\medskip
\chemfig{H-\lewis{26,O}-S(=[2]\lewis{13,O})
(=[6]\lewis{57,O})-\lewis{26,O}-H}
O
H
If one wishes to draw two electrons instead of a line, follow the integer with a :. If one wishes to draw a single
electron, follow it with a .. To draw a lacuna, follow it with a |:
Lewis diagrams
\lewis{0:2:4:6:,C}\qquad\lewis{1:3:5:7:,C}\par\bigskip
\lewis{0.2.4.6.,C}\qquad\lewis{1.3.5.7.,C}\par\bigskip
\lewis{0:2.4|,X}\par\bigskip
Hydronium ion: \chemfig{H-\lewis{5|7,O^+}(-[2]H)-H}
X
H
Hydronium ion: H
O+
All the decorations drawn by \lewis are not included in the bounding box of the atom; they are drawn afterwards.
A consequence of this is seen in the two examples above, where the frame does not appear to be properly tted
to the drawing of the molecule, which extends downward slightly. This will be seen more often in this the
Decorations chapter, which presents commands which do not change the bounding box.
The \Lewis macro works the same way as \lewis but decorations are taken into account in the bounding box.
This can be seen more clearly by drawing an \fbox around decorated atoms:
Bounding box and the \lewis macro
\fboxsep0pt
\fbox{\lewis{0.2.4.6.,A}}\quad\fbox{\Lewis{0.2.4.6.,A}}\par\medskip
\fbox{\lewis{13,B}}\quad\fbox{\Lewis{13,B}}
is the width of the rectangle which represents the empty slot obtained whith the character |;
is the distance between the bounding box and the decoration. It is 0.2ex by default;
is the length of the line segment representing a pair of electrons. It is 1.5ex by default;
<code tikz> is code which is passed directly to tikz. This code is empty by default.
<dim1>
<dim2>
<dim3>
A problem sometimes occurs with the decorations of Lewis in the odd directions. In the example below with the
atom O, the decoration in position 1 seems farther from the atom than the decoration in position 4:
Odd directions
\huge
\Lewis{1|4|,O}
O
29
ChemFig
DECORATIONS
However, it is not the case as shown below by drawing the bounding box of the atom:
Optical illusion
\huge
\fboxsep0pt
\def\printatom#1{\fbox{$\mathrm{#1}$}}
\Lewis{1|4|,O}
The impression of greater distance is due to the shape of the letter O which is farther from the one of the
bounding box in the corners, that is to say, in odd directions.
To move nearer (or farther) the Lewis drawings in odd directions, the \lewis and \Lewis accept an optional
argument that contains a factor which multiplies the gap between the bounding box and decoration Lewis set
with the \setlewis command. For the letter O, it semms that 0.5 is the appropriated value:
Optional argument of \lewis
\huge
\Lewis{1|4|,O}\quad \Lewis[0.5]{1|4|,O}
\Lewis{0:3:,O}\quad
\Lewis[2]{0:5:,O}\quad
\Lewis[0]{0:5:,O}\quad
O
O
\Lewis[0.5]{0:5:,O}
O
O
Finally, the \setlewisdist macro sets the distance between the two disks representing a pair of electrons. The
argument of this macro must be valid distance for TEX or, if it is empty sets the default value is 0.3em:
Distance between electrons
\Lewis{1:3:5:7:,X}\qquad\Lewis{0:2:4:6:,X}\bigskip
\setlewisdist{0.2em}\Lewis{1:3:5:7:,X}\qquad\Lewis{0:2:4:6:,X}\bigskip
\setlewisdist{4pt}\Lewis{1:3:5:7:,X}\qquad\Lewis{0:2:4:6:,X}
and
\chembelow[<dim>]{<code>}{<stuff>}
place the <stuff> above and below the <code> respectively at a vertical distance <dim>, without changing the
bounding box of <code>. The optional argument allows, if written, to specify this dimension at each call. If the
optional argument is not used, a default size will be taken: its value is 1.5pt but it can be modied with the macro
\setstacksep{<dimension>}
These commands are independent of the macro \chemfig and can be used either inside or outside its argument.
They are especially useful in rings, if care is taken to put braces around the letters A, B, C and D in order to
prevent ChemFig from starting a new atom on these letters:
Staking in rings
D
C
\chemfig{*5(-\chembelow{A}{B}--\chemabove{C}{D}--)}
A
B
They are sometimes useful for placing pseudo-exponents which do not change the bounding box of the atoms, so
that the bonds do not end up being too short:
LATEXed by Christian T, the November 27, 2013.
30
ChemFig
DECORATIONS
Hydronium ion
H
\chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle+}(-[2]H)-H}
Les commandes \Chemabove et \Chembelow fonctionnent de la mme faon sauf que la bote englobante tient
compte du <matriel> plac au dessus ou au dessous.
A
A
A
A
A
A\chemrel{->}B\par
A\chemrel{<-}B\par
A\chemrel{<->}B\par
A\chemrel{<>}B\par
A\chemrel{->,red,thick}B
B
B
B
B
B
The command \setchemrel{<dim1>}{<dim2>}{<dim3>} allows settings of the dimensions used in drawing the
arrow:
<dim1> is the vertical spacing between the arrow and the optional text above and/or below it. If the
argument is empty, it defaults to 2pt;
<dim2> is the unbreakable horizontal space inserted before and after the arrow. If the argument is empty,
it defaults to 0.7em;
<dim3> is the length of the arrow. If the argument is empty, if defaults to 4em.
Text above arrows
\setchemrel{1pt}{}{6em}
A\chemrel[\footnotesize above][\tiny below]{<->}B
above
below
+ H3 C
Cl
Catalyst
+ H
Cl
And another:
Synthesis of phenylacetylene
\chemfig{*6(-=*6(-(-Br)-(-Br))-=-=)}
\chemrel[\chemfig{NaNH_2}][\chemfig{NH_3}]{->}
\chemfig{*6(-=(-~)-=-=)}
NaNH2
Br
NH3
Br
31
ChemFig
10
BEYOND CHEMISTRY
\begin{tikzpicture}[help lines/.style={thin,draw=black!50}]
\draw[help lines] (0,0) grid (4,4);
\draw(0,0) -- (2,1);
\draw(2,2) circle (0.5);
\node at (1,3) {\chemfig{A=B-[:30]C}};
\node[draw,red,anchor=base] at(3,2){\chemfig{X>[2,,,,blue]Y}};
\end{tikzpicture}
Y
X
10 Beyond chemistry
At heart ChemFig is a tool for drawing graphs, and this tool has been programmed to adapt it for chemistry. In
some ways it is possible to return ChemFig to its roots to draw organization charts or other diagrams represented
by graphs.
Each atom is contained in a tikz node. By default these nodes have an inner sep and an outer sep equal to 0pt.
They are rectangular as seen on page 6. These defaults can be overwritten with the macro \setnodestyle, the
argument of which is passed to tikz and species the style of the nodes containing the atoms.
In this example we specify only draw,inner sep=2pt, which has the eect of drawing the outline of the nodes
and separating the outline and node contents by 2pt. We also specify \setbondoffset{0pt}\setbondoffset so
that the bonds touch the edges of the nodes. The interatomic spacing is increased to 75pt. Finally, the command
\printatom is made as simple as possible so that math mode is no longer used and spaces are thus preserved.
An organization chart
\setnodestyle{draw,inner sep=2pt}
\setbondoffset{0pt}
\setatomsep{75pt}
\renewcommand\printatom[1]{#1}
\chemfig{The boss-[6]Me(-[4]Them(-[6]The others)(-[7,2]Group 1))-You(-[:-120,0.5]Him)(-[:-60,0.5]Her)}
The boss
You
Me
Them
Him
Her
The others
Group 1
Here is another organization chart where the nodes are circular and coloured cyan:
Family diagram
\setnodestyle{draw,circle,fill=cyan,minimum size=30pt}
\setbondoffset{0pt}
32
ChemFig
11
ANNOTATED EXAMPLES
\setatomsep{80pt}
\renewcommand\printatom[1]{\textsf{#1}}
\chemfig{Me(-[:-50,1.2]Brother)(-[:-10]Brother(-[:15]Niece)(-[:-35]Niece))
(-[:-155,0.8]Sister-[:-80]Nephew)(-[:95,1.25]Father(-[:-25,0.8]Uncle)(-[:-65,0.8]Aunt))
(-[:135]Mother-[:-95,0.5]Uncle)}
Father
Uncle
Mother
Aunt
Uncle
Niece
Me
Brother
Sister
Niece
Brother
Nephew
11 Annotated examples
In this chapter, several molecules will be drawn, putting into use the methods previously described. The aim here
is to show a logical order for putting together a molecule so that the user unfamiliar with ChemFig will learn
how to construct complex molecules. The construction steps will be shown to help with this learning process.
In addition, several possibilities some intuitive and others less so will be shown which give the same graphical
results, with the objective being to show that ChemFig allows some exibility in encoding molecules. One can
see how each is put together and adopt the methods with which one is most comfortable.
11.1
Ethanal
H
O
C
H
H
The best method for non-cyclic molecules is to select the longest chain. Here one could take H-C-C=0 for example.
The bond C=O is tilted to 45 by using the predened angle [1]. This give a backbone of the molecule to which
the branches merely have to be added:
Backbone of ethanal
O
\chemfig{H-C-C=[1]O}
The three hydrogen atoms still have to placed at the correct orientation with the help of predened angles. The
rst is at 90 with the branch (-[2]H), the second at 270 with (-[6H]), and the one on the right at 315 with
(-[7]H):
33
ChemFig
11
ANNOTATED EXAMPLES
Ethanal
H
\chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}
C
H
11.2
2-amino-4-oxohexanoic acid
O
OH
O
NH2
As is often the case for most molecules, there are several methods and for each several dierent ways of getting
the result. Here we will look at four dierent methods.
11.2.1
Absolute angles
We will rst of all draw the central chain with absolute angles. We set the default angle to +30 with the optional
argument, and so only the descending bonds need to have their absolute angle set to 30 :
Backbone (absolute angles)
\chemfig{[:30]--[:-30]--[:-30]--[:-30]OH}
OH
The branches (=[6]O), (-[6]NH_2) and (=[2]O) still have to be added to the correct vertices:
Molecule (absolute angles)
O
\chemfig{[:30]--[:-30](=[6]O)--[:-30](-[6]NH_2)-(=[2]O)-[:-30]OH}
OH
O
11.2.2
NH2
Relative angles
OH
then
Molecule (relative angles)
O
\chemfig{[:30]--[::-60](=[::-60]O)--[::-60](-[::-60]NH_2)
-(=[::60]O)-[::-60]OH}
OH
O
NH2
34
ChemFig
11.2.3
11
ANNOTATED EXAMPLES
Ring
Since the angles between the bonds are 120 , it is possible to use a 6-ring, although this method is less natural.
Here we take advantage of the fact that a ring can be left unnished. The ring must be rotated 120 so that the
rst vertex is to the south-east of the ring:
Backbone (ring)
\chemfig{[:120]NH_2*6(---=O)}
NH2
\chemfig{[:120]NH_2*6(-(-(=[::60]O)-[::-60]OH)--(--[::60])=O)}
OH
O
11.2.4
NH2
Nested rings
Delving deeper into the ring method, we can also consider nesting incomplete 6-rings. We could start with this
backbone:
Backbone (nested rings)
O
\chemfig{*6(--*6(--=O))}
And then add the bonds which leave the vertices of these rings. There are no angles to worry about because the
bonds leaving the rings are the bisectors of the sides of the ring, exactly what we want here:
Molecule (nested rings)
O
\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)=O))}
OH
O
NH2
A close look shows that the second line segment of the double bond to the oxygen atom is inside the incomplete
6-ring10 Despite its brevity, this code does not give a perfect drawing. This can of course be corrected by adding a
little to the code:
Molecule (corrected nested rings)
\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)(=[::60]O)))}
OH
O
11.3
NH2
Glucose
The goal here is to represent the glucose molecule according to several dierent conventions.
10 This
was also true for the preceding method with one ring.
35
ChemFig
11.3.1
11
ANNOTATED EXAMPLES
Skeleton diagram
The code here looks like that of 2-amino-4-oxohexanoic acid. This gives almost the same structure with absolute
angles, except here the default angle is 30 :
Backbone
HO
\chemfig{[:-30]HO--[:30]--[:30]--[:30]-H}
OH
HO
\chemfig{[:-30]HO--[:30](<[2]OH)-(<:[6]OH)
-[:30](<:[2]OH)-(<:[6]OH)-[:30](=[2]O)-H}
H
OH
11.3.2
OH
Fisher projection
OH
OH
OH
OH
OH
The idea is to begin to draw the longest chain vertically by giving a default angle of [2]. Here is the skeleton,
where we have added lower case letters at the end of each vertical bond:
Skeleton
O
d
c
\chemfig{[2]OH-[3]-a-b-c-d-=[1]O}
b
a
OH
36
ChemFig
11
ANNOTATED EXAMPLES
Next we dene two aliases for the horizontal bonds and the atoms at their ends. Lets choose x which we will put
in place of the lower case a, c and d, and y which will replace the letter c. Since these alias are just one character,
we do not need braces and can write !x instead of !{x}:
Glucose (Fisher projection)
O
OH
OH
\definesubmol{x}{(-[4]H)(-[0]OH)}
\definesubmol{y}{(-[0]H)(-[4]OH)}
\chemfig{[2]OH-[3]-!x-!x-!y-!x-=[1]O}
OH
OH
OH
11.3.3
Chair representation
OH
OH
OH
OH
OH
To do this, we will rst of all draw ve sides of the chair and link the rst vertex to the last with a hook ?. We
will use the following absolute angles, running counterclockwise: 50 , 10 , 10 , 130 , 190 .
Structure
O
\chemfig{?-[:-50]-[:10]-[:-10]-[:130]O-[:190]?}
Now we simply add the branches inside parentheses. The angles are chosen to give the best impression of
perspective, and some bonds are shortened by a factor of 0.7:
Chair representation
OH
\chemfig{?(-[:190]OH)-[:-50](-[:170]OH)-[:10](-[:-55,0.7]OH)
-[:-10](-[6,0.7]OH)-[:130]O-[:190]?(-[:150,0.7]-[2,0.7]OH)}
OH
OH
OH
11.3.4
OH
Haworth projection
OH
O
OH
OH
OH
First of all we will choose the longest chain, which starts at the HO group on the left and continues through
ves sides of the ring. The ring will be closed with a hook. For the vertical bond which leaves from the rst HO
37
ChemFig
11
ANNOTATED EXAMPLES
group, we need to specify that it will leave from the second atom using the optional argument. Furthermore, it
will be shortened with a coecient of 0.5. Its optional argument will thus be [2,0.5,2].
Next, to give the impression of perspective to the ring, the diagonal bonds will be shortened by a coecient
of 0.7. For the bold diagonal lines we will use Cram bonds, having redened the base of the triangles to be
2pt. The bold horizontal bond needs to be drawn with a thickness of 2pt, and so its optional argument will be
[0,,,,line width=2pt]. Here is the skeleton of the molecule:
Structure
O
\setcrambond{2pt}{}{}
\chemfig{HO-[2,0.5,2]?<[7,0.7]-[,,,,
line width=2pt]>[1,0.7]-[3,0.7]O-[4]?}
HO
All that needs to be done now is to add the branches at the correct places, giving the right absolute angles and
sometimes reducing the length to better give the illusion of perspective:
Haworth projection
OH
\setcrambond{2pt}{}{}
\chemfig{HO-[2,0.5,2]?<[7,0.7](-[2,0.5]OH)-[,,,,
line width=2pt](-[6,0.5]OH)>[1,0.7](-[6,0.5]OH)-[3,0.7]
O-[4]?(-[2,0.3]-[3,0.5]OH)}
11.4
O
OH
HO
OH
OH
Adrenaline
OH
HO
HN
HO
CH3
First of all, we start with a 6-ring and we draw the start of the branches which leave it:
Skeleton of adrenaline
HO
\chemfig{*6((-HO)-=-(-)=-(-HO)=)}
HO
The branch on the right still needs to be completed using, for example, relative angles:
Adrenaline, step two
HO
\chemfig{*6((-HO)-=-(--[::-60]-[::-60]
HN-[::+60]CH_3)=-(-HO)=)}
HN
HO
CH3
Then we need to add a Cram-bonded OH and indicate that the bond which arrives at HN does so on the second
atom, i.e., N. We use the fourth optional argument of the bond:
38
ChemFig
11
ANNOTATED EXAMPLES
Adrenaline
OH
\chemfig{*6((-HO)-=-(-(<[::60]OH)-[::-60]-[::-60,,,2]
HN-[::+60]CH_3)=-(-HO)=)}
HO
HN
HO
11.4.2
CH3
This method is less natural, but the goal is to show here how to make a bond invisible.
We could improve this code by considering that the drawing of the adrenaline molecule is made of two 6-rings
adjacent to each other:
Adrenaline, two-ring skeleton
HO
\chemfig{*6((-HO)-=*6(--HN---)-=-(-HO)=)}
HN
HO
Now the rst two bonds of the ring on the right need to be made invisible. To do this we use the argument that is
passed to tikz, specifying draw=none. These bonds will thus have this code: -[,,,,,draw=none]. To keep the
code readable, we dene an alias named & for these bonds:
Adrenaline, step two
HO
\definesubmol{&}{-[,,,,draw=none]}
\chemfig{*6((-HO)-=*6(!&!&HN---)-=-(-HO)=)}
HN
HO
The rest becomes easy; just add the branches to the right vertices:
Adrenaline, step three
OH
\definesubmol{&}{-[,,,,draw=none]}
\chemfig{*6((-HO)-=*6(!&!&HN(-CH_3)--(<OH)-)-=-(-HO)=)}
HO
HN
HO
CH3
To nish, we specify that the bonds that arrive at and leave from HN must do so at the second atom. We therefore
dene another alias for the invisible bond which arrives at HN:
Adrenaline
OH
\definesubmol{&}{-[,,,,draw=none]}
\definesubmol{&&}{-[,,,2,draw=none]}
\chemfig{*6((-HO)-=*6(!&!{&&}HN(-CH_3)-[,,2]-(<OH)-)-=-(-HO)=)}
HO
HN
HO
CH3
39
ChemFig
11.5
11
ANNOTATED EXAMPLES
Guanine
O
HN
N
H
First of all, lets begin by drawing the nested rings, putting just the nitrogen atoms at the vertices:
Guanine, skeleton
N
\chemfig{*6(=N-*6(-N-=N)=--N-)}
Then we can draw the horizontal bond in the right ring with a hook. We will also place a hydrogen atom under
the nitrogen atom of the 5-ring with the command \chembelow{N}{H}. We also need to write HN instead of N
at the vertex at the upper left of the molecule:
Guanine, step two
HN
\chemfig{*6(=N-*6(-\chembelow{N}{H}-=N?)=?--HN-)}
N
H
We note that one bond leaves from the wrong atom11 ! The automatic calculation mechanism must be corrected so
that the bond leaves from the second atom N instead of the rst. To do this we give an optional argument for the
last bond of the rst 6-ring [,,2]:
Guanine, step three
HN
\chemfig{*6(=N-*6(-\chembelow{N}{H}-=N?)=?--HN-[,,2])}
N
H
Simply add the branches to the right vertices. Note especially the branch leaving the rst vertex of the rst 6-ring
(-N_2N):
Guanine
O
\chemfig{*6((-H_2N)=N-*6(-\chembelow{N}{H}-=N?)=?-(=O)-HN-[,,2])}
HN
H2 N
N
H
We could also draw the same molecule with a regular 5-ring, as is sometimes done:
11 This seems illogical because the angle of the bond from the HN group toward the rst vertex lies between 90 and 90 ; ChemFig
should therefore leave from the second atom. To explain this contradiction, one must know that in rings, the last bond always links the
last vertex to the rst, ignoring the calculated theoretical angle of this bond (which here is 90 ). ChemFig uses this theoretical angle to
determine the departure and arrival atoms, but does not use it to draw the bond because the two ends are already dened. The departure atom
for the last bond is thus the rst atom.
40
ChemFig
12
HOW TO . . .
\chemfig{*6((-H_2N)=N-*5(-\chembelow{N}{H}-=N-)=-(=O)-HN-[,,2])}
HN
H2 N
N
H
12 How to . . .
12.1
Since the package xcolor is loaded by tikz, itself loaded by ChemFig, we can write color commands in the code
of a molecule, mainly \color and \textcolor. The atoms are displayed in tikz nodes which behaves like boxes of
TEX and it is as if these atoms were put in a group. Therefore, the color change remains local to the atom.
Colors
O
\chemfig{C\color{blue}H_3-C(=[1]O)-[7]O\color{red}H}
CH3
C
OH
This code does not work, because of the rule used to separate atoms: here, the rst atom sarts at C and spreads
to the next uppercase letter. Therefore, this atom is C\color{blue} and the color change occurs at the end of
atom and has no eect. We need to force ChemFig to cut the rst atom just after C with the character | and
then include \color{blue}H_3 between braces so that ChemFig does not stop the atom 2 before the uppercase
H which would leave the color change alone and therefore ineective in an atom:
Colors
O
\chemfig{C|{\color{blue}H_3}-C(=[1]O)-[7]O|{\color{red}H}}
CH3
C
OH
CH3
C
OH
The main disadvantage is that we have to do the same for every atom that need to be colored, even if they are
contiguous.
12.2
Adding a charge to an atom with a mathematical exponent implies that the box (and therefore the tikz node)
containing the atom has its dimensions modied. It has no importance when the atom is trailing but the alignment
may be compromised if a bond is attached to the atom. The rst reaction is to put the charge in a box with no
width and therefore use the command \rlap12 , which often gives good results. We see here that with \rlap, the
horizontal alignment of atoms is preserved:
Charge and bond
\chemfig{A^+-[2]B}
\qquad
\chemfig{A\rlap{${}^+$}-[2]B}
12 If
B
A+
B
A+
you have to put the charge at the left of the atom, you must use the command \llap.
41
ChemFig
12
HOW TO . . .
If you want to use the command \oplus which displays , some could nd that the charge is too low: A . In
that case, why not use \chemabove to put as precisely as you will, both vertically and horizontally the charge:
Charge et \chemabove
\chemfig{\chemabove[0.5pt]{A}{\scriptstyle\hspace{3.5mm}\oplus}-[2]B}
\qquad
\chemfig{{\chemabove[-0.5pt]{A}{\scriptstyle\hspace{3.5mm}\oplus}}-[2]B}
We notice an additional level of braces for the second molecule. Indeed, as we specify -0.5pt for the optional
argument of \chemabove to lower the charge, it is necessary to prevent ChemFig to understand the sign - as a
single bond.
To add a load near the vertex of a cycle , the best method is to attach an invisible bond to this vertex, which is
done here with \definesubmol with a bond with a length coecient equal to 0.2:
Charges and cycles
\definesubmol\nobond{-[,0.2,,,draw=none]}
\chemfig{*5(---(!\nobond\scriptstyle\oplus)-(!\nobond\scriptstyle{-})-)}
12.3
We have already seen that with the tikz library decorations.pathmorphing, we can draw a wavy bond:
Wavy bond
\chemfig{A-[,3,,,decorate,decoration=snake]B}
\chemfig{A-[,3,,,decorate,decoration={snake,amplitude=1.5mm,
segment length=2.5mm}]B}
A
A
B
B
For more exibility, you can also dene nodes using the character @ and reuse these nodes after the molecule
has been drawn to connect them with a curved line using \chemmove:
Curved bonds
\chemfig{@{a}A-[,,,,draw=none]@{b}B}
\chemmove{\draw[-](a)..controls +(45:7mm) and +(225:7mm)..(b);}
\bigskip
\chemfig{*6(@{a}---@{b}---)}
\chemmove{\draw[-](a)..controls +(60:3em) and +(240:3em)..(b);}
\quad
\chemfig{*6(@{a}---@{b}---)}
\chemmove{\draw[-](a)..controls +(60:3em) and +(30:1em)..
++(20:2em) ..controls +(210:3em) and +(-120:4em) ..(b);}
12.4
Two parameters determine the default size of a molecule: the font size and the parameter of \setatomsep which
is 3em the default. We can modify independently these two parameters to change the size of a molecule:
Change the size
\definesubmol\hho{H-[:30]O-[:-30]H}
\chemfig{!\hho}
\setatomsep{2.5em}\chemfig{!\hho}
\scriptsize\chemfig{!\hho}
O
H
H
O
H
\tiny\chemfig{!\hho}\setatomsep{5em}\chemfig{!\hho}
HH
You can use the optional second argument of \chemfig to globally enlarge or reduce a molecule, i.e. the text and
links will be reduced by the same ratio:
LATEXed by Christian T, the November 27, 2013.
42
ChemFig
12
HOW TO . . .
O
H
\chemfig[][scale=0.75]{!\hho}
\chemfig[][scale=0.5]{!\hho}
H
O
\chemfig[][scale=0.33]{!\hho}
12.5
The diculty lies in the display of delimiters (parentheses or brackets) on bond. For this, we will again use the
character @ to dene global nodes that will be used later as anchors for delimiters.
We will write a simple macro \setpolymerbracket, followed by two characters which dene the opening delimiter
and closing delimiter.
Then, the macro \makebraces has an argument of the form [<dim up>,<dim down>]. These two dimensions are
the height and depth of the delimiters from the baseline. The following arguments are the subscript located at the
right bottom of the closing delimiter and the names of the 2 nodes at which the opening and closing delimiters
will be drawn.
Polymers
\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]
{$\left.\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}
\setpolymerdelim()
Polythylne:
\chemfig{\vphantom{CH_2}-[@{op,.75}]CH_2-CH_2-[@{cl,0.25}]}
\makebraces[5pt,5pt]{\!\!n}{op}{cl}
\bigskip
Polyvinyl chloride:
\chemfig{\vphantom{CH_2}-[@{op,.75}]CH_2-CH(-[6]Cl)-[@{cl,0.25}]}
\makebraces[5pt,25pt]{\!\!\!n}{op}{cl}
\bigskip
Nylon 6:
\chemfig{\phantom{N}-[@{op,.75}]{N}(-[2]H)-C(=[2]O)-{(}CH_2{)_5}-[@{cl,0.25}]}
\makebraces[30pt,5pt]{}{op}{cl}
\bigskip
Polycaprolactame:\setatomsep{2em}
\chemfig{[:-30]-[@{left,.75}]N(-[6]H)-[:30](=[2]O)--[:30]--[:30]--[@{right,0.25}:30]}
\makebraces[5pt,25pt]{\!\!\!n}{left}{right}
\bigskip
\setpolymerdelim[]
Polyphnylne sulfide:
\chemfig{\vphantom{S}-[@{op,.75}]S-(**6(---(-[@{cl,0.25}])---))}
\makebraces[15pt,15pt]{}{op}{cl}
\bigskip
\chemfig{-CH_2-CH([6]-CO-NH-CH_2-NH-CO-CH([4]-CH_2-)([0]-[@{downleft,0.8},2]CH_2
-CH([2]-CO-NH_2)-[@{downright,0.3},2]CH_2-[,1.5]C?H-))-[@{upleft,0.8},2]CH_2
-CH([6]-CO-NH_2)-[@{upright,0.3},2]CH_2-[,1.5]CH([6]-CO-NH-CH_2-NH-C?O)-}
\makebraces[5pt,40pt]{n}{upleft}{upright}
\makebraces[38pt,7pt]{n}{downleft}{downright}
Polythylne:
CH2
CH2
43
ChemFig
12
Polyvinyl chloride:
0
Nylon 6:
0
B
@
BH
B
@
N
CH2
CH
Cl
O
(CH2 )5
HOW TO . . .
1
C
A
1
C
C
A
O
Polycaprolactame: 0
BN
@
H
Polyphnylne sulde:
CH2
CH
CO
NH
CH2
NH
CO
CH 2
12.6
CH
2
6
6
6
6
4
CH2
6
4S
CH
7
7
CO 7
7
5
NH2
CH2
NH2 7
7
CO 7
7
5
CH
C
A
7
5
CH2
CH
CO
NH
CH2
2
6
6
6
6
4
NH
CO
n
CH2
CH
The two commands \hflipnext and \vflipnext allow to draw the symmetrical of the next molecule about a
horizontal or vertical axis. If we want to draw more symmetrical molecules, we need to write these commands
before each molecule involved.
Symmetry
O
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}% original
\vflipnext
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}\medskip
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}% original
\hflipnext
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}
H3 C
C
OH
OH
H3 C
C
O
O
H3 C
CH 3
OHHO
12.7
Once we have understood that the character @ can put a global tikz node, that is to say a node accessible
after the molecule has been drawn, everything that tikz can do with nodes (that is to say a lot of things) becomes
possible.
To write something above or below a bond, we can put two global nodes on the atoms at the ends of this bond
and write midway of them a text, raised or lowered so that it falls to just above or below the bond. This is done by
the macro \bondname in the code below 13 .
To draw an arc between two bonds, three atoms are involved on which we have to put three global nodes. The
macro \arcbetweennodes calculates the angle between two lines drawn from a node. Then \arclabel draws an
arc between two bonds and writes a text next to the arc: the optional argument of this macro is the tikz code used
to custom the arc. The second argument is the radius of the arc and the following three arguments are the names
13 The \si
44
ChemFig
12
HOW TO . . .
of global nodes between which the arc must be drawn, the middle name needs to be the vertex of the angle. The
last argument is the text to write.
Arcs and text on bonds
\newcommand\namebond[4][5pt]{\chemmove{\path(#2)--(#3)node[midway,sloped,yshift=#1]{#4};}}
\newcommand\arcbetweennodes[3]{%
\pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}%
\let#3\pgfmathresult}
\newcommand\arclabel[6][stealth-stealth,shorten <=1pt,shorten >=1pt]{%
\chemmove{%
\arcbetweennodes{#4}{#3}\anglestart \arcbetweennodes{#4}{#5}\angleend
\draw[#1]([shift=(\anglestart:#2)]#4)arc(\anglestart:\angleend:#2);
\pgfmathparse{(\anglestart+\angleend)/2}\let\anglestart\pgfmathresult
\node[shift=(\anglestart:#2+1pt)#4,anchor=\anglestart+180,rotate=\anglestart+90,inner sep=0pt,
outer sep=0pt]at(#4){#6};}}
\chemfig{@{a}A=[:30,1.5]@{b}B-[7,2]@{c}C-@{d}D}
\namebond{a}{b}{\scriptsize My text}
\namebond[-3.5pt]{b}{c}{\small\color{red}$\pi$}
\namebond{c}{d}{\small1\si\angstrom}
\medskip
Horizontal water molecule: \chemfig{@{1}H-[::37.775,2]@{2}O-[::-75.55,2]@{3}H}.
\namebond{1}{2}{\footnotesize0.9584\si\angstrom}
\namebond{2}{3}{\footnotesize0.9584\si\angstrom}
\arclabel{0.5cm}{1}{2}{3}{\footnotesize104.45\si\degree}
\qquad
Water molecule rorated 30\si\degree: \chemfig{[:30]@1H-[::37.775,2]@2O-[::-75.55,2]@3H}
\namebond12{\footnotesize0.9584\si\angstrom}
\namebond23{\footnotesize0.9584\si\angstrom}
\arclabel{0.5cm}{1}{2}{3}{\footnotesize104.45\si\degree}
My
t
tex B
12.8
1 D
84
0.95
O 0
.95
84
84
5
9
.
104.45
0
H.
O 0.9584
H
.45
104
Pour quelques cas trs particuliers, il est parfois ncessaire de positionner des schmas de Lewis au degrs prs et
non plus des multiples de 45 degrs.
Pour cela, il est relativement facile dcrire une macro \mylewis, admettant un argument optionnel (la longueur
du doublet) qui vaut ici 2ex et deux arguments obligatoires; le premier tant le nom de latome et le second tant
la liste des angles spars par des virgules.
Lastuce consiste crer un nud invisible circulaire qui contient latome et tracer les doublets aux angles dsirs
de faon ce quils soient tangents ce cercle :
Doublets au degrs prs
\makeatletter
\newcommand\mylewis[3][2ex]{% #1=longueur, #2=atome #3=liste des angles
\tikzpicture[baseline,anchor=base]%
\node[inner sep=0pt,outer sep=1pt,circle,overlay](atom@@)at(0,0){\phantom{#2}};%
\node[inner sep=0pt,outer sep=0pt]at(0,0){#2};%
\def\list@angle{#3,}%
\loop
\expandafter\grab@angle\list@angle\@nil
\pgfextractx\CF@dim{\pgfpointanchor{atom@@}\current@angle}\edef\CF@dimax{\the\CF@dim}%
\pgfextracty\CF@dim{\pgfpointanchor{atom@@}\current@angle}\edef\CF@dimay{\the\CF@dim}%
\pgfmathparse{#1*sin(\current@angle)/2}\let\offset@xx\pgfmathresult
\pgfmathparse{#1*cos(\current@angle)/2}\let\offset@yy\pgfmathresult
45
ChemFig
12
HOW TO . . .
\draw[line width=.4pt,overlay]
(\CF@dimax-\offset@xx,\CF@dimay+\offset@yy)--(\CF@dimax+\offset@xx,\CF@dimay-\offset@yy);%
\unless\ifx\@empty\list@angle
\repeat
\endtikzpicture
}
\def\grab@angle#1,#2\@nil{\def\current@angle{#1}\def\list@angle{#2}}
\makeatother
Essai : \mylewis{Cl}{15}\qquad \mylewis[3ex]{Cl}{-60}\qquad \mylewis[1.5ex]{Cl}{60,120,240,300}
\bigskip
\chemfig{P(-[:72]\mylewis{Cl}{-18,72,162})(-[:-72]Cl)
(-[:144]Cl)(-[:-144]Cl)-\mylewis{Cl}{0,90,-90}}
Essai : Cl
Cl
Cl
Cl
Cl
Cl
P
Cl
Cl
46
ChemFig
OVERVIEW
PART IV
Reaction schemes
Following several requests from users, it had become evident that ChemFig had a weakness regarding the
drawing of reaction schemes. The gap is now lled. Therefore, ChemFig has now reached version 1.0 since I
consider that the main features sought are now available.
I thank Clemens N for his help and the tests he carried out on the new features presented in this part.
Overview
A reaction scheme must be contained between the commands \schemestart and \schemestop. As shown
in this example, debug information is either hidden or displayed with the command \schemedebug and the
argument false or true:
Example 1
\schemedebug{false}
\schemestart
\chemfig{*6(-=-=-=)}\arrow
\chemfig{X=[1]Y}\arrow
\chemfig{S>T}
\schemestop
\bigskip
Y
S
X
c1
\schemedebug{true}
\schemestart
\chemfig{*6(-=-=-=)}\arrow
\chemfig{X=[1]Y}\arrow
\chemfig{S>T}
\schemestop
c2
Y
S
c3
Some comments:
the \arrow commands draw the arrows;
everything lying between two \arrow commands is considered a compound. It was decided that all possible
settings, whether for arrows or compounds, are controlled by the arguments of the \arrow command,
whose syntax may become quite complex;
arrows are plotted horizontally, this can obviously be modied;
arrows are plotted on the imaginary line connecting the center of the compounds bounding boxes (the
red and blue squares are the anchoring points of arrows). This behavior can also be modied;
debug information is displayed with the \schemedebug command. It consists of:
the green label above the bounding boxes is the default name assigned to compounds by ChemFig.
It follows the series "c1", "c2", etc. Numbering is reset to 1 for every reaction scheme.
display of the compounds bounding boxes;
the arrows start and end points represented by red points and anchors by blue points;
the distance from edge to edge between two compounds is dened with the \setcompoundsep{<dim>}
command, where the argument is a valid dimension in the sense of TEX. By default, and if the argument is
empty, this dimension is 5em;
nally, the distance between the edges of the compounds and the beginning and end of the arrows is
dened with the \setarrowoffset{<dim>} command where the argument is valid under a dimension of
TEX. By default, and if the argument is empty, this dimension is 4pt.
47
ChemFig
ARROWS FEATURES
Arrow types
When the \arrow command is followed by an optional argument in braces (which is not mandatory), the argument
denes the type of arrow:
Arrow types
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
A\arrow{->}B\schemestop\par % by default
A\arrow{-/>}B \schemestop\par
A\arrow{<-}B \schemestop\par
A\arrow{<->}B \schemestop\par
A\arrow{<=>}B \schemestop\par
A\arrow{<->>}B \schemestop\par
A\arrow{<<->}B \schemestop\par
A\arrow{0}B \schemestop\par
A\arrow{-U>}B \schemestop
A
A
A
A
A
A
A
A
A
B
B
B
B
B
B
B
B
B
The arrow -U> is not fully drawn, an arc can be added tangent to the arrow center using optional arguments on
y
the command, see page 55. Here is a -U> arrow with the arc on top of it: A
For the sake of clarity, capital letters will be used throughout the documentation instead of chemical formulas
made with the \chemfigcommand except for specic examples. Reaction schemes obviously work identically
with letters and drawn molecules. Several examples are shown in the Gallery with proper reaction schemes.
Arrows features
\setarrowdefault{15,1.5,red,thick}
\schemestart A\arrow B\arrow C\schemestop
\setarrowdefault{,2.5,dashed}
\schemestart A\arrow B\arrow C\schemestop
A
A
A
\setarrowdefault{}
\schemestart A\arrow B\arrow C\schemestop
In order to locally modify one or all of these default values, the \schemestart command accepts an optional
argument in the form [angle,coeff,style] which changes the default arrow features within the sole reaction
scheme:
Optional argument
\setarrowdefault{5,2.5,blue}
\schemestart A\arrow B\arrow C\schemestop
\schemestart[0] A\arrow B\arrow C\schemestop
\schemestart[0,1] A\arrow B\arrow C\schemestop
\schemestart[0,1,thick] A\arrow B\arrow C\schemestop
A
A
A
A
A
B
B
B
B
C
C
C
C
C
48
ChemFig
ANCHORING
Regarding style, the rule is: the style specied in the argument in brackets applies after the default style, without
overwrting it! This is why only the black color attribute is able to overwrite the blue default style.
Finally, the \arrow command accepts an optional argument in brackets in the form [angle,coeff,style] to
change the feature of that given arrow. As above, style applies after the default style and after the style possiblyspecied in the optional argument of the \schemestart command, again without overwrting them.
Arrows features
B
\schemestart
A\arrow[45]B\arrow[-20,2]C
\schemestop
\bigskip
A
C
\schemestart
A\arrow[90,,thick]B\arrow[,2]C
\arrow[-45,,dashed,red]D
\schemestop
D
A
Compounds names
Automatic naming of compounds (c1, c2, etc.) can be overridden. For this, the \arrow command must be
immediately followed by an argument in parentheses. The argument is of the form: (n1--n2). The compounds
located at the beginning and at the end of the arrow are named n1 and n2, respectively. Any alphanumeric
string can be used. The numbering of the names "c<n>" continues internally, so if a compound has a dierent
name than the default one, it does not aect the default name of the subsequent compounds.
Names are optional, and the argument can be either (n1--) and (--n2).
Compounds names
\schemedebug{true}
\schemestart
A\arrow(aa--bb)B\arrow(--cc)C\arrow(--dd)D\arrow E
\schemestop
\bigskip
\schemestart
A\arrow(aa--)B\arrow(bb--)C\arrow(cc--dd)D\arrow E
\schemestop
aa
bb
cc
dd
c5
aa
bb
cc
dd
c5
E
E
Note that both methods are equivalent. Therefore, compounds can either be named by arrows preceding or
following them. However, when a compound is surrounded by two arrows specifying its name, the rst name is
ignored and a warning message is generated:
Overful naming
\schemedebug{true}
\schemestart
A\arrow(--foo)B\arrow(bar--)C
\schemestop
c1
bar
c3
Here compound B is called foo by the arrow pointing at it, and bar by the arrowing leaving from it. Thus
ChemFig generates a warning mentioning that the name "foo" will be ignored:
Package chemfig Warning: two names for the same node, first name "foo" ignored
Anchoring
As noted above, arrows lie on the line connecting the center of the compounds bounding boxes. Default anchors
are called center in the sense of tikz. Non-default anchoring points can be user-specied as well with an
argument between brackets:
(n1.a1--n2.a2)
49
ChemFig
ANCHORING
where the anchor a1 or a2 can be: north west, north, north east, west, center, east, mid west, mid, mid east,
base west, base, base east, south west, south , south east, text, or any angle. Here is an example from the tikz
manual where the anchors are located on the bounding box:
TikZ anchoring
\Huge
\begin{tikzpicture}[baseline]
\node[anchor=base west,name=x,draw,inner sep=25pt] {\color{lightgray}Rectangle\vrule width 1pt height 2cm};
\foreach \anchor/\placement in
{north west/above left, north/above, north east/above right,west/left, center/above, east/right,
mid west/left, mid/above, mid east/right,base west/left, base/below, base east/right,
south west/below left, south/below, south east/below right,text/below,10/right,45/above,150/left}
\draw[shift=(x.\anchor)] plot[mark=x] coordinates{(0,0)}
node[\placement,inner sep=0pt,outer sep=2pt] {\scriptsize\texttt{(\anchor)}};
\end{tikzpicture}
(north west)
(north)
(45)
(north east)
(150)
(10)
(west)
(mid west)
(base west)
(south west)
(center)
(east)
Rectangle
(mid)
(text)
(mid east)
(base east)
(base)
(south)
(south east)
Like for names, arrival and departure anchoring points are independent and optional.
In this example, the default alignment is not good because the two A are not aligned vertically. Debug information
show that the default center anchors are not suitable:
Alignment problems
\schemedebug{true}
\schemestart
\chemfig{A*5(-----)}
\arrow
\chemfig{A*5(---(-)--)}
\schemestop
c2
c1
A
A
For the alignment to be correct, arrows will leave/arrive either from the anchor base east/base west, or from
anchor mid east/mid west:
Alignment problems
\schemedebug{true}
\schemestart
\chemfig{A*5(-----)}
\arrow(.base east--.base west)
\chemfig{A*5(---(-)--)}
\schemestop
\bigskip
\schemestart
\chemfig{A*5(-----)}
\arrow(foo.mid east--bar.mid west)
\chemfig{A*5(---(-)--)}
\schemestop
c2
c1
A
bar
foo
One last anchor need be specied: the anchor of the rst compound with respect to the baseline of the text just
before it. This is illustrated by the green point on the left-hand side of the scheme below:
Initial anchoring
\schemedebug{true}
Preceding text:
\schemestart
\chemfig{A*5(-----)}\arrow A
\schemestop
c1
c2
Preceding text: A
50
ChemFig
COMPOUNDS STYLE
The default position of this anchor on the rst compounds bounding box is that given by text. This position can
be controlled with the second optional argument of the \schemestart command:
Adjusting the initial anchoring
c1
\schemedebug{true}
Preceding text:
\schemestart[][south]
\chemfig{A*5(-----)}\arrow A
\schemestop
\bigskip
c2
Preceding text:
Preceding text:
Preceding text:
\schemestart[][north west]
\chemfig{A*5(-----)}\arrow A
\schemestop
\bigskip
c1
c2
A
c1
Preceding text:
\schemestart[][west]
\chemfig{A*5(-----)}\arrow A
\schemestop
c2
Preceding text:
Compounds style
The \arrow command can also include tikz instructions to dene the bounding box style s of the reactant and the
product of the reaction. This is done with the argument between parentheses. Always style through the argument
in brackets of the \arrow, we can specify with tikz instructions the style s to bounding box of the compound of
departure or of arrival. Therefore the complete syntax of the \arrow command, with each specication being
optional, is as follows:
\arrow(n1.a1[s1]--n2.a2[s2]){arrow type}[angle,coeff,arrow style]
Like forn names, if specic styles are given to one compound by arrows arriving on it and leaving from it, the
rst style will be ignored with a warning.
Compounds style
\schemestart
A
\arrow([red]--[fill=blue,semitransparent,text opacity=1,
inner sep=10pt,rounded corners=2mm])
B
\schemestop
\bigskip
B
B
\schemestart
A\arrow(--foo[yshift=5mm])B
\schemestop
The macro \setcompoundstyle{<code tikz>} allows to globally dene the style of compounds displayed thereafter. Entering an empty argument results in the absence of style, which corresponds to the default case.
Here a style is dened with round corner-shaped boxes and semitransparent background:
Global styles
\setcompoundstyle{draw,line width=0.8pt,semitransparent,
text opacity=1,inner sep=8pt,rounded corners=1mm}
\schemestart
A\arrow([fill=red]--[fill=blue])[90]
B\arrow(--[fill=gray])
C\arrow(--[fill=green])[-90]
D\arrow(--[draw=none])[-180]
\schemestop
51
ChemFig
SUBSCHEME
Branching
So far, only linear reaction schemes have been treated. Branched schemes are also possible and this is where
compound names play a key role. When a name is preceded by @ in the argument between brackets of the
\arrow command, it means that the compound already exists. Several scenarios are possible:
(@n1--n2): the arrow will leave from the existing compound n1 and the scheme will continue following
the arrow, thus creating a branch;
(@n1--@n2): the arrow is drawn between two existing compounds, no matter whether they are already
dened or whether they will later in the reaction scheme: therefore this syntax can be placed anywhere in
the code of the reaction scheme;
(n1--@n2): this syntax is not permitted;
In the following example, 3 branches are made, a rst one from B, a second one from D and a last one from
X. Finally one more arrow connects two existing compounds: XX and D:
Branching
A
\schemestart
A\arrow(aa--bb)B\arrow(--cc)C\arrow D
\arrow(@bb--xx1)[-90]X\arrow[-90]Y% 1st branch
\arrow(@c4--)[-90]Z\arrow W% 2nd branch
\arrow(@xx1--xx2)[-45]XX% 3rd branch
\arrow(@xx2--@c4)% XX-to-D arrow
\schemestop
XX
Y
One may wish to have Y and XX on the same horizontal line. To achieve this, a horizontal invisible bond is
drawn between Y and XX; the scheme is completed with a nal arrow between the two existing compounds
XX and D:
Branching
A
\schemestart
A\arrow(aa--bb)B\arrow(--cc)C\arrow D
\arrow(@bb--xx1)[-90]X\arrow[-90]Y\arrow(--xx2){0}XX
\arrow(@c4--)[-90]Z\arrow W
\arrow(@xx1--@xx2)% X-to-XX arrow
\arrow(@xx2--@c4)% XX-to-D arrow
\schemestop
XX
Subscheme
A fraction of the reaction scheme can be dened within a single bounding box, so that ChemFig treats it as
a compound. The reaction scheme fraction is dened inside the compulsory argument between braces of the
\subscheme command so it is subsequently reagarded as a single entity. When \subscheme is located after an
arrow, the command labels this subscheme as a compound named c<n+1>:
Subscheme
c2
c3
\schemedebug{true}
\schemestart
A\arrow
\subscheme{B\arrow[-90,2]C}
\arrow
D
\schemestop
c1
c5
c4
52
ChemFig
SUBSCHEME
Although this is not clearly seen because of labels overlap, the box around the subscheme is called c2, and name
numbering continues inside the subscheme with B called c3 and C called c4. Since the rst compound in the
subscheme is B, the subschemes baseline is that of B. This can be pointed out by specifying the anchors:
Subscheme
c1
c2
c3
\schemedebug{true}
\schemestart
A\arrow(--.mid west)
\subscheme{B\arrow[-90,2]C}
\arrow
D
\schemestop
c5
c4
where <car1> and <car2> can be ( et ) or [ and ], or any other expandable delimiter consistent with the
et \right commands.
\left
\chemleft\lfloor\chemfig{A-[1]B}\chemright)
\chemleft\{\chemfig{A-[1,1.25]B-[6,1.25]C}\chemright|
\chemleft[\chemfig{H-[1]O-[7]H}\chemright]
8A
>
>
<
>
>
:A
"
C
O
The code of the reaction scheme discussed above including \chemleft and \chemright is written:
Reaction scheme with \chemleft and \chemright
\schemestart
A\arrow
\chemleft[\subscheme{B\arrow[-90,2]C}\chemright]
\arrow
D
\schemestop
2 3
B
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
6 7
4 5
By analogy, the macros \chemup and \chemdown can be used to draw expandable delimiters above and below the
material, respectively:
\chemup<car1><material>\chemdown<car2>
For example:
53
ChemFig
SUBSCHEME
6
6
6
4
8
>
>
>
<
>
>
>
:
B
A
7
7
7
5
9
>
>
>
=
>
>
>
;
\schemestart[-90]
X\arrow
\chemup\{\chemfig{A-[1]B-[7]C}\chemdown\}
\arrow Y
\schemestop
\qquad
\schemestart[-90]
X\arrow
\chemup[\chemfig{A-[1]B-[7]C}\chemdown]
\arrow Y
\schemestop
Delimiters can can also be drawn through compounds style and apply them to a random compound (and hereby to
a subscheme). These expandable delimiters (parentheses, brackets, braces) can be used upon loading the matrix
tikz library in the document preamble:
\usetikzlibrary{matrix}
Since the \chemleft, \chemright, \chemup and \chemdown commands are available, the ChemFig package will
not automatically load the library. As long as the user want to access this special set of delimiters, the library
must be explicitly loaded.
The same brackets-delimited subscheme as above is presented again:
The matrix library delimiters
2B3
\schemestart
A\arrow(--[left delimiter={[}, right delimiter={]}])
\subscheme{B\arrow[-90,2]C}
\arrow
D
\schemestop
6
6
6
6
6
6
6
6
6
6
6
6
4
7
7
7
7
7
7
7
7
7
7
7
7
5
Since the delimiters are drawn outside the bounding box, it is advisable to slightly shorten the incoming and
outgoing arrows:
Subscheme
\schemestart
A\arrow(--[left delimiter={[},
right delimiter={]}])[,,shorten >=6pt]
\subscheme{B\arrow[-90,2]C}
\arrow[,,shorten <=6pt]
D
\schemestop
2B3
6
6
6
6
6
6
6
6
6
6
6
6
4
7
7
7
7
7
7
7
7
7
7
7
7
5
Subschemes should be used with care, undesired results are sometimes observed. In this example, a subscheme is
used to horizontally align 3 dierent compounds:
Subscheme
\schemedebug{true}
\schemestart
A
\arrow{0}[-90]
\subscheme{%
tagada\arrow{}
tsoin\arrow{}
fin}
\arrow(xx--yy){}E
\arrow(@c1--@c3){}
\arrow(@c1--@c5){}
\arrow(@c1--@c4){}
\schemestop
c1
c3
tagada
xxc4
tsoin
c5
yy
54
ChemFig
The center of the subscheme is exactly located on the same vertical lign as the center of compound "A". This is
because the two entities are connected by an invisible arrow with a 90 angle. However, the arrow between the
two pre-existing compounds A and tsoin is not vertical because tsoin is not on the center of the subscheme
since "tagada" is wider than "end". If this arrow is to be vertical within the use of the \subscheme command, one
must nd a correct angle for the arrival anchor of the invisible arrow by try-and-error.
A much simpler method is to use a branch instead of a subscheme: draw a visible arrow between A and tsoin,
and then draw horizontal arrows on both sides of tsoin, with a branch for the right-hand side arrows.
Subscheme
\schemedebug{true}
\schemestart
A
\arrow(--tsoin){->}[-90]
tsoin
\arrow{<-}[180]
tagada
\arrow(@tsoin--fin){}
fin
\arrow{}
E
\arrow(@c1--@c3){}
\arrow(@c1--@fin){}
\schemestop
c1
c3
tsoin
tagada
tsoin
c5
Within the argument in braces of the \arrowcommand, the arrow name can be followed by optional arguments
written between brackets. Here are the possible values for these optional arguments and their meaning, as dened
by ChemFig:
the arrows ->, <-, <->, <=>, <<->,<->>, -/> have three optional arguments:
the rst one contains the label to be placed above the arrow;
the second one contains the label to be placed below the arrow. The orientation of these two
labels is given by the same angle as the arrow. The perpendicular shift between the arrow and
the label anchor can be adjusted with the \setarrowlabelsep{<dim>} command, its argument is a
valid dimension in the sense of TEX. By default or if the argument is empty, this distance is 3pt.
Labels contained in the two optional arguments are not typed in math mode.
the third one is a dimension corresponding to a shift perpendicular to the arrow that can be applied
to it: the dimension is positive for an upward shift of the arrow (and of its labels, if any), and
negative for a downward shift.
the -U> arrow has 5 optional arguments:
the rst three are identical to those found in the other arrow types;
the fourth one is a coecient (which is 0.333 by default) which multiplies the length of the arrow
to get the radius of the arc;
the fth one is the half-angle from the center of the arc path, it is 60 degrees by default.
the invisible arrow 0 accepts two optional arguments of the same type as the rst two listed above;
Arrows optional arguments
\schemedebug{false}
\schemestart A\arrow{->[up][down]}B \schemestop
\qquad
\schemestart A\arrow{->[up][down][4pt]}B \schemestop
\qquad
\schemestart A\arrow{->[up][down][-4pt]}B \schemestop
\medskip
\schemestart A\arrow{<=>[up][down]}[30,1.5]B \schemestop
\medskip
\schemestart[-20]
A\arrow{->}B\arrow{->[][][3pt]}C\arrow{->[][][-3pt]}D
\schemestop
up
up
down
down
up
down
up
A
wn
do
A
B
C
D
55
ChemFig
down
\schemestart
A\arrow{->[up][down]}[-90]B
\schemestop
For the sake of clarity, one may prefer to have the above and below labels written horizontally. Label angles
can be specied, while default is the same angle as that of the arrow. To choose a specic angle, *{<angle>} can
be written at the beginning of the optional arguments:
Choice of angles
c2
\schemedebug{true}
\schemestart A\arrow{->[*{0}up][*{0}down]}[90]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}up][*{0}down]}[45]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}up][*{0}down]}[-45]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}up][*{0}down]}[-90]B\schemestop
c2
up down
c1
c1
up
down
c1
c1
up
down
c2
down up
c2
The default position of the label anchor can lead to undesired results:
Anchors
c2
\schemedebug{true}
\schemestart
A\arrow{->[*{0}on top of][*{0}underneath]}[45,2]B
\schemestop
on top of
underneath
c1
To counter this, the anchoring position can be specied as well to override the one selected by ChemFig by
default. The syntax for this is: *{<angle>.<ancre>}.
Anchors
\schemedebug{true}
\schemestart
A\arrow{->[*{0.0}on top of][*{0.180}underneath]}[45,2]B
\schemestop
on
\qquad
\schemestart
A\arrow{->[*{0.south east}on top of]%
c1
[*{0.north west}underneath]}[45,2]B
A
\schemestop
c2
c2
top of
underneath
on top of
underneath
c1
The -U> arrow remains a particular case. If one of the two labels from the rst two optional arguments is present,
the corresponding arc is plotted:
The -U> arrow
\schemestart A\arrow{-U>[123][456]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123]}[30]B\schemestop
\qquad
\schemestart A\arrow{-U>[][456]}[-30]B\schemestop
123
123
456
456
B
The fourth and fth optional arguments modify the appearance of the arc: respectively the arrow length coecient
which sets the arc radius, and the angle that denes the half arc:
The -U> arrow
\schemestart A\arrow{-U>[123][456][][0.25]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123][456][][][90]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123][456][][1][45]}B\schemestop
123 456
123
B
456
123
B
456
B
56
ChemFig
10
ARROWS CUSTOMIZATION
With negative values for the radius and the angle, the arc is drawn below the arrow:
The -U> arrow
\schemestart
A\arrow{-U>[123][456][][-0.333][-60]}B
\schemestop
A 123
456 B
Label angles and anchoring customization is controlled with the rst two arguments, just like for other arrows:
The -U> arrow
A
A
123
456
\schemestart
A\arrow{-U>[123][456]}[-90]B
\schemestop
\qquad
\schemestart
A\arrow{-U>[*{0.180}123][*{0.180}456]}[-90]B
\schemestop
123
456
10 Arrows customization
This section is quite technical and requires some knowledge of tikz. It is targeted at advanced users only who
need to dene their own arrows.
The \definearrow command allows to build custom arrows. Its syntax is:
\definearrow{<number>}{<arrow name>}{<code>}
where <number> is the number of optional arguments that will be used in the <code>, with the usual syntax #1, #2,
etc. These optional arguments cannot accept default values; if no value is specied upon using the macro \arrow,
the arguments will remain empty.
Before going further, lets examine the available internal macros when drawing arrows. Since these macros
include the @ character in their name, they can only be accessed through the \makeatletter and \makeatother
commands.
\CF@arrow@start@name and \CF@arrow@end@name include the names of the compounds (considered as
nodes by tikz) between which the arrow is drawn;
\CF@arrow@start@node and \CF@arrow@end@node include the node names where arrow ends will be
located. After these names, user-dened anchors can be specied in the argument between brackets of the
\arrowcommand, unless the eld is left empty;
\CF@arrow@current@style and \CF@arrow@current@angle contain the style and the angle of the arrow
to be drawn;
\CF@arrow@shift@nodes{<dim>} shifts the nodes \CF@arrow@start@node and \CF@arrow@end@node
perpendicularly relative to the arrow by a dimension specied in the argument;
\CF@arrow@display@label{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8} is the most complex one. It gives the
labels position with the following arguments:
#1 and #5 are the labels to be written;
#2 and #6 are real numbers between 0 and 1. They specify the location of the labels on the arrow. 0
is the beginning of the arrow and 1 is its end, assuming a straight arrow;
#3 and #7 are the + or - characters. + displays the label above the arrow, while - does it
below it;
#4 and #8 are the names of the nodes corresponding to the beginning and the end of the arrow.
arrow ends are either CF@full14 for a full arrow or CF@half for an upper-half arrow.
10.1
First arrow
As an example, assume we want to make an arrow with a circle on its center. Lets call it -.>. This arrow will
accept four optional arguments. Like for previously-dened arrows, the rst and second arguments will be the
labels to be located above and below the arrow. The third one will dene the perpendicular shift relative to the
14 this
57
ChemFig
10
ARROWS CUSTOMIZATION
arrow direction. Finally, the 4th argument will dene the circle size. If this last argument is absent the default
circle size will be equal to 2pt.
Lets start with \definearrow{4}{-.>} to declare that the arrow will have 4 optional arguments and that it will
be called -.>. First, the position of the nodes between which the arrow is to be drawn must be modied in order
to take the third-argument shift into account. This is made with the macro \CF@arrow@shift@nodes, so the code
of the arrow will start with: \CF@arrow@shift@nodes{#3}%. Then, one must plot the arrow itself, while taking
the opportunity to set a node on the center of the segment, which will be called "mid@point". Finally, the circle is
dened with its center on that node. The whole tikz code is:
\edef\pt@radius{\ifx\@empty#4\@empty 2pt\else #4\fi}% circle radius
\expandafter\draw\expandafter[\CF@arrow@current@style,-CF@full]
(\CF@arrow@start@node)--(\CF@arrow@end@node)coordinate[midway](mid@point);
\filldraw(mid@point)circle(\pt@radius);%
The last step is to enter the labels, if any, with the folwing line:
\CF@arrow@display@label{#1}{0.5}{+}{\CF@arrow@start@node}{#2}{0.5}{-}{\CF@arrow@end@node}
D
A
10.2
above
below
above
w
elo
Curved arrow
How about a curved arrow? To make things as simple as possible, assume it will have one single optional argument
with the tikz code that will specify the point(s) of control. If this argument is empty, a -> type arrow will be
plotted.
If #1 is not empty, attention should not be drawn to \CF@arrow@start@node and \CF@arrow@end@node which
contain the node names of arrow ends positions, because the location of these nodes is already determined by
the anchors calculated for straight arrows! Instead we will use \CF@arrow@start@name and \CF@arrow@end@name
which contain the names of the compound (which are nodes for tikz), since the arrow must be plotted between
them. Heres the tikz code to draw the curved arrow between the two compounds:
\draw[shorten <=\CF@arrow@offset,shorten >=\CF@arrow@offset,\CF@arrow@current@style,-CF@full,
(\CF@arrow@start@name).. controls #1 ..(\CF@arrow@end@name);%
One must add a tikz code to shorten the arrowby an amount \CF@arrow@offset dened by \setarrowoffset.
Indeed, the nodes ar not the same as those for straight arrows (\CF@arrow@start@node and \CF@arrow@end@node).
So before \CF@arrow@current@style, the follwing code must be added:
shorten <=\CF@arrow@offset, shorten >=\CF@arrow@offset
58
ChemFig
11
Curved arrow
\makeatletter
\definearrow1{s>}{%
\ifx\@empty#1\@empty
\expandafter\draw\expandafter[\CF@arrow@current@style,-CF@full](\CF@arrow@start@node)--(\CF@arrow@end@node);%
\else
\def\curvedarrow@style{shorten <=\CF@arrow@offset,shorten >=\CF@arrow@offset,}%
\CF@expadd@tocs\curvedarrow@style\CF@arrow@current@style
\expandafter\draw\expandafter[\curvedarrow@style,-CF@full](\CF@arrow@start@name)..controls#1..(\CF@arrow@end@name);
\fi
}
\makeatother
\schemestart
A\arrow{s>}
B\arrow{s>[+(0.5cm,0.5cm)]}
C\arrow{s>[+(45:1cm)]}
D\arrow(.60--.120){s>[+(60:1cm) and +(-120:1cm)]}
E\arrow{s>[+(45:1) and +(-135:1)]}
F\arrow{s>[+(-30:1) and +(150:1)]}[,1.5]
G\arrow(.90--.90){s>[+(60:1)and+(120:1)]}[,2]
H
\schemestop
\schemestart
A\arrow(.90--.180){s>[+(90:0.8) and +(180:0.8)]}[45]B
\arrow(.0--.90){s>[+(0:0.8) and +(90:0.8)]}[-45]C
\arrow(.-90--.0){s>[+(-90:0.8) and +(0:0.8)]}[-135]D
\arrow(.180--.-90){s>[+(180:0.8) and +(-90:0.8)]}[135]
\schemestop
B
A
C
D
where the ni names before the double dash are those already-dened compounds from which outcoming arrows
will merge into a single one. One can also specify the ai anchor, when the default one is not convenient. Like for
the \arrowcommand, the command n.a[s] includes the name, the anchor and the style of the target compound.
59
ChemFig
11
The \mergecommand
NO
\schemestart
ABC\arrow[30]EFGHIJ\arrow[45]KLM\arrow[60]NO
\merge>(c1)(c2)(c3)--()series 1
\arrow series 2
\schemestop
\bigskip
KLM
series 1
EFGHIJ
series 2
ABC
\schemestart
Foooo\arrow(foo--bar){<=>}Bar\arrow(--baz){<=>}Bz
\merge^(foo)(bar)(baz)--()series
\schemestop
\bigskip
series
\schemedebug{true}
\schemestart
A\arrow{<->}[90]B
\merge<(c1.120)(c2)--(foobar.45[circle,blue])CCC
\schemestop
Foooo
Bar
Bz
c2
foobar
CCC
c1
Regarding the geometry of the \merge arrow, it consists of n segments leaving from n compounds up to the
perpendicular line that connects them: the default length of the shortest of these segments is worth half of the
compound-spacing distance dened by \setcompoundsep. The arrow drawn from the connecting line to the target
compound has the same default length, its origin is on the middle of the connecting line. These three geometric
features can be customized with the optional argument immediately after the target compound:
\merge{dir}(n1.a1)(n2.a2)(...)(ni.ai)--(n.a[s])[c1,c2,c,style]
where:
the shortest segment distance between reactants and the connecting line is controlled through the multiplication of the \setcompoundsep distance by a coecient c1, whose default value is 0.5;
the length of the arrow between the connecting line and the product compound is controlled through the
multiplication of the \setcompoundsep distance by a coecient c2, whose default value is 0.5;
the origin of the arrow between the connecting line and the product compound is determined by the
coecient c, a value of 0 involves a departure from the the left of the connect line (or from its top if the
direction is v or ^);
the style of the \merge arrow is dened with the last argument: style.
Geometrical parameters of \merge
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
\bigskip
A\arrow{<=>}[90]B\merge(c1)(c2)--()C\schemestop\qquad
A\arrow{<=>}[90]B\merge(c1)(c2)--()[1]C\schemestop\qquad
A\arrow{<=>}[90]B\merge(c1)(c2)--()[,1]C\schemestop\qquad
A\arrow{<=>}[90]B\merge(c1)(c2)--()[,,0.2]C\schemestop\qquad
A\arrow{<=>}[90]B\merge(c1)(c2)--()[,,0.9,red,thick]C\schemestop
\schemestart
\schemestart
\schemestart
\schemestart
\schemestart
A\arrow{<=>}B\merge^(c1)(c2)--()C\schemestop\qquad
A\arrow{<=>}B\merge^(c1)(c2)--()[1]C\schemestop\qquad
A\arrow{<=>}B\merge^(c1)(c2)--()[,1]C\schemestop\qquad
A\arrow{<=>}B\merge^(c1)(c2)--()[,,0.2]C\schemestop\qquad
A\arrow{<=>}B\merge^(c1)(c2)--()[,,0.9,red,thick]C\schemestop
B
C
B
C
C
A
60
ChemFig
12
THE + SIGN
Finally, it is possible to write labels above or below the merged arrow. For this, the direction character accepts
two optional arguments in brackets, a rst one for the label above the arrow and a second one for the label below
it. Therefore, the full syntax of the merge command is:
\merge{dir}[labelup][labeldow](n1.a1)(n2.a2)(...)(ni.ai)--(n.a[s])[c1,c2,c,style]
All the features introduced before for arrow labelling can be implemented here as well, i.e. rotation angle and
anchoring with the syntax *{angle.anchor} entered just before the content of the label.
Labels of the \mergecommand
\schemestart
ABC\arrow{<=>}[90]DEF\merge>[above][below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}[90]DEF\merge>[*{45.south west}above][*{45.north east}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}[90]DEF\merge>[*{90}above][*{90}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop
\bigskip
\schemestart
ABC\arrow{<=>}DEF\merge v[above][below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}DEF\merge v[*{45.north west}above][*{45.south east}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}DEF\merge v[*{0}above][*{0}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop
above
below
GHIJ
ab
lo
w
ABC
ABC
DEF
ov
e
DEF
GHIJ
be
ABC
ab
ABC
GHIJ
lo
w
ABC
ABC
GHIJ
DEF
below above
be
above
below
DEF
below above
DEF
ov
e
DEF
GHIJ
GHIJ
12 The + sign
The use of a \+ macro that displays a + sign is available between the commands \schemestart and \schemestop.
This macro accepts an optional argument in braces with 3 dimensions in the form {<dim1>,<dim2>,<dim3>},
where:
<dim1> and <dim2> are the dimensions to be inserted before and after the + sign;
<dim3> is the vertical oset of the sign.
If one argument is left empty or if the argument in braces is missing, the dimensions take their default values,
which can be specied with the \setandsign{<dim1>,<dim2>,<dim3>} command. An empty eld leads <dim1>
and <dim2> to be worth 0.5em, while <dim3> becomes 0pt empty. The default values {0.5em,0.5em,0pt} are used
when the user does not specify dierent ones.
LATEXed by Christian T, the November 27, 2013.
61
ChemFig
12
THE + SIGN
The \+ command
\schemestart
A\+B\+{2em,,5pt}C\+{0pt,0pt,-5pt}D\arrow E\+F
\schemestop
A + B
\setandsign{1em,1em,0pt}
\schemestart
A\+B\+{2em,,5pt}C\+{0pt,0pt,-5pt}D\arrow E\+F
\schemestop
A +
C D
+
+
C D
+
E + F
E +
As shown in the example below, it should be kept in mind that the + sign inserted by the \+ command is part of
the compound:
Compounds and \+
\schemedebug{true}
\schemestart A\+ B\+{,,5pt}C\arrow D\+ E\schemestop
c1
A + B
c2
D + E
This makes it dicult to draw a vertical arrow exactly below the letter A since this letter is not a single compound
for ChemFig. This issue can be solved with the use of the \subscheme command to uniquely dene the letter A
as a single compound (the same procedure can be applied to the + sign itself) so that it can be referred to later
on with its own name:
Subcompound and \+
c2 c1
A + B
\schemedebug{true}
\schemestart
\subscheme{A}\+ B\arrow C
\arrow(@c2--)[-90]E
\schemestop
\medskip
c3
c4
c2 c1
A + BCDEF
\schemestart
A\subscheme{\+}BCDEF \arrow G
\arrow(@c2--)[-90]H
\schemestop
c3
c4
A common problem can be the misalignment of the + sign with the molecules before or after it. For example:
+ sign alignment
\schemedebug{true}
\schemestart
\chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
\+
\chemfig{\lewis{246,Br}-\lewis{026,Br}}
\schemestop
c1
+ Br
Br
Here, the + sign sits on the same baseline as the compound before it, and this baseline is that of the top carbon
atom. One may shift the + sign, but this would not change the vertical position of Br
Br . In fact, the +
sign does not prevent ChemFig from reading a compound, as shown in the example above where everything
is included in the compound c1. Therefore, one must stop the compound right after the rst molecule with
a \arrow{0}[,0] that will draw an invisible, zero-length arrow. In order to vertically center the whole scheme,
one must also set the the anchor of the rst compound as west (or 180, which is a synonym) with the second
optional argument of the \schemestart command:
+ sign alignment
\schemedebug{true}
\schemestart[][west]
\chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
\arrow{0}[,0]\+
\chemfig{\lewis{246,Br}-\lewis{026,Br}}
\schemestop
c1
c2
+ Br
Br
Thus, the rst compound c1 consists of the rst molecule and the second compound consists of everything
else, i.e. the + sign and the second molecule. Alternatively, one can play with anchors or styles via the \arrow
command to move the second compound to another location. Here, for example, the second compound is shifted
downwards by 10pt in the rst case. In the second case, the south east anchor of the rst compound matches
the south west anchor of the second one:
LATEXed by Christian T, the November 27, 2013.
62
ChemFig
12
+ sign alignment
\schemedebug{true}
\schemestart[][west]
\chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
\arrow(--[yshift=-10pt]){0}[,0]\+
\chemfig{\lewis{246,Br}-\lewis{026,Br}}
\schemestop
\medskip
\schemestart[][west]
\chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
\arrow(.south east--.south west){0}[,0]\+
\chemfig{\lewis{246,Br}-\lewis{026,Br}}
\schemestop
THE + SIGN
c1
C
C
c2
+ Br
Br
c1
C
C
c2
+ Br
Br
63
ChemFig
PART V
List of commands
The commands created by ChemFig are:
Commands
\chemfig<code>
\printatom
\setnodestyle{<style tikz>}
\setbondestyle{<style tikz>}
\hflipnext
\vflipnext
\definesubmol{<nom>}[code1]{<code2>}
\chemskipalign
\redefinesubmol{<nom>}{<code>}
\setcrambond{<dim1>}{<dim2>}{<dim3>}
\setatomsep{<dim>}>
\setbondoffset{<dim>}
\setdoublesep{<dim>}
\lewis[coeff]{<codes>,<atome>}
\Lewis[coeff]{<codes>,<atome>}
\setlewis{<dim1>}{<dim2>}{<code tikz>}
\setlewisdist{dim}
\chemsign[<dim>]<sign>
\chemrel[<txt1>][<txt2>]{<arrow code>}
Description
draws the molecule whose design is described by the <code>
displays the atoms within the molecules. It can be redened to customize the
output. See page 23
using tikz syntax, this macro denes the style of nodes containing the atoms.
See page 32
with the tikz syntax, this macro denes the style of the bonds. See page 6
the next molecule will be horizontally ipped
the next molecule will be vertically ipped
creates an alias !<nom> which can be put in the code of molecules to be drawn,
and which will be replaced with <code1> or <code2> depending on the angle of
the last bond. See page 27
tells the vertical alignment mechanism to ignore the current group of atoms.
See page 25.
replaces a preexisting alias !<name> with the new <code>. See page 28
sets the dimensions of the triangles representing Cram bonds: <dim1> is the size
of the base, <dim2> is the spacing between the dashes and <dim3> is the side of
the dashes. See page 7
sets the interatomic distance. See page 6
sets the space between bonded atoms and the bond. See page 6
sets the spacing between the two lines of a double bond. See page 6
displays the <atom> and places Lewis dot decorations as specied in the <code>.
The dots drawn do not change the bounding box. See page 28
displays the <atom> and places Lewis dot decorations as specied in the <code>.
See page 28
sets the Lewis dot parameters; <dim1> is the distance between the atoms and
the decoration, <dim2> is the length of the line representing the pair of electrons
and <tikz code> is code which is passed directly to tikz. See page 29
sets the distace between the 2 disks representing a pair of electrons. See page 30
\setchemrel{<dim1>}{<dim2>}{<dim3>}
sets the dimensions of the arrow drawn with the command \chemrel: <dim1>
is the vertical space between the arrow and the optional text, <dim2> is the
unbreakable horizontal space inserted before and after the arrow and <dim3> is
the length of the arrow. See page 31
\chemabove[<dim>]{<txt1>}{txt2}
writes <txt1> and places <txt2> above, leaving <dim> of vertical space. This
command does not change the bounding box of <txt1>. See page 30
64
ChemFig
\chembelow[<dim>]{<txt1>}{txt2}
\Chemabove[<dim>]{<txt1>}{txt2}
\Chembelow[<dim>]{<txt1>}{txt2}
\chemname[<dim>]{<molecule>}{<name>}
\chemnameinit
\schemestart. . . \schemestop
\arrow
\+
\subscheme{<code>}
\definearrow
\chemleft<car1><stuff>\chemright<car1>
\chemup<car1><matriel>\chemdown<car1>
\setcompoundsep{<dim>}
\setarrowoffset{<dim>}
\setarrowdefault{angle,coeff,style}
\setcompoundstyle{<code tikz>}
\setarrowlabelsep{<dim>}
\setandsign{<dim1>,<dim2>,<dim3>}
writes {txt1} and places <txt2> below, leaving <dim> of vertical space. This
command does not change the bounding box of <txt1>. See page 30
writes <txt1> and places <txt2> above, leaving <dim> of vertical space. See
page 30
writes {txt1} and places <txt2> below, leaving <dim> of vertical space. See
page 30
Places <name> under the <molecule>
Initializes the greatest molecule depth to ensure correct alignment of the names
of the following molecules.
65
ChemFig
PART VI
Gallery
This manual concludes with drawings of molecules of varying complexity.
The curious user can look at the <code> of each molecule, though it does become less attractive the more complex
the molecule gets. Indeed, beyond a certain level of complexity, though it it is fairly easy to write <code>, it
becomes much harder to read the <code> to analyze it afterwards. We quickly reached the limits of immediate
readability of the code of a complex drawing.
Anyway, I hope that this package will help all LATEX users wishing to draw molecules. Although ChemFig
has been thoroughly tested and although its version number is now greater than 1.0, I hope that you will be
forgiving with bugs you encounter and send me an email to let me know of any malfunctions or suggestions for
improvement.
Christian T
?
?
2-methylpentane
\chemfig{[7]H_3C-CH(-[6]CH_3)-[1]CH_2-CH_2-[1]CH_3}
H3 C
CH2
CH
CH3
CH2
CH3
3-ethyl-2-methylhexane
\chemfig{H_3C-[7]CH(-[6]CH_3)-[1]CH(-[7]C_3H_7)-[2]CH_2-[3]H_3C}
H3 C
CH2
H3 C
CH
C3 H 7
CH
CH3
O
CH2
C17 H33
O
CH
C17 H33
O
CH2
C17 H33
66
ChemFig
Stearine, skeleton diagram
\definesubmol{x}{-[:+30,.6]-[:-30,.6]}
\definesubmol{y}{-O-(=[2,.6]O)-!x!x!x!x!x!x!x!x}
\chemfig{[2]([0]!y)-[,1.5]([0]!y)-[,1.5]([0]!y)}
O
O
O
O
O
O
Methyl 2-methylpropanoate
\chemfig{H_3C-CH_2(-[2]CH_3)-C(=[1]O)-[7]O-CH_3}
CH3
H3 C
CH2
C
O
CH3
Vanillin
\chemfig{HC*6(-C(-OH)=C(-O-[::-60]CH_3)-CH=C(-[,,,2]HC=[::-60]O)-HC=[,,2])} \quad or \quad
\chemfig{*6(-(-OH)=(-OCH_3)-=(-=[::-60]O)-=)}
HC
C
HC
CH
HC
or
C
C
OH
CH3
OCH3
OH
Caffeine
\chemfig{*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}
CH3
H3 C
N
CH3
Aspirin
\chemfig{*6(-=-(-O-[::-60](=[::-60]O)-[::+60])=(-(=[::+60])-[::-60]OH)-=)}
OH
67
ChemFig
Phthalic anhydride
\chemfig{*6(=*5(-(=O)-O-(=O)-)-=-=-)}
O
O
O
Camphor
\chemfig{*6(-(<:[::120](-[::-100,0.7])(-[::100,0.7]))--(=O)-(-)(<:[::120])--)}
\quad or \quad
\setcrambond{3pt}{}{}
\chemfig{<[:10](>[:85,1.8]?(-[:160,0.6])-[:20,0.6])
>[:-10]-[:60](=[:30,0.6]O)-[:170]?(-[:30,0.6])-[:190]-[:240]}
O
O
or
Triphenylmethane
\chemfig{*6(-=-*6(-(-*6(=-=-=-))-*6(=-=-=-))=-=)}
\quad or \quad
\definesubmol{@}{*6(=-=-=-)}
\chemfig{(-[:-30]!@)(-[:90]!@)(-[:210]!@)}
or
Amygdalin
\setcrambond{2pt}{}{}
\definesubmol{c1}{-[:200]-[:120]O-[:190]}
\definesubmol{c2}{-[:170](-[:200,0.7]HO)<[:300](-[:170,0.6]HO)
-[:10,,,,line width=2pt](-[:-40,0.6]OH)>[:-10]}
\definesubmol{csub}{-[:155,0.65]-[:90,0.65]}
\chemfig{O(!{c1}(!{csub}O(!{c1}(!{csub}OH)!{c2}))!{c2})-[:-30](-[:-90]CN)-[:30]*6(=-=-=-)}
OH
O
HO
HO
O
OH
HO
O
HO
O
OH
CN
68
ChemFig
Adenosine triphosphate
\setcrambond{3pt}{}{}
\definesubmol{a}{-P(=[::-90,0.75]O)(-[::90,0.75]HO)-}
\chemfig{[:-54]*5((--[::60]O([::-60]!aO([::-60]!aO([::60]!aHO))))<(-OH)
-[,,,,line width=2pt](-OH)>(-N*5(-=N-*6(-(-NH_2)=N-=N-)=_-))-O-)}
O
HO
HO
HO
O
O
NH2
HO
OH
OH
Viagra
\chemfig{N*6((-H_3C)---N(-S(=[::+120]O)(=[::+0]O)-[::-60]*6(-=-(-O-[::-60]-[::+60]CH_3)
=(-*6(=N-*5(-(--[::-60]-[::+60]CH_3)=N-N(-CH_3)-=)--(=O)-N(-H)-))-=))---)}
O
H
N
O
CH3
S
N
N
H3 C
O
CH3
CH3
Cholesterol ester
\chemfig{[:30]R-(=[::+60]O)-[::-60]O-*6(--*6(=--*6(-*5(---(-(-[::+60]Me)
-[::-60]-[::-60]-[::+60]-[::-60](-[::-60]Me)-[::+60]Me)-)-(-[::+0]Me)---)--)-(-[::+0]Me)---)}
Me
Me
Me
Me
Me
O
Porphyrin
\chemfig{?=[::+72]*5(-N=(-=[::-72]*5(-[,,,2]HN-[,,2](=-[::-36]*5(=N-(=-[::-72]*5(-NH-[,,1]?=-=))
-=-))-=-))-=-)}
69
ChemFig
HN
NH
N
N
Mn
N
N
Penicillin
\chemfig{[:-90]HN(-[::-45](-[::-45]R)=[::+45]O)>[::+45]*4(-(=O)-N*5(-(<:(=[::-60]O)
-[::+60]OH)-(<[::+0])(<:[::-108])-S>)--)}
70
ChemFig
HN
S
R
O
N
O
OH
O
LSD
\chemfig{[:150]?*6(=*6(--*6(-N(-CH_3)--(<(=[::+60]O)-[::-60]N(-[::+60]-[::-60])
-[::-60]-[::+60])-=)([::-120]<H)---)-*6(-=-=-(-[::-30,1.155]\chembelow{N}{H}?)=))}
N
O
CH3
H
N
H
Strychnine
\chemfig{*6(=-*6(-N*6(-(=O)--([::-120]<:H)*7(-O--=?[0]([::-25.714]-[,2]?[1]))
-*6(-?[0,{>}]--(<N?[1]?[2])-(<[::-90]-[::-60]?[2]))(<:[::+0]H)-([::+120]<H))--?)=?-=-)}
H
N
H
O
O
H
Codeine
\chemfig{[:-30]**6(-(-OH)-?-*6(-(-[3]-[2,2]-[0,.5])*6(-(<:[:-150,1.155]O?)
-(<:OH)-=-)-(<:[1]H)-(-[2]NCH_3)--)---)}
NCH3
H
OH
OH
71
ChemFig
A dye (red)
\chemfig{**6(--*6(-(-NO_2)=-(-\lewis{26,O}-[0]H)=(-\lewis{4,N}=[0]\lewis{2,N}-[0]Ar)-)----)}
Ar
O
NO2
Menthone
\chemfig{CH_3-?(-[2]H)(-[::-30,2]-[::+60](=[1]\lewis{20,O})
-[::-150,1.5](-[:20]CH(-[1]CH_3)(-[7]CH_3))(-[6]H)-[::-90,2]-[::+60]?)}
H
O
CH3
CH3
CH
CH3
H
Fischer indole synthesis
\schemestart
\chemfig{*6(=-*6(-\chembelow{N}{H}-NH_2)=-=-)}
\+
\chemfig{(=[:-150]O)(-[:-30]R_2)-[2]-[:150]R_1}
\arrow(.mid east--.mid west){->[\chemfig{H^+}]}
\chemfig{*6(-=*5(-\chembelow{N}{H}-(-R_2)=(-R_1)-)-=-=)}
\schemestop
R1
R1
N
H
R2
H+
NH2 +
N
H
R2
72
ChemFig
O
R
CH 3
R
NH2 +
OH
addition
CH3
NH
CH 3
CH3
CH3
R
CH3
OH
CH3
limination
+ H3 O
CH3
Reaction scheme
\setatomsep{2em}
\schemestart[-90]
\chemfig{**6(---(-NH _2)---)}\arrow{0}\chemfig{HNO_2}
\merge(c1)(c2)--()
\chemfig{**6(---(-N_2|{}^\oplus)---)}\arrow{0}\chemfig{**6(---(-NH _2)---)}
\merge(c3)(c4)--()
\chemfig{**6(---(-N=[::-30]N-[::-30]**6(---(-NH_2)---))---)}
\schemestop
NH2
N2
HNO2
NH2
NH2
73
ChemFig
Addition
\setatomsep{2.5em}
\schemestart
\chemfig{*6(=-(-)(=[2]O))}
\arrow{->[\+\chemfig{H^\oplus}]}
\chemleft[\subscheme[90]{%
\chemfig{*6((-[2,0.33,,,draw=none]\scriptstyle\oplus)-=(-)-OH)}
\arrow{<->}
\chemfig{*6(=-(-)(-[6,0.33,,,draw=none]\scriptstyle\oplus)-OH)}}\chemright]
\arrow(@c3--)\chemfig{*6((-[2]R)-=(-)-OH)}
\arrow(@c4--)\chemfig{*6(=-(-)(-[6]R)-OH)}
\schemestop
2
O
+ H
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
4
OH
OH
OH
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
5
OH
Br
Benzne 1
AlBr4
2
6
6
6
4
Bromobenzne 2
Br H
Br H
Br H
3
7
7
7
5
74
ChemFig
\chemmove[line width=0.2pt,-stealth,dash pattern = on 2pt off 1pt]{
\draw[shorten <=2pt](a1)..controls+(200:5mm)and+(200:5mm)..(a2);
\draw[shorten >=2pt](oh1.west)..controls+(180:15mm)and+(60:5mm)..(a0);
\draw[shorten <=6pt,shorten >=2pt](o1)..controls+(270:5mm)and+(270:5mm)..(o0);
\draw[shorten <=2pt](cl0)..controls+(150:5mm)and+(150:5mm)..(cl1.150);
\draw[shorten <=2pt](o3)..controls +(30:3mm) and +(30:5mm)..(o4.east);
\draw[shorten >=2pt](oh2.135).. controls +(150:10mm) and +(90:10mm).. (o2);
\draw[shorten >=2pt,shorten <=5pt]([xshift=-1.5mm]o6.315)..controls +(315:5mm) and +(315:5mm)..(o5);
\draw[shorten <=2pt](cl2)..controls +(135:5mm) and +(135:5mm)..(cl3.north west);}
OH
Cl
O
Cl +
Cl
Cl
O
O
O
+ HCl
Cl
OH
Cl
O
O
Cl +
+ HCl
O
O
Cannizzaro reaction
\chemfig{[:-30]*6(=-=(-@{atoc}C([6]=[@{db}]@{atoo1}O)-H)-=-)}
\chemrel[\chemfig{@{atoo2}\chemabove{O}{\scriptstyle\ominus}}H]{-stealth}
\chemmove[-stealth,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
\draw[shorten <=8pt](atoo2) ..controls +(up:10mm) and +(up:10mm)..(atoc);
\draw[shorten <=2pt](db) ..controls +(left:5mm) and +(west:5mm)..(atoo1);}
\chemfig{[:-30]*6(=-=(-C([6]-[@{sb1}]@{atoo1}\chembelow{O}{\scriptstyle\ominus})([2]-OH)-[@{sb2}]H)-=-)}
\hspace{1cm}
\chemfig{[:-30]*6((-@{atoc}C([6]=[@{db}]@{atoo2}O)-[2]H)-=-=-=)}
\chemmove[-stealth,shorten <=2pt,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
\draw([yshift=-4pt]atoo1.270) ..controls +(0:5mm) and +(right:10mm)..(sb1);
\draw(sb2) ..controls +(up:10mm) and +(north west:10mm)..(atoc);
\draw(db) ..controls +(right:5mm) and +(east:5mm)..(atoo2);}
\vspace{1cm}
\par
\chemrel{-stealth}
\chemfig{[:-30]*6(=-=(-C([1]-@{atoo2}O-[@{sb}0]@{atoh}H)([6]=O))-=-)} \hspace{1cm}
\chemfig{[:-30]*6((-C(-[5]H)(-[7]H)-[2]@{atoo1}\chemabove{O}{\scriptstyle\ominus})-=-=-=)}
\chemmove[-stealth,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
\draw[shorten <=7pt](atoo1.90) ..controls +(+90:8mm) and +(up:10mm)..(atoh);
\draw[shorten <=2pt](sb) ..controls +(up:5mm) and +(up:5mm)..(atoo2);}
OH
OH
C
C
O
C
H
Beckmann rearrangement
\setbondoffset{1pt}
\setatomsep{2.5em}
\setcompoundsep{5em}
\setarrowoffset{6pt}
\schemestart
\chemfig{(-[:-150]R)(-[:-30]R)=[2]N-[:30]OH}
\arrow{<=>[\chemfig{H^\oplus}]}
\chemfig{(-[@{a0}:-150]R)(-[:-30]R)=[2]@{a1}N-[@{b0}:30]@{b1}\chemabove{O}{\scriptstyle\oplus}H_2}
75
ChemFig
\chemmove[red,-stealth,red,shorten <=2pt]{
\draw(a0)..controls +(135:2mm) and +(215:4mm).. (a1);
\draw(b0)..controls +(120:2mm) and +(180:3mm).. ([yshift=7pt]b1.180);}
\arrow{<=>[\chemfig{{-}H_2O}]}[,1.1]
\chemleft[\subscheme[90]{%
\chemfig{R-\chemabove{N}{\scriptstyle\oplus}~C-R}
\arrow{<->}[,0.75]
\chemfig{R-\lewis{2:,N}=@{a1}\chemabove{C}{\scriptstyle\oplus}-R}}\chemright]
\arrow{<=>[\chemfig{H_2@{a0}\lewis{0:2:,O}}]}[,1.1]
\chemmove[red,-stealth,red,shorten <=3pt]{
\draw(a0)..controls+(90:10mm)and+(45:10mm)..([yshift=6pt]a1.45);}
\arrow(@c1--){0}[-90,0.333]
\chemfig{*6(R\rlap{$$}-N=(-R)-\chemabove{O}{\scriptstyle\oplus} H_2)}
\arrow{<=>[\chemfig{{-}H^\oplus}]}
\chemfig{*6(R\rlap{$$}-N=(-R)-OH)}
\arrow
\chemfig{*6(R\rlap{$$}-\chembelow{N}{H}-(-R)(=[2]O))}
\schemestop
OH
N
R0
OH2
N
H
R0
R
OH2
H2 O
R
2
6
6
6
4
R0
OH
3
7
7
7
5
H2 O
R0
R0
N
R0
R0
R
N
H
Reaction scheme
\setatomsep{1.5em}
\setcompoundsep{4em}
\schemestart
\chemfig{-[::30]=_[::-60](-[:: -60])-[::60]}
\arrow{->[\chemfig{HCl}]}
\chemfig{-[::30]-[::-60](-[::120]Cl)(-[::-60])-[::60]}\+\chemfig{-[::30](-[::60]Cl)-[::-60](-[::-60])-[::60]}
\arrow(@c1--.north west){->[\chemfig{H_2O}]}[-45,1.7]
\chemfig{-[::30]-[::-60](-[::120]OH)(-[::-60])-[::60]}\+\chemfig{-[::30](-[::60]OH)-[::-60](-[::-60])-[::60]}
\schemestop
HCl
Cl
Cl
+
2O
OH
OH
+
76
ChemFig
\arrow{-U>[\scriptsize\chemfig{HSO_4^\ominus}][\scriptsize\chemfig{H_2SO_4^{}}][][.25]}[,1.5]
\chemfig{H-C(=[:60]O)-[:-60]O-CH_3}
\arrow(@M1--[yshift=-5pt]){0}[180,.5]{\tiny protolysis}
\chemmove[->,red,shorten <=3pt,shorten >=1pt]{
\draw(a1)..controls +(0:1.5cm)and+(0:3cm).. (a2);
\draw(b1)..controls +(0:5mm)and+(20:5mm)..(a3);}
\schemestop
H2 SO4 HSO4
O
H
protolysis
6
6 H
4
H
O
3
7
7
5
CH3
addition
O
H
O
H
H
6
6 H
4
CH3
protolysis
H
CH3
O
H
H
H2 O
H
O
C
O
elimination
CH3
C
O
CH3
HSO4 H2 SO4
7
7
5
O
O
CH3
77
ChemFig
C
+ Br
Br
rapide
C
complexe
Br
Br
t,
len
t,
len
Br
C
C
C
Br
C
bromonium ion
Br
carbenium ion
carbenium ion
Sulfonation of naphthalene
\definesubmol\cycleoplus{-[,0.25,,,draw=none]\oplus}
\definesubmol{so2oh}{S(=[::90]O)(=[::-90]O)-OH}
\setatomsep{2.5em}
\schemestart[,1.5]
\chemname{\chemfig{*6(=-*6(-=-=-)=-=-)}}{Naphtalne}\+\chemfig{H_2SO_4}
\arrow(nph.mid east--.south west){->[80\degres C]}[45]
\chemname{\chemfig{*6(=-*6(-=-(!\cycleoplus)-(-SO_3H)-)=-=-)}}{Ion 1-arenium}
\arrow(.mid east--.mid west)
\chemname{\chemfig{*6(=-*6(-=-=(-!{so2oh})-)=-=-)}}{Acide 1-naphthalenesulfonique}
\arrow(@nph.mid east--.north west){->[160\degres C]}[-45]
\chemname{\chemfig{*6(=-*6(-=-(-SO_3H)-(!\cycleoplus)-)=-=-)}}{Ion 2-arenium}\kern-4em
\arrow(.mid east--.mid west)
\chemname{\chemfig{*6(=-*6(-=-(-!{so2oh})=-)=-=-)}}{Acide 2-naphthalenesulfonique}
\schemestop
78
ChemFig
OH
SO3 H
Ion 1-arenium
Acide 1-naphthalenesulfonique
80
+ H2 SO4
16
C
O
SO3 H
OH
S
Naphtalne
Ion 2-arenium
Acide 2-naphthalenesulfonique
Explanatory diagram
\parbox{0.8\linewidth}{
\hspace{10em}
\tikz[remember picture]\node(n0){\chemname{}{Attacks\\nucleophiles}};\par
\vspace{2ex}\hspace{15em}
\chemfig{R^2-(-[:-60]@{a0}H)-[:60]@{a1}(-[:120]R^1)(-[1,0.25,,,draw=none]\scriptstyle\color{red}\delta+)
=[@{a2}]@{a3}\lewis{1:7:,O}-[1,0.5,,,draw=none]\scriptstyle\color{red}\delta{-}}
\hspace{5em}
\chemname[-15ex]{}{\tikz[remember picture]\node(n1){};Addition reactions}\kern1em
\chemname{}{\tikz[remember picture]\node(n2){};Basic properties}\par
\vspace{6ex}\hspace{8em}
\chemname{}{Acidic properties of hydrogen\tikz[remember picture]\node(n3){};
\\atom in $\alpha$ position}
\chemmove[-stealth,line width=0.8pt,green!60!black!70]{
\draw[shorten >=2pt](n0)..controls+(270:4em)and+(180:2em)..(a1);
\draw[shorten >=8pt](n1)..controls+(180:2em)and+(60:2em)..(a2);
\draw[shorten >=5pt](n2)..controls+(180:2em)and+(270:2em)..([xshift=3pt]a3.315);
\draw[shorten >=2pt](n3)..controls+(0:2em)and+(270:2em)..(a0);
}}
79
ChemFig
Attacks
nucleophiles
R1
+
R2
H
Addition reactions
Basic properties
80
ChemFig
Taxotere
\chemfig{-[::-30](-[5])(-[7])-[::+60]-[::-60]O-[::+60](=[::-45]O)-[::+90]HN>:[::-60](-[::+60]**6(------))
-[::-30](<:[2]OH)-[::-60](=[6]O)-[::+60]O>:[::-60]*7(---?(<[::-120]OH)-(<|[1]CH_3)(<:[::-90]CH_3)
-(-[1](<[::+80]HO)-[0](=[::+60]O)-[7](<|[::+130]CH_3)(-[::+75](<|[2]OH)-[::-60]-[::-60](<[::+30]O-[::-90])
-[::-60](<[::+90])(<:[::+30]O-[7](-[6]CH_3)=[0]O)-[::-60])-[6]-[5,1.3]?(<:[7]O-[5](=[::-60]O)
-[6]**6(------)))=(-[2]CH_3)-)}
CH3
OH
HO
OH
CH3
O
CH3
HN
CH3
O
O
O
OH
O
O
O
CH3
81
ChemFig
INDEX
Index
Symbols
! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . see save a molecule
(
) . . . . . . . . . . . . . . . . . . . . . . see branched molecule
* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . see ring
** . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . see ring/inside arc
\+ . . . . . . . . . . . . . . . . . . . . . . . . . . 61, 62, 65, 7274, 7678
-, =, ~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . see bond/types
=_, =^ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . see bond/shifted
>, <, >|, <|, >:, <: . . . . . . . . . . . . . . . . . . see Cram diagram
? . . . . . . . . . . . . . . . . . . . . . . . . . . . . see bond/distant atoms
@ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18, 4244, 7275, 79
| . . . . . . . . . . . . . . . . . . . . see separating atom mechanism
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6, 26
\\ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
A
arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
anchoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48, 57
coecient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
invisible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5558
anchoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55, 56
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
optional argument . . . . . . . . . . . . . . . . . . . . . . . . . . 55
shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55, 57
style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48, 49, 57
type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
\arrow . . . . . . . . . . . . . 4749, 51, 52, 55, 57, 59, 65, 7378
B
baseline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 21, 25, 50
bond
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
absolute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7, 34
arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
predened . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7, 33
relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8, 28, 34
branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 34
customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
delocalized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
departure and arrival atoms . . . . . . . . . . . . . . . 9, 18
distant atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
invisible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10, 39, 42
length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6, 8
optional argument . . . . . . . . . . . . . . . . . . . . . 710, 18
shifted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
wavy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
with text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
bounding box . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 20, 29, 30
branched molecule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
\CF@arrow@current@angle . . . . . . . . . . . . . . . . . . . . . . . 57
\CF@arrow@current@style . . . . . . . . . . . . . . . . . . . . 57, 58
\CF@arrow@display@label . . . . . . . . . . . . . . . . . . . . . . . 57
\CF@arrow@end@name . . . . . . . . . . . . . . . . . . . . . . . . . 57, 58
\CF@arrow@end@node . . . . . . . . . . . . . . . . . . . . . . . . . 57, 58
\CF@arrow@offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
\CF@arrow@shift@nodes . . . . . . . . . . . . . . . . . . . . . . 57, 58
\CF@arrow@start@name . . . . . . . . . . . . . . . . . . . . . . . 57, 58
\CF@arrow@start@node . . . . . . . . . . . . . . . . . . . . . . . 57, 58
chair representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
charge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 42
\delta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
\ominus . . . . . . . . . . . . . . . . . . . . . . . . . . 72, 74, 75, 77
\oplus . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 42, 7278
\Chemabove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 65
\chemabove . . . . . . . . . . . . 20, 30, 42, 64, 65, 72, 73, 75, 77
\Chembelow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 65
\chembelow . . . . . . . . . . . . . . . . . . . . . 30, 40, 65, 7173, 75
\chemdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53, 54, 65
\chemfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
optional arguments . . . . . . . . . . . . . . . . 24, 34, 38, 42
\chemfig . . . . . . . . . . . . . . . . . . . . . . . . . 4, 18, 24, 32, 48, 64
chemical reaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21, 31
\chemleft . . . . . . . . . . . . . . . . . . . . . . . . . 53, 54, 65, 7375
\chemmove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1820
\chemmove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42, 64, 7279
\chemname . . . . . . . . . . . . . . . . . . . . . . 20, 21, 65, 74, 7779
\chemnameinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21, 65
\chemrel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 64, 72, 75
\chemright . . . . . . . . . . . . . . . . . . . . . . . . 53, 54, 65, 7375
\chemsign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 64
\chemskipalign . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 26, 64
\chemup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53, 54, 65
\chenameinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
\color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 79
color (atom) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
compilation method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
compound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47, 4953
anchoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49, 50
name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
ConTEXt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 24
control points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 20
Cram representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
D
debug information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47, 50
\definearrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57, 58, 65
\definesubmol . . 27, 28, 37, 39, 42, 64, 6670, 74, 78, 80
dvi mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
E
electron movements . . . . . . . . . . . . . . . . . . . . . . . . . . 1820
82
ChemFig
INDEX
\usemodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
\usepackage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4
V
vertical alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
\vflipnext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 64, 77
\vphantom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
R
reaction scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4762
alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
subscheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
anchoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
delimiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5354
\redefinesubmol . . . . . . . . . . . . . . . . . . . . . . . . . 28, 64, 80
ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1418
angular position . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16, 35, 38
charge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
inside arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 35, 39, 40
unnished . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 35
\rlap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
S
save a molecule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 28
\schemedebug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
\schemestart . . . . . . . . . . . . . 47, 48, 51, 53, 61, 65, 7278
\schemestop . . . . . . . . . . . . . . 47, 53, 61, 65, 73, 74, 76, 78
separating atom mechanism . . . . . . . . . . . . . . . . . 5, 23, 41
\setandsign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61, 65
LATEXed by Christian T, the November 27, 2013.
83