summaryrefslogtreecommitdiffstats
path: root/contrib/chem
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/chem')
-rw-r--r--contrib/chem/ChangeLog373
-rw-r--r--contrib/chem/README.txt50
-rw-r--r--contrib/chem/chem.1.man925
-rw-r--r--contrib/chem/chem.am120
-rw-r--r--contrib/chem/chem.pic89
-rwxr-xr-xcontrib/chem/chem.pl1231
-rw-r--r--contrib/chem/examples/122/README.txt57
-rw-r--r--contrib/chem/examples/122/ch2a_ethyl.chem43
-rw-r--r--contrib/chem/examples/122/ch2b_benzene.chem38
-rw-r--r--contrib/chem/examples/122/ch2c_benzene_right.chem36
-rw-r--r--contrib/chem/examples/122/ch4a_stick.chem45
-rw-r--r--contrib/chem/examples/122/ch4b_methyl_acetate.chem47
-rw-r--r--contrib/chem/examples/122/ch4c_colon.chem42
-rw-r--r--contrib/chem/examples/122/ch4d_HCl.H2O.chem38
-rw-r--r--contrib/chem/examples/122/ch4e_CaSO4.2H2O.chem38
-rw-r--r--contrib/chem/examples/122/ch4f_C.chem48
-rw-r--r--contrib/chem/examples/122/ch4g_BP.chem48
-rw-r--r--contrib/chem/examples/122/ch4h_methacrylate.chem65
-rw-r--r--contrib/chem/examples/122/ch4i_cyclo.chem45
-rw-r--r--contrib/chem/examples/122/ch4j_ring4.chem40
-rw-r--r--contrib/chem/examples/122/ch4k_ring3.chem40
-rw-r--r--contrib/chem/examples/122/ch4l_vertex.chem45
-rw-r--r--contrib/chem/examples/122/ch4m_double.chem38
-rw-r--r--contrib/chem/examples/122/ch4n_triple.chem38
-rw-r--r--contrib/chem/examples/122/ch4o_aromatic.chem37
-rw-r--r--contrib/chem/examples/122/ch4p_cholestanol.chem60
-rw-r--r--contrib/chem/examples/122/ch4q_rings.chem46
-rw-r--r--contrib/chem/examples/122/ch4r_spiro.chem42
-rw-r--r--contrib/chem/examples/122/ch4s_heteroatoms.chem38
-rw-r--r--contrib/chem/examples/122/ch4t_polycyclic.chem49
-rw-r--r--contrib/chem/examples/122/ch4u_nicotine.chem42
-rw-r--r--contrib/chem/examples/122/ch4v_histidine.chem44
-rw-r--r--contrib/chem/examples/122/ch4w_lsd.chem50
-rw-r--r--contrib/chem/examples/122/ch4x_anisole.chem42
-rw-r--r--contrib/chem/examples/122/ch4y_reserpine.chem62
-rw-r--r--contrib/chem/examples/122/ch4z1_eqn_glutamic.chem78
-rw-r--r--contrib/chem/examples/122/ch4z2_text.chem53
-rw-r--r--contrib/chem/examples/122/ch5a_size.chem45
-rw-r--r--contrib/chem/examples/122/ch6a_pic.chem43
-rw-r--r--contrib/chem/examples/122/ch6b_dna.chem59
-rw-r--r--contrib/chem/examples/122/chAa_polymer.chem72
-rw-r--r--contrib/chem/examples/122/chAb_vinyl_chloro.chem62
-rw-r--r--contrib/chem/examples/122/chAc_morphine.chem52
-rw-r--r--contrib/chem/examples/122/chAd_chlorophyll.chem69
-rw-r--r--contrib/chem/examples/122/chAe_chair.chem49
-rw-r--r--contrib/chem/examples/122/chAf_arrow.chem68
-rw-r--r--contrib/chem/examples/122/chAg_circle.chem54
-rw-r--r--contrib/chem/examples/122/chAh_brackets.chem60
-rw-r--r--contrib/chem/examples/122/chAi_poly_vinyl_chloride.chem141
-rw-r--r--contrib/chem/examples/122/chBa_jump.chem41
-rw-r--r--contrib/chem/examples/122/chBb_bonds.chem42
-rw-r--r--contrib/chem/examples/122/chBc_rings.chem43
-rw-r--r--contrib/chem/examples/README.txt47
-rw-r--r--contrib/chem/examples/atp.chem58
-rw-r--r--contrib/chem/examples/cholesterin.chem47
-rw-r--r--contrib/chem/examples/ethamivan.chem43
-rw-r--r--contrib/chem/examples/lsd.chem46
-rw-r--r--contrib/chem/examples/morphine.chem51
-rw-r--r--contrib/chem/examples/penicillin.chem52
-rw-r--r--contrib/chem/examples/reserpine.chem63
60 files changed, 5529 insertions, 0 deletions
diff --git a/contrib/chem/ChangeLog b/contrib/chem/ChangeLog
new file mode 100644
index 0000000..ad40944
--- /dev/null
+++ b/contrib/chem/ChangeLog
@@ -0,0 +1,373 @@
+2022-08-18 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * chem.pl: Refactor.
+ - Rename scalars.
+ Copyright -> copyright
+ Program_Version -> chem_version
+ Groff_Version -> groff_version
+ Chem_Name -> chem
+ before_make -> is_in_source_tree
+ - Rename hash.
+ at_at -> makevar
+ - Drop unused hash member `$makevar{'BINDIR'}`.
+ - Drop scalar `Groff_Version_Preset`, which apparently hadn't
+ been updated since groff 1.20. Instead, follow grog(1) and
+ set the `groff_version` scalar to "DEVELOPMENT" if this is
+ the version from the groff source tree. Overwrite its value
+ with that determined by make(1) if available.
+ - Tighten usage and version messages; make the latter more
+ conformant with the format recommended in the GNU Coding
+ Standards. Explicitly identify license as GNU GPLv2.
+ (usage): Refer to "pic" with its command prefix if it is known
+ to have one. (If running "unbuilt", we have no way to know.)
+
+2022-08-18 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * chem.pl: Stop copying "pic.tmac" (fallback troff macro
+ definitions) into the output. It might not be necessary and it
+ is inappropriate to do so if a macro package offers its own
+ definitions or the user has made other arrangements on the
+ command line. (The same thing can be achieved with the "-mpic"
+ argument to the formatter or a front end.) Bump version number.
+
+2022-06-15 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * chem.1.man: Fix markup nits. Use idiomatic input style,
+ placing newlines after sentences and commas. Also put an empty
+ request between sentences.
+
+ Fixes <https://savannah.gnu.org/bugs/?51328>.
+
+2022-04-12 Ingo Schwarze <schwarze@openbsd.org>
+
+ Delete the harmful, ill-designed, buggy, and essentially
+ unmaintained and untested --with-doc option of the configure
+ script. See the NEWS file for more details on the rationale.
+
+ * chem.am: Delete three BUILD_EXAMPLES conditionals.
+
+2020-04-22 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * chem.1.man:
+ * examples/122/README.txt:
+ * examples/README.txt: Delete references to groffer.
+
+2018-02-28 Werner LEMBERG <wl@gnu.org>
+
+ * chem.am (chem, README): Use $(AM_V_GEN) to silence file generation.
+
+2015-08-22 Bernd Warken <bernd.warken@web.de>
+
+ * chem.1.man: Rename `chem.man'.
+
+ * chem.am: Include renaming.
+
+2015-08-05 Bernd Warken <bernd.warken@web.de>
+
+ * chem.am: Add `Last update'. Setup Emacs makefile-automake-mode.
+
+2015-04-03 Werner LEMBERG <wl@gnu.org>
+
+ * chem.man: Make it work in compatibility mode.
+ (EL): Fix typo.
+
+2014-09-25 Bernd Warken <bernd.warken@web.de>
+
+ * chem.pl: New chem version 1.0.5.
+
+ * Makefile.sub: Add .PHONY. Restructure install and uninstall.
+
+2014-09-03 Bernd Warken <bernd.warken@web.de>
+
+ * chem.pl: New chem version 1.0.4. Change version().
+
+ * all `chem' source files: Add and improve the copying
+ information. Remove last update. Add Emacs setting if necessary.
+
+2014-07-05 Bernd Warken <bernd.warken@web.de>
+ ________________________________________________________________
+ * chem.pl: New chem version 1.0.3
+
+ * chem.man: Make file doclifter compatible.
+
+2014-07-04 Bernd Warken <bernd.warken@web.de>
+ ________________________________________________________________
+ * release of chem 1.0.2
+
+ * chem.man: Remove definition of `.FONT'.
+
+2014-07-04 Bernd Warken <bernd.warken@web.de>
+
+ * chem.man: Transform into classical man-page style.
+
+2014-07-04 Bernd Warken <bernd.warken@web.de>
+
+ * chem.man: Remove definition of .Env-var.
+
+2014-07-03 Bernd Warken <bernd.warken@web.de>
+ ________________________________________________________________
+ * release of chem 1.0.1
+
+ * chem.man: Add `.mso' for `groffer.man'.
+
+2014-06-17 Bernd Warken <bernd.warken@web.de>
+ ________________________________________________________________
+ * release of chem 1.0.0
+
+ * Makefile.sub: Add Emacs final part.
+
+ * ChangeLog: Correct the space characters in this file as Emacs
+ style.
+
+2014-03-29 Steffen Nurpmeso <sdaoden@yandex.com>
+
+ * Makefile.sub (uninstall_examples): Remove superfluous `rmdir'.
+
+2014-03-29 Steffen Nurpmeso <sdaoden@yandex.com>
+
+ * Makefile.sub (install_examples): Use `find', not shell globs.
+
+ Instead of using rm(1) two times with shell globs the expansion of
+ which will include subdirectories (thus resulting in error
+ messages), use find(1) and its `-exec' operand.
+
+2014-03-29 Steffen Nurpmeso <sdaoden@yandex.com>
+
+ * Makefile.sub: Handle examples separately, controlled by
+ $(make{_,_install_,_uninstall_}examples).
+
+2013-01-29 Bernd Warken <bernd.warken@web.de>
+
+ * all: Change license into GPL2.
+
+2013-01-29 Werner LEMBERG <wl@gnu.org>
+
+ * Makefile.sub (MOSTLYCLEANADD): Fix typo.
+
+2010-12-13 Werner LEMBERG <wl@gnu.org>
+
+ Really fix handling of examples/122.
+
+ * examples/122/README: Renamed to...
+ * examples/122/README.txt: This.
+
+ * Makefile.sub (all, MOSTLYCLEANADD): Add `examples/122/README'.
+ (examples/122/README): New target.
+ (install_data): Fix typo.
+
+2010-06-02 Larry Jones <lawrence.jones@siemens.com>
+
+ * Makefile.sub (install): Fix handling of examples/122.
+ It tried to process the CVS subdirectory as a file.
+
+2009-01-03 Werner LEMBERG <wl@gnu.org>
+
+ * chem.pl: Prepare for groff version 1.20.
+
+2008-01-04 Werner LEMBERG <wl@gnu.org>
+
+ * chem.man: Insert `\:' in URLs where appropriate.
+
+2007-02-06 Eric S. Raymond <esr@snark.thyrsus.com>
+
+ * chem.man: Change .UR/.UE and .MT/.ME so the start macro no
+ longer takes a second argument that is pasted to the end of the
+ generated text. Instead, the end macro takes an argument that
+ does the same thing.
+
+2007-02-02 Werner LEMBERG <wl@gnu.org>
+
+ * chem.man: Further refinements and normalizations.
+
+2007-02-02 Eric S. Raymond <esr@snark.thyrsus.com>
+
+ * chem.man: Converted to use .SY/.OP/.YS and for cross-viewer
+ portability. Conversion checked using the protocol described in
+ tmac/TESTING-HINTS.
+
+2006-11-10 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.3.1
+
+ * chem.man: Add information about example files.
+
+2006-11-10 Werner LEMBERG <wl@gnu.org>
+
+ * chem.man1: Rename back to...
+ * chem.man: This.
+ Use @G@, @MACRODIR@, and @DATASUBDIR@.
+
+ * Makefile.sub (CLEANADD, all): Don't handle chem.man.
+ (chem.man): Remove rule.
+ (chem): s/tmacdir/MACRODIR/, s/picdir/PICDIR/.
+
+ * chem.pl: s/tmacdir/MACRODIR/, s/picdir/PICDIR/.
+
+2006-11-10 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.3.0
+
+ * chem.man1: Rename `chem.man' to translate some `@...@'
+ constructs. Some minor corrections. Remove some unused macros.
+
+ * examples/README.txt, examples/122/README: Add information on
+ `roff2*' programs.
+
+ * chem.pic: Rename `macros.pic'.
+
+ * Makefile.sub, chem.pl: Replace `macros.pic' by `chem.pic'.
+
+2006-11-09 Werner LEMBERG <wl@gnu.org>
+
+ * chem.man: Revised.
+
+2006-11-08 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.2.0
+
+ * pic.tmac: Remove this file. Use instead the installed pic.tmac
+ in $(tmacdir).
+
+ * Makefile.sub, chem.pl:
+ - Install macros.pic to $(tmacdir)/pic/chem.pic.
+ - Remove parts with `libdir'.
+
+2006-11-07 Werner LEMBERG <wl@gnu.org>
+
+ * Makefile.sub: Add and fix $(srcdir) where necessary to make it
+ compile with srcdir != builddir. Other minor fixes improvements.
+
+2006-11-07 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.1.2
+
+ ### `chem' works now with all example files (examples/*.chem and
+ examples/122/*.chem).
+
+ * examples/122/README: Add some information on the example files.
+
+ * examples/122/chAi_poly_vinyl_chloride.chem: Use .ps with
+ argument `-2' and recall `.ps +2' at the end of the file. This
+ stops the size shift in the following files.
+
+ * examples/122/ch6b_dna.chem: Make the file runnable, it works
+ now.
+
+ * examples/reserpine.chem: Change access to `begin chem'.
+
+ * chem.man:
+ - Fix the BUGS section.
+ - Correct the name of the macro file to `macros.pic'.
+ - Extent section DESCRIPTION and LANGUAGE.
+ - Moieties and Strings: Rewritten section about moieties and
+ double quoted strings.
+
+ * chem.pl:
+ - parameter check: Add filespecs only when non-empty file.
+ - Set $Last_Type to $OTHER for the `pic' command.
+ - joinring(), label(), labsave(), reduce(): Remove these functions.
+ - `[', `]', `{', `}', `define': Make these and the defined
+ functions commands for `chem' without using the `pic' word.
+ - @Words: Fix it such that all double quoted strings are
+ completely in an element.
+ - `Last: ': Remove this prefix from all commands that are related
+ to `pic'.
+
+ ### global variables
+
+ * chem.pl:
+ - $Line: Add this variable to store the unchanged input line.
+ - %Params: Add the variables from setparams() to this hash.
+ - %Types: Add BOND, MOL, RING, OTHER from init() to this hash.
+ - %Put: Move %put to this.
+ - %Dbl: Move %dbl to this.
+ - %Labtype: Move %labtype to this.
+ - %Aromatic: Move $aromatic to this.
+ - %Dc: Move %dc to this.
+ - %Nput: Move $nput to this.
+ - %Define: New hash for storing the names of the `define'
+ constructs during `chem'. Use the elements in `%Define' as `chem'
+ commands.
+
+2006-10-27 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.1.1
+
+ * chem.pl:
+ - Add handling of `[' and `]' (extension of chem awk).
+ - Restrict line break after labels.
+
+ * ChangeLog: Correct the former entry.
+
+2006-10-26 Bernd Warken <groff-bernd.warken-72@web.de>
+ ________________________________________________________________
+ * release of chem 0.1.0
+
+ ### Extensions to the chem awk version.
+
+ * chem.pl:
+ - parameters: -h, --help, -v, --version, -- are added as options.
+ The minus character - is added as filespec for standard input, it
+ may be used several times.
+ - remove the functions `inline', `shiftfields', and `set'.
+ - Fix the handling of the initialization commands .PS, .cstart,
+ `begin chem', and `end'.
+ - Add error massages.
+ - error(): Add file name.
+ - Add concatenation of lines with final backslash `\'.
+ - Add pic.tmac to guarantee that each pic display is centered.
+ - Warnings and strict are active.
+
+ ### Source files of the chem Perl version
+
+ * chem.pl: Source file for the Perl version of chem.
+
+ * macros.pic: Pic macro file that is loaded by each run of chem.
+
+ * pic.tmac: Macro file for .PS and .PE; taken over from the groff
+ source file <groff-top-source>/tmac/pic.tmac.
+
+ * Makefile.sub: Make file for the groff system.
+
+ * ChangeLog: This file.
+
+ * chem.man: Manual page for the Perl version of chem.
+
+ * README.txt: File for information on this chem version.
+
+ * examples/*.chem: Self-constructed example files for chem.
+
+ * examples/README.txt: Information on the example files.
+
+ * examples/122/*.chem: Example files from the classical chem book
+ 122.ps at <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+ * examples/122/README: Information on the example files in this
+ directory.
+
+2006-10-16 Bernd Warken <groff-bernd.warken-72@web.de>
+
+ * awk version of chem
+ chem is a roff preprocessor that generates chemical structure
+ diagrams suitable for the pic preprocessor. The original version
+ of chem is an awk script written by Brian Kernighan. This project
+ is a rewrite of chem in Perl.
+
+2006-10-15 Bernd Warken <groff-bernd.warken-72@web.de>
+________________________________________________________________
+License
+
+Copyright (C) 2006-2020 Free Software Foundation, Inc.
+Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+Copying and distribution of this file, with or without
+modification, are permitted provided the copyright notice and this
+notice are preserved.
+
+This file is part of `chem', which is part of the `groff' project.
+
+
+##### Editor settings
+Local Variables:
+mode: change-log
+End:
diff --git a/contrib/chem/README.txt b/contrib/chem/README.txt
new file mode 100644
index 0000000..06baed2
--- /dev/null
+++ b/contrib/chem/README.txt
@@ -0,0 +1,50 @@
+'chem' is a 'roff' language to generate chemical structure diagrams.
+'@g@chem' is a 'groff' preprocessor that produces output suitable for
+the '@g@pic' preprocessor.
+
+The original version of 'chem' is an 'awk' script written by Brian
+Kernighan <http://cm.bell-labs.com/cm/cs/who/bwk/index.html>. The
+source files of the 'awk' version of 'chem' are available at
+<http://cm.bell-labs.com/netlib/typesetting/chem.gz>.
+
+This project is a rewrite of 'chem' in Perl for the GNU 'roff' project
+'groff'. It was written under Perl v5.8.8, but at least Perl v5.6 is
+needed to run the Perl version of 'chem'.
+
+In comparison to the original 'awk' version of 'chem', the Perl
+version does the following changements:
+- the options -h, --help, -v, --version to output usage and version
+information are added.
+- remove some functions 'inline', 'shiftfields', and 'set' and some
+variables that are used only once.
+
+The subdirectory 'examples/' contains example files for chem. They
+are written in the 'chem' language. The file names end with .chem.
+
+
+####### License
+
+Copyright (C) 2006-2020 Free Software Foundation, Inc.
+Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+This file is part of 'chem', which is part of 'groff'.
+
+'groff' is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License (GPL) version 2 as
+published by the Free Software Foundation.
+
+'groff' is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+The GPL2 license text is available in the internet at
+<http://www.gnu.org/licenses/gpl-2.0.html>.
+
+
+##### Editor settings
+Local Variables:
+fill-column: 72
+mode: text
+End:
+vim: set textwidth=72:
diff --git a/contrib/chem/chem.1.man b/contrib/chem/chem.1.man
new file mode 100644
index 0000000..a02242f
--- /dev/null
+++ b/contrib/chem/chem.1.man
@@ -0,0 +1,925 @@
+.TH @g@chem @MAN1EXT@ "@MDATE@" "groff @VERSION@"
+.SH Name
+@g@chem \- embed chemical structure diagrams in
+.I groff
+documents
+.
+.
+.\" ====================================================================
+.\" Legal Terms
+.\" ====================================================================
+.\"
+.\" Copyright (C) 2006-2020 Free Software Foundation, Inc.
+.\"
+.\" This file is part of chem, which is part of groff, a free software
+.\" project.
+.\"
+.\" You can redistribute it and/or modify it under the terms of the GNU
+.\" General Public License version 2 (GPL2) as published by the Free
+.\" Software Foundation.
+.\"
+.\" The license text for GPL2 is available in the internet at
+.\" <http://www.gnu.org/licenses/gpl-2.0.html>.
+.
+.
+.\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
+.do nr *groff_chem_1_man_C \n[.cp]
+.cp 0
+.
+.\" Define fallback for groff 1.23's MR macro if the system lacks it.
+.nr do-fallback 0
+.if !\n(.f .nr do-fallback 1 \" mandoc
+.if \n(.g .if !d MR .nr do-fallback 1 \" older groff
+.if !\n(.g .nr do-fallback 1 \" non-groff *roff
+.if \n[do-fallback] \{\
+. de MR
+. ie \\n(.$=1 \
+. I \%\\$1
+. el \
+. IR \%\\$1 (\\$2)\\$3
+. .
+.\}
+.rr do-fallback
+.
+.
+.\" ====================================================================
+.SH Synopsis
+.\" ====================================================================
+.
+.SY @g@chem
+.RB [ \-\- ]
+.RI [ file\~ .\|.\|.]
+.YS
+.
+.
+.SY @g@chem
+.B \-h
+.
+.SY @g@chem
+.B \-\-help
+.YS
+.
+.
+.SY @g@chem
+.B \-v
+.
+.SY @g@chem
+.B \-\-version
+.YS
+.
+.
+.\" ====================================================================
+.SH Description
+.\" ====================================================================
+.
+.I chem
+produces chemical structure diagrams.
+.
+Today's version is best suited for organic chemistry (bonds, rings).
+.
+The
+.I @g@chem
+program is a
+.I groff
+preprocessor like
+.IR @g@eqn ,
+.IR @g@pic ,
+.IR @g@tbl ,
+etc.
+.
+It generates
+.I pic
+output such that all
+.I chem
+parts are translated into diagrams of the
+.I pic
+language.
+.
+.
+.P
+If no operands are given,
+or if
+.I file
+is
+.RB \[lq] \- \[rq],
+.I @g@chem
+reads the standard input stream.
+.
+.B \-h
+and
+.B \-\-help
+display a usage message,
+whereas
+.B \-v
+and
+.B \-\-version
+display version information;
+all exit.
+.
+.
+.P
+The program
+.I @g@chem
+originates from the Perl source file
+.IR chem.pl .
+.
+It tells
+.I @g@pic
+to include a copy of the macro file
+.IR chem.pic .
+.
+Moreover the
+.I groff
+source file
+.I pic.tmac
+is loaded.
+.
+.
+.P
+In a style reminiscent of
+.I eqn
+and
+.IR pic ,
+the
+.I chem
+diagrams are written in a special language.
+.
+.
+.P
+A set of
+.I chem
+lines looks like this
+.
+.
+.IP
+.EX
+\&.cstart
+.I chem data
+\&.cend
+.EE
+.
+.
+.P
+Lines containing the keywords
+.B .cstart
+and
+.B .cend
+start and end the input for
+.IR @g@chem ,
+respectively.
+.
+In
+.I pic
+context, i.e., after the call of
+.BR .PS ,
+.I chem
+input can optionally be started by the line
+.B \%begin\~chem
+and ended by the line with the single word
+.B end
+instead.
+.
+.
+.P
+Anything outside these initialization lines is copied through
+without modification;
+all data between the initialization lines is converted into
+.I pic
+commands to draw the diagram.
+.
+.
+.P
+As an example,
+.
+.IP
+.EX
+\&.cstart
+CH3
+bond
+CH3
+\&.cend
+.EE
+.
+.
+.P
+prints two
+.B CH3
+groups with a bond between them.
+.
+.
+.P
+If you want to create just
+.I groff
+output, you must run
+.I @g@chem
+followed by
+.I groff
+with the option
+.B \-p
+for the activation of
+.IR @g@pic :
+.IP
+.I @g@chem
+.RI [ file\~ .\|.\|.\&]
+.BR "| groff \-p\~" .\|.\|.
+.
+.
+.\" ====================================================================
+.SH Language
+.\" ====================================================================
+.
+The
+.I chem
+input language is rather small.
+.
+It provides rings of several styles and a way to glue them together as
+desired,
+bonds of several styles,
+moieties
+(e.g.,
+.BR C ,
+.BR NH3 ,
+\&.\|.\|.,
+and strings.
+.
+.
+.\" ====================================================================
+.SS "Setting variables"
+.\" ====================================================================
+.
+There are some variables that can be set by commands.
+.
+Such commands have two possible forms, either
+.
+.RS
+.P
+.I "variable value"
+.RE
+.
+.P
+or
+.
+.RS
+.P
+.IB "variable " = " value"
+.RE
+.
+.P
+This sets the given
+.I variable
+to the argument
+.IR value .
+If more arguments are given only the last argument is taken, all other
+arguments are ignored.
+.
+.
+.P
+There are only a few variables to be set by these commands:
+.
+.TP
+.BI textht " arg"
+Set the height of the text to
+.IR arg ;
+default is 0.16.
+.
+.TP
+.BI cwid " arg"
+Set the character width to
+.IR arg ;
+default is 0.12.
+.
+.TP
+.BI db " arg"
+Set the bond length to
+.IR arg ;
+default is 0.2.
+.
+.TP
+.BI size " arg"
+Scale the diagram to make it look plausible at point size
+.IR arg ;
+default is 10 point.
+.
+.
+.\" ====================================================================
+.SS Bonds
+.\" ====================================================================
+.
+This
+.
+.RS
+.SY bond
+.RI [ direction ]
+.RI [ length\ n ]
+.RB [ from\ \c
+.IR Name | picstuff ]
+.YS
+.RE
+.
+.P
+draws a single bond in direction from nearest corner of
+.IR Name .
+.B bond
+can also be
+.BR "double bond" ,
+.BR "front bond" ,
+.BR "back bond" ,
+etc.
+.
+(We will get back to
+.I Name
+soon.)
+.
+.
+.P
+.I direction
+is the angle in degrees (0\~up, positive clockwise)
+or a direction word like
+.BR up ,
+.BR down ,
+.B sw
+(=\~southwest), etc.
+.
+If no direction is specified, the bond goes in the current direction
+(usually that of the last bond).
+.
+.
+.P
+Normally the bond begins at the last object placed; this
+can be changed by naming a
+.B from
+place.
+.
+For instance, to make a simple alkyl chain:
+.
+.RS
+.TS
+tab (@);
+lb l.
+CH3
+bond@(this one goes right from the CH3)
+C@(at the right end of the bond)
+double bond up@(from the C)
+O@(at the end of the double bond)
+bond right from C
+CH3
+.TE
+.RE
+.
+.
+.P
+A length in inches may be specified to override the default length.
+.
+Other
+.I pic
+commands can be tacked on to the end of a bond command, to created
+dotted or dashed bonds or to specify a
+.B to
+place.
+.
+.
+.\" ====================================================================
+.SS Rings
+.\" ====================================================================
+.
+There are lots of rings,
+but only five- and six-sided rings get much support.
+.
+.B ring
+by itself is a six-sided ring;
+.B benzene
+is the benzene ring with a circle inside.
+.B aromatic
+puts a circle into any kind of ring.
+.
+.RS
+.SY ring
+.RB [ \%pointing\ ( up | right | left | down )]
+.RB [ \%aromatic ]
+.RB [ put\ Mol\ at\ \fIn\/\fP ]
+.RB [ \%double\ \c
+.IR i , j\ \/\c
+.IR k , l\ \/\c
+\&.\|.\|.\&
+.RI [ picstuff ]
+.YS
+.RE
+.
+.
+.P
+The vertices of a ring are numbered 1, 2, \&.\|.\|.\& from the
+vertex that points in the natural compass direction.
+.
+So for a hexagonal ring with the point at the top, the top vertex
+is\~1, while if the ring has a point at the east side, that is
+vertex\~1.
+.
+This is expressed as
+.
+.IP
+.EX
+R1: ring pointing up
+R2: ring pointing right
+.EE
+.
+.
+.P
+The ring vertices are named
+.BR .V1 ,
+\&.\|.\|.,
+.BI .V n\fR,\fP
+with
+.B .V1
+in the pointing direction.
+.
+So the corners of
+.B R1
+are
+.B R1.V1
+(the
+.IR top ),
+.BR R1.V2 ,
+.BR R1.V3 ,
+.B R1.V4
+(the
+.IR bottom ),
+etc., whereas for
+.BR R2 ,
+.B R2.V1
+is the rightmost vertex and
+.B R2.V4
+the leftmost.
+.
+These vertex names are used for connecting bonds or other rings.
+.
+For example,
+.
+.IP
+.EX
+R1: benzene pointing right
+R2: benzene pointing right with .V6 at R1.V2
+.EE
+.
+.
+.P
+creates two benzene rings connected along a side.
+.
+.
+.P
+Interior double bonds are specified as
+.B \%double
+.IB n1 , "n2 n3" , n4
+.RB .\|.\|. ;
+each number pair adds an interior bond.
+.
+So the alternate form of a benzene ring is
+.
+.IP
+.B "ring double 1,2 3,4 5,6"
+.
+.
+.P
+Heterocycles (rings with something other than carbon at a vertex) are
+written as
+.BI put\ X\ at\ V\fR,\fP
+as in
+.
+.IP
+.B "R: ring put N at 1 put O at 2"
+.
+.
+.P
+In this heterocycle,
+.B R.N
+and
+.B R.O
+become synonyms for
+.B R.V1
+and
+.BR R.V2 .
+.
+.
+.P
+There are two five-sided rings.
+.
+.B ring5
+is pentagonal with a side that matches the six-sided ring;
+it has four natural directions.
+.
+A
+.B \%flatring
+is a five-sided ring created by chopping one corner of a six-sided ring
+so that it exactly matches the six-sided rings.
+.
+.
+.P
+The description of a ring has to fit on a single line.
+.
+.
+.\" ====================================================================
+.SS "Moieties and strings"
+.\" ====================================================================
+.
+A moiety is a string of characters beginning with a capital letter,
+such as N(C2H5)2.
+.
+Numbers are converted to subscripts (unless they appear to be
+fractional values, as in N2.5H).
+.
+The name of a moiety is determined from the moiety after special
+characters have been stripped out: e.g., N(C2H5)2) has the name NC2H52.
+.
+.
+.P
+Moieties can be specified in two kinds.
+.
+Normally a moiety is placed right after the last thing mentioned,
+separated by a semicolon surrounded by spaces, e.g.,
+.
+.IP
+.B "B1: bond ; OH"
+.
+.P
+Here the moiety is
+.BR OH ;
+it is set after a bond.
+.
+.
+.P
+As the second kind a moiety can be positioned as the first word in a
+.IR pic -like
+command, e.g.,
+.
+.IP
+.B "CH3 at C + (0.5,0.5)"
+.
+.P
+Here the moiety is
+.BR CH3 .
+It is placed at a position relative to
+.BR C ,
+a moiety used earlier in the chemical structure.
+.
+.
+.P
+So moiety names can be specified as
+.I chem
+positions everywhere in the
+.I chem
+code.
+.
+Beneath their printing moieties are names for places.
+.
+.
+.P
+The moiety
+.B BP
+is special.
+.
+It is not printed but just serves as a mark to be referred to in later
+.I chem
+commands.
+.
+For example,
+.
+.IP
+.B "bond ; BP"
+.
+.P
+sets a mark at the end of the bond.
+.
+This can be used then for specifying a place.
+.
+The name
+.B BP
+is derived from
+.I branch point
+(i.e., line crossing).
+.
+.
+.P
+A string within double quotes
+.B \(dq
+is interpreted as a part of a
+.I chem
+command.
+.
+It represents a string that should be printed (without the quotes).
+.
+Text within quotes
+.BR \(dq .\|.\|.\& \(dq
+is treated more or less like a moiety except that no changes are made to
+the quoted part.
+.
+.
+.\" ====================================================================
+.SS Names
+.\" ====================================================================
+.
+In the alkyl chain above, notice that the carbon atom
+.B C
+was used both to draw something and as the name for a place.
+.
+A moiety always defines a name for a place; you can use
+your own names for places instead, and indeed, for rings
+you will have to.
+.
+A name is just
+.
+.IP
+.IB Name :
+\&.\|.\|.
+.
+.
+.P
+.I Name
+is often the name of a moiety like
+.BR CH3 ,
+but it need not to be.
+.
+Any name that begins with a capital letter and which contains
+only letters and numbers is valid:
+.
+.RS
+.TP
+.B First:
+.B bond
+.TQ
+\&
+.B "bond 30 from First"
+.RE
+.
+.
+.\" ====================================================================
+.SS Miscellaneous
+.\" ====================================================================
+.
+The specific construction
+.RS
+.TP
+.BR bond \~.\|.\|.\&\~ "; moiety"
+.RE
+.P
+is equivalent to
+.IP
+.EX
+bond
+moiety
+.EE
+.
+.
+.P
+Otherwise, each item has to be on a separate line (and only one line).
+Note that there must be whitespace after the semicolon which separates
+the commands.
+.
+.
+.P
+A period character
+.B .\&
+or a single quote
+.B \[aq]
+in the first column of a line signals a
+.I troff
+command, which is copied through as-is.
+.
+.
+.P
+A line whose first non-blank character is a hash character
+.RB ( # )
+is treated as a comment and thus ignored.
+.
+However, hash characters within a word are kept.
+.
+.
+.P
+A line whose first word is
+.B pic
+is copied through as-is after the word
+.B pic
+has been removed.
+.
+.
+.P
+The command
+.IP
+.B size
+.I n
+.P
+scales the diagram to make it look plausible at point size\~\c
+.I n
+(default is 10\~point).
+.
+.
+.P
+Anything else is assumed to be
+.I pic
+code, which is copied through with a label.
+.
+.
+.P
+Since
+.I @g@chem
+is a
+.I @g@pic
+preprocessor, it is possible to include
+.I pic
+statements in the middle of a diagram to draw things not provided for
+by
+.I chem
+itself.
+.
+Such
+.I pic
+statements should be included in
+.I chem
+code by adding
+.B pic
+as the first word of this line for clarity.
+.
+.
+.P
+The following
+.I pic
+commands are accepted as
+.I chem
+commands, so no
+.B pic
+command word is needed:
+.
+.IP
+.B define
+Start the definition of
+.I pic
+macro within
+.IR chem .
+.
+.RS
+.TP
+.B [
+Start a block composite.
+.
+.TP
+.B ]
+End a block composite.
+.
+.TP
+.B {
+Start a macro definition block.
+.
+.TP
+.B }
+End a macro definition block.
+.RE
+.
+.P
+The macro names from
+.B define
+statements are stored and their call is accepted as a
+.I chem
+command as well.
+.
+.
+.\" ====================================================================
+.SS "Wish list"
+.\" ====================================================================
+.
+.P
+This TODO list was collected by Brian Kernighan.
+.
+.
+.P
+Error checking is minimal; errors are usually detected and reported in
+an oblique fashion by
+.IR pic .
+.
+.
+.P
+There is no library or file inclusion mechanism, and there is no
+shorthand for repetitive structures.
+.
+.
+.P
+The extension mechanism is to create
+.I pic
+macros, but these are tricky to get right and don't have all the
+properties of built-in objects.
+.
+.
+.P
+There is no in-line chemistry yet
+(e.g.,
+analogous to the
+.BR $ .\|.\|. $
+construct of
+.IR eqn ).
+.
+.
+.P
+There is no way to control entry point for bonds on groups.
+.
+Normally a bond connects to the carbon atom if entering from
+the top or bottom and otherwise to the nearest corner.
+.
+.
+.P
+Bonds from substituted atoms on heterocycles do not join at the proper
+place without adding a bit of
+.IR pic .
+.
+.
+.P
+There is no decent primitive for brackets.
+.
+.
+.P
+Text (quoted strings) doesn't work very well.
+.
+.
+.P
+A squiggle bond is needed.
+.
+.
+.\" ====================================================================
+.SH Files
+.\" ====================================================================
+.
+.TP
+.I @DATASUBDIR@/\:pic/\:chem\:.pic
+A collection of
+.I pic
+macros needed by
+.IR @g@chem .
+.
+.TP
+.I @MACRODIR@/\:pic\:.tmac
+A macro file which redefines
+.BR .PS ,
+.BR .PE ,
+and
+.B .PF
+to center
+.I pic
+diagrams.
+.
+.TP
+.IR @DOCDIR@/\:\%examples/\:chem/\: * .chem
+Example files for
+.IR chem .
+.
+.TP
+.IR @DOCDIR@/\:\%examples/\:chem/\:122/\: * .chem
+Example files from the
+.I chem
+article by its authors,
+\[lq]CHEM\[em]A Program for Typesetting Chemical Structure Diagrams:
+User Manual\[rq]
+(CSTR\~#122).
+.
+.
+.\" ====================================================================
+.SH Authors
+.\" ====================================================================
+.
+The GNU version of
+.I chem
+was written by
+.MT groff\-bernd\:.warken\-72@\:web\:.de
+Bernd Warken
+.ME .
+.
+It is based on the documentation of Brian Kernighan's original
+.I awk
+version of
+.IR chem .
+.
+.
+.\" ====================================================================
+.SH "See also"
+.\" ====================================================================
+.
+\[lq]CHEM\[em]A Program for Typesetting Chemical Diagrams: User
+Manual\[rq]
+by Jon L.\& Bentley,
+Lynn W.\& Jelinski,
+and
+Brian W.\& Kernighan,
+1992,
+AT&T Bell Laboratories Computing Science Technical Report No.\& 122
+.
+.
+.P
+.MR groff @MAN1EXT@ ,
+.MR @g@pic @MAN1EXT@
+.
+.
+.\" Restore compatibility mode (for, e.g., Solaris 10/11).
+.cp \n[*groff_chem_1_man_C]
+.do rr *groff_chem_1_man_C
+.
+.
+.\" Local Variables:
+.\" fill-column: 72
+.\" mode: nroff
+.\" End:
+.\" vim: set filetype=groff textwidth=72:
diff --git a/contrib/chem/chem.am b/contrib/chem/chem.am
new file mode 100644
index 0000000..abee480
--- /dev/null
+++ b/contrib/chem/chem.am
@@ -0,0 +1,120 @@
+# Automake rules for 'chem'
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+# Moved to automake by Bertrand Garrigues
+#
+# This file is part of 'chem' which is part of 'groff'.
+#
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+#
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+chem_srcdir = $(top_srcdir)/contrib/chem
+prefixexecbin_SCRIPTS += chem
+
+# Files installed in $(datasubdir)/pic
+chempicdir = $(datasubdir)/pic
+dist_chempic_DATA = contrib/chem/chem.pic
+
+
+CHEM_GENEXAMPLES = contrib/chem/examples/README
+CHEM_EXAMPLES = \
+ contrib/chem/examples/atp.chem \
+ contrib/chem/examples/cholesterin.chem \
+ contrib/chem/examples/ethamivan.chem \
+ contrib/chem/examples/lsd.chem \
+ contrib/chem/examples/morphine.chem \
+ contrib/chem/examples/penicillin.chem \
+ contrib/chem/examples/reserpine.chem
+
+# Files installed in $(exampledir)/chem
+chemexampledir = $(exampledir)/chem
+nodist_chemexample_DATA = $(CHEM_GENEXAMPLES)
+dist_chemexample_DATA = $(CHEM_EXAMPLES)
+
+# Files installed in $(exampledir)/chem/122. All the .chem files in 122 are
+# lazily installed by the local install target
+chemexample122dir = $(chemexampledir)/122
+nodist_chemexample122_DATA = contrib/chem/examples/122/README
+EXTRA_DIST += \
+ contrib/chem/ChangeLog \
+ contrib/chem/chem.1.man \
+ contrib/chem/chem.pic \
+ contrib/chem/chem.pl \
+ contrib/chem/README.txt \
+ contrib/chem/examples/README.txt \
+ contrib/chem/examples/122/README.txt
+
+man1_MANS += contrib/chem/chem.1
+MOSTLYCLEANFILES += $(CHEM_GENEXAMPLES) $(nodist_chemexample122_DATA) \
+ contrib/chem/README
+
+# This is strangely built but not installed
+all: contrib/chem/README
+
+contrib/chem/README: $(chem_srcdir)/README.txt
+ $(AM_V_GEN)$(MKDIR_P) contrib/chem/ \
+ && sed -e "s|[@]g[@]|$(g)|g" $? >$@
+
+contrib/chem/examples/README: $(chem_srcdir)/examples/README.txt
+ $(AM_V_GEN)$(MKDIR_P) contrib/chem/examples \
+ && sed -e "s|[@]g[@]|$(g)|g" $? >$@
+
+contrib/chem/examples/122/README: $(chem_srcdir)/examples/122/README.txt
+ $(AM_V_GEN)$(MKDIR_P) contrib/chem/examples/122 \
+ && sed -e "s|[@]g[@]|$(g)|g" $? >$@
+
+chem: $(chem_srcdir)/chem.pl $(SH_DEPS_SED_SCRIPT)
+ $(AM_V_GEN)$(RM) $@ \
+ && sed -f "$(SH_DEPS_SED_SCRIPT)" \
+ -e "s|[@]g[@]|$(g)|g" \
+ -e "s|[@]BINDIR[@]|$(DESTDIR)$(bindir)|g" \
+ -e "s|[@]MACRODIR[@]|$(DESTDIR)$(tmacdir)|g" \
+ -e "s|[@]PICDIR[@]|$(DESTDIR)$(datasubdir)/pic|g" \
+ -e "s|[@]VERSION[@]|$(VERSION)|g" \
+ -e "$(SH_SCRIPT_SED_CMD)" \
+ $(chem_srcdir)/chem.pl \
+ >$@ \
+ && chmod +x $@
+
+install-data-local: install_chem_extra
+install_chem_extra:
+ -test -d $(DESTDIR)$(chemexample122dir) \
+ || $(mkinstalldirs) $(DESTDIR)$(chemexample122dir);
+ for i in $(chem_srcdir)/examples/122/*.chem; do \
+ n=`echo $$i | sed 's|$(chem_srcdir)/examples/122/||g'`; \
+ $(INSTALL_DATA) $$i $(DESTDIR)$(chemexample122dir)/$$n; \
+ done
+
+uninstall-local: uninstall_chem_extra
+uninstall_chem_extra:
+ $(RM) $(DESTDIR)$(exampledir)/chem/122/*
+ -rmdir $(DESTDIR)$(exampledir)/chem/122
+ $(RM) $(DESTDIR)$(exampledir)/chem/*
+ -rmdir $(DESTDIR)$(exampledir)/chem
+ -rmdir $(DESTDIR)$(datasubdir)/pic
+
+dist-hook: dist_chem
+dist_chem:
+ chmod u+w $(distdir)/contrib/chem/examples/122
+ for i in $(chem_srcdir)/examples/122/*.chem; do \
+ cp -f $$i $(distdir)/contrib/chem/examples/122; \
+ done
+
+
+# Local Variables:
+# mode: makefile-automake
+# fill-column: 72
+# End:
+# vim: set autoindent filetype=automake textwidth=72:
diff --git a/contrib/chem/chem.pic b/contrib/chem/chem.pic
new file mode 100644
index 0000000..33e932c
--- /dev/null
+++ b/contrib/chem/chem.pic
@@ -0,0 +1,89 @@
+# macros for chem
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Brian Kernighan <http://cm.bell-labs.com/cm/cs/who/bwk>,
+# modified by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# The license text for GPL2 is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+pi = 3.141592654
+deg = 57.29578
+# cr = 0.08 # radius of invis circle at ring vertices (see cr[vh])
+# crh = 0.16; crw = 0.12 # ht & wid of invis ellipse around atoms at ring vertices
+# dav = 0.015 # vertical shift up for atoms in atom macro
+
+# atom(text, wid, ht, carbon position, crh, crw, dav)
+define atom { [
+ T: $1 wid $2 ht $3-2*$7
+ C: ellipse invis ht $5 wid $6 at T.w + ($4,$7)
+ L: ellipse invis ht $5 wid $6 at T.w + (cwid/2,$7)
+ R: ellipse invis ht $5 wid $6 at T.e + (-cwid/2,$7)
+] }
+
+# bond(length, angle in degrees, whatever)
+define bond {
+ line $3 by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
+}
+
+# fancy bonds: r, theta, from/at
+define doublebond {
+ line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
+ V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
+ norm = sqrt(dx*dx + dy*dy)
+ ny = dx * .02 / norm
+ nx = -dy * .02 / norm
+ line from V1 + (nx,ny) to V2 + (nx,ny)
+ line from V1 - (nx,ny) to V2 - (nx,ny)
+ move to V2
+}
+define triplebond {
+ line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
+ V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
+ norm = sqrt(dx*dx + dy*dy)
+ ny = dx * .025 / norm
+ nx = -dy * .025 / norm
+ line from V1 + (nx,ny) to V2 + (nx,ny)
+ line from V1 - (nx,ny) to V2 - (nx,ny)
+ line from V1 to V2
+ move to V2
+}
+define backbond {
+ line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
+ V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
+ norm = sqrt(dx*dx + dy*dy)
+ n = norm / .025
+ ny = dx * .02 / norm
+ nx = -dy * .02 / norm
+ for i = 1 to n-1 do {
+ XZ: i/n <V1,V2>
+ line from XZ + (nx,ny) to XZ - (nx,ny)
+ }
+ move to V2
+}
+define frontbond {
+ line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
+ V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
+ ah = arrowht; aw = arrowwid; ahead = arrowhead
+ arrowht = sqrt(dx*dx + dy*dy)
+ arrowwid = 0.05
+ arrowhead = 7
+ line <- from V1 to V2
+ arrowht = ah; arrowwid = aw; arrowhead = ahead
+}
+# Local Variables:
+# mode: Nroff
+# End:
diff --git a/contrib/chem/chem.pl b/contrib/chem/chem.pl
new file mode 100755
index 0000000..5ca3fa2
--- /dev/null
+++ b/contrib/chem/chem.pl
@@ -0,0 +1,1231 @@
+#! /usr/bin/env perl
+
+# chem - a groff preprocessor for producing chemical structure diagrams
+
+my $copyright = 'Copyright (C) 2006-2014, 2022'
+ . ' Free Software Foundation, Inc.';
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+# settings
+########################################################################
+
+my $chem_version = '1.0.6';
+my $groff_version = 'DEVELOPMENT';
+
+require v5.6;
+
+
+########################################################################
+# begin
+########################################################################
+
+use warnings;
+use strict;
+use Math::Trig;
+
+# for catfile()
+use File::Spec;
+
+# $Bin is the directory where this script is located
+use FindBin;
+
+my $chem;
+my $File_chem_pic;
+
+my $is_in_source_tree;
+{
+ $is_in_source_tree = 1 if '@VERSION@' eq '@' . 'VERSION' . '@';
+}
+
+my %makevar;
+
+if ($is_in_source_tree) {
+ my $chem_dir = $FindBin::Bin;
+ $makevar{'G'} = '';
+ $File_chem_pic = File::Spec->catfile($chem_dir, 'chem.pic');
+ $chem = 'chem';
+} else {
+ $groff_version = '@VERSION@';
+ $makevar{'G'} = '@g@';
+ $makevar{'PICDIR'} = '@PICDIR@';
+ $File_chem_pic = File::Spec->catfile($makevar{'PICDIR'}, 'chem.pic');
+ $chem = $makevar{'G'} . 'chem';
+}
+
+
+########################################################################
+# check the parameters
+########################################################################
+
+if (@ARGV) {
+ # process any FOO=bar switches
+ # eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
+ my @filespec = ();
+ my $dbl_minus;
+ my $wrong;
+ foreach (@ARGV) {
+ next unless $_;
+ if (/=/) {
+ # ignore FOO=bar switches
+ push @filespec, $_ if -f;
+ next;
+ }
+ if ($dbl_minus) {
+ if (-f $_) {
+ push @filespec, $_ if -s $_;
+ } else {
+ warn "chem: argument $_ is not an existing file.\n";
+ $wrong = 1;
+ }
+ next;
+ }
+ if (/^--$/) {
+ $dbl_minus = 1;
+ next;
+ }
+ if (/^-$/) {
+ push @filespec, $_;
+ next;
+ }
+ if (/^-h$/ or '--help' =~ /^$_/) {
+ &usage();
+ exit 0;
+ }
+ if (/^-v$/ or '--version' =~ /^$_/) {
+ &version();
+ exit 0;
+ }
+ if (-f $_) {
+ push @filespec, $_ if -s $_;
+ } else {
+ $wrong = 1;
+ if (/^-/) {
+ warn "chem: wrong option ${_}.\n";
+ } else {
+ warn "chem: argument $_ is not an existing file.\n";
+ }
+ }
+ }
+ if (@filespec) {
+ @ARGV = @filespec;
+ } else {
+ exit 0 if $wrong;
+ @ARGV = ('-');
+ }
+} else { # @ARGV is empty
+ @ARGV = ('-') unless @ARGV;
+}
+
+
+########################################################################
+# main process
+########################################################################
+
+my %Dc = ( 'up' => 0, 'right' => 90, 'down' => 180, 'left' => 270,
+ 'ne' => 45, 'se' => 135, 'sw' => 225, 'nw' => 315,
+ 0 => 'n', 90 => 'e', 180 => 's', 270 => 'w',
+ 30 => 'ne', 45 => 'ne', 60 => 'ne',
+ 120 => 'se', 135 => 'se', 150 => 'se',
+ 210 => 'sw', 225 => 'sw', 240 => 'sw',
+ 300 => 'nw', 315 => 'nw', 330 => 'nw',
+ );
+
+my $Word_Count;
+my @Words;
+
+my $Line_No;
+my $Last_Name = '';
+
+# from init()
+my $First_Time = 1;
+my $Last_Type;
+my $Dir; # direction
+my %Types = (
+ 'RING' => 'R',
+ 'MOL' => 'M',
+ 'BOND' => 'B',
+ 'OTHER' => 'O' # manifests
+ );
+
+# from setparams()
+my %Params;
+
+# from ring()
+my $Nput;
+my $Aromatic;
+my %Put;
+my %Dbl;
+
+my %Labtype;
+my %Define = ();
+
+my $File_Name = '';
+my $Line = '';
+
+&main();
+
+{
+ my $is_pic = '';
+ my $is_chem = '';
+ my $former_line = '';
+
+ ##########
+ # main()
+ #
+ sub main {
+ my $count_minus = 0;
+ my @stdin = ();
+ my $stdin = 0;
+
+ foreach (@ARGV) {
+ $count_minus++ if /^-$/;
+ }
+
+ foreach my $arg (@ARGV) {
+ &setparams(1.0);
+ next unless $arg;
+ $Line_No = 0;
+ $is_pic = '';
+ $is_chem = '';
+ if ($arg eq '-') {
+ $File_Name = 'standard input';
+ if ($stdin) {
+ &main_line($_) foreach @stdin;
+ } else {
+ $stdin = 1;
+ if ($count_minus <= 1) {
+ while (<STDIN>) {
+ &main_line($_);
+ }
+ } else {
+ @stdin = ();
+ while (<STDIN>) {
+ push @stdin, $_;
+ &main_line($_);
+ }
+ }
+ }
+### main()
+ } else { # $arg is not -
+ $File_Name = $arg;
+ open FILE, "<$arg";
+ &main_line($_) while <FILE>;
+ close FILE;
+ } # if $arg
+ if ($is_pic) {
+ printf ".PE\n";
+ }
+ }
+ } # main()
+
+
+ ##########
+ # main_line()
+ #
+ sub main_line {
+ my $line = $_[0];
+# $Last_Type = $Types{'OTHER'};
+# $Last_Type = '';
+ my $stack;
+ $Line_No++;
+ chomp $line;
+
+ $line = $former_line . $line if $former_line;
+ if ($line =~ /^(.*)\\$/) {
+ $former_line = $1;
+ return 1;
+ } else {
+ $former_line = '';
+ }
+ $Line = $line;
+
+ {
+ @Words = ();
+ my $s = $line;
+ $s =~ s/^\s*//;
+ $s =~ s/\s+$//;
+ return 1 unless $s;
+ $s = " $s";
+ $s =~ s/\s+#.*$// if $is_pic;
+ return 1 unless $s;
+ $line = $s;
+ $line =~ s/^\s*|\s*$//g;
+ my $bool = 1;
+ while ($bool) {
+ $s =~ /^([^"]*)\s("[^"]*"?\S*)(.*)$/;
+ if (defined $1) {
+ my $s1 = $1;
+ my $s2 = $2;
+ $s = $3;
+ $s1 =~ s/^\s*|\s*$//g;
+ push @Words, split(/\s+/, $s1) if $s1;
+ push @Words, $s2;
+ }
+ if ($s !~ /\s"/) {
+ $s =~ s/^\s*|\s*$//g;
+ push @Words, split(/\s+/, $s) if $s;
+ $bool = 0;
+ }
+ }
+
+# @Words = split(/\s+/, $s);
+ return 1 unless @Words;
+# foreach my $i (0..$#Words) {
+# if ($Words[$i] =~ /^\s*#/) {
+# $#Words = $i - 1;
+# last;
+# }
+# }
+# return 1 unless @Words;
+ }
+
+ if ($line =~ /^([\.']\s*PS\s*)|([\.']\s*PS\s.+)$/) {
+ # .PS
+ unless ($is_pic) {
+ $is_pic = 'running';
+ print "$line\n";
+ }
+ return 1;
+ }
+### main_line()
+ if ( $line =~ /^([\.']\s*PE\s*)|([\.']\s*PE\s.+)$/ ) {
+ # .PE
+ $is_chem = '';
+ if ($is_pic) {
+ $is_pic = '';
+ print "$line\n";
+ }
+ return 1;
+ }
+ if ($line =~ /^[\.']\s*cstart\s*$/) {
+ # line: '.cstart'
+ if ($is_chem) {
+ &error("additional '.cstart'; chem is already active.");
+ return 1;
+ }
+ unless ($is_pic) {
+ &print_ps();
+ $is_pic = 'by chem';
+ }
+ $is_chem = '.cstart';
+ &init();
+ return 1;
+ }
+### main_line()
+ if ($line =~ /^\s*begin\s+chem\s*$/) {
+ # line: 'begin chem'
+ if ($is_pic) {
+ if ($is_chem) {
+ &error("additional 'begin chem'; chem is already active.");
+ return 1;
+ }
+ $is_chem = 'begin chem';
+ &init();
+ } else {
+ print "$line\n";
+ }
+ return 1;
+ }
+ if ($line =~ /^[\.']\s*cend\s*/) {
+ # line '.cend'
+ if ($is_chem) {
+ &error("you end chem with '.cend', but started it with 'begin chem'.")
+ if $is_chem eq 'begin chem';
+ if ($is_pic eq 'by chem') {
+ &print_pe();
+ $is_pic = '';
+ }
+ $is_chem = '';
+ } else {
+ print "$line\n";
+ }
+ return 1;
+ }
+ if ($line =~ /^\s*end\s*$/) {
+ # line: 'end'
+ if ($is_chem) {
+ &error("you end chem with 'end', but started it with '.cstart'.")
+ if $is_chem eq '.cstart';
+ if ($is_pic eq 'by chem') {
+ &print_pe();
+ $is_pic = '';
+ }
+ $is_chem = '';
+ } else {
+ print "$line\n";
+ }
+ return 1;
+ }
+
+### main_line()
+ if (! $is_chem) {
+ print "$line\n";
+ return 1;
+ }
+ if ($line =~ /^[.']/) {
+ # groff request line
+ print "$line\n";
+ return 1;
+ }
+
+ if ($Words[0] eq 'pic') {
+ # pic pass-through
+ return 1 if $#Words == 0;
+ my $s = $line;
+ $s =~ /^\s*pic\s*(.*)$/;
+ $s = $1;
+ print "$s\n" if $s;
+ $Last_Type = $Types{'OTHER'};
+ $Define{ $Words[2] } = 1 if $#Words >= 2 && $Words[1] eq 'define';
+ return 1;
+ }
+
+ if ($Words[0] eq 'textht') {
+ if ($#Words == 0) {
+ &error("'textht' needs a single argument.");
+ return 0;
+ }
+ &error("only the last argument is taken for 'textht', " .
+ "all others are ignored.")
+ unless $#Words <= 1 or ($#Words == 2 && $Words[1] =~ /^=/);
+ $Params{'textht'} = $Words[$#Words];
+ return 1;
+ }
+### main_line()
+ if ($Words[0] eq 'cwid') { # character width
+ if ($#Words == 0) {
+ &error("'cwid' needs a single argument.");
+ return 0;
+ }
+ &error("only the last argument is taken for 'cwid', " .
+ "all others are ignored.")
+ unless $#Words <= 1 or ($#Words == 2 && $Words[1] =~ /^=/);
+ $Params{'cwid'} = $Words[$#Words];
+ return 1;
+ }
+ if ($Words[0] eq 'db') { # bond length
+ if ($#Words == 0) {
+ &error("'db' needs a single argument.");
+ return 0;
+ }
+ &error("only the last argument is taken for 'db', " .
+ "all others are ignored.")
+ unless $#Words <= 1 or ($#Words == 2 && $Words[1] =~ /^=/);
+ $Params{'db'} = $Words[$#Words];
+ return 1;
+ }
+ if ($Words[0] eq 'size') { # size for all parts of the whole diagram
+ my $size;
+ if ($#Words == 0) {
+ &error("'size' needs a single argument.");
+ return 0;
+ }
+ &error("only the last argument is taken for 'size', " .
+ "all others are ignored.")
+ unless $#Words <= 1 or ($#Words == 2 && $Words[1] =~ /^=/);
+ if ($Words[$#Words] <= 4) {
+ $size = $Words[$#Words];
+ } else {
+ $size = $Words[$#Words] / 10;
+ }
+ &setparams($size);
+ return 1;
+ }
+
+### main_line()
+ print "\n#", $Line, "\n"; # debugging, etc.
+ $Last_Name = '';
+# $Last_Type = $Types{'OTHER'};
+# $Last_Type = '';
+
+ if ($Words[0] =~ /^[A-Z].*:$/) {
+ # label; falls thru after shifting left
+ my $w = $Words[0];
+ $Last_Name = $w;
+ $Last_Name =~ s/:$//;
+ print "$w";
+ shift @Words;
+ if (@Words) {
+ print " ";
+ $line =~ s/^\s*$w\s*//;
+ } else {
+ print "\n";
+ return 1;
+ }
+ }
+
+ if ($Words[0] eq 'define') {
+ print "$line\n";
+ $Define{ $Words[1] } = 1 if $#Words >= 1;
+ $Last_Type = $Types{'OTHER'};
+ return 1;
+ }
+ if ($Words[0] =~ /^[\[\]{}]/) {
+ print "$line\n";
+ $Last_Type = $Types{'OTHER'};
+ return 1;
+ }
+
+ if ($Words[0] =~ /^"/) {
+ print 'Last: ', $line, "\n";
+ $Last_Type = $Types{'OTHER'};
+ return 1;
+ }
+
+ if ($Words[0] =~ /bond/) {
+ &bond($Words[0]);
+ return 1;
+ }
+
+ if ($#Words >= 1) {
+ if ($Words[0] =~ /^(double|triple|front|back)$/ &&
+ $Words[1] eq 'bond') {
+ my $w = shift @Words;
+ $Words[0] = $w . $Words[0];
+ &bond($Words[0]);
+ return 1;
+ }
+ if ($Words[0] eq 'aromatic') {
+ my $temp = $Words[0];
+ $Words[0] = $Words[1] ? $Words[1] : '';
+ $Words[1] = $temp;
+ }
+ }
+
+ if ($Words[0] =~ /ring|benz/) {
+ &ring($Words[0]);
+ return 1;
+ }
+ if ($Words[0] eq 'methyl') {
+ # left here as an example
+ $Words[0] = 'CH3';
+ }
+### main_line()
+ if ($Words[0] =~ /^[A-Z]/) {
+ &molecule();
+ return 1;
+ }
+ if ($Words[0] eq 'left') {
+ my %left; # not used
+ $left{++$stack} = &fields(1, $#Words);
+ printf (("Last: [\n"));
+ return 1;
+ }
+ if ($Words[0] eq 'right') {
+ &bracket();
+ $stack--;
+ return 1;
+ }
+ if ($Words[0] eq 'label') { # prints the vertex numbers in a ring
+ if ( exists $Labtype{$Words[1]} and
+ $Labtype{$Words[1]} =~ /^$Types{'RING'}/ ) {
+ my $v = substr($Labtype{$Words[1]}, 1, 1);
+ $Words[1] = '' unless $Words[1];
+ foreach my $i ( 1..$v ) {
+ printf "\"\\s-3%d\\s0\" at 0.%d<%s.C,%s.V%d>\n", $i, $v + 2,
+ $Words[1], $Words[1], $i;
+ }
+ } else {
+ &error("$Words[1] is not a ring.");
+ }
+ return 1;
+ }
+
+ if ( exists $Define{ $Words[0] } ) {
+ print $line, "\n";
+ $Last_Type = $Types{'OTHER'};
+ return 1;
+ }
+ return 1 unless $line;
+# print STDERR "# $Line\n";
+# &error('This is not a chem command. To include a command for pic, ' .
+# "add 'pic' as the first word to the command.");
+ print $line, "\n";
+ $Last_Type = $Types{'OTHER'};
+ 1;
+ } # main_line()
+
+}
+
+########################################################################
+# functions
+########################################################################
+
+##########
+# atom(<string>)
+#
+sub atom {
+ # convert CH3 to atom(...)
+ my ($s) = @_;
+ my ($i, $n, $nsub, $cloc, $nsubc, @s);
+ if ($s eq "\"\"") {
+ return $s;
+ }
+ $n = length($s);
+ $nsub = $nsubc = 0;
+ $cloc = index($s, 'C');
+ if (! defined($cloc) || $cloc < 0) {
+ $cloc = 0;
+ }
+ @s = split('', $s);
+ $i = 0;
+ foreach (@s) {
+ unless (/[A-Z]/) {
+ $nsub++;
+ $nsubc++ if $i < $cloc;
+ $i++;
+ }
+ }
+ $s =~ s/([0-9]+\.[0-9]+)|([0-9]+)/\\s-3\\d$&\\u\\s+3/g;
+ if ($s =~ /([^0-9]\.)|(\.[^0-9])/) { # centered dot
+ $s =~ s/\./\\v#-.3m#.\\v#.3m#/g;
+ }
+ sprintf( "atom(\"%s\", %g, %g, %g, %g, %g, %g)",
+ $s, ($n - $nsub / 2) * $Params{'cwid'}, $Params{'textht'},
+ ($cloc - $nsubc / 2 + 0.5) * $Params{'cwid'}, $Params{'crh'},
+ $Params{'crw'}, $Params{'dav'}
+ );
+} # atom()
+
+
+##########
+# bond(<type>)
+#
+sub bond {
+ my ($type) = @_;
+ my ($i, $moiety, $from, $leng);
+ $moiety = '';
+ for ($i = 1; $i <= $#Words; $i++) {
+ if ($Words[$i] eq ';') {
+ &error("a colon ';' must be followed by a space and a single word.")
+ if $i != $#Words - 1;
+ $moiety = $Words[$i + 1] if $#Words > $i;
+ $#Words = $i - 1;
+ last;
+ }
+ }
+ $leng = $Params{'db'}; # bond length
+ $from = '';
+ for ($Word_Count = 1; $Word_Count <= $#Words; ) {
+ if ($Words[$Word_Count] =~
+ /(\+|-)?\d+|up|down|right|left|ne|se|nw|sw/) {
+ $Dir = &cvtdir($Dir);
+ } elsif ($Words[$Word_Count] =~ /^leng/) {
+ $leng = $Words[$Word_Count + 1] if $#Words > $Word_Count;
+ $Word_Count += 2;
+ } elsif ($Words[$Word_Count] eq 'to') {
+ $leng = 0;
+ $from = &fields($Word_Count, $#Words);
+ last;
+ } elsif ($Words[$Word_Count] eq 'from') {
+ $from = &dofrom();
+ last;
+ } elsif ($Words[$Word_Count] =~ /^#/) {
+ $Word_Count = $#Words + 1;
+ last;
+ } else {
+ $from = &fields($Word_Count, $#Words);
+ last;
+ }
+ }
+### bond()
+ if ($from =~ /( to )|^to/) { # said "from ... to ...", so zap length
+ $leng = 0;
+ } elsif (! $from) { # no from given at all
+ $from = 'from Last.' . &leave($Last_Type, $Dir) . ' ' .
+ &fields($Word_Count, $#Words);
+ }
+ printf "Last: %s(%g, %g, %s)\n", $type, $leng, $Dir, $from;
+ $Last_Type = $Types{'BOND'};
+ $Labtype{$Last_Name} = $Last_Type if $Last_Name;
+ if ($moiety) {
+ @Words = ($moiety);
+ &molecule();
+ }
+} # bond()
+
+
+##########
+# bracket()
+#
+sub bracket {
+ my $t;
+ printf (("]\n"));
+ if ($Words[1] && $Words[1] eq ')') {
+ $t = 'spline';
+ } else {
+ $t = 'line';
+ }
+ printf "%s from last [].sw+(%g,0) to last [].sw to last [].nw to last " .
+ "[].nw+(%g,0)\n", $t, $Params{'dbrack'}, $Params{'dbrack'};
+ printf "%s from last [].se-(%g,0) to last [].se to last [].ne to last " .
+ "[].ne-(%g,0)\n", $t, $Params{'dbrack'}, $Params{'dbrack'};
+ if ($Words[2] && $Words[2] eq 'sub') {
+ printf "\" %s\" ljust at last [].se\n", &fields(3, $#Words);
+ }
+} # bracket()
+
+
+##########
+# corner(<dir>)
+#
+# Return the corner name next to the given angle.
+#
+sub corner {
+ my ($d) = @_;
+ $Dc{ (45 * int(($d + 22.5) / 45)) % 360 };
+} # corner()
+
+
+##########
+# cvtdir(<dir>)
+#
+# Maps "[pointing] somewhere" to degrees.
+#
+sub cvtdir {
+ my ($d) = @_;
+ if ($Words[$Word_Count] eq 'pointing') {
+ $Word_Count++;
+ }
+ if ($Words[$Word_Count] =~ /^[+\\-]?\d+/) {
+ return ( $Words[$Word_Count++] % 360 );
+ } elsif ($Words[$Word_Count] =~ /left|right|up|down|ne|nw|se|sw/) {
+ return ( $Dc{$Words[$Word_Count++]} % 360 );
+ } else {
+ $Word_Count++;
+ return $d;
+ }
+} # cvtdir()
+
+
+##########
+# dblring(<v>)
+#
+sub dblring {
+ my ($v) = @_;
+ my ($d, $v1, $v2);
+ # should canonicalize to i,i+1 mod v
+ $d = $Words[$Word_Count];
+ for ($Word_Count++; $Word_Count <= $#Words &&
+ $Words[$Word_Count] =~ /^[1-9]/; $Word_Count++) {
+ $v1 = substr($Words[$Word_Count], 0, 1);
+ $v2 = substr($Words[$Word_Count], 2, 1);
+ if ($v2 == $v1 + 1 || $v1 == $v && $v2 == 1) { # e.g., 2,3 or 5,1
+ $Dbl{$v1} = $d;
+ } elsif ($v1 == $v2 + 1 || $v2 == $v && $v1 == 1) { # e.g., 3,2 or 1,5
+ $Dbl{$v2} = $d;
+ } else {
+ &error(sprintf("weird %s bond in\n\t%s", $d, $_));
+ }
+ }
+} # dblring()
+
+
+##########
+# dofrom()
+#
+sub dofrom {
+ my $n;
+ $Word_Count++; # skip "from"
+ $n = $Words[$Word_Count];
+ if (defined $Labtype{$n}) { # "from Thing" => "from Thing.V.s"
+ return 'from ' . $n . '.' . &leave($Labtype{$n}, $Dir);
+ }
+ if ($n =~ /^\.[A-Z]/) { # "from .V" => "from Last.V.s"
+ return 'from Last' . $n . '.' . &corner($Dir);
+ }
+ if ($n =~ /^[A-Z][^.]*\.[A-Z][^.]*$/) { # "from X.V" => "from X.V.s"
+ return 'from ' . $n . '.' . &corner($Dir);
+ }
+ &fields($Word_Count - 1, $#Words);
+} # dofrom()
+
+
+##########
+# error(<string>)
+#
+sub error {
+ my ($s) = @_;
+ printf STDERR "chem: error in %s on line %d: %s\n",
+ $File_Name, $Line_No, $s;
+} # error()
+
+
+##########
+# fields(<n1>, <n2>)
+#
+sub fields {
+ my ($n1, $n2) = @_;
+ if ($n1 > $n2) {
+ return '';
+ }
+ my $s = '';
+ foreach my $i ($n1..$n2) {
+ if ($Words[$i] =~ /^#/) {
+ last;
+ }
+ $s = $s . $Words[$i] . ' ';
+ }
+ $s;
+} # fields()
+
+
+##########
+# init()
+#
+sub init {
+ if ($First_Time) {
+ printf "copy \"%s\"\n", $File_chem_pic;
+ printf "\ttextht = %g; textwid = .1; cwid = %g\n",
+ $Params{'textht'}, $Params{'cwid'};
+ printf "\tlineht = %g; linewid = %g\n",
+ $Params{'lineht'}, $Params{'linewid'};
+ $First_Time = 0;
+ }
+ printf "Last: 0,0\n";
+ $Last_Type = $Types{'OTHER'};
+ $Dir = 90;
+} # init()
+
+
+##########
+# leave(<last>, <d>)
+#
+sub leave {
+ my ($last, $d) = @_;
+ my ($c, $c1);
+ # return vertex of $last in direction $d
+ if ( $last eq $Types{'BOND'} ) {
+ return 'end';
+ }
+ $d %= 360;
+ if ( $last =~ /^$Types{'RING'}/ ) {
+ return &ringleave($last, $d);
+ }
+ if ( $last eq $Types{'MOL'} ) {
+ if ($d == 0 || $d == 180) {
+ $c = 'C';
+ } elsif ($d > 0 && $d < 180) {
+ $c = 'R';
+ } else {
+ $c = 'L';
+ }
+ if (defined $Dc{$d}) {
+ $c1 = $Dc{$d};
+ } else {
+ $c1 = &corner($d);
+ }
+ return sprintf('%s.%s', $c, $c1);
+ }
+ if ( $last eq $Types{'OTHER'} ) {
+ return &corner($d);
+ }
+ 'c';
+} # leave()
+
+
+##########
+# makering(<type>, <pt>, <v>)
+#
+sub makering {
+ my ($type, $pt, $v) = @_;
+ my ($i, $j, $a, $r, $rat, $fix, $c1, $c2);
+ if ($type =~ /flat/) {
+ $v = 6;
+ # vertices
+ ;
+ }
+ $r = $Params{'ringside'} / (2 * sin(pi / $v));
+ printf "\tC: 0,0\n";
+ for ($i = 0; $i <= $v + 1; $i++) {
+ $a = (($i - 1) / $v * 360 + $pt) / 57.29578; # 57. is $deg
+ printf "\tV%d: (%g,%g)\n", $i, $r * sin($a), $r * cos($a);
+ }
+ if ($type =~ /flat/) {
+ printf "\tV4: V5; V5: V6\n";
+ $v = 5;
+ }
+ # sides
+ if ($Nput > 0) {
+ # hetero ...
+ for ($i = 1; $i <= $v; $i++) {
+ $c1 = $c2 = 0;
+ if ($Put{$i} ne '') {
+ printf "\tV%d: ellipse invis ht %g wid %g at V%d\n",
+ $i, $Params{'crh'}, $Params{'crw'}, $i;
+ printf "\t%s at V%d\n", $Put{$i}, $i;
+ $c1 = $Params{'cr'};
+ }
+ $j = $i + 1;
+ if ($j > $v) {
+ $j = 1;
+ }
+### makering()
+ if ($Put{$j} ne '') {
+ $c2 = $Params{'cr'};
+ }
+ printf "\tline from V%d to V%d chop %g chop %g\n", $i, $j, $c1, $c2;
+ if ($Dbl{$i} ne '') {
+ # should check i<j
+ if ($type =~ /flat/ && $i == 3) {
+ $rat = 0.75;
+ $fix = 5;
+ } else {
+ $rat = 0.85;
+ $fix = 1.5;
+ }
+ if ($Put{$i} eq '') {
+ $c1 = 0;
+ } else {
+ $c1 = $Params{'cr'} / $fix;
+ }
+ if ($Put{$j} eq '') {
+ $c2 = 0;
+ } else {
+ $c2 = $Params{'cr'} / $fix;
+ }
+ printf "\tline from %g<C,V%d> to %g<C,V%d> chop %g chop %g\n",
+ $rat, $i, $rat, $j, $c1, $c2;
+ if ($Dbl{$i} eq 'triple') {
+ printf "\tline from %g<C,V%d> to %g<C,V%d> chop %g chop %g\n",
+ 2 - $rat, $i, 2 - $rat, $j, $c1, $c2;
+ }
+ }
+ }
+### makering()
+ } else {
+ # regular
+ for ($i = 1; $i <= $v; $i++) {
+ $j = $i + 1;
+ if ($j > $v) {
+ $j = 1;
+ }
+ printf "\tline from V%d to V%d\n", $i, $j;
+ if ($Dbl{$i} ne '') {
+ # should check i<j
+ if ($type =~ /flat/ && $i == 3) {
+ $rat = 0.75;
+ } else {
+ $rat = 0.85;
+ }
+ printf "\tline from %g<C,V%d> to %g<C,V%d>\n",
+ $rat, $i, $rat, $j;
+ if ($Dbl{$i} eq 'triple') {
+ printf "\tline from %g<C,V%d> to %g<C,V%d>\n",
+ 2 - $rat, $i, 2 - $rat, $j;
+ }
+ }
+ }
+ }
+### makering()
+ # punt on triple temporarily
+ # circle
+ if ($type =~ /benz/ || $Aromatic > 0) {
+ if ($type =~ /flat/) {
+ $r *= .4;
+ } else {
+ $r *= .5;
+ }
+ printf "\tcircle rad %g at 0,0\n", $r;
+ }
+} # makering()
+
+
+##########
+# molecule()
+#
+sub molecule {
+ my ($n, $type);
+ if ($#Words >= 0) {
+ $n = $Words[0];
+ if ($n eq 'BP') {
+ $Words[0] = "\"\" ht 0 wid 0";
+ $type = $Types{'OTHER'};
+ } else {
+ $Words[0] = &atom($n);
+ $type = $Types{'MOL'};
+ }
+ }
+ $n =~ s/[^A-Za-z0-9]//g; # for stuff like C(OH3): zap non-alnum
+ if ($#Words < 1) {
+ printf "Last: %s: %s with .%s at Last.%s\n",
+ $n, join(' ', @Words), &leave($type, $Dir + 180),
+ &leave($Last_Type, $Dir);
+### molecule()
+ } else {
+ if (! $Words[1]) {
+ printf "Last: %s: %s with .%s at Last.%s\n",
+ $n, join(' ', @Words), &leave($type, $Dir + 180),
+ &leave($Last_Type, $Dir);
+ } elsif ($#Words >= 1 and $Words[1] eq 'below') {
+ $Words[2] = '' if ! $Words[2];
+ printf "Last: %s: %s with .n at %s.s\n", $n, $Words[0], $Words[2];
+ } elsif ($#Words >= 1 and $Words[1] eq 'above') {
+ $Words[2] = '' if ! $Words[2];
+ printf "Last: %s: %s with .s at %s.n\n", $n, $Words[0], $Words[2];
+ } elsif ($#Words >= 2 and $Words[1] eq 'left' && $Words[2] eq 'of') {
+ $Words[3] = '' if ! $Words[3];
+ printf "Last: %s: %s with .e at %s.w+(%g,0)\n",
+ $n, $Words[0], $Words[3], $Params{'dew'};
+ } elsif ($#Words >= 2 and $Words[1] eq 'right' && $Words[2] eq 'of') {
+ $Words[3] = '' if ! $Words[3];
+ printf "Last: %s: %s with .w at %s.e-(%g,0)\n",
+ $n, $Words[0], $Words[3], $Params{'dew'};
+ } else {
+ printf "Last: %s: %s\n", $n, join(' ', @Words);
+ }
+ }
+
+ $Last_Type = $type;
+ if ($Last_Name) {
+ # $Last_Type = '';
+ $Labtype{$Last_Name} = $Last_Type;
+ }
+ $Labtype{$n} = $Last_Type;
+} # molecule()
+
+
+##########
+# print_hash(<hash_or_ref>)
+#
+# print the elements of a hash or hash reference
+#
+sub print_hash {
+ my $hr;
+ my $n = scalar @_;
+ if ($n == 0) {
+ print STDERR "empty hash\n;";
+ return 1;
+ } elsif ($n == 1) {
+ if (ref($_[0]) eq 'HASH') {
+ $hr = $_[0];
+ } else {
+ warn 'print_hash(): the argument is not a hash or hash reference;';
+ return 0;
+ }
+ } else {
+ if ($n % 2) {
+ warn 'print_hash(): the arguments are not a hash;';
+ return 0;
+ } else {
+ my %h = @_;
+ $hr = \%h;
+ }
+ }
+
+### print_hash()
+ unless (%$hr) {
+ print STDERR "empty hash\n";
+ return 1;
+ }
+ print STDERR "hash (ignore the ^ characters):\n";
+ for my $k (sort keys %$hr) {
+ my $hk = $hr->{$k};
+ print STDERR " $k => ";
+ if (defined $hk) {
+ print STDERR "^$hk^";
+ } else {
+ print STDERR "undef";
+ }
+ print STDERR "\n";
+ }
+
+ 1;
+} # print_hash()
+
+
+##########
+# print_pe()
+#
+sub print_pe {
+ print ".PE\n";
+} # print_pe()
+
+
+##########
+# print_ps()
+#
+sub print_ps {
+ print ".PS\n";
+} # print_ps()
+
+##########
+# putring(<v>)
+#
+sub putring {
+ # collect "put Mol at n"
+ my ($v) = @_;
+ my ($m, $mol, $n);
+ $Word_Count++;
+ $mol = $Words[$Word_Count++];
+ if ($Words[$Word_Count] eq 'at') {
+ $Word_Count++;
+ }
+ $n = $Words[$Word_Count];
+ if ($n !~ /^\d+$/) {
+ $n =~ s/(\d)+$/$1/;
+ $n = 0 if $n !~ /^\d+$/;
+ error('use single digit as argument for "put at"');
+ }
+ if ($n >= 1 && $n <= $v) {
+ $m = $mol;
+ $m =~ s/[^A-Za-z0-9]//g;
+ $Put{$n} = $m . ':' . &atom($mol);
+ } elsif ($n == 0) {
+ error('argument of "put at" must be a single digit');
+ } else {
+ error('argument of "put at" is too large');
+ }
+ $Word_Count++;
+} # putring()
+
+
+##########
+# ring(<type>)
+#
+sub ring {
+ my ($type) = @_;
+ my ($typeint, $pt, $verts, $i, $other, $fused, $withat);
+ $pt = 0; # points up by default
+ if ($type =~ /([1-8])$/) {
+ $verts = $1;
+ } elsif ($type =~ /flat/) {
+ $verts = 5;
+ } else {
+ $verts = 6;
+ }
+ $fused = $other = '';
+ for ($i = 1; $i <= $verts; $i++) {
+ $Put{$i} = $Dbl{$i} = '';
+ }
+ $Nput = $Aromatic = $withat = 0;
+ for ($Word_Count = 1; $Word_Count <= $#Words; ) {
+ if ($Words[$Word_Count] eq 'pointing') {
+ $pt = &cvtdir(0);
+ } elsif ($Words[$Word_Count] eq 'double' ||
+ $Words[$Word_Count] eq 'triple') {
+ &dblring($verts);
+ } elsif ($Words[$Word_Count] =~ /arom/) {
+ $Aromatic++;
+ $Word_Count++; # handled later
+### ring()
+ } elsif ($Words[$Word_Count] eq 'put') {
+ &putring($verts);
+ $Nput++;
+ } elsif ($Words[$Word_Count] =~ /^#/) {
+ $Word_Count = $#Words + 1;
+ last;
+ } else {
+ if ($Words[$Word_Count] eq 'with' || $Words[$Word_Count] eq 'at') {
+ $withat = 1;
+ }
+ $other = $other . ' ' . $Words[$Word_Count];
+ $Word_Count++;
+ }
+ }
+ $typeint = $Types{'RING'} . $verts . $pt; # RING | verts | dir
+ if ($withat == 0) {
+ # join a ring to something
+ if ( $Last_Type =~ /^$Types{'RING'}/ ) {
+ # ring to ring
+ if (substr($typeint, 2) eq substr($Last_Type, 2)) {
+ # fails if not 6-sided
+ $fused = 'with .V6 at Last.V2';
+ }
+ }
+ # if all else fails
+ $fused = sprintf('with .%s at Last.%s',
+ &leave($typeint, $Dir + 180), &leave($Last_Type, $Dir));
+ }
+ printf "Last: [\n";
+ &makering($type, $pt, $verts);
+ printf "] %s %s\n", $fused, $other;
+ $Last_Type = $typeint;
+ $Labtype{$Last_Name} = $Last_Type if $Last_Name;
+} # ring()
+
+
+##########
+# ringleave(<last>, <d>)
+#
+sub ringleave {
+ my ($last, $d) = @_;
+ my ($rd, $verts);
+ # return vertex of ring in direction d
+ $verts = substr($last, 1, 1);
+ $rd = substr($last, 2);
+ sprintf('V%d.%s', int( (($d - $rd) % 360) / (360 / $verts)) + 1,
+ &corner($d));
+} # ringleave()
+
+
+##########
+# setparams(<scale>)
+#
+sub setparams {
+ my ($scale) = @_;
+ $Params{'lineht'} = $scale * 0.2;
+ $Params{'linewid'} = $scale * 0.2;
+ $Params{'textht'} = $scale * 0.16;
+ $Params{'db'} = $scale * 0.2; # bond length
+ $Params{'cwid'} = $scale * 0.12; # character width
+ $Params{'cr'} = $scale * 0.08; # rad of invis circles at ring vertices
+ $Params{'crh'} = $scale * 0.16; # ht of invis ellipse at ring vertices
+ $Params{'crw'} = $scale * 0.12; # wid
+ $Params{'dav'} = $scale * 0.015; # vertical shift up for atoms in atom macro
+ $Params{'dew'} = $scale * 0.02; # east-west shift for left of/right of
+ $Params{'ringside'} = $scale * 0.3; # side of all rings
+ $Params{'dbrack'} = $scale * 0.1; # length of bottom of bracket
+} # setparams()
+
+
+sub usage {
+ print <<EOF;
+usage: $chem [file ...]
+usage: $chem { -h | --help | -v | --version }
+
+$chem is a groff preprocessor for producing chemical structure
+diagrams. It produces input for the $makevar{'G'}pic preprocessor. If
+no file operands are given, or if file is "-", the standard input stream
+is read.
+
+Options:
+ -h, --help Display this message and exit.
+ -v, --version Display version information and exit.
+EOF
+}
+
+
+sub version {
+ print <<EOF;
+$chem (groff $groff_version) $chem_version
+$copyright
+License GPLv2: GNU GPL version 2
+<https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+EOF
+}
+
+1;
+
+# Local Variables:
+# fill-column: 72
+# mode: CPerl
+# End:
+# vim: set cindent noexpandtab shiftwidth=2 softtabstop=2 textwidth=72:
diff --git a/contrib/chem/examples/122/README.txt b/contrib/chem/examples/122/README.txt
new file mode 100644
index 0000000..6f3809b
--- /dev/null
+++ b/contrib/chem/examples/122/README.txt
@@ -0,0 +1,57 @@
+This directory contains the examples for the 'chem' language written
+in the book:
+
+ Computing Science Technical Report No. 122
+ CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+ by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+
+The book is available in the internet at
+<http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+Many of the examples had to be fixed. Unfortunately, the 'chem' akw
+version does not run on many of these programs. But the Perl version
+of 'chem' works on all examples.
+
+Most examples do not use the modern chemical display. They have C
+atoms added, whereas the modern method omits all C atoms and their
+directly appended H atoms.
+
+The examples are named and sorted by the chapter where they are found
+in the book. For example, the file 'ch4c_colon.chem' means a 'chem'
+example in chapter 4; according to 'c', it is the third example in
+this chapter; the name 'colon' is used to describe the context of the
+example.
+
+You can view the graphical display of the examples by calling
+
+ @g@chem <file> | groff -p ...
+
+
+####### License
+
+Copyright (C) 2006-2020 Free Software Foundation, Inc.
+Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+This file is part of 'chem', which is part of 'groff'.
+
+'groff' is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License (GPL) version 2 as
+published by the Free Software Foundation.
+
+'groff' is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+The GPL2 license text is available in the internet at
+<http://www.gnu.org/licenses/gpl-2.0.html>.
+
+
+##### Editor settings
+
+Local Variables:
+mode: text
+End:
diff --git a/contrib/chem/examples/122/ch2a_ethyl.chem b/contrib/chem/examples/122/ch2a_ethyl.chem
new file mode 100644
index 0000000..089de73
--- /dev/null
+++ b/contrib/chem/examples/122/ch2a_ethyl.chem
@@ -0,0 +1,43 @@
+ch2a_ethyl.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ CH3
+ bond
+ CH2
+ bond
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/122/ch2b_benzene.chem b/contrib/chem/examples/122/ch2b_benzene.chem
new file mode 100644
index 0000000..0af1c9f
--- /dev/null
+++ b/contrib/chem/examples/122/ch2b_benzene.chem
@@ -0,0 +1,38 @@
+ch2b_benzene.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ benzene
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch2c_benzene_right.chem b/contrib/chem/examples/122/ch2c_benzene_right.chem
new file mode 100644
index 0000000..d9f29b5
--- /dev/null
+++ b/contrib/chem/examples/122/ch2c_benzene_right.chem
@@ -0,0 +1,36 @@
+ch2c_benzene_right.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ benzene pointing right # a rotated benzene ring
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4a_stick.chem b/contrib/chem/examples/122/ch4a_stick.chem
new file mode 100644
index 0000000..f4caef3
--- /dev/null
+++ b/contrib/chem/examples/122/ch4a_stick.chem
@@ -0,0 +1,45 @@
+ch4a_stick.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ bond right
+ bond 60
+ bond 120
+ bond 60
+ bond 120
+ bond down
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/122/ch4b_methyl_acetate.chem b/contrib/chem/examples/122/ch4b_methyl_acetate.chem
new file mode 100644
index 0000000..31625a3
--- /dev/null
+++ b/contrib/chem/examples/122/ch4b_methyl_acetate.chem
@@ -0,0 +1,47 @@
+ch4b_methyl_acetate.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+CH3 # the 3 is automatically turned into a subscript
+bond # the implicit direction is right
+ # implicit connection is to right side of CH3
+C
+double bond 30 # by default, from the substituent C
+O
+bond 120 from C # must be "from C"; otherwise would leave from O
+O
+bond right
+CH3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4c_colon.chem b/contrib/chem/examples/122/ch4c_colon.chem
new file mode 100644
index 0000000..5e42f6b
--- /dev/null
+++ b/contrib/chem/examples/122/ch4c_colon.chem
@@ -0,0 +1,42 @@
+ch4c_colon.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ CH3
+ bond ; C
+ double bond 30 ; O
+ bond 120 from C ; O
+ bond right ; CH3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4d_HCl.H2O.chem b/contrib/chem/examples/122/ch4d_HCl.H2O.chem
new file mode 100644
index 0000000..b6ac99d
--- /dev/null
+++ b/contrib/chem/examples/122/ch4d_HCl.H2O.chem
@@ -0,0 +1,38 @@
+ch4d_HCl.H2O.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ HCl.H2O
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4e_CaSO4.2H2O.chem b/contrib/chem/examples/122/ch4e_CaSO4.2H2O.chem
new file mode 100644
index 0000000..b2f8bc0
--- /dev/null
+++ b/contrib/chem/examples/122/ch4e_CaSO4.2H2O.chem
@@ -0,0 +1,38 @@
+ch4e_CaSO4.2H2O.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ CaSO4.2H2O
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4f_C.chem b/contrib/chem/examples/122/ch4f_C.chem
new file mode 100644
index 0000000..d54461f
--- /dev/null
+++ b/contrib/chem/examples/122/ch4f_C.chem
@@ -0,0 +1,48 @@
+ch4f_C.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ bond ; C # 1st definition of C
+ bond up from C
+ bond down from C
+ bond right from C ; C # 2nd definition of C
+ bond up from C
+ bond down from C
+ bond right from C ; C # 3rd definition of C
+ bond up from C
+ bond down from C
+ bond right from C
+
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4g_BP.chem b/contrib/chem/examples/122/ch4g_BP.chem
new file mode 100644
index 0000000..9c6af4b
--- /dev/null
+++ b/contrib/chem/examples/122/ch4g_BP.chem
@@ -0,0 +1,48 @@
+ch4g_BP.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+# this is the isopropyl group
+ bond 120 ; BP # BP is right end of this bond
+ bond -120 from BP
+ bond right from BP ; C
+ front bond up ; CH3
+ back bond down from C ; D
+ bond right from C ; BP
+# redefine BP to mean the center carbon of this t-butyl group
+ bond up from BP
+ bond right from BP
+ bond down from BP
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4h_methacrylate.chem b/contrib/chem/examples/122/ch4h_methacrylate.chem
new file mode 100644
index 0000000..8300d25
--- /dev/null
+++ b/contrib/chem/examples/122/ch4h_methacrylate.chem
@@ -0,0 +1,65 @@
+ch4h_methacrylate.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ bond dotted
+ bond right ; BP
+ bond up from BP ; C
+ double bond -60 from C ; O
+ bond 60 length .1 from C ; OCH3
+ bond down from BP ; CH3
+# begin second segment of polymer
+ bond right length .5 from BP ; BP
+ bond up length .1 from BP ; H
+ bond down length .1 from BP ; H
+# begin third segment of polymer
+ bond right length .5 from BP ; BP
+ bond up from BP ; C
+ double bond -60 from C ; O
+ bond 60 length .1 from C ; OCH3
+ bond down from BP ; CH3
+# begin fourth segment of polymer
+ bond right length .5 from BP ; BP
+ bond up length .1 from BP ; H
+ bond down length .1 from BP ; H
+# begin fifth segment of polymer
+ bond right length .5 from BP ; BP
+ bond up from BP ; C
+ double bond -60 from C ; O
+ bond 60 length .1 from C ; OCH3
+ bond down from BP ; CH3
+ bond right from BP
+ bond dotted
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4i_cyclo.chem b/contrib/chem/examples/122/ch4i_cyclo.chem
new file mode 100644
index 0000000..866e6f7
--- /dev/null
+++ b/contrib/chem/examples/122/ch4i_cyclo.chem
@@ -0,0 +1,45 @@
+ch4i_cyclo.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R3: ring3
+R4: ring4 at R3 + (.75,0)
+R5: ring5 at R4 + (.75,0)
+R6: ring6 at R5 + (.75,0)
+B: benzene at R6 + (.75,0)
+R7: ring7 at B + (.75,0)
+R8: ring8 at R7 + (.75,0)
+
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4j_ring4.chem b/contrib/chem/examples/122/ch4j_ring4.chem
new file mode 100644
index 0000000..9caf718
--- /dev/null
+++ b/contrib/chem/examples/122/ch4j_ring4.chem
@@ -0,0 +1,40 @@
+ch4j_ring4.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ ring4 pointing 45
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/122/ch4k_ring3.chem b/contrib/chem/examples/122/ch4k_ring3.chem
new file mode 100644
index 0000000..2a2d856
--- /dev/null
+++ b/contrib/chem/examples/122/ch4k_ring3.chem
@@ -0,0 +1,40 @@
+ch4k_ring3.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R: ring3
+ back bond 120 from R.V2 ; C2H5
+ front bond -120 from R.V3 ; HO
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4l_vertex.chem b/contrib/chem/examples/122/ch4l_vertex.chem
new file mode 100644
index 0000000..d9fcb07
--- /dev/null
+++ b/contrib/chem/examples/122/ch4l_vertex.chem
@@ -0,0 +1,45 @@
+ch4l_vertex.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R: benzene pointing right
+ bond left from R.V4 ; HO
+ bond -150 from R.V3 ; CH3O
+ bond right from R.V1 ; C
+ double bond up from C ; O
+ bond right from C ; N
+ bond 45 ; C2H5
+ bond 135 from N ; C2H5
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4m_double.chem b/contrib/chem/examples/122/ch4m_double.chem
new file mode 100644
index 0000000..c5b1373
--- /dev/null
+++ b/contrib/chem/examples/122/ch4m_double.chem
@@ -0,0 +1,38 @@
+ch4m_double.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ ring double 1,2 3,4 5,6
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4n_triple.chem b/contrib/chem/examples/122/ch4n_triple.chem
new file mode 100644
index 0000000..5766f85
--- /dev/null
+++ b/contrib/chem/examples/122/ch4n_triple.chem
@@ -0,0 +1,38 @@
+ch4n_triple.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ ring8 triple 3,4
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4o_aromatic.chem b/contrib/chem/examples/122/ch4o_aromatic.chem
new file mode 100644
index 0000000..aa303c7
--- /dev/null
+++ b/contrib/chem/examples/122/ch4o_aromatic.chem
@@ -0,0 +1,37 @@
+ch4o_aromatic.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R: aromatic ring7
+ "+" at R
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4p_cholestanol.chem b/contrib/chem/examples/122/ch4p_cholestanol.chem
new file mode 100644
index 0000000..e292bea
--- /dev/null
+++ b/contrib/chem/examples/122/ch4p_cholestanol.chem
@@ -0,0 +1,60 @@
+ch4p_cholestanol.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: ring6
+ "R1" at R1 # this puts a label at R1
+ front bond -120 from R1.V5 ; HO
+ # the following line says "fuse the next six-
+ # membered ring with its 6th vertex joining
+ # the second vertex of R1"
+R2: ring6 with .V6 at R1.V2
+ front bond up from R2.V6 ; CH3
+ back bond down from R2.V4 ; H
+ back bond down from R2.V1 ; H
+ front bond up from R2.V2 ; H
+R3: ring6 with .V4 at R2.V2
+R4: flatring with .V5 at R3.V2
+ front bond up from R4.V5 ; CH3
+ back bond down from R4.V4 ; H # this is the alkyl chain
+ bond up from R4.V1 ; BP
+ bond -60 from BP
+ bond 60 from BP
+ bond 120
+ bond 60
+ bond 120 ; BP
+ bond down from BP
+ bond 60 from BP
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4q_rings.chem b/contrib/chem/examples/122/ch4q_rings.chem
new file mode 100644
index 0000000..bafdd92
--- /dev/null
+++ b/contrib/chem/examples/122/ch4q_rings.chem
@@ -0,0 +1,46 @@
+ch4q_rings.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R3: ring3
+R4: ring4 pointing 45 with .V1 at R3.V2
+R5: ring5 pointing down with .V4 at R4.V2
+R6: ring6 pointing 54 with .V6 at R5.V5
+ # the following lines specify the labels inside the rings
+ "3" at R3
+ "4" at R4
+ "5" at R5
+ "6" at R6
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4r_spiro.chem b/contrib/chem/examples/122/ch4r_spiro.chem
new file mode 100644
index 0000000..24ec050
--- /dev/null
+++ b/contrib/chem/examples/122/ch4r_spiro.chem
@@ -0,0 +1,42 @@
+ch4r_spiro.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: ring6
+R2: ring6 with .V1 at R1.V4
+R3: ring5 with .V5 at R2.V3
+ back bond 60 from R3.V2 ; OH
+ front bond 150 from R3.V3 ; OH
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4s_heteroatoms.chem b/contrib/chem/examples/122/ch4s_heteroatoms.chem
new file mode 100644
index 0000000..7dc8ba7
--- /dev/null
+++ b/contrib/chem/examples/122/ch4s_heteroatoms.chem
@@ -0,0 +1,38 @@
+ch4s_heteroatoms.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ ring put N at 2 put S at 4 double 2,3 4,5 6,1
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4t_polycyclic.chem b/contrib/chem/examples/122/ch4t_polycyclic.chem
new file mode 100644
index 0000000..fc6b580
--- /dev/null
+++ b/contrib/chem/examples/122/ch4t_polycyclic.chem
@@ -0,0 +1,49 @@
+ch4t_polycyclic.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: benzene pointing right
+ bond 30 from R1.V6 ; Br
+R2: benzene pointing right with .V5 at R1.V1
+R3: benzene pointing right with .V1 at R2.V3
+ bond 150 from R3.V2 ; CO2H
+R4: benzene pointing right with .V1 at R1.V3
+# next line names bond B1 so we can refer to its end
+B1: bond left from R4.V4
+ ring6 put N at 4 double 2,3 4,5 6,1 with .V3 at B1.end
+B2: bond right from R2.V1
+R5: benzene with .V5 at B2.end
+ ring6 put N at 4 double 1,2 3,4 with .V5 at R5.V3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4u_nicotine.chem b/contrib/chem/examples/122/ch4u_nicotine.chem
new file mode 100644
index 0000000..d38a7c8
--- /dev/null
+++ b/contrib/chem/examples/122/ch4u_nicotine.chem
@@ -0,0 +1,42 @@
+ch4u_nicotine.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ benzene put N at 4
+ bond right
+ ring5 pointing down put N at 1
+ bond down from .N ; CH3 # or .V1
+
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4v_histidine.chem b/contrib/chem/examples/122/ch4v_histidine.chem
new file mode 100644
index 0000000..33a4e9d
--- /dev/null
+++ b/contrib/chem/examples/122/ch4v_histidine.chem
@@ -0,0 +1,44 @@
+ch4v_histidine.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: flatring pointing down put N at 2 put N at 5 double 1,2 3,4
+ H right of R1.V5
+ bond right from R1.V4 ; CH2
+ bond right ; C
+ bond up from C ; H
+ bond down from C ; NH2
+ bond right from C ; CO2H
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4w_lsd.chem b/contrib/chem/examples/122/ch4w_lsd.chem
new file mode 100644
index 0000000..aa68b00
--- /dev/null
+++ b/contrib/chem/examples/122/ch4w_lsd.chem
@@ -0,0 +1,50 @@
+ch4w_lsd.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+B: benzene pointing right
+F: flatring pointing left put N at 5 double 3,4 with .V1 at B.V2
+ H below F.N
+R: ring pointing right with .V4 at B.V6
+ front bond right from R.V6 ; H
+W: ring pointing right with .V2 at R.V6 put N at 1 double 3,4
+ bond right from W.N ; CH3
+ back bond -60 from W.V5 ; H
+ bond up from W.V5 ; C
+ double bond up from C ; O
+ bond right from C ; N
+ bond 45 from N ; C2H5
+ bond 135 from N ; C2H5
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4x_anisole.chem b/contrib/chem/examples/122/ch4x_anisole.chem
new file mode 100644
index 0000000..ec78417
--- /dev/null
+++ b/contrib/chem/examples/122/ch4x_anisole.chem
@@ -0,0 +1,42 @@
+ch4x_anisole.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: benzene
+ bond down from R1.V4 ; OCH3
+R2: benzene at R1 + (1.5,0)
+ bond down from R2.V4 ; O
+ CH3 right of O
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4y_reserpine.chem b/contrib/chem/examples/122/ch4y_reserpine.chem
new file mode 100644
index 0000000..fb5d1ca
--- /dev/null
+++ b/contrib/chem/examples/122/ch4y_reserpine.chem
@@ -0,0 +1,62 @@
+ch4y_reserpine.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+# Some corrections were added.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ CH3O
+ bond 60
+R1: benzene
+R2: aromatic flatring5 pointing down put N at 1 with .V3 at R1.V2
+ H below R2.V1
+R3: ring put N at 3 with .V5 at R2.V5
+R4: ring put N at 1 with .V1 at R3.V3
+ back bond -120 from R4.V4 ; H
+ back bond 60 from R4.V3 ; H
+R5: ring with .V1 at R4.V3
+ bond -120 ; C
+ double bond down from C ; O
+ CH3O left of C
+ back bond 60 from R5.V3 ; H
+ back bond down from R5.V4 ; O
+ CH3 right of O
+ bond 120 from R5.V3 ; O
+ bond right length .1 from O ; C
+ double bond down ; O
+ bond right length .1 from C
+B: benzene pointing right
+ bond 30 from B.V6 ; OCH3
+ bond right from B.V1 ; OCH3
+ bond 150 from B.V2 ; OCH3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch4z1_eqn_glutamic.chem b/contrib/chem/examples/122/ch4z1_eqn_glutamic.chem
new file mode 100644
index 0000000..6cecd7c
--- /dev/null
+++ b/contrib/chem/examples/122/ch4z1_eqn_glutamic.chem
@@ -0,0 +1,78 @@
+ch4z1_eqn_glutamic.chem:
+.br
+.EQ
+delim $$
+.EN
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+# Some corrections were added.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+# a left bracket
+ bond right length .1 ; BP
+ bond up length .3
+ bond right length .1
+ bond down length .3 from BP
+ bond right length .1
+# this is the mainchain amide structure
+ bond right length .1 from BP ; NH
+ bond right ; CH
+# label the CH with an alpha, intended for eqn.
+# this line says "put the north edge of the alpha at the
+# south edge of the CH"
+ "$alpha$" with .n at CH.s
+ bond right from CH ; C
+ double bond up from C ; O
+ bond right length .1 from C ; BP
+# a right bracket
+ bond up length .3
+ bond left length .1
+ bond right length .1 from BP
+ bond down length .3 from BP ; BP
+ bond left length .1
+# label the degree of polymerization
+ "$n$" with .w at BP.se
+# this is the sidechain
+ bond up from CH ; CH2
+ "$beta$" with .e at CH2.w
+ bond up from CH2 ; CH2
+ "$gamma$" with .e at CH2.w
+ bond up from CH2 ; C
+# this is the benzyl ester part
+ double bond -60 from C ; O
+ bond 60 from C ; O
+ bond right ; CH2C6H5
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
+.EQ
+delim off
+.EN
diff --git a/contrib/chem/examples/122/ch4z2_text.chem b/contrib/chem/examples/122/ch4z2_text.chem
new file mode 100644
index 0000000..2000636
--- /dev/null
+++ b/contrib/chem/examples/122/ch4z2_text.chem
@@ -0,0 +1,53 @@
+ch4z2_text.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ bond 120 dotted
+ bond 120 length .3 ; BP
+ back bond -120 length .25 from BP ; H
+ front bond 120 length .25 from BP ; CH3
+ bond 60 length .5 from BP ; BP
+ bond -60 length .25 from BP ; H
+# note the pic move command to position the text
+ move left .35 ; "(ANTI)"
+ front bond 60 length .25 from BP ; H
+# another positioning of text
+ move right .35 ; "(SYN)"
+ bond 120 length .4 from BP ; BP
+ back bond -120 length .25 from BP ; H
+ front bond 120 length .25 from BP ; CH3
+ bond 60 length .5 from BP
+ bond 60 dotted
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch5a_size.chem b/contrib/chem/examples/122/ch5a_size.chem
new file mode 100644
index 0000000..d4eb33f
--- /dev/null
+++ b/contrib/chem/examples/122/ch5a_size.chem
@@ -0,0 +1,45 @@
+ch5a_size.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+.ps 14
+size 16
+R: ring6 put O at 1 put C at 2 put O at 3 put C at 4 put O at 5 put C at 6
+ double bond 60 from R.V2 ; NH
+ double bond down from R.V4 ; NH
+ double bond -60 from R.V6 ; HN
+size 10 # if you are doing more than one
+.ps 10
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch6a_pic.chem b/contrib/chem/examples/122/ch6a_pic.chem
new file mode 100644
index 0000000..ad6dea6
--- /dev/null
+++ b/contrib/chem/examples/122/ch6a_pic.chem
@@ -0,0 +1,43 @@
+ch6a_pic.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R: ring double 2,3
+ line from R.V6 to R.C
+ line from R.C to R.V4
+ X1: 1/2 <R.V5,R.C>
+ X2: 1/2 <R.C,R.V2>
+ bond from X1 to X2
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/ch6b_dna.chem b/contrib/chem/examples/122/ch6b_dna.chem
new file mode 100644
index 0000000..00abbba
--- /dev/null
+++ b/contrib/chem/examples/122/ch6b_dna.chem
@@ -0,0 +1,59 @@
+ch6b_dna.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+P: [
+R1: flatring pointing up put N at 1 put N at 4 double 5,1
+ bond -135 from R1.V4 ; BP
+ "deoxyribose" rjust with .e at BP.w
+R2: ring6 put N at 2 put N at 4 double 1,2 3,4 5,6 with .V6 at R1.V2
+ pic Conn: R2.V2.ne #because naming is too restricted in pic
+ bond up from R2.V1 ; N
+ bond -60 from N ; H
+ bond 60 from N ; H
+]
+ # thymine
+Q: [
+R3: ring6 put N at 3 put N at 5 double 1,2
+ bond up from R3.V1 ; CH3
+ bond 120 from R3.V3 ; BP
+ "deoxyribose" ljust with .w at BP.e
+ double bond down from R3.V4 ; O
+ double bond -60 from R3.V6 ; O
+ bond -120 from R3.V5 ; H
+] with .O at P.H + (.3,.3)
+ bond from Q.O.sw to P.H.ne dotted
+ bond from Q.H.sw to P.Conn dotted
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAa_polymer.chem b/contrib/chem/examples/122/chAa_polymer.chem
new file mode 100644
index 0000000..3293454
--- /dev/null
+++ b/contrib/chem/examples/122/chAa_polymer.chem
@@ -0,0 +1,72 @@
+chAa_polymer.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+# epoxy based on the m-phenyldiamine cured bisphenol-A
+ size 8
+ bond dotted
+ bond ; N
+ bond ; CH2
+ bond down from N
+R1: benzene
+ bond 120 length .1 from R1.V3 ; N
+ bond right length .1 from N
+ bond down length .1 from N
+# back to the CH2
+ bond right from CH2 ; CH
+ bond down from CH ; OH
+ bond right from CH ; CH2
+ bond right ; O
+ bond right
+ benzene pointing right
+ bond right ; C
+ bond up from C ; CH3
+ bond down from C ; CH3
+ bond right from C
+ benzene pointing right
+ bond right ; O
+ bond right from O ; CH2
+ bond right ; CH
+ bond down from CH ; OH
+ bond right from CH ; CH2
+ bond right ; N
+ bond right from N
+ bond dotted
+ bond down from N
+R2: benzene
+ bond 120 length .1 from R2.V3 ; N
+ bond right length .1 from N
+ bond down length .1 from N
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAb_vinyl_chloro.chem b/contrib/chem/examples/122/chAb_vinyl_chloro.chem
new file mode 100644
index 0000000..dff97fc
--- /dev/null
+++ b/contrib/chem/examples/122/chAb_vinyl_chloro.chem
@@ -0,0 +1,62 @@
+chAb_vinyl_chloro.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ Cl
+ bond 120 length .25 ; BP
+ bond 60 length .25 from BP ; Cl
+B1: double bond down length .3 from BP
+ bond 120 length .35 ; BP
+# now comes the ring
+R1: ring6 double 1,2 3,4 5,6 with .V6 at BP
+ bond up length .1 from R1.V1 ; H
+ bond 60 length .1 from R1.V2 ; H
+ bond 120 from R1.V3 ; O
+ bond 60 from O ; C
+ double bond up from C ; O
+ bond 120 from C
+# continue decorating the ring
+ bond down length .1 from R1.V4 ; H
+ bond -120 length .1 from R1.V5 ; H
+# now go back and do the left hand ring
+ bond -120 length .35 from B1.end ; BP
+R2: ring6 double 1,2 3,4 5,6 with .V2 at BP
+ bond up length .1 from R2.V1 ; H
+ bond -60 length .1 from R2.V6 ; H
+ bond -120 from R2.V5 ; O
+ bond -60 from O
+ bond down length .1 from R2.V4 ; H
+ bond 120 length .1 from R2.V3 ; H
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAc_morphine.chem b/contrib/chem/examples/122/chAc_morphine.chem
new file mode 100644
index 0000000..c9fbf10
--- /dev/null
+++ b/contrib/chem/examples/122/chAc_morphine.chem
@@ -0,0 +1,52 @@
+chAc_morphine.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: ring6 double 1,2
+ bond -60 from R1.V6 ; HO
+R2: ring6 with .V1 at R1.V3
+ bond 60 from R2.V2 ; N
+ bond right from N ; CH3
+R3: benzene with .V1 at R2.V5
+ bond -120 from R3.V5 ; HO
+# this is the furan ring
+ bond -135 length .33 from R1.V5 ; O
+ bond -45 length .33 from R3.V6
+# this is the odd ring
+ bond up length .1 from N ; BP
+B1: bond up length .33 from R1.V4
+ bond to BP
+
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAd_chlorophyll.chem b/contrib/chem/examples/122/chAd_chlorophyll.chem
new file mode 100644
index 0000000..e2acb22
--- /dev/null
+++ b/contrib/chem/examples/122/chAd_chlorophyll.chem
@@ -0,0 +1,69 @@
+chAd_chlorophyll.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ Mg
+ bond 45 ; N
+R1: ring5 pointing up put N at 4 double 1,2 4,5 with .V4 at N
+ bond up from R1.V1 ; CH3
+ bond right from R1.V2 ; CH2CH3
+ bond 135 from Mg ; N
+R2: ring5 pointing down put N at 3 double 1,2 4,5 with .V3 at N
+ bond right from R2.V5 ; CH3
+ bond 225 from Mg ; N
+R3: ring5 pointing down put N at 4 double 3,4 with .V4 at N
+ bond -45 from Mg ; N
+R4: ring5 pointing up put N at 3 double 1,5 with .V3 at N
+ bond left from R4.V5 ; H3C
+ bond up from R4.V1 ; CH
+ double bond right length .1 from CH ; CH2
+ double bond 150 length .3 from R1.V3
+ bond to R2.V4
+R5: ring5 pointing 72 with .V5 at R2.V2
+ double bond 135 from R5.V2 ; O
+ bond down from R5.V3 ; C
+ double bond left length .1 from C ; O
+ bond down from C ; O
+ CH3 left of O
+ double bond -25 from R5.V4
+ bond down from R3.V1 ; CH2
+ CH2 left of CH2
+ bond left ; C
+ double bond -45 ; O
+ bond -135 from C ; C20H39O
+ bond left from R3.V2 ; H3C
+ double bond -150 length .3 from R4.V4
+ bond to R3.V3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAe_chair.chem b/contrib/chem/examples/122/chAe_chair.chem
new file mode 100644
index 0000000..27b046a
--- /dev/null
+++ b/contrib/chem/examples/122/chAe_chair.chem
@@ -0,0 +1,49 @@
+chAe_chair.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+pic define chair { [
+ V1: bond 120 length .25
+ V2: bond right length .35
+ V3: bond 150 length .35
+ V4: bond -60 length .25
+ V5: bond left length .35
+ V6: bond to V1.start
+pic ] }
+R1: chair
+R2: chair with .V1 at R1.V4.start
+bond 60 from R2.V4.start ; CH3
+bond down from R2.V4.start ; OH
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAf_arrow.chem b/contrib/chem/examples/122/chAf_arrow.chem
new file mode 100644
index 0000000..f135ecb
--- /dev/null
+++ b/contrib/chem/examples/122/chAf_arrow.chem
@@ -0,0 +1,68 @@
+chAf_arrow.chem:
+.br
+.EQ
+delim $$
+.EN
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+ bond length .1 ; BP
+ bond up length .5
+ bond right
+ bond down length .5 from BP
+ bond right
+ bond right from BP ; C
+ double bond up ; O
+ bond right from C
+ benzene pointing right
+ bond right ; C
+ double bond up from C ; O
+ bond right from C ; O
+ bond right ; CH2
+# this is the statement to make the arrow
+ line <- from CH2.s down
+ move down .1 ; "0.085"
+ CH2CH2CH2 right of CH2
+ bond right ; O
+ bond right length .1 ; BP
+ bond up length .5 from BP
+ bond left
+ bond right length .1 from BP
+ bond down length .5 from BP ; BP
+ bond left
+ "$n$" with .w at BP.se
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
+.EQ
+delim off
+.EN
diff --git a/contrib/chem/examples/122/chAg_circle.chem b/contrib/chem/examples/122/chAg_circle.chem
new file mode 100644
index 0000000..576c926
--- /dev/null
+++ b/contrib/chem/examples/122/chAg_circle.chem
@@ -0,0 +1,54 @@
+chAg_circle.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+bond 120 ; C
+bond 60 ; C
+bond up ; Cl
+double bond 120 from C ; C
+bond 60 ; C
+bond 120 ; C
+bond 60 ; C
+bond up ; Cl
+double bond 120 from C ; C
+circle at C rad .08
+bond 60 from C ; C
+bond 120 ; C
+bond 60 ; C
+double bond 120 ; C
+bond down ; Cl
+bond 60 from C ; C
+bond 120
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chAh_brackets.chem b/contrib/chem/examples/122/chAh_brackets.chem
new file mode 100644
index 0000000..7605a38
--- /dev/null
+++ b/contrib/chem/examples/122/chAh_brackets.chem
@@ -0,0 +1,60 @@
+chAh_brackets.chem:
+.br
+.EQ
+delim $$
+.EN
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+[
+ bond right ; CH2
+ bond 120 ; (CH2)
+ "$nothing sub n$"
+ bond 60 ; .CH2
+]
+# now put the arrow in
+ move right .3
+ arrow .5
+ move right .3
+# begin second structure
+[
+ bond right ; CH.
+ bond 120 ; (CH2)
+ "$nothing sub n$"
+ bond 60 ; CH3
+]
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
+.EQ
+delim $$
+.EN
diff --git a/contrib/chem/examples/122/chAi_poly_vinyl_chloride.chem b/contrib/chem/examples/122/chAi_poly_vinyl_chloride.chem
new file mode 100644
index 0000000..e4539bb
--- /dev/null
+++ b/contrib/chem/examples/122/chAi_poly_vinyl_chloride.chem
@@ -0,0 +1,141 @@
+chAi_poly_vinyl_chloride.chem:
+.br
+.ps -2
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+db = .12
+cwid = .095
+A: [
+ bond dotted
+ bond right ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; C.
+ bond down ; Cl
+ bond right from C ; CH2
+ bond ; CH2
+ bond down ; Cl
+]
+" (6.13a)" ljust at A.e
+arrow down .5 from A.s
+[
+ CH2
+ double bond right ; CHCl
+] with .w at last arrow.c
+B: [
+ bond dotted
+ bond right ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; C
+ bond up ; Cl
+ bond down from C ; CH2
+ bond ; CH2Cl
+ bond right from C ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH
+ bond dotted
+] with .n at end of last arrow
+" (6.13b)" ljust at B.e
+C: [
+ bond dotted
+ bond right ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; C.
+ bond down ; Cl
+ bond right from C ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH2
+ bond down ; Cl
+] with .n at B.s - (0,.5)
+" (6.14a)" ljust at C.e
+arrow down .3 from C.s
+[
+ CH2
+ double bond right
+ CHCl
+] with .w at last arrow.s
+arrow down .3 from last arrow.s
+
+D: [
+ bond dotted
+ bond right ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; C
+ bond up ; Cl
+ bond down from C ; CH2
+ bond ; CHCl
+ bond ; CH2
+ bond ; CH2Cl
+ bond right from C ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH
+ bond dotted
+] with .n at last arrow.s
+" (6.14b)" ljust at D.e
+E: [
+ bond dotted
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+ bond right from CH ; CH2
+ bond ; CH
+ bond down ; Cl
+] with .e at B.w - (.5,0)
+
+arrow from E.ne to A.sw
+arrow from E.se to C.nw
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
+.ps +2
diff --git a/contrib/chem/examples/122/chBa_jump.chem b/contrib/chem/examples/122/chBa_jump.chem
new file mode 100644
index 0000000..cd40a3a
--- /dev/null
+++ b/contrib/chem/examples/122/chBa_jump.chem
@@ -0,0 +1,41 @@
+chBa_jump.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+SiO2 # name = SiO2
+move right 1
+CH3CH2NH2.HCl # name = CH3CH2NH2HCl
+
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chBb_bonds.chem b/contrib/chem/examples/122/chBb_bonds.chem
new file mode 100644
index 0000000..bc29895
--- /dev/null
+++ b/contrib/chem/examples/122/chBb_bonds.chem
@@ -0,0 +1,42 @@
+chBb_bonds.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+C
+frontbond -170 from C ; H
+backbond 10 from C ; CO2H
+bond left length .15 from C ; H2N
+bond right from C ; CH3
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/122/chBc_rings.chem b/contrib/chem/examples/122/chBc_rings.chem
new file mode 100644
index 0000000..950cd0b
--- /dev/null
+++ b/contrib/chem/examples/122/chBc_rings.chem
@@ -0,0 +1,43 @@
+chBc_rings.chem:
+.br
+.cstart
+
+# Example file for 'chem':
+
+# This originates from Computing Science Technical Report No. 122
+# CHEM - A Program for Typesetting Chemical Diagrams: User Manual
+# by Jon L. Bentley, Lynn W. Jelinski, Brian W. Kernighan
+# <http://cm.bell-labs.com/cm/cs/cstr/122.ps.gz>.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+########################################################################
+
+R1: benzene
+ bond -120 from R1.V5 ; CH3O
+R2: ring4 pointing 45 with .V4 at R1.V2
+R3: aromatic ring6 put N at 4 put S at 2 at R2 + (.75,0)
+R4: ring5 pointing left at R3 + (.75,0)
+ label R4
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/README.txt b/contrib/chem/examples/README.txt
new file mode 100644
index 0000000..6786705
--- /dev/null
+++ b/contrib/chem/examples/README.txt
@@ -0,0 +1,47 @@
+This directory contains examples for the 'chem' language.
+
+You can view the graphical display of the examples by calling
+
+ @g@chem <file> | groff -p ...
+
+On the displays, you can see rings consisting of several lines and
+bonds (lines). All points on rings and bonds that do not have a
+notation mean a C atom (carbon) filled with H atoms (hydrogen) such
+that the valence of 4 is satisfied.
+
+For example, suppose you have just a single line without any
+characters. That means a bond. It has two points, one at each end of
+the line. So each of these points stands for a C atom, the bond
+itself connects these 2 C atoms. To fulfill the valence of 4, each
+points has to carry additionally 3 H atoms. So the single empty bond
+stands for CH3-CH3, though this combination doesn't make much sense
+chemically.
+
+
+####### License
+
+Copyright (C) 2006-2020 Free Software Foundation, Inc.
+Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+This file is part of 'chem', which is part of 'groff'.
+
+'groff' is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+'groff' is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+The GPL2 license text is available in the internet at
+<http://www.gnu.org/licenses/gpl-2.0.html>.
+
+
+##### Editor settings
+Local Variables:
+fill-column: 72
+mode: text
+End:
+vim: set textwidth=72:
diff --git a/contrib/chem/examples/atp.chem b/contrib/chem/examples/atp.chem
new file mode 100644
index 0000000..738c4da
--- /dev/null
+++ b/contrib/chem/examples/atp.chem
@@ -0,0 +1,58 @@
+atp.chem:
+.cstart
+
+# Example file for 'chem':
+# ATP or C10_H16_N5_O13_P3 or
+# [[[5-(6-aminopurin-9-yl)-3,4-dihydroxy-oxolan-2-yl]methoxy-hydroxy-
+# phosphoryl]oxy-hydroxy-phosphoryl]oxyphosphonic acid
+
+# Found at http://www.chemindustry.com/apps/chemicals.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+R1: ring5 pointing left double 1,2 3,4 put N at 2 put N at 5
+B: benzene put N at 2 with .V6 at R1.V3 with .V5 at R1.V4
+ bond up ; NH2
+ backbond 170 length .7 from R1.V5
+R2: ring5 pointing down with .V2 put O at 1
+ bond down at R2.V2 ; H
+ bond down length .1 at R2.V3 ; H
+ bond up length .1 at R2.V3 ; OH
+ bond down length .1 at R2.V4 ; H
+ bond up length .1 at R2.V4 ; OH
+ frontbond 70 at R2.V5
+ bond 110 ; O
+ bond right ; P
+ doublebond up ; O
+ bond down from P ; OH
+ bond right from P ; O
+ bond right ; P
+ doublebond up ; O
+ bond down from P ; OH
+ bond right from P ; O
+ bond right ; P
+ doublebond up ; O
+ bond down from P ; OH
+ bond right from P ; OH
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/cholesterin.chem b/contrib/chem/examples/cholesterin.chem
new file mode 100644
index 0000000..12ac076
--- /dev/null
+++ b/contrib/chem/examples/cholesterin.chem
@@ -0,0 +1,47 @@
+cholesterin.chem:
+.cstart
+
+# Example file for 'chem':
+# Cholesterin or C27_H46O or
+# 10,13-dimethyl-17-(6-methylheptan-2-yl)-2,3,4,5,6,9,11,12,14,15,16,17-
+# dodecahydro-1H-cyclopenta[a]phenanthren-3-ol
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+R1: ring6
+ bond -120 ; HO
+R2: ring6 with .V5 at R1.V3 with .V6 at R1.V2 double 4,5
+ bond up at R2.V6
+R3: ring6 with .V5 at R2.V1 with .V4 at R2.V2
+R4: flatring5 pointing up with .V4 at R3.V3 with .V5 at R3.V2
+ bond up at R4.V5
+ bond up at R4.V1
+B1: bond -60
+ bond 60 at B1.start
+ bond 120
+ bond 60
+ bond 120
+B2: bond 60
+ bond down at B2.start
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/ethamivan.chem b/contrib/chem/examples/ethamivan.chem
new file mode 100644
index 0000000..a0a8aa2
--- /dev/null
+++ b/contrib/chem/examples/ethamivan.chem
@@ -0,0 +1,43 @@
+ethamivan.chem:
+.cstart
+
+# Example file for 'chem':
+# Ethamivan or Analepticon or C12_H17_N_O3 or
+# N,N-diethyl-4-hydroxy-3-methoxy-benzamide
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+R: ring pointing left double 2,3 4,5 6,1
+ bond left from R.V1 ; O
+ bond left ; H
+ bond -150 from R.V6 ; O
+ bond left
+ bond 60 from R.V4
+B1: double bond up ; O
+ bond 120 from B1.start ; N
+ bond 45
+ bond right
+ bond 135 from N
+ bond right
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/lsd.chem b/contrib/chem/examples/lsd.chem
new file mode 100644
index 0000000..4879ea8
--- /dev/null
+++ b/contrib/chem/examples/lsd.chem
@@ -0,0 +1,46 @@
+lsd.chem:
+.cstart
+
+# Example file for 'chem':
+# LSD or Lysergic acid dethylamide or C20_H25_N3O or
+# 9,10-Didehydro-N,N-diethyl-6-methyl-ergoline-8-beta-carboxamide
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+F: flatring5 pointing left put N at 5 double 3,4
+ H below F.N
+B: benzene pointing right with .V1 at F.V2
+R1: ring pointing right with .V4 at B.V6
+ front bond right from R1.V6 ; H
+R2: ring pointing right with .V2 at R1.V6 put N at 1 double 3,4
+ bond right from R2.N
+ back bond -60 from R2.V5 ; H
+ bond up from R2.V5
+B1: double bond up ; O
+ bond right from B1.start ; N
+ bond 45
+ bond right
+ bond 135 from N
+ bond right
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+.cend
diff --git a/contrib/chem/examples/morphine.chem b/contrib/chem/examples/morphine.chem
new file mode 100644
index 0000000..5c236ca
--- /dev/null
+++ b/contrib/chem/examples/morphine.chem
@@ -0,0 +1,51 @@
+morphine.chem:
+.cstart
+
+# Example file for 'chem':
+# Morphine or C23_H31_N3O or
+# N,N-diethyl-N'-(2-methoxyacridin-9-yl)-pentane-1,4-diamine
+
+# Found at http://www.chemindustry.com/apps/chemicals.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+R1: benzene
+R2: benzene with .V6 at R1.V2 with .V5 at R1.V3 put N at 4
+R3: benzene with .V6 at R2.V2 with .V5 at R2.V3
+ bond 60 at R3.V2 ; O
+ bond 120
+ bond up at R2.V1 ; N
+ bond 60 ; H
+ bond -60 at N
+B1: backbond -120
+ bond up at B1.start
+ bond -60
+ bond up
+ bond -60 ; N
+ bond up
+ bond -60
+ bond -120 at N
+ bond -60
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/penicillin.chem b/contrib/chem/examples/penicillin.chem
new file mode 100644
index 0000000..ef522bc
--- /dev/null
+++ b/contrib/chem/examples/penicillin.chem
@@ -0,0 +1,52 @@
+penicillin.chem:
+.cstart
+
+# Example file for 'chem':
+# Penicillin or C16_H18_N2_O4_S or
+# 3,3-dimethyl-6-oxo-7-(2-phenylacetyl)amino-2-thia-5-
+# azabicyclo[3.2.0]heptane-4-carboxylic acid
+
+# Found at http://www.chemindustry.com/apps/chemicals.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+R1: flatring5 pointing up put S at 1 put N at 4
+ bond 45 at R1.V2
+ bond 135 at R1.V2
+ bond 120 at R1.V3
+D1: doublebond 45 ; O
+ bond 135 at D1.start ; OH
+ bond left at R1.N
+ doublebond -135 ; O
+ bond left at R1.V5
+B1: bond down length .3
+ bond -60 at B1.start ; N
+ bond up ; H
+ bond -120 at N
+D2: doublebond down ; O
+ bond -60 at D2.start
+ bond -120
+ benzene
+
+# Local Variables:
+# mode: Nroff
+# End:
+.cend
diff --git a/contrib/chem/examples/reserpine.chem b/contrib/chem/examples/reserpine.chem
new file mode 100644
index 0000000..d1b4046
--- /dev/null
+++ b/contrib/chem/examples/reserpine.chem
@@ -0,0 +1,63 @@
+reserpine.chem:
+.PS
+begin chem
+
+# Example file for 'chem':
+# Reserpine or C33H40N2O9
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
+
+# This file is part of 'chem', which is part of 'groff'.
+
+# 'groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) version 2 as
+# published by the Free Software Foundation.
+
+# 'groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# The GPL2 license text is available in the internet at
+# <http://www.gnu.org/licenses/gpl-2.0.html>.
+
+R1: benzene pointing up
+ bond -120 from R1.V5 ; O
+ bond left
+R2: flatring5 pointing down double 4,5 with .V2 at R1.V3 with .V3 at R1.V2 put N at 1
+ H below R2.V1
+R3: ring put N at 3 with .V5 at R2.V5
+R4: ring put N at 1 with .V1 at R3.V3
+ back bond -120 from R4.V4 ; H
+ back bond 60 from R4.V3 ; H
+R5: ring with .V1 at R4.V3
+ bond -120
+D1: double bond down ; O
+ bond left from D1.start ; O
+ bond left
+ back bond 60 from R5.V3 ; H
+ back bond down from R5.V4 ; O
+ bond down from O
+ bond 120 from R5.V3 ; O
+ bond 50 from O
+D2: double bond up ; O
+ bond right length .1 from D2.start
+B: benzene pointing right
+ bond 45 from B.V6 ; O
+ bond right
+ bond right from B.V1 ; O
+ bond right
+ bond 135 from B.V2 ; O
+ bond right
+
+# Local Variables:
+# fill-column: 72
+# mode: Nroff
+# End:
+# vim: set textwidth=72:
+end
+.PE