Homepage von Ingo Klöckl
 - My LaTeX book
 - ifsym
 - Links etc.
Ingo Klöckl

Homepage (LaTeX for Chemists)

Unfortunately, the LaTeX support is much better for mathematicians than for chemists, so I have decided to write a package for typesetting chemical formula within LaTeX documents. The means of choice for this highly graphical project is the PostScript language, so a first package (independent of LaTeX) purely written in PostScript was created. 1999, this package was updated and an interaction with LaTeX was introduced. The description of formula was newly written in a special language. So it is now possible to place the commands of the formula description language within LaTeX environments where you want the formula to appear. After two LaTeX runs and one run of a specialized perl script (interpreting the formula description language) the generated PostScript output is placed in the LaTeX document. No manual linking of formula pictures and documents is necessary. The following typical sequence is needed to compile a chemical document:

latex test
chemie.pl test.chm
latex test
dvips test

The highest quality is achived with mixed LaTeX/Postscript output. All textual sequences (notes, digits, greek cahracters ...) are typeset with LaTeX as usual, all graphical output is done via PostScript. You can then create a PostScript document with DVIPS and print it directly on a PostScript printer. If you have ink jet printers or other, non-PostScript printers, you can print the document without any problems with the printing features of the PostScript previewer GSview on nearly every printer.

Another way is to generate LaTeX picture environments with pure LaTeX drawing commands. The results are normally not as good as the PostScript one, especially when using uncommon bond angles or stereo-chemistry features.

With the perl script makePics.pl, all formula can be converted into PNG format for web presentations. Many examples for the look of the generated formula in this PNG format can be found in the chapter about colour chemistry, Chemie-und-Malerei-Abschnitten on my web site. By using an external conversion program like ImageMagick, all graphics formats can be created if the external program can convert EPS to the desired format. So this problem is out of scope for OCHEM.

To use OCHEM, each LaTeX document has to load the package OCHEM; in the example, the crassanine use a pre-defined ring system (2,2,2-Bicyclooctane) which is located in an external library for bicyclic structures, which has to be loaded, too:



Normaler Text ...

