FxEditor
User guideQuickstartExamplesAPIDesignFxTeX
OverviewAPIExamplesRight-click menuSupported commandsAccessibilityFxTeX Packages
Using packagesmhchemchemfigphysics
FxTeX Server
OverviewAPIAccess and keysSelf-hostingSpeedPlugins
OverviewLicensing
How licensing workschemfig
chemfig draws molecules from a line of text: atoms, the bonds between them, the angles of those bonds, branches and rings. fxTeX Pro draws each one as SVG, inside the equation, so a structure can sit in a sentence or beside an arrow like any other piece of maths. The editor below has the chemistry panels — chemfig's and mhchem's — with the maths a chemist needs around them. Click any example on this page to open it there.
Adding chemfig to your page
In fxTeX Pro, name chemfig when you render the page:
fxTeXPro.ready.then(() => {
fxTeXPro.unlock('fx_pk_your-key-here');
fxTeXPro.autoRender({ packages: ['chemfig'] });
});
In the equation editor, name it to EqEditor.init() and add its
panels to the toolbar. This is the editor above, with mhchem as well:
<script src="https://fxeditor.codecogs.com/fxeditor.api.min.js"></script>
<div id="toolbar"></div>
<div id="mathview"></div>
<div id="latex"></div>
<script>
const ready = EqEditor.init({
licence: 'fx_pk_your-key-here',
packages: ['mhchem', 'chemfig']
});
const toolbar = EqEditor.Toolbar.link('toolbar', [
['mhchem', 'mhchem_arrows', 'chemfig', 'chemfig_ext', 'arrows'],
['operators_core', 'subsupset', 'brackets', 'greeklower', 'greekupper', 'symbols', 'spaces']
]);
ready.then(() => {
const latex = EqEditor.LaTeXView.link('latex');
const mathview = EqEditor.MathView.link('mathview').addLaTeXView(latex);
toolbar.addLaTeXView(latex).addMathView(mathview);
mathview.setLatex('\\chemfig{H_3C-C(=[1]O)-[7]OH}');
});
</script>
The chemfig panel has rings, bonds, bond angles and branches, and writes inside
\chemfig{} — adding it only when the caret is not in one already, so each
button extends the molecule you are drawing. chemfig_ext has charges, lone pairs,
names, brackets and reaction schemes. chemfig is the largest of the packages, 112 kB
gzipped: name it only on the pages that use it. See Using
packages for more on both steps.
Atoms and bonds
Atoms are letters, with subscripts as in maths; bonds are the symbols between them.
\chemfig{A-B}Single bond.
\chemfig{A=B}Double bond.
\chemfig{A~B}Triple bond.
\chemfig{A>B}Wedge: towards the viewer.
\chemfig{A<B}Wedge the other way.
\chemfig{A>:B}Hashed wedge: away from the viewer.
\chemfig{A>|B}Hollow wedge.
\chemfig{CH_3-CH_2-OH}Ethanol: groups of atoms, with subscripts.
Bond angles
A bond goes to the right unless told otherwise, in square brackets after it: a number
n on its own is n×45°, :30 is an absolute angle in degrees,
and ::30 is relative to the bond before.
\chemfig{A-[1]B}45°.
\chemfig{A-[2]B}90°, straight up.
\chemfig{A-[7]B}315°, down to the right.
\chemfig{A-[:30]B}30°, absolute.
\chemfig{A-[::30]B-[::30]C}30° on from the bond before, each time.
\chemfig{A-[,2]B}The second option is the bond's length: twice as long.
\chemfig{-[:30]-[:-30]-[:30]-[:-30]}A skeletal chain: bonds with no atoms.
Branches
A bond in round brackets after an atom is a branch off it; the chain carries on after the bracket.
\chemfig{H-C(-[2]H)(-[6]H)-H}Methane, with branches up and down.
\chemfig{H_3C-C(=[1]O)-[7]OH}Acetic acid.
\chemfig{H-C(-[2]H)(-[6]H)-C(=[1]O)-[7]H}Acetaldehyde.
Rings
*6(...) is a ring of six, with its bonds in the brackets; **6 draws a
circle inside it. Anything in brackets on a ring's atom is a substituent, and a ring can be one.
\chemfig{*6(-=-=-=)}Benzene, with alternating double bonds.
\chemfig{**6(------)}Benzene, with a circle.
\chemfig{*6(------)}Cyclohexane.
\chemfig{*5(-----)}A five-membered ring.
\chemfig{CH_2*3(-CH_2-CH_2-)}Cyclopropane, with its atoms named.
\chemfig{*6(-=-(-OH)=-=)}Phenol: a substituent on the ring.
\chemfig{*6(=-*6(-=-=-)=-=-)}Naphthalene: a ring fused to a ring.
\chemfig{[:-30]*6(-=-=-=)}The whole molecule turned 30°.
Charges and lone pairs
\charge puts something beside an atom at an angle; \: is a lone
pair. \chemabove and \chembelow put it above or below.
\chemfig{\charge{90=\:,270=\:}{O}}Lone pairs above and below.
\chemfig{\Charge{45=$\scriptstyle\oplus$}{N}}\Charge sets it a little further out.
\chemfig{\chemabove{N}{\oplus}(-[2]H)(-[6]H)-H}A charge above an atom, with branches.
\chemfig{H_3\chemabove{N}{\oplus}-CH_2-COO^{\ominus}}Glycine as a zwitterion.
\setcharge{circle}\chemfig{\charge{90=+}{N}}\setcharge styles every charge after it.
Names and brackets
\chemname{\chemfig{*6(=-=-=-)}}{Benzene}\chemname sets a name under a molecule.
\chemleft[\chemfig{A-B}\chemright]^{\ominus}Brackets sized to the molecule, with a charge.
Reaction schemes
Between \schemestart and \schemestop, \arrow joins
whatever is either side of it: text, or molecules. Its type goes in braces, with labels in
square brackets above and below; \+ is a plus.
\schemestart A \arrow B \arrow C \schemestopA sequence.
\schemestart A \+ B \arrow C \schemestopTwo reactants.
\schemestart A \arrow{<=>} B \schemestopEquilibrium.
\schemestart A \arrow{<->} B \schemestopResonance.
\schemestart A \arrow{-/>} B \schemestopNo reaction.
\schemestart A \arrow{->[a][b]} B \schemestopLabels above and below.
\schemestart \chemfig{*6(-=-=-=)} \arrow{->[\chemfig{Br_2}][\chemfig{FeBr_3}]} \chemfig{*6(-=-=(-Br)-=)} \schemestopThe bromination of benzene.
Settings and shortcuts
Options in square brackets after \chemfig apply to that molecule;
\setchemfig sets them for every one after it. \definesubmol names a
piece of a molecule, to use again with !{name}.
\chemfig[atom sep=2em]{A-B-C}Shorter bonds, for this molecule.
\setchemfig{atom sep=3em}\chemfig{A-B}For every molecule after it.
\chemfig{A-[,,,,red]B}The fifth bond option styles it.
\definesubmol{x}{-[:30]-[:-30]}\chemfig{A!{x}!{x}B}A piece defined once, used twice.
The chemfig manual
This page covers the parts of chemfig used most. chemfig itself is by Christian Tellechea; its manual has every option, and many more molecules:
chemfig manual (PDF) — the LaTeX package's documentation, in English, on CTAN.
chemfig on CTAN — the package, its licence, and the manual in French.
More
mhchem — chemical formulae, equations and units.
Using packages — turning packages on, and their panels.
Supported commands — every chemistry command fxTeX reads.
CodeCogs®