How to use structures in LaTeX (chemfig and mhchem)

Select the structure, press Ctrl+K and choose Copy as chemfig or Copy as mhchem formula, then paste into your .tex file. chemfig needs \usepackage{chemfig}; mhchem needs \usepackage[version=4]{mhchem}.

On a Mac, Ctrl is Cmd.

Steps

  1. Draw or insert the structure, for example aspirin (press / and type aspirin), and select it.
  2. Press Ctrl+K and choose Copy as chemfig or Copy as mhchem formula. A notice confirms it and names the package you need.
  3. Paste into your .tex file and add the package to the preamble.

chemfig: the drawing

Copy as chemfig gives the structure as chemfig code, with each bond's angle and ring closures. For aspirin:

\usepackage{chemfig}
...
\chemfig{-[:30](=[:90]O)-[:330]O-[:270]?[a]-[:210]=[:270]-[:330]=[:30]-[:90]?[a,{=}]-[:30](=[:90]O)-[:330]O}

The angles follow your drawing, so the LaTeX picture looks like the structure on the canvas. It works in Overleaf and any LaTeX install with chemfig.

mhchem: the formula

Copy as mhchem formula gives the molecular formula for running text:

\usepackage[version=4]{mhchem}
...
\ce{C9H8O4}

Tip

For a figure that has to match a journal's style exactly, export a PDF or SVG with the journal preset instead and include it with \includegraphics. See export a figure for a paper.

Is this helpful?

Last updated Nov 12, 2026