Crassanine is described as follows. Each chemical unit (a single formula or a complete reaction sequence) is placed in a chemistry environment, each formula in a formula command. Formula consists of the basic elements bonds, ring structures (n-membered, aromatic or predefined structures of an external library), atom symbols and text.

  formula(L,R,"Crassanin", HR,24)
  { ring("bc222o",,,N)
    { 2: bond(30) bond(-30);
      0: ring(,,H,N)
         { 1: ring(,4,H,#N,5,-70)
              { 0: bond(-70,=C) atom("O");
                1: atom("N") bond(r) atom("H");
                { 4: bond(r) atom("O",C,L) atom("H$_3$C",R);
                  5: bond(r) atom("O",C,L) atom("H$_3$C",R);  
      0: bond(-90,o,NN) atom("C",C,R) atom("OOCH$_3$",L);
      4: bond(-60,<<) atom("H");
      7: atom("N");

When describing reaction sequences, a lot of the positioning work is done by the perl script. You have to give it hints about the direction in which the sequences should be drawn, the fine-tuning is done automatically. Besides simple linear sequences, also complex schemes with branching into many partial sequences or joining of many sequences are possible. Each formula in the sequence can be given a text (name).

{ formula(L,R,"Zimts""aure")
  { ring(){5: bond(r;r/,=;r) atom("COOH",L); } }

  { ring(){5: bond(r;r/,=;r) atom("COOH",L);
           2: bond(r) atom("O",C,L) atom("H",R); }

  { ring(){5: bond(r;r/,=;r) atom("COOH",L);
           2: bond(r) atom("O",C,L) atom("H",R); 
           1: bond(r) atom("O",C,L) atom("H",R); }

setcontext(#1,B) arrow(-90){}
{ ring(,,H5=)
  { vertex(,1,1){};
    3: atom("O");
    4: bond(r,=C) atom("O"); }

setcontext(#2,BR) arrow(-45){}

The diazo synthesis shows the joining of several individual sequences into a single one:

{ joinh(2,R)
  { formula(L,R,"Anilin")
    { ring(){ 4: bond(r) atom("N",C,R) atom("H$_2$",L);} }
    formula(L,R,"Salpetrige S""aure")
    { atom("HNO$_2$") }
  { ring(){ 4: bond(r) atom("N",C,R) atom("$_2^+$",L);} }
  { ring(){ 5: bond(r) atom("N",C,R) atom("H$_2$",L);} }
{ ring(){ 4: bond(r) atom("N=N",L,R) bond(r/)
             { 3: bond(r) atom("N",C,R) atom("H$_2$",L);};


OCHEM is a perl script and therefore highly portable. It will run on Linux boxes as well as Win32 systems, if you have installed a working Perl (see above). Furthermore, it uses LaTeX for text formatting which you will need also.

The OCHEM package requires an installed perl interpreter, which is not be contained in the OCHEM distribution. You have to get it from another source, in CPAN you will surely find a suitable distribution for your system (can be used for funny programming projects besides OCHEM, too:-) ). On Linux boxes, Perl normally comes installed out of the box, on Win32 systems you might also use ActivePerl, the Perl distribution from ActiveState.

To use the macro packages, you will also need a working M4 preprocessor. You can download it from GNU website, if you miss it (common on Win32 platform). I strongly recommend the download of the small program, because the usage of the macro packages can drastically increase your productivitiy!

For the conversion of the generated EPS files into another graphics file format I use the program convert of ImageMagick. You can download the ImageMagick distribution here. Again, most Linux boxes will have ImageMagick pre-installed. Win32 user normally have to download the distribution.

New features, patches and corrections

Naturally, I'am glad about suggestions, criticism and - patches! If you miss a useful feature, tell it to me, mayby it can be implemented and increase the use of OCHEM. If you find bugs, please report them, and if you want, send me a patch :-) The following list contains the new features and corrections of the OCHEM distribution in chronical order. If you remark something, please have a look here, maybe the bug was already fixed or the feature implemented in a new version!

  • Version 1.00 (OCHEM 3.00) 18.05.1999: Bei PostScript-Ausgabe fehlerhafte Interferenz mit METAPOST-Abbildungen beseitigt (PS-Kommando fshow wurde von beiden Programmen benutzt).
  • Version 1.0a (OCHEM 3.0a) 20.10.1999: \unitlength wird nun innerhalb einer TeX-Gruppe und vor der picture-Umgebung auf 1pt gesetzt. Damit behobener Fehler: wenn andere Pakete dieses Maß modifizieren, ist die Positionierung der Formel entsprechend falsch.
  • Version 1.0b (OCHEM 3.0b) 9.1.2000: Neue Bindungstypen >>, >. und b (projektive und fette Bindungen).
  • 17.1.2000: Neuer Ringtyp furanose für Furanoseringe.
  • Version 1.0c (OCHEM 3.0c) 17.1.2000: Neuer Bindungstyp ~ für Anomerenbindung. Bindungslänge durch beliebige Zusammensetzung der Kennzeichnungen n, N, l, L, s und S additiv kombinierbar. Neuer Befehl package erlaubt die Übergabe von LaTeX-Paketen an den Chemiecompiler, so daß nun an allen Textpositionen auch selbstdefinierte Makros erlaubt sind.
  • Version 1.0d (OCHEM 3.0d) 19.4.2000: Überflüssige Leerzeichen bei der Einbindung von Formeln in Fließtext entfernt.
  • Version 1.0d (OCHEM 3.0d) 6.4.2001: Möglichkeit, aus den einzelnen Formeln jeweils EPS- und JPG/PNG/...-Dateien für Cross Media Publishing zu erzeugen.
  • Version 1.0d (OCHEM 3.0d) 25.5.2001: Erweiterte Syntax bei Ausdrücken, die Punktkoordinaten berechnen können und so die geometrische Beschreibung komplizierter und unregelmäßiger Moleküle erleichtert.
  • Version 1.0e (OCHEM 3.0e) 28.5.2001: Befehl cutline hinzugefügt.