There are a few
L
a
T
e
X
packages to create chemistry formulae:
chemfig
,
ochem
,
streetex
, and
xymtex
. The most intuitive is probably
chemfig
package. This article explains how to use the
chemfig
package to create chemical formulas in
L
a
T
e
X
.
Contents |
Drawing a molecule consists mainly in connecting groups of atoms with lines. Simple linear formulas can be easily drawn with chemfig , let's see:
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{chemfig} \section{Introduction} Writting chemical formulae with chemfig is straightforward. \chemfig{O=H} \end{document}
The package is imported by
\usepackage{chemfig}
in the preamble, then the command
\chemfig{O=H}
draws the molecule, the symbol
=
determines the type of bond. See the
reference guide
for a list of bond types.
Open an example of the chemfig package in ShareLaTeX
There are several ways to define angles to draw the bonds between molecules.
To define chemical formulae you can use units that define the angles \chemfig{A-[1]B-[7]C} Absolute angles \chemfig{A-[:50]B-[:-25]C} Relative angles \chemfig{A-[::50]B-[::-25]C}
Each one of the three commands in the example above uses a different method to determine the angle between bonds.
\chemfig{A-[1]B-[7]C}
the parameters inside brackets set the angle in special units, each unit equals 45°. Hence in the example the angles are 45° and 315°.
\chemfig{A-[:50]B-[:-25]C}
the parameter inside the brackets represent the angle, in degrees, measured from the horizontal baseline. Negative angles are allowed.
\chemfig{A-[::50]B-[::-25]C}
the angles are measured from the previous bond, instead of the baseline.
Open an example of the chemfig package in ShareLaTeX
The example below presents the syntax to draw regular polygons
The syntax of the command
\chemfig{A*5(-B=C-D-E=)}
is explained below:
A
*5
(-B=C-D-E=)
There is an additional parameter that can be passed to this command, a double asterisk. For instance, if "**5" is set instead of "*5" a circle is drawn inside the polygon.
Open an example of the chemfig package in ShareLaTeX
Chemical formulas are not always linear, branched formulas are actually the most common type. Below an example on how to create them.
Branches in each node are created by adding formulas inside parentheses. For instance, the code
C(-[2]H)(-[6]H)
creates two branches in "C", one with a 2 units angle (90°) and other with a 6 units angle (270°).
Branches can also be added to rings
The syntax is similar, using parentheses a branch can be attached to a node (atom). For instance
F(=G)
attaches a branch to the node "F". More complex examples can be created using nested branches and even attaching rings as branches.
Open an example of the chemfig package in ShareLaTeX
Several parameters such as colours and the node separation can be changed, also additional text to describe the formula can be added.
{\huge \setbondstyle{red,line width=2pt,dash pattern=on 2pt off 2pt} \setatomsep{2em} \chemname {\chemfig{H-C(-[2]H)(-[6]H)-C(=[1]O)-[7]H}} {Ethanal} }
There are three new command here:
\setbondstyle{ }
\setatomstep{2em}
\chemname{}{}
Notice also that the font used is
huge
. You can use any other
font size
and the formula will be scaled accordingly.
Open an example of the chemfig package in ShareLaTeX
Bond types
For more information see