chemfig and LaTeX
Short answer: Click Download and pick chemfig (LaTeX) to save a .tex file that compiles with pdflatex. To copy only the code, right click and pick Copy as, then chemfig (LaTeX). To draw from chemfig, copy the code and press Ctrl+V on the canvas.
chemfig is a LaTeX package for chemical structures. MolDraw writes chemfig code from your drawing and reads chemfig code back onto the canvas.
- Select what you want to export. With nothing selected, MolDraw exports the whole canvas.
- Click Download and look in the Text group.
- Click chemfig (LaTeX). MolDraw saves a
.texfile. - Compile the file with pdflatex.
Download or copy#
| Way | What you get | Use it when |
|---|---|---|
| Download, chemfig (LaTeX) | A full standalone document in a .tex file |
You want a PDF of the figure right away |
| Right click, Copy as, chemfig (LaTeX) | The chemfig code only, with no document around it | You paste the figure into your own paper or thesis |
On a phone, open the More menu, then Copy as, then chemfig (LaTeX).
If you copy only the code, add these lines to your preamble:
\usepackage{chemfig}
\usetikzlibrary{arrows.meta,decorations.pathmorphing}
What the export writes#
- Bond angles and lengths come from your drawing, so the PDF matches the canvas. The code sets
atom septo 2.5em. - Reaction schemes become
\schemestartto\schemestop, one per row. - Curly arrows and fish-hooks become
\chemmovecurves that follow the same path as on the canvas.
Some objects have no chemfig form. MolDraw leaves them out and lists them in the status line, so nothing goes missing silently:
| Object | What happens |
|---|---|
| Images, shapes, glassware, freehand strokes, orbitals | Left out |
| Ring fills and highlights | Left out |
| Query bonds | Written as plain bonds |
| Curved or S-shaped scheme arrows | Written as straight scheme arrows |
| Curly arrows not attached to a structure | Left out |
| Text placed beside the drawing | Kept as comments in the code |
| Brackets that cross more than two bonds | Left out |
Paste chemfig code#
- Copy chemfig code from your editor. A whole
.texfile works too. - Click the canvas and press Ctrl+V, or click Paste in the top bar.
- MolDraw draws the structures and selects them. The status line says "Pasted chemfig".
MolDraw spots chemfig when the text contains \chemfig or \schemestart. Pasted text uses a serif font so it looks like the LaTeX output. The open file dialog does not take .tex files, so paste the code instead.
What MolDraw reads#
- Chains and branches, bond angles
[n],[:a]and[::a], and length factors. - Bond types
-,=,~,<,>,<:,>:and their looks: wavy, bold, dotted, dative, colored or hidden. - Rings
*n(...)and**n(...), ring closure hooks?[...]and\definesubmol. - Atom groups with H, charges, colors,
\lewis,\chargeand\chemabove. - Schemes with
\arrowtext above and below,\+,\chemnamecaptions and\subscheme. \chemleft[and\chemright]brackets and\polymerdelim.- Plain text lines, such as titles and notes.
\chemmovecurly arrows between@{name}nodes.
Common problems#
| Problem | Fix |
|---|---|
| "Could not read that chemfig code" | Check that every brace is closed. Paste one \chemfig{...} at a time to find the bad one. |
| The PDF has missing arrow tips or wavy bonds | Add the two TikZ libraries above to your preamble. |
| Ctrl+V pastes a picture instead | The clipboard held an image. Copy the code as plain text and paste again. |
For worked examples, read the chemfig and MolDraw guide and the chemfig mechanism samples. For other formats, see Download and file formats.
Questions and answers
How do I convert a structure to chemfig?
Draw it in MolDraw, click Download and pick chemfig (LaTeX). Or right click, pick Copy as and choose chemfig (LaTeX) to copy only the code.
Which LaTeX packages does the chemfig export need?
It needs the chemfig package and the TikZ libraries arrows.meta and decorations.pathmorphing. The downloaded .tex file already includes them.
Can MolDraw read chemfig code?
Yes. Copy the code and press Ctrl+V on the canvas. MolDraw draws structures, schemes and \chemmove curly arrows.
Does the chemfig export keep curly arrows?
Yes. Curly arrows and fish-hooks attached to a structure are written as \chemmove curves.
Can I open a .tex file in MolDraw?
Not with the open file dialog. Open the file in a text editor, copy the code and paste it onto the canvas.
Last updated: