Chemical structures

I have just spent a couple of days working out how best to do molecular structures within LaTeX. I want to do it programmatically rather than importing an encapsulated postscript (EPS) file because it’s just so much better. For this reason, and others, I do like the tikz package, an interface to PGF a lot (there’s all manner of reasons given in the documentation (PDF file) as to why LaTeX-created pictures are better).

I tried to draw the structures using tikz, but it’s tedious, and not ideal — I see no easy way to draw stereochemical bonds, for a start. I looked elsewhere.

I found the XyMTeX package, which looks horrendous to use. I also discovered it’s obsolete, even though it’s only from 2009. Still, I’m not surprised with that level of excess complexity. I looked elsewhere.

I found the chemstruct package, which doesn’t seem to be what I want. I looked elsewhere.

Eventually, I came across chemfig. At first glance, this seems exactly what I want: it’s built on top of the tikz package, for a start — hooray! — and it seems reasonably straightforward to use. Something like thisis always going to be complicated due to the nature of the beast, but we’ll see.

Update: there is a conflict between the chemfig package as provided by TeXlive and the gb4e package, which does example numbering for linguistics. This has probably never come up before — who draws chemical structures in the same document as linguistic examples? I suspect the problem is that both packages mess with the mathematical subscripts; they both seem to allow roman fonts in subscripts, but put the two together, and you get italicised digits in your chemical formulae. This is not right! Changing the order the packages are declared in makes no difference. I wonder what, if anything, the solution is. I am so disappointed!

Update: solved! Using the version of the gb4e package provided by MiKTeX solves the problem! (MiKTeX is available on Windows and Linux.)

I’m now happy with my chemical structures. They’re easy to draw and they look good. One problem, however, is that I can’t name individual atoms anymore, which would be useful to do for annotations and so on. However, if I put the chemfig{} command in a node command, I can use the node’s generic anchor points, which will do for my current needs.

Advertisements
5 Comments

5 thoughts on “Chemical structures

  1. Yes! I’ve tried many packages, some listed here and I totally agree with you, chemfig is the best package ever! Only one issue: I’m curious to know if you worked out how to draw for example an aromatic ring with a circle of whatsoever to show the aromaticity and a charge, for example a + in the center. Thank you in advance for your help!!!

  2. Due to an error with the template, the comments weren’t showing up. Sorry, Luigi – I wasn’t ignoring you! We were being failed by the technology. All fixed now, as you can see.

  3. Great post. What are your thoughts on ppchtex? Also, is there a way to generate chemfig code from say SMILES — that would be really useful, right?

What do you have to say about this?

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: