%SUBJECT: File CHEMDOC.TEX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Dokumentation zu:
%
%  STRUCTURE - Makropaket zum Erstellen von chem. Strukturformeln
%
%  Autor: Dr. Michael Ramek
%         Institut fuer Physikal. und Theoret. Chemie
%         Technische Universitaet Graz
%
%  November 1987
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%-----
% modified by H.Partl, TU Wien:
%    88-04-11 (\input file names changed)
%    88-11-21 (Titelseite erweitert fuer TU Wien
%-----
 
\magnification=1200
 
% Titlepage inserted by H.Partl ---->
 
\null\vfil
\centerline{\bf CHEMSTRUCT}
\bigskip
\centerline{\bf Chemische Strukturformeln mit \TeX}
\bigskip
\centerline{Dr.~Michael Ramek}
\centerline{Technische Universit\"at Graz}
\centerline{November 1987}
\vfil\vfil
 
\noindent
Anmerkungen:
\medskip
\noindent
An der CYBER des EDV-Zentrums der TU~Wien
sind die in diesem Handbuch beschriebenen Macros im File
{\tt CHEMSTRUCT\_TEX} definiert, sie werden also mit dem \TeX-Befehl
\medskip
\centerline{\tt \char'134{}input chemstruct}
\medskip\noindent
verf\"ugbar gemacht.
 
Die Verwendung ist sowohl in Plain \TeX\ als auch (mit Einschr\"ankungen)
in La\TeX\ m\"oglich.
 
Die schr\"agen Linien in den Strukturformeln werden aus sehr vielen Punkten
zusammengesetzt. Dies kann bei manchen Driver-Programmen und
Ausgabe\-ger\"aten zu Speicher-Problemen f\"uhren.
Bei dem an der TU Wien installierten PostScript-Driver von Nelson Beebe
sind bisher {\it keine\/} solchen Probleme aufgetreten.
 
Das EDV-Zentrum der TU Wien dankt Herrn Dr.~Ramek daf\"ur, da\ss\ er uns
seine Macros zur Verf\"ugung gestellt hat.
 
\medskip
\rightline{H.~Partl, TU Wien, 1988-11-28}
 
\vfil\vfil
\rightline{Handbuch-Nummer: X14}
 
\eject
 
% End of Titlepage <---
 
 
 
%---\input chemstruct.def
\input chemstruct % <--- new file name CHEMSRTUCT.TEX <----
 
 
 
\def\tex{\TeX}
\def\section#1{\vskip 2truecm plus 1truecm\goodbreak\leftline{\bf #1}\bigskip}
\def\Structure{{\tt {\char'134}structure}}
%\def\Nsingle{{\tt {\char'134}nsingle}}
%\def\Ssingle{{\tt {\char'134}ssingle}}
%\def\Esingle{{\tt {\char'134}esingle}}
%\def\Wsingle{{\tt {\char'134}wsingle}}
%\def\Sesingle{{\tt {\char'134}sesingle}}
%\def\Swsingle{{\tt {\char'134}swsingle}}
%\def\Nesingle{{\tt {\char'134}nesingle}}
%\def\Nwsingle{{\tt {\char'134}nwsingle}}
%\def\Ssesingle{{\tt {\char'134}ssesingle}}
%\def\Sswsingle{{\tt {\char'134}sswsingle}}
%\def\Nnesingle{{\tt {\char'134}nnesingle}}
\def\Nnwsingle{{\tt {\char'134}nnwsingle}}
%\def\Ndouble{{\tt {\char'134}ndouble}}
%\def\Sdouble{{\tt {\char'134}sdouble}}
%\def\Edouble{{\tt {\char'134}edouble}}
%\def\Wdouble{{\tt {\char'134}wdouble}}
%\def\Sedouble{{\tt {\char'134}sedouble}}
%\def\Swdouble{{\tt {\char'134}swdouble}}
%\def\Nedouble{{\tt {\char'134}nedouble}}
%\def\Nwdouble{{\tt {\char'134}nwdouble}}
%\def\Ssedouble{{\tt {\char'134}ssedouble}}
%\def\Sswdouble{{\tt {\char'134}sswdouble}}
%\def\Nnedouble{{\tt {\char'134}nnedouble}}
\def\Nnwdouble{{\tt {\char'134}nnwdouble}}
%\def\Ntriple{{\tt {\char'134}ntriple}}
%\def\Striple{{\tt {\char'134}striple}}
%\def\Etriple{{\tt {\char'134}etriple}}
%\def\Wtriple{{\tt {\char'134}wtriple}}
%\def\Setriple{{\tt {\char'134}setriple}}
%\def\Swtriple{{\tt {\char'134}swtriple}}
%\def\Netriple{{\tt {\char'134}netriple}}
%\def\Nwtriple{{\tt {\char'134}nwtriple}}
%\def\Ssetriple{{\tt {\char'134}ssetriple}}
%\def\Sswtriple{{\tt {\char'134}sswtriple}}
%\def\Nnetriple{{\tt {\char'134}nnetriple}}
\def\Nnwtriple{{\tt {\char'134}nnwtriple}}
%\def\Nphantom{{\tt {\char'134}nphantom}}
%\def\Sphantom{{\tt {\char'134}sphantom}}
%\def\Ephantom{{\tt {\char'134}ephantom}}
%\def\Wphantom{{\tt {\char'134}wphantom}}
%\def\Sephantom{{\tt {\char'134}sephantom}}
%\def\Swphantom{{\tt {\char'134}swphantom}}
%\def\Nephantom{{\tt {\char'134}nephantom}}
%\def\Nwphantom{{\tt {\char'134}nwphantom}}
%\def\Ssephantom{{\tt {\char'134}ssephantom}}
%\def\Sswphantom{{\tt {\char'134}sswphantom}}
%\def\Nnephantom{{\tt {\char'134}nnephantom}}
\def\Nnwphantom{{\tt {\char'134}nnwphantom}}
\def\Sebelow{{\tt {\char'134}sebelow}}
%\def\Swbelow{{\tt {\char'134}swbelow}}
\def\Nebelow{{\tt {\char'134}nebelow}}
%\def\Nwbelow{{\tt {\char'134}nwbelow}}
\def\Sseabove{{\tt {\char'134}sseabove}}
%\def\Sswabove{{\tt {\char'134}sswabove}}
\def\Nneabove{{\tt {\char'134}nneabove}}
\def\Nnwabove{{\tt {\char'134}nnwabove}}
%\def\Sseevoba{{\tt {\char'134}sseevoba}}
%\def\Sswevoba{{\tt {\char'134}sswevoba}}
%\def\Nneevoba{{\tt {\char'134}nneevoba}}
\def\Nnwevoba{{\tt {\char'134}nnwevoba}}
%\def\Ssebelow{{\tt {\char'134}ssebelow}}
\def\Sswbelow{{\tt {\char'134}sswbelow}}
\def\Nnebelow{{\tt {\char'134}nnebelow}}
\def\Nnwbelow{{\tt {\char'134}nnwbelow}}
%\def\Eseabove{{\tt {\char'134}eseabove}}
%\def\Wswabove{{\tt {\char'134}wswabove}}
%\def\Eneabove{{\tt {\char'134}eneabove}}
%\def\Wnwabove{{\tt {\char'134}wnwabove}}
%\def\Eseevoba{{\tt {\char'134}eseevoba}}
%\def\Wswevoba{{\tt {\char'134}wswevoba}}
%\def\Eneevoba{{\tt {\char'134}eneevoba}}
%\def\Wnwevoba{{\tt {\char'134}wnwevoba}}
%\def\Esebelow{{\tt {\char'134}esebelow}}
%\def\Wswbelow{{\tt {\char'134}wswbelow}}
%\def\Enebelow{{\tt {\char'134}enebelow}}
%\def\Wnwbelow{{\tt {\char'134}wnwbelow}}
\def\Wmostaromatatom{{\tt {\char'134}wmostaromatatom}}
\def\Emostaromatatom{{\tt {\char'134}emostaromatatom}}
\def\Nmostaromatatom{{\tt {\char'134}nmostaromatatom}}
\def\Smostaromatatom{{\tt {\char'134}smostaromatatom}}
\def\Firstbicycloatom{{\tt {\char'134}firstbicycloatom}}
\def\Secondbicycloatom{{\tt {\char'134}secondbicycloatom}}
\def\Atom{{\tt {\char'134}atom}}
\def\Phantatom{{\tt {\char'134}phantatom}}
\def\Side{{\tt {\char'134}side}}
\def\Spin{{\tt {\char'134}spin}}
\def\Epin{{\tt {\char'134}epin}}
\def\Wpin{{\tt {\char'134}wpin}}
\def\Npin{{\tt {\char'134}npin}}
\def\Nopositioncheck{{\tt {\char'134}nopositioncheck}}
% --- \nopagenumbers
 
\section{INTRODUCTION}
 
\TeX\ offers excellent tools for mathematical formulae but lacks
corresponding commands
for most other fields of science. The purpose of this contribution
is to present the macro \Structure\ and a set of secondary
macros, which allow an easy
(but not unlimited) generation of the structural formulas used in
chemistry.
Portability should be guaranteed, since these macros are designed
to work in the plain \TeX\ environment.
No additional font tables are required.
 
The following sections explain the rules for usage and the limitations of
\Structure\ and all its secondary macros. As examples,
the instructions used to generate the figures
of this paper are listed in an appendix;
readers are encouraged to crosscheck this appendix
with the figures.
 
 
\section{THE CONNECTION TO PLAIN \TeX}
 
\Structure\ will generate a hbox, which can be used either
immediately or saved by
{\tt {\char'134}newbox{\char'134}name
{\char'134}setbox{\char'134}name={\char'134}structure{\char'173}...{\char'175}}
for a later
{\tt {\char'134}copy{\char'134}name} or {\tt {\char'134}box{\char'134}name},
if the same structural formula is needed
more than once.
 
The baseline of the hbox generated is identical
with the baseline of the first atom or bond entry in
the argument of \Structure,
height and depth depend on the subsequent entries. The width of this
hbox is adjusted by \Structure\ in processing the argument
twice: once, without printing, to determine the amount of backspacing
produced by all entries and a second time, after proper
kerning, to actually do the print. This two step process combines
correct positioning with the possibility to commence
the structural formula definition at any atom.
For testing purposes, or when starting with the leftmost atom,
the first pass can and should be suppressed by issuing the
command \Nopositioncheck\ as the first entry in the argument of \Structure.
 
The secondary macros, which actually generate the formulas, are
described in the following sections. They should only be used
inside the argument of \Structure; an outside use may cause severe troubles by
changing registers, dimensions, and boxes.
Additional macros are used by the secondary macros; the names of
these further macros contain one uppercase vowel somewhere in the
middle to avoid inference with other user defined macros.
 
\section{ATOMS AND BONDS}
 
Atoms are depicted in structural formulas by their chemical
symbol. It is easy to generate all possible symbols with
\TeX's font tables at hand, quite contrary to their proper
positioning. Latter is achieved by the \Atom\ macro with
the chemical symbol as the argument.
``Invisible'' atoms, i.\thinspace e. empty boxes with correct height,
depth, and width for a given chemical symbol, can be generated by the
\Phantatom\ macro with that symbol as the argument.
 
Chemical bonding is symbolized in structural formulas by lines
connecting the atoms. These lines also bear additional
information: electronic properties (single, double, or triple
bonding), nuclear geometry (esp. linear vs. non-linear), and
steric arrangement (in plane, above or below the plane).
The bond macros available in \Structure\ are named according to a
system which combines all these informations in a simple
way: the direction of the bond (given in ``geographic'' terms:
{\tt n}, {\tt nne}, {\tt ne}, {\tt ene}, {\tt e}, {\tt ese}, {\tt se},
{\tt sse}, {\tt s}, {\tt ssw}, {\tt sw}, {\tt wsw}, {\tt w}, {\tt wnw},
{\tt nw}, {\tt nnw}) is followed either by
{\tt single}, {\tt double}, {\tt triple}, or {\tt phantom}
(i.\thinspace e. invisible) for in-plane bonds or, for
out-of-plane bonds, by
{\tt below}, {\tt above}, or {\tt evoba} (i.\thinspace e. a bond
from above-plane down to in-plane).
Directions for in-plane and
out-of-plane bonds are not compatible:
\Nnwsingle, \Nnwdouble, \Nnwtriple, and \Nnwphantom\
have one common direction;
\Nnwabove, \Nnwevoba, and \Nnwbelow\ have another common direction,
which is slightly different from that of the
\Nnwsingle-group.
Not all combinations of direction and bond type are defined;
fig.~1 shows all available visible bonds with their
direction codes. Bond macros have no argument.
 
For correct positioning, the last entry of \Structure\ is
expected to be either \Atom\ or \Phantatom. (The first entry may be an atom
or a bond.)
 
\vskip 2truecm plus 2truecm
\input chemf1
\vskip 2truecm plus 2truecm
 
\section{RINGS}
 
The in-plane bonds allow a variety of ring shapes; fig.~2 shows
a sample collection. Rings built up by identical atoms will close
as perfect as the ones in fig.~2 do: the $(n+1)$th atom in a $n$-membered
ring is printed
exactly at the same position as the first atom. For rings built
up by different atoms, however, chances are high for a mismatch due to
different widths of the atom symbols. In such cases it is
adviseable to begin a ring with an \Atom\ and to end it with a \Phantatom.
 
\vskip 2truecm plus 2truecm
\input chemf2
\vskip 2truecm plus 2truecm
 
Aromatic rings can be specified by generating
four outmost ring atoms by \Wmostaromatatom, \Nmostaromatatom,
\Smostaromatatom, and
\Emostaromatatom\ instead of simply \Atom. The order of these four atoms is
arbitrary; they can not be made invisible though.
 
Unusually long single bonds, connecting atoms across a ring,
can be generated by using the macros \Firstbicycloatom\ and
\Secondbicycloatom\ instead of \Atom. Again, these atoms are always
visible. As the names indicate, the \Firstbicycloatom\ must be
definied before the \Secondbicycloatom.
Nesting of such long bond definitions is impossible:
a second or third bond
across a ring can not be specified before completion of the
previous one.
 
Both of these groups of macros
(aromatic rings and bicyclo bonds) use the same internal registers, so
they can only be used one after the other.
Chemists will not regret the impossibility to define a ring as both, aromatic
and bicyclic. They will, however, appreciate a facility to nest
bridging bonds for the generation of tricyclic or polycyclic
rings; the instructions used to generate fig.~3, which displays
an aromatic, a bicyclic, a tricyclic, and a tetracyclic ring, show
how to handle such problems.
 
Bicyclo bonds and the ellipses marking aromatic rings have more in
common than just internal registers: they can never be predefined in a
font table but have to be generated anew whenever needed
by a long sequence of tiny
little rule boxes. Only this method of generation makes them
flexible enough to handle all possible situations (fig.~3 and 4
show how different aromatic rings may look). There is, however, a
problem caused by this method of generation: it needs a large portion
of \TeX's memory. Pages full of aromatic rings or bicyclo bonds
may require memory enlargement. (This manuscript was prepared with
the standard main memory size of 58000.)
 
\vskip 2truecm plus 2truecm
\input chemf3
\vskip 2truecm plus 2truecm
 
Due to their generation by a series of rule boxes,
bicyclo bonds need considerably more computer
time than ordinary bonds do.
Whenever possible, bridging in bicyclic rings should therefore
be specified by normal bonds, as it was done in fig.~4. Bicyclo
bonds can also be used to close mismatching rings (as the one shown
in fig.~5 with mixed in-plane and out-of-plane bonds
having slightly different lengths).
 
\vskip 2truecm plus 2truecm
%\input chemf45
\vskip 2truecm plus 2truecm
 
\section{SIDE CHAINS}
 
Side chains are generated by the \Side\ macro.
(In this context, a ``side chain''
is anything attached to the main chain by some type of bond.)
The \Side\ macro argument is the sequence of bonds and atoms, which
define the side chain. This sequence must begin
with a bond and must end with an \Atom\ or \Phantatom.
 
\Side\ has to be called immediately after the atom, to which the
side chain is bound. The definition of the main
chain will be completely suspended while \Side\ is processed,
which is especially important for the definition of aromatic
rings or bicyclo bonds: partially specified aromatic rings or
bicyclo bonds will be saved when \Side\ is entered and restored
when \Side\ is left, thus \Side\ does not affect incomplete
specifications of aromatic rings or bicyclo bonds at all. Furthermore,
\Side\ is able to generate aromatic rings or bicyclo bonds of its own,
as long as all necessary specifications are part of its argument
(fig.~6 was generated in this way).
 
Side chains often have side chains themselves. Therefore \Side\ may
be called from inside \Side, the maximum nesting of side
chains being 20:
\Side\ may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side,
which in turn may be called from an outer \Side.
(Nesting side chains to that extent might need an enlargement of
\tex's input stack size; this manuscript was prepared with the
standard input stack size of 200.)
 
\vskip 2truecm plus 2truecm
\input chemf6
\vskip 2truecm plus 2truecm
 
\section{LARGER STRUCTURES}
 
Structural formulas of considerable complexity can be generated with the
macros discussed so far. Fig.~7--10 show a number of examples.
These examples have also been included to point out the following
details:
\noindent \Sseabove\ goes with \Sebelow\ in fig.~6 and with \Sswbelow\
in fig.~7 (as does \Nneabove\ with \Nebelow\ and \Nnebelow\ etc.);
 
\vskip 2truecm plus 2truecm
\input chemf7
\vskip 2truecm plus 2truecm
\input chemf8
\vskip 2truecm plus 2truecm
 
\noindent bonds below the plane may also be used to symbolize weak
bonds (fig.~9);
\noindent an active character ({\tt\catcode`\~=12 ~})
can be used to compensate additional superscripts or subscripts (fig.~9);
 
\vskip 2truecm plus 2truecm
\input chemf9
\vskip 2truecm plus 2truecm
 
\noindent the choice of baseline, eventually
with the help of invisible atoms and bonds, may be
essential when structural formulas are combined with text or other
symbols (fig.~10).
 
\vskip 2truecm plus 2truecm
\input chemf10
\vskip 2truecm plus 2truecm
 
For even larger structures like the ones shown in fig.~11 and 12
the four macros \Wpin, \Epin, \Spin, and \Npin\ may be of interest:
these macros generate side chains, which are attached to the main
chain without an explicitly drawn bond. Fig.~11 also illustrates the
multiple use of substructures saved in boxes.
 
\vskip 2truecm plus 2truecm
\input chemf11
\vfil\eject
\input chemf12
\vfill\eject
 
\section{APPENDIX}
 
Here the instructions used to generate the figures in this paper
are given.
 
\begingroup\frenchspacing\parindent=0pt
\catcode`\|=0  |catcode`|\=12 |catcode`|{=12 |catcode`|}=12 |catcode`|~=12
|catcode`|$=12 |catcode`|%=12 |catcode`|_=12 |catcode`|^=12 |obeylines
 
|bigskip|goodbreak|rm Fig. 1:|tt|bigskip|input chemf1
|bigskip|goodbreak|rm Fig. 2:|tt|bigskip|input chemf2
|bigskip|goodbreak|rm Fig. 3:|tt|bigskip|input chemf3
|bigskip|goodbreak|rm Fig. 4 |& 5:|tt|bigskip|input chemf45
|bigskip|goodbreak|rm Fig. 6:|tt|bigskip|input chemf6
|bigskip|goodbreak|rm Fig. 7:|tt|bigskip|input chemf7
|bigskip|goodbreak|rm Fig. 8:|tt|bigskip|input chemf8
|bigskip|goodbreak|rm Fig. 9:|tt|bigskip|input chemf9
|bigskip|goodbreak|rm Fig. 10:|tt|bigskip|input chemf10
|bigskip|goodbreak|rm Fig. 11:|tt|bigskip|input chemf11
|bigskip|goodbreak|rm Fig. 12:|tt|bigskip|input chemf12
 
|endgroup
\end
 
