chris blogs

May 2004

20may2004 · ppchTeX

Today I experimented with ppchTeX, a macro package for plain TeX, LaTeX and ConTeXt to typeset chemical formulas.

It’s stucture is very interesting; it uses an arcane syntax which in fact is a domain specific language. I’ll show some examples here.

Chemical formula of Ethene First, Ethene (CH2CH2).

The code of this looks like this (there is some stuff around it, but this is the code unique to this certain formula):


This reads like a simple program:

  • ONE: This is the command to introduce an “node” inside the formula.

  • SB46: Draw a Single Bond on position 4 and 6 of the current node. This is bottom-left and top-left.

  • DB1: Draw a Double Bond on position 1 of the current node. This is right-middle.

  • Z0146: Add the name of the atoms at position 0 (the middle of the node), 1, 4 and 6. These get the names from the data attached to the call; i.e. the current node gets named C, just like the right node, and the two left ones get H.

  • MOV1: Move to the node at position 1, that is, the right node.

  • SB28 and Z28: Draw the upper-right and bottom-right bonds, and name them accordingly.

This sounds quite compilicated, but once you got how to look at the formula, its quite easy to write.

Chemical formula of two
acetic acid molecules connected by hydrogen bonds

Now, a bit more complicated example, two acetic acid molecules connected by hydrogen bonds. The code:


I’ll only explain the stuff not covered above:

  • PB:posPE: Start a subdiagram at position pos.

  • SUB1: move one structure in relation to another in the direction given.

  • 18OFF1: do 18 small steps in direction 1 (right).

Now, a quite tricky one, Guanine:


Chemical formula of Guanine

  • FIVE draws a five-ring.
  • RZ draws substituents using names from the data given.
  • ADJ1 moves another structure in the direction given adjacent to a bond.

Yeah, that’s it. Lots of fun and a source of endless frustration… :-)

NP: Grateful Dead—Mountains Of The Moon

Copyright © 2004–2016