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.
categories: Nature and Science and Tech
tags: chemistry, computing, latex
last modified: 29th Sep 2011


