LaTeX/Chemical Graphics
| Getting Started
Common Elements
Mechanics Technical Texts
Special Pages Special Documents Creating Graphics Programming Miscellaneous Help and Recommendations Appendices |
|
|
This book was last edited on 13 March 2013, and is still under heavy construction. Content that is added is likely to be moved/deleted/edited significantly in a short amount of time. All Wikibookians with knowledge in this subject are welcome to help out. You can remove this tag when the book has become more mature. |
chemfig is a package used to draw 2D chemical structures. It is an alternative to ochem. Whereas ochem requires Perl to draw chemical structures, chemfig uses the tikz package to produce its graphics. chemfig is used by adding the following to the preamble:
\usepackage{chemfig}
Contents |
Basic Usage [edit]
The primary command used in this package is \chemfig{}:
\chemfig{<atom1><bond type>[<angle>,<coeff>,<tikz code>]<atom2>}
<angle> is the bond angle between two atoms (or nodes). There are three types of angles: absolute, relative, and predefined. Absolute angles give a precise angle (generally, 0 to 360, though they can also be negative), and are represented with the syntax [:<absolute angle>]. Relative angles require the syntax [::<relative angle>] and produce an angle relative to the angle of the preceding bond. Finally, predefined angles are whole numbers from 0 to 7 indicating intervals of 45 degrees. These are produced with the syntax [< predefined angle>]. The predefined angles and their corresponding absolute angles are represented in the diagram below.
|
\chemfig{(-[:0,1.5,,,draw=none]\scriptstyle\color{red}0) |
<bond type> describes the bond attaching <atom1> and <atom2>. There are 9 different bond types:
|
\chemfig{A-B}\\ |
<coeff> represents the factor by which the bond's length will be multiplied.
<tikz code> includes additional options regarding the color or style of the bond.
A methane molecule, for instance, can be produced with the following code:
|
\chemfig{C(-[:0]H)(-[:90]H)(-[:180]H)(-[:270]H)} |
Linear molecules (such as methane) are a weak example of this, but molecules are formed in chemfig by nesting.
Skeletal Diagrams [edit]
Skeleton diagrams can be produced as follows:
|
\chemfig{-[:30]-[:-30]-[:30]} |
|
\chemfig{-[:30]=[:-30]-[:30]} |
Rings [edit]
Rings follow the syntax <atom>*<n>(code), where "n" indicates the number of sides in the ring and "code" represents the specific content of each ring (bonds and atoms).
|
\chemfig{A*6(-B-C-D-E-F-)} |
|
\chemfig{A*5(-B-C-D-E-)} |
|
\chemfig{*6(=-=-=-)} |
|
\chemfig{**5(------)} |
Lewis Structures [edit]
Lewis structures can be created by using the command
\lewis{<electron angle><electron>,<atom>}
within \chemfig{}.
Ions [edit]
For example, consider an acetate ion:
|
\chemfig{-(-[1]O^{-})=[7]O} |
Because the chemfig commands enters the math mode, ion charges can be added as superscripts (one caveat: a negative ion requires that the minus sign be enclosed in brackets, as in the example).
The charge of an ion can be circled by using \oplus and \ominus:
|
\chemfig{-(-[1]O^{\ominus})=[7]O} |
Alternatively, charges can be placed above ions using \chemabove{}{}:
|
\chemfig{-\chemabove{N}{\scriptstyle\oplus}(=[1]O)-[7]O^{\ominus}} |
Resonance Structures and Formal Charges [edit]
Resonance structures require a few math commands:
% see "Advanced Mathematics" for use of \left and \right % add to preamble: % \usepackage{mathtools} % \Longleftrightarrow $\left\{\chemfig{O-N(=[:60]O)-[:300]O}\right\} \Longleftrightarrow \left\{\chemfig{O=N(-[:60]O)-[:300]O}\right\} \Longleftrightarrow \left\{\chemfig{O-N(-[:60]O)=[:300]O}\right\}$
Chemical Reactions [edit]
Chemical reactions can be created with the following commands:
\chemrel[<arg1>][<arg2>]{<arrow code>}
\chemsign+ % produces a +
In \chemrel{}, <arg1> and <arg2> represent text placed above and below the arrow, respectively.
There are four types of arrows that can be produced with \chemrel{}:
A\chemrel{->}B\par A\chemrel{<-}B\par A\chemrel{<->}B\par A\chemrel{<>}B
Naming Chemical Graphics [edit]
Molecules can be named with the command
\chemname[<dim>]{\chemfig{<code of the molecule>}}{<name>}
<dim> is inserted between the bottom of the molecule and the top of the name defined by <name>. It is 1.5ex by default.
<name> will be centered relative to the molecule it describes.
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid} \chemsign{+} \chemname{\chemfig{R’OH}}{Alcohol} \chemrel{->} \chemname{\chemfig{R-C(-[:-30]OR’)=[:30]O}}{Ester} \chemsign{+} \chemname{\chemfig{H_2O}}{Water}
In the reaction above, \chemname{} inserts 1.5ex plus the depth of the carboxylic acid molecule in between each molecule and their respective names. This is because the graphic for the first molecule in the reaction (carboxylic acid) extends deeper than the rest of the molecules. A different result is produced by putting the alcohol first:
\chemname{\chemfig{R’OH}}{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}
This is fixed by adding \chemnameinit{<deepest molecule>} before the first instance of \chemname{} in a reaction and by adding \chemnameinit{} after the reaction:
\chemnameinit{\chemfig{R-C(-[:-30]OH)=[:30]O}} \chemname{\chemfig{R’OH}}{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{}
Lastly, adding \\ in <name> will produce a line-break, allowing the name to span multiple lines.
Advanced Graphics [edit]
For advanced commands and examples, refer to the chemfig manual, where a more thorough and complete introduction to the package can be found.
