ppchtex.mkiv /size: 115 Kb    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=ppchtex,
3%D        version=1997.03.19,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=\PPCHTEX\ (Plain Pictex Context cHemie \TEX),
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D    suggestions={Tobias Burnus, Dirk Kuypers \& Ton Otten},
9%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
10%C
11%C This module is part of the \CONTEXT\ macro||package and is
12%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
13%C details.
14
15\endinput
16
17% option=test    => boxes
18%        dummy   => file
19%        final   => file / local run
20%
21% constante van phantom in definitie ONE: \setchemicaltextwidth 300
22%
23% it would be interesting to rewrite this module with todays
24% experiences and new context functionality, maybe ...
25
26% Deze module ondersteunt het zetten van chemische
27% (structuur)formules. Hoewel de macro' zijn afgestemd op
28% CONTEXT, zijn ze ook buiten deze zetomgeving te gebruiken.
29%
30% Dit is, afgezien van updates, de definitieve versie van
31% PPCHTEX. Gebruikersgemak, eenvoud, flexibiliteit, en
32% snelheid zijn inmiddels redelijk geoptimaliseerd. Dit neemt
33% niet weg dat hier en daar nog verbetering mogelijk is. Dit
34% zal dan ook nog gebeuren.
35%
36% Volgende versies zullen tenminste dezelfde functionaliteit
37% hebben. We houden ons natuurlijk het recht voor de kwaliteit
38% van de output te verbeteren. Daarnaast staan nog op het
39% wensenlijstje:
40%
41% -  optimaliseren in termen van proces-tijd
42% -  aanpassen naamgeving van interne macro's
43% -  toevoegen van functionaliteit
44% -  in \x!-vorm omzetten van GIVES, TB enz.
45%
46% De mix tussen engels en nederlands lijkt soms verwarrend.
47% Meestal zijn verborgen macro's engels en zichtbare macro's
48% nederlands. Het gebruik van [ ] en { } sluit aan op andere
49% Context-macro's. Hetzelfde geldt voor instellingen en
50% \start-\stop-constructies.
51%
52% De schijnbaar overbodige \bgroup-\egroup constructie
53% garandeert aansluiting bij de Context-macro's voor het
54% plaatsen van figuren, tabellen en andere floats.
55%
56% Binnen Context worden de macro's geladen met
57% \gebruikextras[chemie]. Daarbij wordt een passende melding
58% getoont. Buiten Context genereren we een melding:
59
60\doifundefined{usemodule}
61  {\writestatus{loading}{ConTeXt Chemical Macro's / 1996.3.1}}
62
63% Er kan gebruik worden gemaakt van PiCTeX of PStricks. Een
64% van deze pakketten moet van te voren zijn geladen.
65%
66% \input prepictex.tex (i.g.v. LaTeX)
67% \input pictex.tex
68% \input postpictex.tex (i.g.v. LaTeX)
69%
70% of:
71%
72% \input multido.tex
73% \input pstricks.tex
74% \input pst-plot.tex
75%
76% In \CONTEXT\ kan men de modules m-pictex en m-pstricks
77% gebruiken. De eerste module laad of efficiente wijze PiCTeX
78% en de tweede module koppelt het PSTRICKS kleurmechanisme
79% aan dat van \CONTEXT.
80
81% PSTricks: {-\chemicalangle} instead of {*0}, which produces
82% faulty ps code when \chemicalangle=0
83
84\startcommands dutch english german
85
86    gotochemical:  naarchemie       gotochemical    zurchemie
87   setupchemical:  stelchemiein     setupchemical   stellechemieein
88   startchemical:  startchemie      startchemical   startchemie
89    stopchemical:  stopchemie       stopchemical    stopchemie
90  definechemical:  definieerchemie  definechemical  definierechemie
91        chemical:  chemie           chemical        chemie
92         toptext:  boventekst       toptext         textueber
93         bottext:  ondertekst       bottext         textunter
94         midtext:  middentekst      midtext         textmitte
95
96\stopcommands
97
98\doifundefined{fiverm}  % In the more recent LaTeX versions
99  {\font\fiverm=cmr5 }  % \fiverm is no longer (pre)defined.
100
101\newconstant\chemicaldrawingmode
102
103\doifelsedefined{beginpicture}           % PiCTeX
104  {\doifelsedefined{startMPdrawing}
105     {\chemicaldrawingmode\plustwo  }   % MetaPost
106     {\chemicaldrawingmode\zerocount}}  % raw
107  {\doifelsedefined{psaxes}
108     {\chemicaldrawingmode\plusone  }   % PSTricks
109     {\chemicaldrawingmode\plusthree}}  % unknown
110
111\ifcase\chemicaldrawingmode
112  \writestatus{ppchtex}{using PiCTeX}
113\or
114  \writestatus{ppchtex}{using PSTricks (still experimental)}
115  \writestatus{ppchtex}{automatic sizing not (yet) supported}
116\or
117  \writestatus{ppchtex}{using PiCTeX and MetaPost}
118\else
119  \writestatus{ppchtex}{load PiCTeX (+pre/post) or PSTricks (+pst_plot) first}
120  \bgroup
121  \read16 to \exit
122  \egroup
123  \expandafter\endinput
124\fi
125
126%I n=Chemie
127%I c=\stelchemiein,\chemie
128%I
129%I Chemische formules kunnen worden gezet met behulp van de
130%I onderstaande commando's:
131%I
132%I buiten $ en $$ :
133%I
134%I   \chemie[segmenten][symbolen]
135%I
136%I   \startchemie[instellingen]
137%I     \chemie...
138%I     \chemie...
139%I   \stopchemie
140%I
141%I en binnen $ en $$:
142%I
143%I   \chemie{}{}
144%I
145%I Voor tekst, uitleg en voorbeelde verwijzen we vooralsnog
146%I naar de handleiding.
147%P
148%I Het gedrag van de macro's kan worden ingesteld met:
149%I
150%I   \stelchemiein[breedte=,hoogte=,links=,rechts=,boven=,
151%I     onder=,korps=,schaal=,status=,assenstelsel=,kader=,
152%I     variant=,optie=,formaat=,tekstformaat=,resolutie=,
153%I     offset=,letter=]
154%I
155%I Structuren kunnen worden voorgedefinieerd met het commando
156%I
157%I   \definieerchemie[naam]{\chemie...}
158
159%S \startsetup
160%S   \command
161%S     [\!stelchemiein]
162%S   \type
163%S     [\c!vars!]
164%S   \variable
165%S     [\c!breedte]
166%S     [\c!number!,\v!passend]
167%S     [0]
168%S   \variable
169%S     [\c!hoogte]
170%S     [\c!number!,\v!passend]
171%S     [0]
172%S   \variable
173%S     [\c!links]
174%S     [\c!number!]
175%S     [0]
176%S   \variable
177%S     [\c!rechts]
178%S     [\c!number!]
179%S     [0]
180%S   \variable
181%S     [\c!boven]
182%S     [\c!number!]
183%S     [0]
184%S   \variable
185%S     [\c!onder]
186%S     [\c!number!]
187%S     [0]
188%S   \variable
189%S     [\c!resolutie]
190%S     [\c!number!]
191%S     [\outputresolution]
192%S   \variable
193%S     [\c!korps]
194%S     [10pt,11pt,12pt]
195%S     [\bodyfontsize]
196%S   \variable
197%S     [\c!schaal]
198%S     [\v!klein,\v!middel,\v!groot]
199%S     [\v!middel]
200%S   \variable
201%S     [\c!formaat]
202%S     [\v!klein,\v!middel,\v!groot]
203%S     [\v!groot]
204%S   \variable
205%S     [\c!tekstformaat]
206%S     [\v!klein,\v!middel,\v!groot]
207%S     [\v!groot]
208%S   \variable
209%S     [\c!status]
210%S     [\v!start,\v!stop]
211%S     [\v!start]
212%S   \variable
213%S     [\c!kader]
214%S     [\v!aan,\v!uit]
215%S     [\v!uit]
216%S   \variable
217%S     [\c!assenstelsel]
218%S     [\v!aan,\v!uit]
219%S     [\v!uit]
220%S   \variable
221%S     [\c!optie]
222%S     [\v!test]
223%S     []
224%S   \variable
225%S     [\c!variant]
226%S     [1,2]
227%S     [1]
228%S   \variable
229%S     [\c!offset]
230%S     [HIGH,LOW]
231%S     [LOW]
232%S   \variable
233%S     [\c!letter]
234%S     [\c!command!]
235%S     [\rm]
236%S \stopsetup
237
238%S \startsetup
239%S   \command
240%S     [\v!startchemie]
241%S   \type
242%S     [\c!vars!\c!stp!]
243%S   \inheritvariable
244%S     [\v!stelchemiein]
245%S     []
246%S \stopsetup
247
248%S \startsetup
249%S   \command
250%S     [\v!chemie]
251%S   \type
252%S     [\c!vals!\c!vals!]
253%S   \value
254%S     [\c!list!]
255%S     []
256%S   \value
257%S     [\c!list!]
258%S     []
259%S \stopsetup
260
261%S \startsetup
262%S   \command
263%S     [definieerchemie]
264%S   \type
265%S     [\c!val!\c!arg!]
266%S   \value
267%S     [\c!text!]
268%S     []
269%S \stopsetup
270
271\unprotect
272
273% Om te voorkomen dat sub- en superscripts botsen passen we
274% wat fontdimen's aan (Knuth, The TeXBook, p179). Helaas
275% kunnen deze instellingen niet lokaal worden gehouden door
276% groeperen, vandaar dat een en ander moet worden geset én
277% gereset.
278%
279% Er dient een relatie te worden gelegd met de afmetingen
280% van de letters. In een eerdere versie werden daartoe de
281% \fontdimen's opgehoogd. Omdat dit problemen gaf bij
282% scaled fonts, is bij nader inzien gekozen voor de
283% onderstaande oplossing, waarbij de nieuwe waarden worden
284% afgeleid van de x-height (\fontexheight). De factor 0.70
285% is min of meer experimenteel vastgesteld. Soms worden de
286% regels iets verder uit elkaar gezet. Jammer. Italic fonts
287% hebben grotere cijfers en vallen min of meer uit de boot.
288
289\newif\ifloweredsubscripts % this will be redone in the mkiv ways
290
291\def\setsubscripts
292  {\def\dosetsubscript##1##2##3%
293     {\dimen0=##3\fontexheight##2%
294      \setxvalue{@@\string##1\string##2}{\the##1##2\relax}%
295      ##1##2=\dimen0\relax}%
296   \def\dodosetsubscript##1##2%
297     {\dosetsubscript{##1}{\textfont        2}{##2}%
298      \dosetsubscript{##1}{\scriptfont      2}{##2}%
299      \dosetsubscript{##1}{\scriptscriptfont2}{##2}}%
300   %dodosetsubscript\mathsupnormal  {?}%
301   \dodosetsubscript\mathsubnormal  {.7}%
302   \dodosetsubscript\mathsubcombined{.7}%
303   \global\loweredsubscriptstrue}
304
305\def\resetsubscripts
306  {\ifloweredsubscripts
307     \def\doresetsubscript##1##2%
308       {\dimen0=\getvalue{@@\string##1\string##2}\relax
309        ##1##2=\dimen0}%
310     \def\dodoresetsubscript##1%
311       {\doresetsubscript{##1}{\textfont2}%
312        \doresetsubscript{##1}{\scriptfont2}%
313        \doresetsubscript{##1}{\scriptscriptfont2}}%
314     %dodoresetsubscript\mathsupnormal
315     \dodoresetsubscript\mathsubnormal
316     \dodoresetsubscript\mathsubcombined
317     \global\loweredsubscriptsfalse
318   \fi}
319
320\ifx\Umathchar\undefined \else
321    % for the moment we nil them, soon we will have a proper
322    % way to deal with this
323    \let\setsubscripts  \relax
324    \let\resetsubscripts\relax
325\fi
326
327\def\doresetsubscripts
328  {\resetsubscripts}
329
330\def\sethighsubscripts
331  {\resetsubscripts
332   \let\dosetsubscripts=\relax}
333
334\def\setlowsubscripts
335  {\def\dosetsubscripts{\setsubscripts}}
336
337\setlowsubscripts
338
339\newcount\horchemical % t.z.t. \newcounter
340\newcount\verchemical % t.z.t. \newcounter
341\newcount\txtchemical % t.z.t. \newcounter
342\newcount\levchemical % t.z.t. \newcounter
343
344\newif\ifinchemical            \inchemicalfalse
345\newif\iffixedchemical         \fixedchemicalfalse
346
347\newbox\chemicalsymbols
348
349% Eigenlijk moeten de constanten en variabelen in cont-nl.tex
350% staan. Dit pakket is echter relatief onafhankelijk van CONTEXT.
351
352\definesystemvariable  {chemical}
353
354\definesystemconstant  {chemical}
355
356\definesystemconstant  {translate}
357\definesystemconstant  {distance}
358\definesystemconstant  {mirror}
359\definesystemconstant  {rotate}
360\definesystemconstant  {substitute}
361\definesystemconstant  {angle}
362
363\definesystemconstant  {executechemical}
364\definesystemconstant  {chemicaltextelement}
365\definesystemconstant  {chemicallinesegment}
366\definesystemconstant  {chemicalcircsegment}
367
368\def\chemicalspace     {\quad}
369
370% begin van experiment:
371%
372% De onderstaande twee macro's kunnen worden gebruikt voor
373% bijvoorbeeld een interactiemechanisme.
374%
375% \localgotochemical   {verwijzing} {tekst}
376% \localthisischemical {verwijzing}
377
378\def\dowithchemical%
379  {}
380
381\def\localgotochemical#1#2{\gotobox{#2}[#1]}
382\def\localthisischemical#1{\pagereference[#1]}
383
384% eind van experiment
385
386\def\setchemicalmaximum #1
387  {\def\maxchemical{#1}}
388
389\def\doifchemicalnumber#1#2#3%
390  {\doifelsenumber{#1}
391     {\ifnum#1>\maxchemical\relax
392        \writestatus{ppchtex}{number #1 is skipped}%
393      \else
394        #3%
395      \fi}
396     {\unknownchemical{#2}}}%
397
398\newif\ifsmallchemicaltext
399
400\let\@@localchemicalstyle\empty
401
402\unexpanded\def\setupchemicalformat[#1]%
403  {\processaction
404     [\getvalue{#1\c!size}]
405     [  \v!small=>\def\@@localchemicalformat{\scriptscriptstyle},
406       \v!medium=>\def\@@localchemicalformat{\ifsmallchemicaltext\scriptscriptstyle\else\scriptstyle\fi},
407          \v!big=>\def\@@localchemicalformat{\ifsmallchemicaltext\scriptstyle\else\textstyle\fi},
408      \s!unknown=>\def\@@localchemicalformat{\getvalue{#1\c!size}}]%
409   \processaction
410     [\getvalue{#1\c!textsize}]
411     [  \v!small=>\def\@@localchemicalstyle{\scriptscriptstyle},
412       \v!medium=>\def\@@localchemicalstyle{\ifsmallchemicaltext\scriptscriptstyle\else\scriptstyle\fi},
413          \v!big=>\def\@@localchemicalstyle{\ifsmallchemicaltext\scriptstyle\else\textstyle\fi},
414      \s!unknown=>\def\@@localchemicalstyle{\getvalue{#1\c!textsize}}]%
415   \processaction
416     [\getvalue{#1\c!scale}]
417     [  \v!small=>\def\@@localchemicalscale{500},
418       \v!medium=>\def\@@localchemicalscale{625},
419          \v!big=>\def\@@localchemicalscale{750},
420      \s!unknown=>\def\@@localchemicalscale{\getvalue{#1\c!scale}}]}
421
422\def\@@currentchemicalformat
423  {\ifinchemical
424     \@@localchemicalformat
425   \else
426     \@@localchemicalstyle
427   \fi}
428
429\def\dosetupchemical[#1]%
430  {\getparameters[\??chemical\s!chemical][#1]%
431   \doifelse{\@@chemicalchemicaloffset}{LOW}
432     {\setlowsubscripts}
433     {\sethighsubscripts}%
434   \setupchemicalformat[\??chemical\s!chemical]%
435   \ignorespaces}
436
437\unexpanded\def\setupchemical
438  {\dosingleargument\dosetupchemical}
439
440\def\@@dochemicalstyle%       % default mapping
441  {\@@chemicalstyle}
442
443\def\@@dochemicalcolor%       % no mapping yet
444  {}
445
446\def\@@chemicalstyle         %  $inner-style$  % (overloaded)
447  {\@@chemicalchemicalstyle} % $$outer-style$$
448
449\def\@@writechemicalstate#1#2%
450  {}
451
452\def\@@beginchemicallocalpicture
453  {\ifcase\chemicaldrawingmode
454     \beginpicture
455   \or
456     \pspicture(0,0)(0,0) % is this permitted ?
457   \or
458     \pushMPdrawing
459     \startMPdrawing
460       %prologues := 1 ;
461       %input mp-tool ;
462       u := 10*\@@chemicalunit;
463       bboxmargin := 0pt ;
464       pickup pencircle scaled 2u ; % ???
465     \stopMPdrawing
466     \beginpicture
467   \fi}
468
469\def\@@endchemicallocalpicture#1#2%
470  {\ifcase\chemicaldrawingmode
471     \endpicture
472   \or
473     \endpspicture
474   \or
475     \resetchemicalcoordinates
476     \setbox2\hbox{\ignoreMPboxdepth\getMPdrawing}%
477     \wd2\zeropoint
478     \ht2\zeropoint
479     \dp2\zeropoint
480     \put {\box2} at 0 0
481     \endpicture
482     \popMPdrawing
483   \fi}
484
485\def\@@beginchemicalpicture#1#2#3#4%
486  {\ifnum\chemicaldrawingmode=1
487     \pspicture(#1,#3)(#2,#4)%
488     \def\account##1##2{}%
489     \psaxes[axesstyle=none,labels=none,ticks=none](#1,#3)(#2,#4)%
490   \else
491     \beginpicture
492     \setplotarea
493       x from {#1} to {#2},
494       y from {#3} to {#4}
495     \iffixedchemical
496       \accountingon
497       \def\account##1##2%
498         {\put {} at {##1} {##2} }%
499     \else
500       \accountingoff
501       \def\account##1##2{}%
502     \fi
503   \fi
504   \ignorespaces}
505
506\def\@@endchemicalpicture%
507  {\ifcase\chemicaldrawingmode
508     \put {\box\chemicalsymbols} at 0 0 %  elders
509     \endpicture
510   \or
511     \rput(0,0){\box\chemicalsymbols}%
512     \endpspicture
513   \or
514     \put {\box\chemicalsymbols} at 0 0 %  elders
515     \ifMPdrawingdone
516       \resetchemicalcoordinates
517       \setbox2\hbox{\ignoreMPboxdepth\getMPdrawing}%
518       \wd2\zeropoint
519       \ht2\zeropoint
520       \dp2\zeropoint
521       \put {\box2} at 0 0 %
522     \fi
523     \endpicture
524   \fi}
525
526\def\@@setchemicalcoordinatesystem#1%
527  {\edef\@@chemicalunit{#1}%
528   \ifcase\chemicaldrawingmode
529     \setcoordinatesystem units <\@@chemicalunit,\@@chemicalunit> %
530   \or
531     \psset{unit=\@@chemicalunit}%
532   \or
533     \setcoordinatesystem units <\@@chemicalunit,\@@chemicalunit> %
534     \startMPdrawing
535      %input mp-tool ;
536      %prologues := 1 ;
537       u := 10*#1;
538       bboxmargin := 0pt ;
539       pickup pencircle scaled 2u ; % ???
540     \stopMPdrawing
541   \fi}
542
543\ifx\MPdivten\undefined % hack to prevent overflows in mp
544    \def\MPdivten[#1]{\withoutpt\the\dimexpr#1pt/10\relax}
545\fi
546
547\def\@@setchemicalaxis#1#2#3#4%
548  {\ifcase\chemicaldrawingmode
549     \axis
550       bottom shiftedto y=0
551       ticks from {#1} to {#2} by 500 /
552     \axis
553       left shiftedto x=0
554       ticks from {#3} to {#4} by 500 / %
555   \or
556     \psaxes[labels=none,Dx=500,Dy=500](0,0)(#1,#3)(#2,#4)%
557   \or
558     \global\MPdrawingdonetrue
559     % we need to div beforehand because of mp limitations
560     \startMPdrawing
561        x1 := \MPdivten[#1]u ; x2 := \MPdivten[#2]u;
562        y1 := \MPdivten[#3]u ; y2 := \MPdivten[#4]u;
563        draw z1--(x2,y1)--z2--(x1,y2)--cycle ;
564        d := 50u ; dd := 10u ;
565        draw (x1,0)--(x2,0) ;
566        draw (0,y1)--(0,y2) ;
567        for i=d step -d until x1: draw (i,dd)--(i,-dd) ; endfor ;
568        for i=d step  d until x2: draw (i,dd)--(i,-dd) ; endfor ;
569        for i=d step -d until y1: draw (-dd,i)--(dd,i) ; endfor ;
570        for i=d step  d until y2: draw (-dd,i)--(dd,i) ; endfor ;
571     \stopMPdrawing
572   \fi}
573
574\def\@@setsecondchemicalplotsymbol%
575  {\ifcase\chemicaldrawingmode
576     \!!widtha=50.8mm
577     \divide\!!widtha by \@@chemicalresolution\relax
578     \plotsymbolspacing=\!!widtha
579     \setplotsymbol({\vrule\s!height\!!widtha\s!width\!!widtha})%
580   \fi}
581
582% Something for Dirk:
583
584\newcount \currentchemical
585
586%\newif    \ifskipchemical
587
588\def\setchemicaldimensions#1#2#3%
589  {\bgroup
590   \global\advance\currentchemical by 1
591   \dimen0=#1\relax
592   \dimen2=#2\relax
593   \dimen4=#3\relax
594   \setxvalue{chemical::\the\currentchemical}%
595     {\noexpand\docommand{\the\dimen0}{\the\dimen2}{\the\dimen4}}%
596   \egroup}
597
598\ifx\normalchemicalframe\undefined
599  \let\normalchemicalframe\hbox % hook for educational purposes
600\fi
601
602\unexpanded\def\complexstartchemical[#1]%
603  {\copyparameters
604     [\??chemical][\??chemical\s!chemical]
605     [\c!width,\c!height,\c!left,\c!right,\c!top,\c!bottom,
606      \c!bodyfont,\c!size,\c!scale,\c!state,\c!frame,\c!axis,\c!factor,
607      \c!location,\c!option,\c!alternative,\c!resolution,\c!offset,\c!style,
608      \c!color,\c!rulecolor,\c!rulethickness]%
609   \getparameters
610     [\??chemical]
611     [#1]%
612   %
613   \setupchemicalformat[\??chemical]%
614   %
615   \ifnum\chemicaldrawingmode=2
616     \resetMPdrawing
617   \fi
618   %
619   \doif{\@@chemicalalternative}{2}
620     {\@@setsecondchemicalplotsymbol}%
621   %
622   \doif{\@@chemicalaxis}\v!on
623     {\let\chemicalframe\hbox}%
624   %
625   \!!counta=250000
626   \divide\!!counta by \@@localchemicalscale
627   \!!widtha=\@@chemicalbodyfont
628   \divide\!!widtha by \!!counta
629   \@@setchemicalcoordinatesystem{\the\!!widtha}%
630   %
631   % \!!counta = -x     \!!countc = -y
632   % \!!countb = +x     \!!countd = +y
633   %
634   \def\calculateaxis##1##2##3##4##5%
635     {##1=##3\relax
636      ##2=##4\relax
637      \ifnum##5=0
638        \ifnum##3=0
639          \ifnum##4=0
640            ##1=2000
641            ##2=2000
642           \fi
643        \fi
644      \else
645        \ifnum##3=0
646          \ifnum##4=0
647            ##1=##5\relax
648            \divide##1 by 2
649            ##2=##1\relax
650          \else
651            ##1=##5\relax
652            \advance##1 by -##2\relax
653          \fi
654        \else
655          \ifnum##4=0
656            ##2=##5\relax
657            \advance##2 by -##1\relax
658          \fi
659        \fi
660      \fi}%
661   \fixedchemicalfalse
662   \doif\@@chemicalwidth\v!fit
663     {\edef\@@chemicalwidth
664        {\ifnum\chemicaldrawingmode=1 2000 \else 1 \fi}%
665      \fixedchemicaltrue}%
666   \doif\@@chemicalheight\v!fit
667     {\edef\@@chemicalheight
668        {\ifnum\chemicaldrawingmode=1 2000 \else 1 \fi}%
669      \fixedchemicaltrue}%
670   \doifelse\@@chemicallocation\v!intext
671     {\!!counta=0 \!!countb=0
672      \!!counta=0 \!!countd=0 }
673     {\calculateaxis
674        \!!counta\!!countb
675        \@@chemicalleft\@@chemicalright\@@chemicalwidth
676      \calculateaxis
677        \!!countc\!!countd
678        \@@chemicalbottom\@@chemicaltop\@@chemicalheight}%
679   %
680   \edef\@@chemheight    {\the\!!countc}%
681   \edef\@@chemdepth     {\the\!!countd}%
682   \edef\@@chemicaltop   {\the\!!countc}%
683   \edef\@@chemicalbottom{\the\!!countd}%
684   %
685   \doifelseinset\v!on{\@@chemicalframe,\@@chemicalaxis}
686     {\def\@@chemicalborder{\chemicalframe}}
687     {\def\@@chemicalborder{\normalchemicalframe}}%
688   %
689   \setbox0=\hbox\bgroup    % this was a \vbox which took \hsize
690   %
691   \@@beginchemicalpicture
692     {-\the\!!counta}{\the\!!countb}
693     {-\the\!!countc}{\the\!!countd}%
694   \doif{\@@chemicalstate}\v!start
695     {\doif\@@chemicalaxis\v!on
696        {\@@setchemicalaxis
697           {-\the\!!counta}{\the\!!countb}
698           {-\the\!!countc}{\the\!!countd}}}%
699   \doifelse\@@chemicaloption\v!test
700     {\def\@@writechemicalstate##1##2%
701        {\convertargument##2\to\ascii
702         \writestatus{##1}{\ascii}}}
703     {\def\@@writechemicalstate##1##2{}}%
704   \ignorespaces}
705
706\def\dostartchemical%
707  {\catcode`\^=\superscriptcatcode% t.b.v. \enableduplication
708   \catcode`\_=\subscriptcatcode  % t.b.v. de zekerheid
709   \begingroup
710   \inchemicaltrue
711   \def\toptext##1{\gdef\thetoptext{##1}\ignorespaces}\toptext{}%
712   \def\bottext##1{\gdef\thebottext{##1}\ignorespaces}\bottext{}%
713   \def\midtext##1{\gdef\themidtext{##1}\ignorespaces}\midtext{}%
714   \def\@@chemicalpostponed{}%
715   \complexorsimpleempty\startchemical}
716
717\unexpanded\def\startchemical
718  {\bgroup % t.b.v. ungrouped floats
719   \dostartchemical}
720
721\unexpanded\def\stopchemical
722  {\checkchemicalpicture
723   \@@endchemicalpicture
724   \egroup
725   \ifnum\chemicaldrawingmode=1
726     \dimen0=\@@chemicalunit
727     \setbox0=\hbox{\lower\@@chemdepth\dimen0\box0}%
728     \ht0=\@@chemheight\dimen0
729     \dp0=\@@chemdepth\dimen0
730   \fi
731   \dimen0=\ht0
732   \advance\dimen0 by \dp0
733   \inchemicalfalse % enables \chemie{} in text
734   \setbox4=\alignedchemical\themidtext
735   \setbox6=\alignedchemical\thetoptext
736   \setbox8=\alignedchemical\thebottext
737   \setbox4=\hbox to \wd0
738     {\strut\hss$\vcenter{\box4}$\hss}%
739   \setbox2=\vbox to \dimen0
740     {\hbox to \wd0{\strut\hss\box6\hss}
741      \vfill
742      \hbox to \wd0{\strut\hss\box8\hss}
743      \vss}% disables the depth
744   \wd0=0pt  \wd4=0pt
745   \ht2=\ht0 \dp2=\dp0
746   \ht4=\ht0 \dp4=\dp0
747   \@@chemicalborder{\box0\box4\box2}% text on top of chemicals
748   \endgroup
749   \ignorespaces
750   \egroup}                  % t.b.v. ungrouped floats
751
752\def\alignedchemical#1%
753  {\vtop
754     {\def\par{\egroup\hbox\bgroup\strut}%
755      \let\\=\par
756      \let\endgraf=\par
757      \hbox\bgroup\strut#1\egroup}}
758
759% \setchemicalcoordinates{#1}{#2}
760%
761% #1: verplaatsing in x-richting
762% #2: verplaatsing in y-richting
763
764\newif\ifchemicaldirection
765
766\def\checkchemicaldirection#1#2%
767  {\ifchemicaldirection
768     \ifnum#1>0 \advance\horchemical -\chemicaldirection \fi
769     \ifnum#1<0 \advance\horchemical +\chemicaldirection \fi
770     \ifnum#2>0 \advance\verchemical -\chemicaldirection \fi
771     \ifnum#2<0 \advance\verchemical +\chemicaldirection \fi
772     \chemicaldirectionfalse
773   \fi}
774
775\def\processchemicaldirection%
776  {\chemicaldirectiontrue\processchemicaltranslate}
777
778\def\setchemicalcoordinates#1#2%
779  {\advance\horchemical #1\relax
780   \advance\verchemical #2\relax
781   \checkchemicaldirection{#1}{#2}%
782   \!!counta=-\horchemical\edef\chemicalxoffset{\the\!!counta}%
783   \!!countb=-\verchemical\edef\chemicalyoffset{\the\!!countb}%
784   \ifnum\chemicaldrawingmode=1
785     % njet
786   \else
787     \setcoordinatesystem point at {\the\horchemical} {\the\verchemical}
788   \fi}
789
790\def\resetchemicalcoordinates
791  {\horchemical=0
792   \verchemical=0
793   \edef\chemicalxoffset{0}%
794   \edef\chemicalyoffset{0}%
795   \ifnum\chemicaldrawingmode=1
796     % njet
797   \else
798     \setcoordinatesystem point at 0 0
799   \fi}
800
801\def\restorechemicalcoordinates
802  {%\writestatus{ppchtex}{restoring \the\horchemical,\the\verchemical}%
803   \edef\chemicalxoffset{\the\horchemical}%
804   \edef\chemicalyoffset{\the\verchemical}%
805   \ifnum\chemicaldrawingmode=1
806     % njet
807   \else
808     \setcoordinatesystem point at {\the\horchemical} {\the\verchemical}
809   \fi}
810
811\def\setchemicaltranslate #1 #2 #3
812  {\setvalue{\s!translate#1}{\setchemicalcoordinates{#2}{#3}}}
813
814\def\processchemicaltranslate#1%
815  {\def\doprocess[##1##2]%
816     {\doifchemicalnumber{##1}{MOV#1}
817        {\ifnum##1=0
818           \def\chemicaloffset{0}% incompatible change
819           \resetchemicalcoordinates
820         \else
821           \getvalue{\s!translate##1}%
822           \dochemicaloffset{##1}%
823           \def\chemicaloffset{0}%
824         \fi}}%
825   \doprocess[#1]}
826
827\def\setchemicaldistance #1
828  {\setvalue{\s!distance1}{\setchemicalcoordinates{-#1}{  0}}%
829   \setvalue{\s!distance2}{\setchemicalcoordinates{  0}{ #1}}%
830   \setvalue{\s!distance3}{\setchemicalcoordinates{ #1}{  0}}%
831   \setvalue{\s!distance4}{\setchemicalcoordinates{  0}{-#1}}}
832
833\def\setchemicaldirection #1
834  {\def\chemicaldirection{#1}}
835
836\def\processchemicaldistance#1%
837  {\def\doprocess[##1##2]%
838     {\doifchemicalnumber{##1}{ADJ#1}
839        {\ifnum##1=0
840           \resetchemicalcoordinates
841         \else
842           \def\@@chemicalpostponed{\getvalue{\s!distance##1}}%
843           \@@chemicalpostponed
844         \fi}}%
845   \doprocess[#1]}
846
847\def\setchemicalsubstitute #1
848  {\setvalue{\s!substitute1}{\setchemicalcoordinates{-#1}{  0}}%
849   \setvalue{\s!substitute2}{\setchemicalcoordinates{  0}{ #1}}%
850   \setvalue{\s!substitute3}{\setchemicalcoordinates{ #1}{  0}}%
851   \setvalue{\s!substitute4}{\setchemicalcoordinates{  0}{-#1}}}
852
853\def\processchemicalsubstitute#1%
854  {\def\doprocess[##1##2]%
855     {\doifchemicalnumber{##1}{SUB#1}
856        {\ifnum##1=0
857           \resetchemicalcoordinates
858         \else
859           \def\@@chemicalpostponed{\getvalue{\s!substitute##1}}%
860           \@@chemicalpostponed
861         \fi}}%
862   \doprocess[#1]}
863
864% Het is mogelijk een offset of move meerdere malen uit te
865% voeren, door een nummer voor het commando te plaatsen.
866
867\def\chemicalrepeat       {1}
868
869\def\redoprocesschemical[#1#2]%
870  {\doifelseinstring{#1}{0123456789.}
871     {\edef\chemicalrepeat{\chemicalrepeat#1}%
872      \redoprocesschemical[#2]}
873     {\processchemical[#1#2]%
874      \def\chemicalrepeat{1}}}
875
876\def\doprocesschemical[#1#2]#3%
877  {\doifelseinstring{#1}{0123456789.}
878     {\def\chemicalrepeat{#1}%
879      \redoprocesschemical[#2]}
880     {#3}}
881
882% \dochemicaloffset{#1}
883%
884% #1: binding
885
886\def\chemicaloffset{0}
887
888\def\processchemicaloffset#1%
889  {\dimen0=62500 sp  % real calc on cardinals, funny number
890   \dimen0=\chemicalrepeat\dimen0
891   \divide\dimen0 by \@@localchemicalscale
892   \!!counta=\dimen0
893   \def\doprocess[##1##2]%
894     {\doifelseinstring{##1}{128}
895        {\edef\chemicaloffset{\the\!!counta}}
896        {\doifelseinstring{##1}{456}
897           {\edef\chemicaloffset{-\the\!!counta}}
898           {\doifelse{##1}{0}
899              {\edef\chemicaloffset{0}}
900              {\unknownchemical{OFF#1}}}}}%
901   \doprocess[#1]}
902
903\def\dochemicaloffset#1%
904  {\ifnum\chemicaloffset=0
905     \def\undochemicaloffset{}%
906   \else
907     \setchemicalcoordinates{-\chemicaloffset}{0}%
908     \def\undochemicaloffset%
909       {\setchemicalcoordinates{\chemicaloffset}{0}%
910        \def\undochemicaloffset{}}%
911   \fi}
912
913\def\processchemicalphantom#1#2%
914  {\setbox0=\hbox
915     {\def\splitoff##1????{##1}%
916      $\@@dochemicalstyle{\@@localchemicalformat\splitoff#2}$}%
917   \dimen0=.25\wd0
918   \divide\dimen0 by \@@localchemicalscale
919   \!!counta=\dimen0
920   \doifelseinstring{#1}{128}
921     {\edef\chemicaloffset{\the\!!counta}}
922     {\doifelseinstring{#1}{456}
923        {\edef\chemicaloffset{-\the\!!counta}}
924        {\doifelse{#1}{0}
925           {\edef\chemicaloffset{0}}
926           {\unknownchemical{OF#1:#2}}}}}
927
928% \dosetchemicalrotation{#1}{#2}
929%
930% #1: cos(phi)
931% #2: sin(phi)
932
933\def\chemicalrotation   {1}
934\def\chemicalangle      {0}
935\def\chemicalxoffset    {0}
936\def\chemicalyoffset    {0}
937
938\def\setchemicalmirror#1%
939  {\setvalue{\s!mirror#1}{*}}
940
941\def\resetchemicalmirror#1%
942  {\resetvalue{\s!mirror#1}}
943
944\def\togglechemicalmirror#1%
945  {\doifelse{\getvalue{\s!mirror#1}}{*}
946     {\resetchemicalmirror{#1}}
947     {\setchemicalmirror{#1}}}
948
949\def\setchemicalrotation #1 #2 #3 #4 #5 #6 #7 #8 #9
950  {\setvalue{\s!rotate1.#1}{\dosetchemicalrotation{#2}{#3}}%
951   \setvalue{\s!rotate2.#1}{\dosetchemicalrotation{#4}{#5}}%
952   \setvalue{\s!rotate3.#1}{\dosetchemicalrotation{#6}{#7}}%
953   \setvalue{\s!rotate4.#1}{\dosetchemicalrotation{#8}{#9}}}
954
955\def\setchemicalangle #1 #2 #3 #4 #5
956  {\setvalue{\s!angle1.#1}{\dosetchemicalangle{#2}}%
957   \setvalue{\s!angle2.#1}{\dosetchemicalangle{#3}}%
958   \setvalue{\s!angle3.#1}{\dosetchemicalangle{#4}}%
959   \setvalue{\s!angle4.#1}{\dosetchemicalangle{#5}}}
960
961\def\chemicalrotate[#1]%
962  {\doifelsedefined{\s!mirror#1}
963     {\getvalue{\s!rotate\chemicalrotation.#1\getvalue{\s!mirror#1}}%
964      \getvalue{\s!angle\chemicalrotation.#1\getvalue{\s!mirror#1}}}
965     {\getvalue{\s!rotate\chemicalrotation.#1}%
966      \getvalue{\s!angle\chemicalrotation.#1}}}
967
968\def\dosetchemicalangle#1%   zwak zie onder
969  {\def\chemicalangle{#1}}
970
971\def\dosetchemicalrotation#1#2%
972  {\ifnum\chemicaldrawingmode=1
973     % njet
974   \else
975     \startrotation by {#1} {#2} %% \stoprotation (t.b.v. testen)
976   \fi}
977
978\def\doresetchemicalrotation
979  {\ifnum\chemicaldrawingmode=1
980     % njet
981   \else
982     \stoprotation
983   \fi}
984
985\def\processchemicalrotation#1%
986  {\def\doprocess[##1##2]%
987     {\doifelsenumber{##1}
988        {\def\chemicalrotation{##1}}
989        {\unknownchemical{ROT#1}}}%
990   \doprocess[#1]}
991
992% \filtertextelement[#1][#2][#3][#4]
993%
994% #1: volgnummer
995% #2: offset in uitlijningen
996% #3: lijst met uitlijningen -> \chemicalloca
997% #4: lijst met teksten      -> \chemicaltext
998
999\def\setchemicallocation#1%
1000  {\doifelse{#1}{}
1001     {\edef\chemicalloca{c}}
1002     {\edef\chemicalloca{#1}}}
1003
1004\newif\iffixedchemicaltext
1005
1006\def\filterchemicaltextelement[#1][#2][#3][#4]%
1007  {\ifchemicaltextconstant
1008     \def\chemicaltext{#4}%
1009     \setchemicallocation{}%
1010   \else
1011     \ifnum#1=0\relax
1012       \setchemicallocation{}%
1013     \else
1014       \iffixedchemicaltext
1015         \!!counta#2
1016       \else
1017         \!!counta=\chemicalrotation
1018         \advance\!!counta -1
1019         \multiply\!!counta #2
1020         \advance\!!counta #1
1021       \fi
1022       \getfromcommalist[#3][\the\!!counta]%
1023       \setchemicallocation\commalistelement
1024     \fi
1025     \ifchemicalpicture
1026       \let\chemicaltext\relax
1027     \else
1028       \advance\txtchemical 1
1029       \getfromcommalist[#4][\txtchemical]%
1030       \let\chemicaltext\commalistelement
1031     \fi
1032   \fi
1033   \fixedchemicaltextfalse}
1034
1035% \putchemicaltext{#1}{#2}
1036%
1037% #1 : x-coordinaat
1038% #2 : y-coordinaat
1039%
1040% \chemicaltext en \chemicalloca worden met \gettextelement
1041% opgehaald uit de tweede set bij \chemie
1042%
1043% Ten behoeve van testdoeleinden wordt gebruik gemaakt van
1044% \chemicalframe in plaats van het meer sjieke, maar tevens
1045% meer trage \framed.
1046
1047\ifx\ruledhbox\undefined
1048  \def\chemicalframe#1%
1049     {\hbox
1050        {\vrule\hskip-.4pt
1051         \vbox{\hrule\vskip-.4pt\hbox{#1}\vskip-.4pt\hrule}%
1052         \hskip-.4pt\vrule}}
1053\else
1054  \def\chemicalframe#1%
1055    {\ruledhbox{#1}}
1056\fi
1057
1058\def\doputchemicaltext#1 [#2] at #3 #4 %
1059  {\ifnum\chemicaldrawingmode=1
1060     \rput
1061       {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1062       {\expanded{\rput[#2]{\chemicalangle}(#3,#4){#1}}}%
1063   \else
1064     \put {#1} [#2] at {#3} {#4} %
1065   \fi}
1066
1067\def\dodoifsinglelocation#1#2\\#3%
1068  {\ifx#2\relax#3\fi}
1069
1070\def\doifelsesinglelocation#1%
1071  {\expandafter\dodoifsinglelocationelse#1\relax\\}
1072
1073\let\doifsinglelocationelse\doifelsesinglelocation
1074
1075\def\putchemicaltext#1#2%
1076  {\enablechemicalspecials
1077   \ifchemicalpicture
1078     \setchemicalpicture{#1}{#2}%
1079   \else
1080     \doifelse\@@chemicaloption\v!test
1081       {\def\@@chemicalframe{\chemicalframe}}
1082       {\def\@@chemicalframe{}}%
1083     \dosetsubscripts
1084     \setbox2=\hbox{\@@dochemicalcolor
1085                    $\@@dochemicalstyle{\@@localchemicalformat \chemicaltext}$}%
1086     \setbox4=\hbox{$\@@dochemicalstyle{\@@localchemicalformat C\normalsubscript2\normapsuperscript2}$}%
1087     \setbox6=\hbox{$\@@dochemicalstyle{\@@localchemicalformat O}$}% or C
1088     \doresetsubscripts
1089     \doifnot\@@chemicallocation\v!intext
1090       {\ht2=\ht4
1091        \dp2=\dp4}%
1092     \setbox2=\hbox{\@@chemicalframe{\box2}}%
1093     \ifdim\wd2>\wd6
1094       \doifelse{#1}{0}
1095         {\doifnot{#2}{0}{\wd2=\wd6}}
1096         {%\doifsinglelocation\chemicalloca
1097            {\doifinset{\chemicalloca}{t,b}{\wd2=\wd6}}}% common ?
1098     \fi
1099     \expanded
1100       {\doputchemicaltext
1101          {\noexpand\dowithchemical{\copy2}}     % per se \copy2 i.p.v. \box2
1102          [\chemicalloca] at {#1} {#2} }
1103     \nomoreaccounting
1104   \fi
1105   \disablechemicalspecials}
1106
1107\def\setchemicaltextelement #1 #2 #3
1108  {\setvalue{\s!chemicaltextelement#1}{\putchemicaltext{#2}{#3}}}
1109
1110\def\getchemicalfixedtextelement%
1111  {\fixedchemicaltexttrue
1112   \getchemicaltextelement}
1113
1114\def\getchemicaltextelement[#1][#2][#3][#4][#5]%
1115  {\filterchemicaltextelement[#2][#3][#4][#5]%
1116   \doifelse{#2}{0}
1117     {\dochemicaloffset{#2}%     % incompatible change
1118      \putchemicaltext{0}{0}%
1119      \undochemicaloffset}       % incompatible change
1120     {\chemicalrotate[#2]%
1121      \dochemicaloffset{#2}%
1122      \def\chemicaltextelementnumber{#2}%
1123      \getvalue{\s!chemicaltextelement#1}%
1124      \getvalue{\s!chemicaltextelement#11}%
1125      \getvalue{\s!chemicaltextelement#12}%
1126      \getvalue{\s!chemicaltextelement#13}%
1127      \undochemicaloffset}}
1128
1129\def\processchemicaltextelement#1#2#3#4#5%
1130  {\def\doprocess[##1##2##3##4##5]%
1131     {\doifelse{##1}{?}
1132        {\doprocess[1..\maxchemical ????]}
1133        {\doifchemicalnumber{##1}{#1#2}
1134           {\doifelse{##2##3}{..}
1135              {\doifchemicalnumber{##4}{#1#2}
1136                 {\getchemicaltextelement[#1][##1][#4][#5][#3]%
1137                  \doifnot{##1}{##4}
1138                    {\!!counta=##1\relax
1139                     \advance\!!counta by 1
1140                     \edef\nextsegment{\the\!!counta}%
1141                     \doprocess[\nextsegment..##4##5]}}}
1142              {\getchemicaltextelement[#1][##1][#4][#5][#3]%
1143               \doifnot{##2}{?}{\doprocess[##2##3##4##5]}}}}}%
1144   \doprocess[#2]%
1145   \smallchemicaltextfalse}
1146
1147\def\processchemicalsmalltextelement%
1148  {\smallchemicaltexttrue\processchemicaltextelement}
1149
1150\def\processchemicalsmalltextconstant%
1151  {\smallchemicaltexttrue\processchemicaltextconstant}
1152
1153\def\processchemicalunrotatedtextelement#1#2#3#4#5#6%
1154  {\bgroup
1155   \xdef\@@xxx{0}%
1156   \xdef\@@yyy{0}%
1157   \def\putchemicaltext##1##2%
1158     {\xdef\@@xxx{##1}%
1159      \xdef\@@yyy{##2}}%
1160   \getvalue{\s!chemicaltextelement#1}%
1161   \egroup
1162   \bgroup
1163   \def\doputchemicaltext##1 [##2] at ##3 ##4 %
1164     {\ifnum\chemicaldrawingmode=1
1165        \rput
1166          {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1167          {\rput{\chemicalangle}(\@@xxx,\@@yyy){\expanded{\rput[##2](##3,##4){##1}}}}%
1168      \else
1169        \put
1170          {\stoprotation \setcoordinatesystem point at 0 0
1171           \expanded{\put {##1} [##2] at {##3} {##4} }}
1172          at {\@@xxx} {\@@yyy}
1173      \fi}%
1174   \processchemicaltextelement{#2}{#3}{#4}{#5}{#6}%
1175   \egroup}
1176
1177\newif\ifchemicaltextconstant
1178
1179\def\processchemicaltextconstant#1#2#3#4%
1180  {\chemicaltextconstanttrue
1181   \let\@@oldchemicalframe\@@chemicalframe
1182   \let\@@chemicalframe\relax
1183   \processchemicaltextelement{#1}{#2}{#3}{#4}{}%
1184   \let\@@chemicalframe\@@oldchemicalframe
1185   \chemicaltextconstantfalse}
1186
1187% \plotchemicalline{#1}{#2}{#3}{#4}
1188%
1189% #1: x-coordinaat beginpunt
1190% #2: y-coordinaat beginpunt
1191% #3: x-coordinaat eindpunt
1192% #4: y-coordinaat eindpunt
1193
1194\newconstant\chemicallinetype
1195
1196\def\doplotchemicalline
1197  {\!!counte=\!!countc \advance\!!counte by -\!!counta
1198   \!!countf=\!!countd \advance\!!countf by -\!!countb
1199   \bgroup
1200   \ifcase\chemicaldrawingmode
1201     \ifcase\chemicallinetype
1202     % 0 : normal line
1203       \plot {\!!counta} {\!!countb} {\!!countc} {\!!countd} /%
1204     \or
1205     % 1 : normal arrow
1206       \arrow <5pt> [.2,.67] from {\!!counta} {\!!countb} to {\!!countc} {\!!countd}
1207     \or
1208     % 2 : reverse arrow
1209       \arrow <5pt> [.2,.67] from {\!!countc} {\!!countd} to {\!!counta} {\!!countb}
1210     \or
1211     % 3 : unrotated line
1212       \put {\stoprotation \setcoordinatesystem point at 0 0
1213             \plot 0 0 {\!!counte} {\!!countf} /}
1214            [\chemicallineposition] at {\!!counta} {\!!countb}
1215     \else
1216     % 4 : dashed line
1217       \findlength {\plot {\!!counta} {\!!countb} {\!!countc} {\!!countd} /}%
1218       \setdashesnear <2pt> for <\totalarclength>%
1219       \plot {\!!counta} {\!!countb} {\!!countc} {\!!countd} /%
1220     \fi
1221   \or
1222     \ifcase\chemicallinetype
1223       \rput
1224         {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1225         {\psline(\!!counta,\!!countb)(\!!countc,\!!countd)}%
1226     \or
1227       \rput
1228         {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1229         {\psline{->}(\!!counta,\!!countb)(\!!countc,\!!countd)}%
1230     \or
1231       \rput
1232         {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1233         {\psline{<-}(\!!counta,\!!countb)(\!!countc,\!!countd)}%
1234     \or
1235       \rput
1236         {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1237         {\expanded{\rput[\chemicallineposition]{-\chemicalangle}%
1238            (\!!counta,\!!countb){\psline(0,0)(\!!counte,\!!countf)}}}%
1239     \else
1240       \psset{linestyle=dashed}%
1241       \rput
1242         {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1243         {\psline(\!!counta,\!!countb)(\!!countc,\!!countd)}%
1244     \fi
1245   \or
1246     \global\MPdrawingdonetrue
1247     \setchemicalattributes
1248     \startMPdrawing
1249        x0 := \MPdivten[\chemicalxoffset]u ;
1250        y0 := \MPdivten[\chemicalyoffset]u ;
1251        x1 := \MPdivten[\the\!!counta]u ;
1252        y1 := \MPdivten[\the\!!countb]u ;
1253        x2 := \MPdivten[\the\!!countc]u ;
1254        y2 := \MPdivten[\the\!!countd]u ;
1255        x3 := \MPdivten[\the\!!counte]u ;
1256        y3 := \MPdivten[\the\!!countf]u ;
1257        \ifcase\chemicallinetype
1258        % 0 : normal line
1259          draw ((z1--z2) rotatedaround(origin,-\chemicalangle))
1260            shifted z0 ;
1261        \or
1262        % 1 : normal arrow
1263          drawarrow ((z1--z2) rotatedaround(origin,-\chemicalangle))
1264            shifted z0 ;
1265        \or
1266        % 2 : reverse arrow
1267          drawarrow ((z2--z1) rotatedaround(origin,-\chemicalangle))
1268            shifted z0 ;
1269        \or
1270        % 3 : unrotated line  % nog \chemicalineposition: t/b
1271          draw (origin--z3)
1272            shifted (z1 rotatedaround(origin,-\chemicalangle))
1273            shifted z0 ;
1274        \else
1275        % 4 : dashed line
1276          draw ((z1--z2) rotatedaround(origin,-\chemicalangle))
1277            shifted z0 dashed dashpattern(on 5.5u off 6u) ;
1278       \fi
1279     \stopMPdrawing
1280   \fi
1281   \egroup
1282   \account\!!counta\!!countb
1283   \account\!!countc\!!countd}
1284
1285\def\plotchemicalline#1#2#3#4%
1286  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1287   \doplotchemicalline}
1288
1289\def\plotchemicalfactorline#1#2#3#4%
1290  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1291   \ifdim\@@chemicalfactor\onepoint=\onepoint \else
1292     \scratchdimen\!!counta\s!sp \multiply\scratchdimen1000 \scratchdimen\@@chemicalfactor\scratchdimen \divide\scratchdimen1000 \!!counta\scratchdimen
1293     \scratchdimen\!!countc\s!sp \multiply\scratchdimen1000 \scratchdimen\@@chemicalfactor\scratchdimen \divide\scratchdimen1000 \!!countc\scratchdimen
1294   \fi
1295   \doplotchemicalline}
1296
1297\def\plotchemicalzline#1#2#3#4%
1298  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1299   \ifnum\chemicaldrawingmode=2
1300     \global\MPdrawingdonetrue
1301     \setchemicalattributes
1302     \startMPdrawing
1303        x0 := \MPdivten[\chemicalxoffset]u ;
1304        y0 := \MPdivten[\chemicalyoffset]u ;
1305        x1 := \MPdivten[\the\!!counta]u ;
1306        y1 := \MPdivten[\the\!!countb]u ;
1307        x2 := \MPdivten[\the\!!countc]u ;
1308        y2 := \MPdivten[\the\!!countd]u ;
1309        filldraw ((
1310        \ifnum\chemicalangle>180
1311          z1--z2
1312        \else\ifnum\chemicalangle<90
1313          z1--(z2 shifted (-2u,+2u))--(z2 shifted (+2u,-2u))
1314        \else\ifnum\chemicalangle=90
1315          (z1 shifted (-2u,+2u))--(z1 shifted (+2u,-2u))--
1316          (z2 shifted (+2u,+2u))--(z2 shifted (-2u,-2u))
1317        \else
1318          (z1 shifted (+2u,+2u))--(z1 shifted (-2u,-2u))--z2
1319        \fi\fi\fi
1320        --cycle) rotatedaround(origin,-\chemicalangle)) shifted z0 ;
1321     \stopMPdrawing
1322   \else
1323     \doplotchemicalline
1324     \ifnum\chemicalangle>180 \else
1325       \ifnum\chemicalangle=90
1326          \advance\!!counta by -20 \advance\!!countc by -20
1327          \doplotchemicalline
1328          \advance\!!counta by  40 \advance\!!countc by  40
1329        \else\ifnum\chemicalangle<90
1330          \advance\!!countc by -20 \advance\!!countd by +20
1331          \doplotchemicalline
1332          \advance\!!countc by +40 \advance\!!countd by -40
1333        \else
1334          \advance\!!counta by  20 \advance\!!countb by  20
1335          \doplotchemicalline
1336          \advance\!!counta by -40 \advance\!!countb by -40
1337        \fi\fi
1338     \fi
1339     \doplotchemicalline
1340   \fi}
1341
1342\def\plotchemicaldeltaline#1#2#3#4%
1343  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1344   \ifnum\chemicaldrawingmode=2
1345     \global\MPdrawingdonetrue
1346     \setchemicalattributes
1347     \startMPdrawing
1348        x0 := \MPdivten[\chemicalxoffset]u ;
1349        y0 := \MPdivten[\chemicalyoffset]u ;
1350        x1 := \MPdivten[\the\!!counta]u ;
1351        y1 := \MPdivten[\the\!!countb]u ;
1352        x2 := \MPdivten[\the\!!countc]u ;
1353        y2 := \MPdivten[\the\!!countd]u ;
1354        filldraw ((z1--(z2 rotatedaround(z1,5))--(z2 rotatedaround(z1,-5))
1355                   --cycle) rotatedaround(origin,-\chemicalangle))
1356          shifted z0 ;
1357     \stopMPdrawing
1358     \account{#1}{#2}%
1359     \account{#3}{#4}%
1360   \else
1361     \doplotchemicalline
1362     \advance\!!countc by  16 \advance\!!countd by -21
1363     \doplotchemicalline
1364     \advance\!!countc by  -4 \advance\!!countd by   7
1365     \doplotchemicalline
1366     \advance\!!countc by  -4 \advance\!!countd by   7
1367     \doplotchemicalline
1368     \advance\!!countc by  -8 \advance\!!countd by  14
1369     \doplotchemicalline
1370     \advance\!!countc by  -4 \advance\!!countd by   7
1371     \doplotchemicalline
1372     \advance\!!countc by  -4 \advance\!!countd by   7
1373     \doplotchemicalline
1374     \advance\!!countc by  -4 \advance\!!countd by   7
1375     \doplotchemicalline
1376   \fi}
1377
1378\def\setchemicallinesegment #1 #2 #3 #4 #5
1379  {\setvalue{\s!chemicallinesegment#1}{\plotchemicalline{#2}{#3}{#4}{#5}}}
1380
1381\def\setchemicalfactorlinesegment #1 #2 #3 #4 #5
1382  {\setvalue{\s!chemicallinesegment#1}{\plotchemicalfactorline{#2}{#3}{#4}{#5}}}
1383
1384\def\getchemicallinesegment[#1][#2]%
1385  {\chemicalrotate[#1]%
1386   \dochemicaloffset{#1}%
1387   \getvalue{\s!chemicallinesegment#2}%
1388   \getvalue{\s!chemicallinesegment#21}%
1389   \getvalue{\s!chemicallinesegment#22}%
1390   \undochemicaloffset}
1391
1392\def\getprivatechemicallinesegment[#1][#2]%
1393  {\chemicalrotate[#1]%
1394   \getvalue{\s!chemicallinesegment#2#1}}
1395
1396\def\doprocesschemicallinesegment#1#2#3#4#5%
1397  {\chemicallinetype#1\relax
1398   \def\chemicallineposition{#2}%
1399   \def\doprocess[##1##2##3##4##5]%
1400     {\doifelse{##1}{?}
1401        {\doprocess[1..\maxchemical ????]}
1402        {\doifchemicalnumber{##1}{#4#5}
1403           {\doifelse{##2##3}{..}
1404              {\doifchemicalnumber{##4}{#4#5}
1405                 {#3[##1][#4]%
1406                  \doifnot{##1}{##4}
1407                    {\!!counta=##1\relax
1408                     \advance\!!counta by 1
1409                     \edef\nextsegment{\the\!!counta}%
1410                     \doprocess[\nextsegment..##4##5]}}}
1411              {#3[##1][#4]%
1412               \doifnot{##2}{?}
1413                 {\doprocess[##2##3##4##5]}}}}}%
1414   \doprocess[#5]}
1415
1416\def\processchemicallinesegment
1417  {\doprocesschemicallinesegment0c\getchemicallinesegment}
1418
1419\def\processchemicalzlinesegment#1#2%
1420  {%\doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1421   \bgroup
1422   \def\plotchemicalline{\plotchemicalzline}%
1423   \doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1424   \egroup}
1425
1426\def\processchemicaldeltalinesegment#1#2%
1427  {%\doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1428   \bgroup
1429   \def\plotchemicalline{\plotchemicaldeltaline}%
1430   \doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1431   \egroup}
1432
1433\def\processprivatechemicallinesegment%
1434  {\doprocesschemicallinesegment0c\getprivatechemicallinesegment}
1435
1436\def\processchemicaldownarrowsegment%
1437  {\doprocesschemicallinesegment1c\getchemicallinesegment}
1438
1439\def\processchemicaluparrowsegment%
1440  {\doprocesschemicallinesegment2c\getchemicallinesegment}
1441
1442\def\processchemicalunrotatedlinesegment#1%
1443  {\doprocesschemicallinesegment3{#1}\getchemicallinesegment}
1444
1445\def\processchemicaldashedlinesegment
1446  {\doprocesschemicallinesegment4c\getchemicallinesegment}
1447
1448\def\plotchemicaldasheddeltaline#1#2#3#4%
1449  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1450   \ifnum\chemicaldrawingmode=2
1451     \global\MPdrawingdonetrue
1452     \setchemicalattributes
1453     \startMPdrawing
1454        x0 := \MPdivten[\chemicalxoffset]u ;
1455        y0 := \MPdivten[\chemicalyoffset]u ;
1456        x1 := \MPdivten[\the\!!counta]u ;
1457        y1 := \MPdivten[\the\!!countb]u ;
1458        x2 := \MPdivten[\the\!!countc]u ;
1459        y2 := \MPdivten[\the\!!countd]u ;
1460        z20 = z2 rotatedaround(z1,+5) ;
1461        z21 = z2 rotatedaround(z1,-5) ;
1462        draw (z1 rotatedaround(origin,-\chemicalangle)) shifted z0 ;
1463        save n ; n := 5 ;
1464        for i=1 upto n :
1465          draw ((((z20--z21) shifted -z2) shifted (i/n)[z2,z1])
1466                 rotatedaround(origin,-\chemicalangle)) shifted z0 ;
1467        endfor
1468     \stopMPdrawing
1469     \account{#1}{#2}%
1470     \account{#3}{#4}%
1471   \else
1472     \doplotchemicalline
1473     \advance\!!countc by  16 \advance\!!countd by -21
1474     \doplotchemicalline
1475     \advance\!!countc by  -4 \advance\!!countd by   7
1476     \doplotchemicalline
1477     \advance\!!countc by  -4 \advance\!!countd by   7
1478     \doplotchemicalline
1479     \advance\!!countc by  -8 \advance\!!countd by  14
1480     \doplotchemicalline
1481     \advance\!!countc by  -4 \advance\!!countd by   7
1482     \doplotchemicalline
1483     \advance\!!countc by  -4 \advance\!!countd by   7
1484     \doplotchemicalline
1485     \advance\!!countc by  -4 \advance\!!countd by   7
1486     \doplotchemicalline
1487   \fi}
1488
1489\def\plotchemicalwavyline#1#2#3#4%
1490  {\!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
1491   \ifnum\chemicaldrawingmode=2
1492     \global\MPdrawingdonetrue
1493     \setchemicalattributes
1494     \startMPdrawing
1495        x0 := \MPdivten[\chemicalxoffset]u ;
1496        y0 := \MPdivten[\chemicalyoffset]u ;
1497        x1 := \MPdivten[\the\!!counta]u ;
1498        y1 := \MPdivten[\the\!!countb]u ;
1499        x2 := \MPdivten[\the\!!countc]u ;
1500        y2 := \MPdivten[\the\!!countd]u ;
1501        save d ; pair d ;
1502        d := z2 rotatedaround(z1,+5) shifted -z2 ;
1503        save n ; n := 4 ;
1504        draw ((for i=0 upto n-1 :
1505                     ((i)/n)[z1,z2] ..
1506                 ((i+.25)/n)[z1,z2] shifted d ..
1507                 ((i+.50)/n)[z1,z2] ..
1508                 ((i+.75)/n)[z1,z2] shifted -d ..
1509               endfor
1510               z2) rotatedaround(origin,-\chemicalangle)) shifted z0 ;
1511     \stopMPdrawing
1512     \account{#1}{#2}%
1513     \account{#3}{#4}%
1514   \else
1515     \doplotchemicalline
1516     \advance\!!countc by  16 \advance\!!countd by -21
1517     \doplotchemicalline
1518     \advance\!!countc by  -4 \advance\!!countd by   7
1519     \doplotchemicalline
1520     \advance\!!countc by  -4 \advance\!!countd by   7
1521     \doplotchemicalline
1522     \advance\!!countc by  -8 \advance\!!countd by  14
1523     \doplotchemicalline
1524     \advance\!!countc by  -4 \advance\!!countd by   7
1525     \doplotchemicalline
1526     \advance\!!countc by  -4 \advance\!!countd by   7
1527     \doplotchemicalline
1528     \advance\!!countc by  -4 \advance\!!countd by   7
1529     \doplotchemicalline
1530   \fi}
1531
1532\def\processchemicaldasheddeltalinesegment#1#2%
1533  {\bgroup
1534   \def\plotchemicalline{\plotchemicaldasheddeltaline}%
1535   \doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1536   \egroup}
1537
1538\def\processchemicalwavylinesegment#1#2%
1539  {\bgroup
1540   \def\plotchemicalline{\plotchemicalwavyline}%
1541   \doprocesschemicallinesegment0c\getchemicallinesegment{#1}{#2}%
1542   \egroup}
1543
1544\def\processchemicalopenend#1#2%
1545  {\doprocesschemicallinesegment0c\doprocesschemicalopenend{#1}{#2}}
1546
1547\def\doprocesschemicalopenend[#1][#2]%
1548  {\chemicalrotate[#1]%
1549   \dochemicaloffset{#1}%
1550   \ifcase\chemicaldrawingmode
1551     \beginpicture
1552     \setquadratic\plot
1553       300 0  400   0
1554       500 0  550  75
1555       600 0  650 -75
1556       700 0  750  75
1557       800 0  850 -75
1558       900 0  950   0
1559             1050   0 /
1560     \endpicture
1561   \or
1562     \rput{-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1563       {\psline(300,0)(500,0)%
1564        \rput(500,0){\psplot[yunit=75,plotstyle=curve]{0}{720}{x sin}}%
1565        \psline(950,0)(1050,0)}%
1566   \or
1567     \global\MPdrawingdonetrue
1568     \setchemicalattributes
1569     \startMPdrawing
1570       x0 := \MPdivten[\chemicalxoffset]u ;
1571       y0 := \MPdivten[\chemicalyoffset]u ;
1572       draw
1573        (((30.0u,0)--(50.0u,0){up}..(55.0u,7.5u)..
1574          (60.0u,0)..(65.0u,-7.5u)..(70.0u,0)..
1575          (75.0u,7.5u)..(80.0u,0)..(85.0u,-7.5u)..{up}
1576          (90.0u,0)--(105.0u,0)) rotatedaround(origin,-\chemicalangle))
1577        shifted z0 ;
1578     \stopMPdrawing
1579   \fi
1580   \undochemicaloffset}
1581
1582% \plotchemicalcircle{#1}{#2}{#3}{#4}
1583%
1584% #1: lengte van de boog in graden
1585% #2: x-coordinaat eindpunt
1586% #3: y-coordinaat eindpunt
1587
1588\newif\ifchemicaldotted
1589
1590\def\plotchemicalcircle#1#2#3#4#5#6%
1591  {\bgroup
1592   \ifcase\chemicaldrawingmode
1593     \ifchemicaldotted
1594       \findlength{\circulararc {#4} degrees from {#5} {#6} center at {0} {0} }%
1595       \divide\totalarclength by 6
1596       \def\b{\the\totalarclength}%
1597       \divide\totalarclength by 2
1598       \def\a{\the\totalarclength}%
1599       \setdashpattern <\a,\b,\b,\b,\b,\b,\a>
1600     \fi
1601     \circulararc {#4} degrees from {#5} {#6} center at {0} {0} %
1602   \or
1603     \ifchemicaldotted
1604       \psset{linestyle=dashed}%
1605     \fi
1606     \rput
1607       {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1608       {\psarc(0,0){#3}{#1}{#2}}%
1609   \or
1610     \global\MPdrawingdonetrue
1611     \setchemicalattributes
1612     \startMPdrawing
1613       r := \MPdivten[#3]*2u;
1614       x0 := \MPdivten[\chemicalxoffset]u ;
1615       y0 := \MPdivten[\chemicalyoffset]u ;
1616       draw ((subpath (#1/45,#2/45) of (fullcircle scaled (r)))
1617         rotatedaround (origin,\chemicalangle+150))
1618         shifted z0 \ifchemicaldotted dashed withdots \fi ;
1619     \stopMPdrawing
1620   \fi
1621   \egroup}
1622
1623\def\setchemicalcircsegment #1 #2 #3 #4 #5 #6 #7
1624  {\setvalue{\s!chemicalcircsegment#1}{\plotchemicalcircle{#2}{#3}{#4}{#5}{#6}{#7}}}
1625
1626\def\getchemicalcircsegment[#1][#2]%
1627  {\chemicalrotate[#1]%
1628   \getvalue{\s!chemicalcircsegment#2}}
1629
1630\def\doprocesschemicalcircsegment#1#2%
1631  {\def\doprocess[##1##2##3##4##5]%
1632     {\doifelse{##1}{?}
1633        {\doprocess[1..\maxchemical ????]}
1634        {\doifchemicalnumber{##1}{#1#2}
1635           {\doifelse{##2##3}{..}
1636              {\doifchemicalnumber{##4}{#1#2}
1637                 {\getchemicalcircsegment[##1][#1]%
1638                  \doifnot{##1}{##4}
1639                    {\!!counta=##1\relax
1640                     \advance\!!counta by 1
1641                     \edef\nextsegment{\the\!!counta}%
1642                     \doprocess[\nextsegment..##4##5]}}}
1643              {\getchemicalcircsegment[##1][#1]%
1644               \doifnot{##2}{?}
1645                 {\doprocess[##2##3##4##5]}}}}}%
1646   \doprocess[#2]}
1647
1648\def\processchemicalcircsegment%
1649  {\chemicaldottedfalse\doprocesschemicalcircsegment}
1650
1651\def\processchemicaldottsegment%
1652  {\chemicaldottedtrue\doprocesschemicalcircsegment}
1653
1654\let\endchemicalpicture   = \relax
1655\let\checkchemicalpicture = \relax
1656\let\nomoreaccounting     = \relax
1657
1658\newif\ifchemicalpicture
1659
1660\def\beginchemicalpicture#1% NO PSTRICKS SUPPORT YET
1661  {\checkchemicalpicture
1662   \bgroup                 % DOES NOT HANDLE AUTOWIDTH/HEIGHT
1663   \chemicalpicturetrue
1664   \processchemical[#1]}
1665
1666\def\setchemicalpicture#1#2%
1667  {\chemicalpicturefalse
1668   \def\endchemicalpicture%
1669     {\@@endchemicallocalpicture{#1}{#2}%
1670      \egroup
1671      \ifnum\chemicaldrawingmode=1
1672        \rput
1673          {-\chemicalangle}(\chemicalxoffset,\chemicalyoffset)%
1674          {\expanded{\rput[\chemicalloca]{\chemicalangle}(#1,#2){\box\nextbox}}}%
1675      \else
1676        \expanded{\put{\box\nextbox}[\chemicalloca] at {#1} {#2} }
1677      \fi
1678      \egroup}%
1679   \def\checkchemicalpicture%
1680     {\ifx\endchemicalpicture\relax \else
1681        \writestatus{ppchtex}{missing end of picture (PE)}%
1682        \endchemicalpicture
1683      \fi}%
1684   \setbox\nextbox=\hbox\bgroup
1685   \@@beginchemicallocalpicture
1686   % alternatief: gewoon accounting, en zelf l,r afhandelen
1687   \ifnum\chemicaldrawingmode=1
1688     % njet
1689   \else
1690     \accountingon
1691     \let\nomoreaccounting=\accountingoff
1692   \fi}
1693
1694\def\doskipchemical[#1][#2]%
1695  {{\tt[ppchtex]}}
1696
1697\def\skipchemical%
1698  {\dodoubleargument\doskipchemical}
1699
1700\def\complexchemical% met \expandafter
1701  {\ifinchemical
1702     \expandafter\dochemical
1703   \else
1704     \writestatus{ppchtex}{the [][]-alternative is not permitted here}%
1705     \expandafter\skipchemical
1706   \fi}
1707
1708\newif\ifinnerchemical
1709
1710\def\dosimplechemical#1#2#3%
1711  {\doifelsedefined{\??chemical\c!location}
1712     {\writestatus{ppchtex}{the {}{}-alternative is not permitted here}}
1713     {\ifinnerchemical
1714        \let\chemicalsign         = \chemicalinnersign
1715        \let\chemicalmolecule     = \chemicalinnermolecule
1716        \let\chemicalsinglearrow  = \chemicalsingleinnerarrow
1717        \let\chemicaldoublearrow  = \chemicaldoubleinnerarrow
1718        \let\chemicaltwintiparrow = \chemicaltwintipinnerarrow
1719      \else
1720        \let\chemicalsign         = \chemicaloutersign
1721        \let\chemicalmolecule     = \chemicaloutermolecule
1722        \let\chemicalsinglearrow  = \chemicalsingleouterarrow
1723        \let\chemicaldoublearrow  = \chemicaldoubleouterarrow
1724        \let\chemicaltwintiparrow = \chemicaltwintipouterarrow
1725      \fi
1726      \disablechemicalspecials
1727      \processallactionsinset
1728        [#1]
1729        [       HIGH=>\sethighsubscripts,
1730                 LOW=>\setlowsubscripts,
1731                PLUS=>\chemicalsign{+},
1732               GIVES=>\chemicalsinglearrow{#2}{#3},
1733         EQUILIBRIUM=>\chemicaldoublearrow{#2}{#3},
1734           MESOMERIC=>\chemicaltwintiparrow{#2}{#3},
1735              SINGLE=>\singlechemicalbond,
1736              DOUBLE=>\doublechemicalbond,
1737              TRIPLE=>\triplechemicalbond,
1738                   +=>\chemicalsign{+},
1739                  ->=>\chemicalsinglearrow{#2}{#3},
1740                 <->=>\chemicaldoublearrow{#2}{#3},
1741                  <>=>\chemicaltwintiparrow{#2}{#3},
1742                   -=>\singlechemicalbond,
1743                  --=>\doublechemicalbond,
1744                 ---=>\triplechemicalbond,
1745          \s!unknown=>\enablechemicalspecials
1746                      \chemicalmolecule{\commalistelement}{#2}{#3}]}}
1747
1748\def\dosimplechemicalA#1#2#3% % evt: {#1,\relax}
1749  {\let\chemicalspace=\relax
1750   \expandafter\dosimplechemical\expandafter{\@@chemicalchemicaloffset,#1}{#2}{#3}%
1751   \egroup}
1752
1753\def\dosimplechemicalB#1#2#3%
1754  {\dosimplechemical{#1}{#2}{#3}%
1755   \egroup}
1756
1757\def\dosimplechemicalC#1#2#3%
1758  {$\simplechemical{#1}{#2}{#3}$%
1759   \egroup} % erbij
1760
1761\def\simplechemical
1762  {\ifinner
1763     \innerchemicaltrue
1764   \else
1765     \innerchemicalfalse
1766   \fi
1767   \bgroup
1768   \catcode`\^=\superscriptcatcode %  t.b.v. \enableduplication
1769   \catcode`\_=\subscriptcatcode   %  t.b.v. de zekerheid
1770   \ifmmode
1771     \ifinnerchemical
1772       \def\next{\dotriplegroupempty\dosimplechemicalA}%
1773     \else
1774       \def\next{\dotriplegroupempty\dosimplechemicalB}%
1775     \fi
1776   \else
1777     \def\next{\dotriplegroupempty\dosimplechemicalC}%
1778   \fi
1779   \next}
1780
1781\definecomplexorsimple\chemical
1782
1783\def\dogotochemical#1#2%
1784  {\def\dowithchemical%                       % experiment
1785     {\localgotochemical{#1}}%                % experiment
1786   \chemical}                                 % experiment
1787
1788\def\gotochemical%                            % experiment
1789  {\dosingleargument\dogotochemical}          % experiment
1790
1791\def\dododochemical#1[#2][#3]%                % experiment
1792  {\def\simpledododochemical%                 % experiment
1793     {#1[#2][#3]}%                            % experiment
1794   \def\complexdododochemical[##1]%           % experiment
1795     {\def\dowithchemical%                    % experiment
1796        {\localthisischemical{#2}}%           % experiment
1797      #1[#3][##1]}%                           % experiment
1798   \complexorsimple\dododochemical}           % experiment
1799
1800\def\dodochemical[#1][#2]%
1801  {\ignorespaces
1802   \ifinchemical
1803     \drawchemical[#1][#2]%
1804     \ignorespaces
1805   \else
1806     \startchemical[\c!location=\v!intext]%
1807       \drawchemical[#1][#2]%
1808     \expandafter\stopchemical
1809   \fi
1810   \ignorespaces}
1811
1812\def\dochemical[#1]%
1813  {\def\simpledochemical%
1814     {\@@writechemicalstate{ppchtex}{[#1][]}%
1815      \dodochemical[#1][]}%
1816   %
1817   \def\complexdochemical[##1]%
1818     {\@@writechemicalstate{ppchtex}{[#1][##1]}%
1819      \txtchemical=0%
1820      \dodochemical[#1][##1]}%
1821   %
1822   \def\complexdochemical[##1]%                   % experiment
1823     {\@@writechemicalstate{ppchtex}{[#1][##1]}% % experiment
1824      \txtchemical=0%                             % experiment
1825      \dododochemical\dodochemical[#1][##1]}%     % experiment
1826   %
1827   \complexorsimple\dochemical}
1828
1829% \processlocalchemicals{#1}
1830%
1831% #1: commando's
1832
1833\def\dodoprocesschemical#1%
1834  {\processchemical[#1????]}
1835
1836\def\processlocalchemicals#1%
1837  {\processcommalist[#1]\dodoprocesschemical}
1838
1839% \drawchemical[#1][#2]
1840%
1841% #1: bindingen enz.
1842% #2: atomen enz.
1843
1844\def\localdodochemical[#1][#2]%
1845  {\@@writechemicalstate{ppchtex}{[#1][#2]}%
1846   %\bgroup     % koppelen en afmetingen gaat fout, vandaar:
1847   \advance\levchemical 1
1848   \letvalue{\??chemical\s!unknown\the\levchemical}\unknownchemical
1849   \setevalue{\??chemical\c!text\the\levchemical}{\the\txtchemical}%
1850   \txtchemical=0
1851   \dodochemical[#1][#2]%
1852   % \expandafter\txtchemical\expandafter\csname\??chemical\c!text\the\levchemical\endcsname
1853   \txtchemical\csname\??chemical\c!text\the\levchemical\endcsname
1854   \expandafter\let\expandafter\unknownchemical\csname\??chemical\s!unknown\the\levchemical\endcsname
1855   \advance\levchemical -1
1856   %\egroup
1857   \ignorespaces}
1858
1859\def\drawchemical[#1][#2]%
1860  {\ignorespaces
1861   \def\dodochemical[##1][##2]%
1862     {\drawchemical[##1][##2]%
1863      \ignorespaces}%
1864   \def\dochemical[##1]%
1865     {\def\simpledochemical%
1866        {\@@writechemicalstate{ppchtex}{[##1][#2]}%
1867         \dodochemical[##1][#2]%
1868         \ignorespaces}%
1869      \def\complexdochemical[####1]%
1870        {\dododochemical\localdodochemical[##1][####1,#2]}%
1871     \complexorsimple\dochemical}%
1872   \doif\@@chemicalstate\v!start
1873     {\doifelse\chemicalname\s!unknown
1874        {\getvalue{\s!executechemical\defaultchemical}[#2]}
1875        {\getvalue{\s!executechemical\chemicalname}[#2]}%
1876      \def\unknownchemical##1%
1877        {\processunknownchemical[##1][#2]}%
1878      \processcommalist[\@@chemicaloffset,#1]\dodoprocesschemical}%
1879   \ignorespaces}
1880
1881\unexpanded\def\chemicaloxidation#1#2#3%
1882  {\chemicaltop
1883     {\ifnum#20=0
1884        0%
1885      \else
1886        #1\expandafter\uppercase\expandafter{\romannumeral#2}%
1887      \fi}
1888     {#3}}
1889
1890\def\chemicaltfraction{\ifinchemical.60\else.8\fi}
1891\def\chemicalbfraction{\ifinchemical.45\else.6\fi}
1892\def\chemicallfraction{\ifinchemical.1\else.1\fi}
1893\def\chemicalrfraction{\ifinchemical.1\else.1\fi}
1894
1895\def\chemicaltighttext
1896  {\def\chemicaltfraction{\ifinchemical.3\else.6\fi}%
1897   \def\chemicalbfraction{\ifinchemical.2\else.4\fi}%
1898   \def\chemicallfraction{\ifinchemical 0\else 0\fi}%
1899   \def\chemicalrfraction{\ifinchemical 0\else 0\fi}}
1900
1901\def\dochemicaltop#1#2#3#4%
1902  {\vbox
1903     {\@@dochemicalcolor
1904      \baselineskip=\chemicaltfraction\baselineskip \lineskip0pt
1905      \halign
1906        {#1###2\cr
1907         $\@@dochemicalstyle{\scriptscriptstyle#3}$\cr
1908         $\@@dochemicalstyle{\@@currentchemicalformat#4}$\cr}}}
1909
1910\def\dochemicalbottom#1#2#3#4%
1911  {\vtop
1912     {\@@dochemicalcolor
1913      \baselineskip=\chemicalbfraction\baselineskip \lineskip0pt
1914      \halign
1915        {#1###2\cr
1916         $\@@dochemicalstyle{\@@currentchemicalformat#4}$\cr
1917         $\@@dochemicalstyle{\scriptscriptstyle#3}$\cr}}}
1918
1919\def\chemicalleft#1#2%
1920  {\hbox
1921     {\@@dochemicalcolor
1922      $\@@dochemicalstyle{\scriptscriptstyle#1}$%
1923      $\@@dochemicalstyle{\@@currentchemicalformat\hskip\chemicallfraction em#2}$}}
1924
1925\def\chemicalright#1#2%
1926  {\hbox
1927     {\@@dochemicalcolor
1928      $\@@dochemicalstyle{\@@currentchemicalformat#2\hskip\chemicalrfraction em}$%
1929      $\@@dochemicalstyle{\scriptscriptstyle#1}$}}
1930
1931\def\chemicalcentered#1%
1932  {\setbox0=\hbox{$\@@dochemicalstyle{\scriptscriptstyle#1}$}%
1933   \setbox2=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat C}$}%
1934   \dimen0=.5\ht2
1935   \advance\dimen0 by -.5\ht0
1936   \advance\dimen0 by \dp0
1937   \hbox{\@@dochemicalcolor\raise\dimen0\box0}}
1938
1939\def\chemicalleftcentered#1#2%
1940  {\hbox
1941     {\@@dochemicalcolor
1942      \chemicalcentered{#1}%
1943      $\@@dochemicalstyle{\@@currentchemicalformat\hskip\chemicallfraction em#2}$}}
1944
1945\def\chemicalrightcentered#1#2%
1946  {\hbox
1947     {\@@dochemicalcolor
1948      $\@@dochemicalstyle{\@@currentchemicalformat#2\hskip\chemicalrfraction em}$%
1949      \chemicalcentered{#1}}}
1950
1951\def\chemicaltop          {\dochemicaltop    \hss   \hss  }
1952\def\chemicallefttop      {\dochemicaltop    \relax \hss  }
1953\def\chemicalrighttop     {\dochemicaltop    \hss   \relax}
1954\def\chemicalbottom       {\dochemicalbottom \hss   \hss  }
1955\def\chemicalleftbottom   {\dochemicalbottom \relax \hss  }
1956\def\chemicalrightbottom  {\dochemicalbottom \hss   \relax}
1957
1958\def\chemicaltopleft    #1{\chemicalleft {\chemicallefttop   {#1}{}}}
1959\def\chemicalbottomleft #1{\chemicalleft {\chemicalleftbottom{#1}{}}}
1960\def\chemicaltopright   #1{\chemicalright{\chemicallefttop   {#1}{}}}
1961\def\chemicalbottomright#1{\chemicalright{\chemicalleftbottom{#1}{}}}
1962
1963\def\chemicalsmashedleft#1%
1964  {\hbox\bgroup
1965   \@@dochemicalcolor
1966   \setbox0=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat C}$}%
1967   \setbox2=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat#1}$}%
1968   \wd2=\wd0
1969   \box2
1970   \egroup}
1971
1972\def\chemicalsmashedmiddle#1%
1973  {\hbox\bgroup
1974   \@@dochemicalcolor
1975   \setbox0=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat C}$}%
1976   \setbox2=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat#1}$}%
1977   \hbox{\hskip-.5\wd2\hskip.5\wd0\box2}
1978   \egroup}
1979
1980\def\chemicalsmashedright#1%
1981  {\hbox\bgroup
1982   \@@dochemicalcolor
1983   \setbox0=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat C}$}%
1984   \setbox2=\hbox{$\@@dochemicalstyle{\@@currentchemicalformat#1}$}%
1985   \hbox to \wd0{\hskip-\wd2\hskip\wd0\box2}%
1986   \egroup}
1987
1988\def\+{\tabalign} % is \long in Plain
1989
1990\def\chemicalforever#1#2%
1991  {\bgroup
1992   \setbox0=\hbox
1993     {\@@dochemicalcolor
1994      $\@@dochemicalstyle{\scriptscriptstyle\hskip-.15em#2}$}%
1995   \wd0=0pt
1996   \big#1\normapsubscript{\hskip.1em\box0}%
1997   \egroup}
1998
1999\def\disablechemicalspecials%
2000  {\def\+##1{##1}\def\-##1{##1}%
2001   \def\[{[}\def\]{]}%
2002   \def\1{}\def\2{}\def\3{}\def\4{}\def\5{}\def\6{}\def\7{}%
2003   \def\X{}%
2004   \def\T{}\def\B{}\def\L{}\def\R{}\def\LC{}\def\RC{}%
2005   \def\TL{}\def\BL{}\def\TR{}\def\BR{}%
2006   \def\LT{}\def\LB{}\def\RT{}\def\RB{}%
2007   \def\SL{}\def\SM{}\def\SR{}}
2008
2009\def\enablechemicalspecials%
2010  {\def\+{\dodoublegroupempty\chemicaloxidation{+}}% {} needed!
2011   \def\-{\dodoublegroupempty\chemicaloxidation{-}}% {} needed!
2012   \def\[{\dodoublegroupempty\chemicalforever  {[}}% {} needed!
2013   \def\]{\dodoublegroupempty\chemicalforever  {]}}% {} needed!
2014   \def\1{\chemicaloxidation\relax1}%
2015   \def\2{\chemicaloxidation\relax2}%
2016   \def\3{\chemicaloxidation\relax3}%
2017   \def\4{\chemicaloxidation\relax4}%
2018   \def\5{\chemicaloxidation\relax5}%
2019   \def\6{\chemicaloxidation\relax6}%
2020   \def\7{\chemicaloxidation\relax7}%
2021   \def\X{\chemicaltighttext}%
2022   \def\T{\chemicaltop}%
2023   \def\B{\chemicalbottom}%
2024   \def\L{\chemicalleft}%
2025   \def\LC{\chemicalleftcentered}%
2026   \def\R{\chemicalright}%
2027   \def\RC{\chemicalrightcentered}%
2028   \def\TL{\chemicaltopleft}%
2029   \def\BL{\chemicalbottomleft}%
2030   \def\TR{\chemicaltopright}%
2031   \def\BR{\chemicalbottomright}%
2032   \def\LT{\chemicallefttop}%
2033   \def\LB{\chemicalleftbottom}%
2034   \def\RT{\chemicalrighttop}%
2035   \def\RB{\chemicalrightbottom}%
2036   \def\SL{\chemicalsmashedleft}%
2037   \def\SM{\chemicalsmashedmiddle}%
2038   \def\SR{\chemicalsmashedright}}
2039
2040% \reversechemical#1#2#3
2041%
2042% #1: prefix
2043% #2: volgnummer enz
2044% #3: tegengestelde volgnummers
2045
2046\def\reversechemical#1#2#3%
2047  {\def\doprocess[##1##2]%
2048     {\doifchemicalnumber{##1}{#1#2}%
2049        {\getfromcommalist[#3][##1]%
2050         \let\reversechemicalaction=\commalistelement
2051         \processchemical[#1\reversechemicalaction##2]}}%
2052   \doprocess[#2]}
2053
2054% \processunknownchemical[#1????][#2]
2055%
2056% #1: bindingen enz.
2057% #2: atomen enz.
2058
2059\def\defaultchemical%
2060  {SIX}
2061
2062\def\processunknownchemical[#1????][#2]%
2063  {\processaction
2064     [#1]
2065     [       SAVE=>\executechemicalSAVE,
2066          RESTORE=>\executechemicalRESTORE,
2067             HIGH=>\sethighsubscripts,
2068              LOW=>\setlowsubscripts,
2069      \s!default=>,
2070      \s!unknown=>\doifelsedefined{\s!executechemical#1}
2071                    {\def\chemicalrotation{1}%
2072                     \def\chemicaloffset{0}%
2073                     \doifdefined{\s!executechemical#1}
2074                       {\getvalue{\s!executechemical#1}[#2]}%
2075                     \@@chemicalpostponed}
2076                    {\getpredefinedchemical{#1}}]}
2077
2078\newcount\chemicalstack
2079
2080\setvalue{\s!chemical\c!x1}{0}
2081\setvalue{\s!chemical\c!y1}{0}
2082
2083\def\executechemicalSAVE
2084  {%\writestatus{ppchtex}{saving \the\horchemical,\the\verchemical}%
2085   \advance\chemicalstack by 1
2086   \letvalue {\s!chemical n\the\chemicalstack}=\chemicalname
2087   %\letvalue {\s!chemical p\the\chemicalstack}=\@@chemicalpostponed
2088   \setevalue{\s!chemical x\the\chemicalstack}{\the\horchemical}%
2089   \setevalue{\s!chemical y\the\chemicalstack}{\the\verchemical}}
2090
2091\def\restorechemicalvalues#1%
2092  {\let\oldprocesschemical=\processchemical
2093   \doifdefined{\s!executechemical#1}{\getvalue{\s!executechemical#1}[]}%
2094   \let\processchemical=\oldprocesschemical}
2095
2096\def\executechemicalRESTORE
2097  {\ifnum\chemicalstack=0\relax
2098     \horchemical=\getvalue{\s!chemical x1}\relax
2099     \verchemical=\getvalue{\s!chemical y1}\relax
2100   \else
2101     \restorechemicalvalues{\getvalue{\s!chemical n\the\chemicalstack}}%
2102     %\expandafter\let\expandafter\@@chemicalpostponed\expandafter=\csname\s!chemical p\the\chemicalstack\endcsname
2103     \let\@@chemicalpostponed=\relax
2104     \horchemical=\getvalue{\s!chemical x\the\chemicalstack}\relax
2105     \verchemical=\getvalue{\s!chemical y\the\chemicalstack}\relax
2106     \advance\chemicalstack by -1
2107   \fi
2108   \restorechemicalcoordinates}
2109
2110% De onderstaande macro's zijn verantwoordelijk voor het zetten
2111% van de + en pijlen. De +, en dus ook de pijlen, worden omhoog
2112% gehaald. Dit oogt m.i. fraaier.
2113
2114\def\chemicalinnerclip#1%
2115  {{\setbox0=\hbox{#1}\ht0\ht\strutbox\dp0\dp\strutbox\box0}}
2116
2117\def\chemicalraise#1#2%
2118  {\chemicalinnerclip
2119     {\setbox0=\hbox{$#1+$}%
2120      \raise\dp0\hbox{$#1#2$}}}
2121
2122\def\chemicalinnersign#1% todo: \@@chemicaltextcolor
2123  {\chemicalraise{\@@localchemicalstyle}{#1}}
2124
2125\def\chemicaloutersign#1%
2126  {\chemicalraise{}{\@@dochemicalcolor#1}}
2127
2128\def\chemicalsingleinnerarrow#1#2%
2129  {\chemicalraise{\@@localchemicalstyle}{\longrightarrow}}
2130
2131\def\chemicaldoubleinnerarrow#1#2% todo: \@@chemicaltextcolor
2132  {\chemicalinnerclip
2133     {\lower.2ex\hbox
2134        {\setbox0=\hbox{$\@@localchemicalstyle\longrightarrow$}%
2135         \setbox2=\hbox{$\@@localchemicalstyle\longleftarrow$}%
2136         \wd0=0pt\raise\ht0\box0\box2}}}
2137
2138\def\chemicaltwintipinnerarrow#1#2% todo: \@@chemicaltextcolor
2139  {\chemicalinnerclip
2140     {\setbox0=\hbox{\chemicalraise{\@@localchemicalstyle}{\longrightarrow}}%
2141      \setbox2=\hbox{\chemicalraise{\@@localchemicalstyle}{\longleftarrow}}%
2142      \wd0=0pt\box0\box2}}
2143
2144\def\dochemicalouterarrow#1#2#3%
2145  {\bgroup
2146   \setbox0=\hbox{$\longrightarrow$}%
2147   \setbox2=\hbox{$\@@dochemicalstyle{\scriptstyle\quad#2\quad}$}%
2148   \setbox4=\hbox{$\@@dochemicalstyle{\scriptstyle\quad#3\quad}$}%
2149   \dimen2=\wd0 % \dimen0 is used elsewhere
2150   \ifdim\wd2>\dimen2 \dimen0=\wd2 \fi
2151   \ifdim\wd4>\dimen2 \dimen0=\wd4 \fi
2152   \chemicaloutermolecule
2153     {#1}
2154     {\ifdim\ht2>\zeropoint\box2\fi}  % expands to \empty in test
2155     {\ifdim\ht4>\zeropoint\box4\fi}% % expands to \empty in test
2156   \egroup}
2157
2158\def\chemicalsingleouterarrow
2159  {\dochemicalouterarrow
2160     {\hbox to \dimen2{\rightarrowfill}}}
2161
2162\def\chemicaldoubleouterarrow
2163  {\dochemicalouterarrow
2164     {\lower.5\ht0\vbox
2165        {\offinterlineskip
2166         \hbox to \dimen2{\rightarrowfill}
2167         \hbox to \dimen2{\leftarrowfill}}}}
2168
2169\def\chemicaltwintipouterarrow
2170  {\dochemicalouterarrow
2171     {\hbox
2172        {\hbox to \dimen2{\rightarrowfill}%
2173         \hskip-\dimen2
2174         \hbox to \dimen2{\leftarrowfill}}}}
2175
2176\def\chemicalinnermolecule#1#2#3% no mathop here, can generate space
2177  {\chemicalspace               % todo: \@@chemicaltextcolor
2178   \chemicalinnerclip
2179     {\dosetsubscripts
2180      $\@@dochemicalstyle{\@@localchemicalstyle\strut#1}$%
2181      \doresetsubscripts}%
2182   \chemicalspace}
2183
2184\def\chemicaloutermolecule#1#2#3%
2185  {\chemicalspace
2186   \bgroup
2187   \@@dochemicalcolor
2188   \setbox0=\hbox % else the font is reset
2189     {\dosetsubscripts
2190      \hbox{$\@@dochemicalstyle{\strut#1}$}%
2191      \doresetsubscripts}%
2192   \mathop{\box0}%
2193   \ifthirdargument
2194     \doifnot{#2}{}{\normapsuperscript{\@@dochemicalstyle{\strut#2}}}%
2195     \doifnot{#3}{}{\normapsubscript  {\@@dochemicalstyle{\strut#3}}}%
2196   \else
2197     \doifnot{#2}{}
2198       {\normapsubscript{\@@dochemicalstyle{\strut#2}}}%
2199   \fi
2200   \egroup
2201   \chemicalspace}
2202
2203\def\chemicalsinglepicturearrow#1%
2204  {\lower.5ex\hbox
2205      {\@@dochemicalstyle
2206       $\chemicalspace
2207        \buildrel
2208          \@@dochemicalstyle{\scriptstyle\quad#1\quad}%
2209        \over{\overrightarrow
2210          {\hphantom{\@chemicalstyle{\scriptstyle\quad#1\quad}}}}%
2211        \chemicalspace$}}
2212
2213\def\chemicaldoublepicturearrow#1%
2214  {\lower.5ex\hbox
2215     {\@@dochemicalstyle
2216      $\chemicalspace
2217       \buildrel
2218         \@@dochemicalstyle{\scriptstyle\quad#1\quad}%
2219       \over{\overrightarrow{\overleftarrow
2220         {\hphantom{\@@dochemicalstyle{\scriptstyle\quad#1\quad}}}}}%
2221       \chemicalspace$}}
2222
2223% Bij de in-line bindingen wordt gebruik gemaakt van
2224% een \hrule. De maatvoering wordt bepaald door een
2225% kunstmatige em (\wd0).
2226
2227\def\somechemicalbond%
2228  {\hrule width \wd0 height .4pt}
2229
2230\def\dochemicalbonds#1#2#3% todo: \@@chemicaltextstyle
2231  {{\setbox0=\hbox
2232      {${\@@localchemicalstyle M}$}%
2233    \vbox to \ht0
2234      {\@@dochemicalcolor
2235       \hsize\wd0
2236       \vskip.1\wd0#1\vfill#2\vfill#3\vskip.1\wd0}}}
2237
2238\def\singlechemicalbond%
2239  {\dochemicalbonds{}{\somechemicalbond}{}}
2240
2241\def\doublechemicalbond%
2242  {\dochemicalbonds{\somechemicalbond}{}{\somechemicalbond}}
2243
2244\def\triplechemicalbond%
2245  {\dochemicalbonds{\somechemicalbond}{\somechemicalbond}{\somechemicalbond}}
2246
2247% In plaats van \def\naam{\chemie[...]...} kan beter gebruik
2248% worden gemaakt van het commando
2249%
2250%   \definieerchemie[naam]{commando's}
2251%
2252% De naam krijgt, om problemen met bestaande macro's te
2253% voorkomen, een prefix. Bij het ophalen van een commando
2254% worden beide definities afgehandeld.
2255
2256\def\dodefinechemical[#1]#2%
2257  {\doifdefined{\??chemical#1}
2258     {\writestatus{ppchtex}{chemical definition #1 is redefined}}%
2259   \setvalue{\??chemical#1}{#2}}
2260
2261\unexpanded\def\definechemical%
2262  {\dosingleargument\dodefinechemical}
2263
2264\def\getpredefinedchemical#1%
2265  {\doifelsedefined{\??chemical#1}
2266     {\getvalue{\??chemical#1}}
2267     {\doifelsedefined{#1}
2268        {\getvalue{#1}}
2269        {\writestatus{ppchtex}{unknown chemical definition #1}}}}
2270
2271% Hieronder zijn de definities van de structuren opgenomen. De
2272% naam van de structuur is als volgt opgebouwd:
2273%
2274%   \executechemicalNUMBER[#1]
2275%
2276% waarbij [#1] betrekking heeft op de tekstelementen van \chemie,
2277% de [tweede lijst] dus.
2278%
2279% De aan \chemie[#1][#2] meegegeven lijst van segmenten wordt
2280% deels door de in \execute gedefinieerde macro's afgehandeld,
2281% deels door algemene macro's. Segmenten hebben de vorm:
2282%
2283%   [+|-|]identifier[X|XYZ|X..Y]
2284%
2285% Voorbeelden van segmenten zijn:
2286%
2287%   R1
2288%   R1..4
2289%   R135
2290%   -R1
2291%   +R35
2292
2293\setchemicalmaximum 0
2294
2295\def\processchemical[#1]%
2296  {\unknownchemical{#1}}
2297
2298\def\setchemicalname#1 %
2299  {\def\chemicalname{#1}}
2300
2301\let\chemicalname=\s!unknown
2302
2303% Vooruitlopend op een gedetailleerde documentatie, zijn hier
2304% vast enkele gebruikte afmetingen:
2305%
2306% lengte radikalen          :  500
2307% afstand radikalen         :  100
2308% afstand dubbele radikalen :  260
2309% afstand substituenten     : +125
2310
2311
2312
2313
2314\def\executechemicalONE[#1]%
2315  {\setchemicalname ONE
2316   %
2317   \setchemicalmaximum      8
2318   \setchemicaldistance     0
2319   \setchemicalsubstitute 625
2320   \setchemicaldirection  303
2321   %
2322   \setchemicalrotation 1  1      0      1      0      1      0      1      0
2323   \setchemicalrotation 2  0.707 -0.707  0.707 -0.707  0.707 -0.707  0.707 -0.707
2324   \setchemicalrotation 3  0     -1      0     -1      0     -1      0     -1
2325   \setchemicalrotation 4 -0.707 -0.707 -0.707 -0.707 -0.707 -0.707 -0.707 -0.707
2326   \setchemicalrotation 5 -1      0     -1      0     -1      0     -1      0
2327   \setchemicalrotation 6 -0.707  0.707 -0.707  0.707 -0.707  0.707 -0.707  0.707
2328   \setchemicalrotation 7  0      1      0      1      0      1      0      1
2329   \setchemicalrotation 8  0.707  0.707  0.707  0.707  0.707  0.707  0.707  0.707
2330   %
2331   \setchemicalangle 1   0  90 180 270
2332   \setchemicalangle 2  45 135 225 315
2333   \setchemicalangle 3  90 180 270   0
2334   \setchemicalangle 4 135 225 315  45
2335   \setchemicalangle 5 180 270   0  90
2336   \setchemicalangle 6 225 315  45 135
2337   \setchemicalangle 7 270   0  90 180
2338   \setchemicalangle 8 315  45 135 225
2339   %
2340   \setchemicaltranslate 1 -1000     0
2341   \setchemicaltranslate 2 -1000  1000
2342   \setchemicaltranslate 3     0  1000
2343   \setchemicaltranslate 4  1000  1000
2344   \setchemicaltranslate 5  1000     0
2345   \setchemicaltranslate 6  1000 -1000
2346   \setchemicaltranslate 7     0 -1000
2347   \setchemicaltranslate 8 -1000 -1000
2348   %
2349   \setchemicallinesegment  SB  300   0 700    0
2350   \setchemicallinesegment DB1  300  50 700   50
2351   \setchemicallinesegment DB2  300 -50 700  -50
2352   %
2353   %setchemicallinesegment        EP  200 125 200 -125
2354   \setchemicalfactorlinesegment  EP  200 125 200 -125
2355   %
2356   \setchemicaltextelement  ES  200   0
2357   \setchemicaltextelement ED1  200  50
2358   \setchemicaltextelement ED2  200 -50
2359   \setchemicaltextelement ET1  200  75
2360   \setchemicaltextelement ET2  200   0
2361   \setchemicaltextelement ET3  200 -75
2362   \setchemicaltextelement HB1  300   0
2363   \setchemicaltextelement HB2  475   0
2364   \setchemicaltextelement HB3  650   0
2365   %
2366   \setchemicaltextelement   Z  800    0
2367   \setchemicaltextelement  RZ  950    0
2368   \setchemicaltextelement  ZN  500    0
2369   \setchemicaltextelement ZTN  500  150
2370   \setchemicaltextelement ZBN  500 -150
2371   %
2372   \def\processchemical[##1##2##3##4##5]%
2373     {\doprocesschemical[##1##2##3##4##5]
2374        {\processaction
2375           [##1##2##3##4##5]
2376           [    PB:##4##5=>\beginchemicalpicture{##4##5},
2377                   PE????=>\endchemicalpicture,
2378                SUB##4##5=>\processchemicalsubstitute{##4##5},
2379                ADJ##4##5=>\processchemicaldistance{##4##5},
2380                MOV##4##5=>\processchemicaltranslate{##4##5},
2381                DIR##4##5=>\processchemicaldirection{##4##5},
2382                OFF##4##5=>\processchemicaloffset{##4##5},
2383                CCD##4##5=>\processchemicaldottsegment{CC}{##4##5},
2384                LDD##4##5=>\processchemicaldashedlinesegment{DB1}{##4##5}%
2385                           \processchemicallinesegment{DB2}{##4##5},
2386                RDD##4##5=>\processchemicallinesegment{DB1}{##4##5}%
2387                           \processchemicaldashedlinesegment{DB2}{##4##5},
2388                OF##3:##5=>\processchemicalphantom{##3}{##5},
2389              OE##3##4##5=>\processchemicalopenend{OE}{##3##4##5},
2390              EP##3##4##5=>\processchemicallinesegment{EP}{##3##4##5},
2391              ES##3##4##5=>\processchemicaltextconstant{ES}{##3##4##5}{\hbox{$\cdot$}}{0},
2392              ED##3##4##5=>\processchemicaltextconstant{ED}{##3##4##5}{\hbox{$\cdot$}}{0},
2393              ET##3##4##5=>\processchemicaltextconstant{ET}{##3##4##5}{\hbox{$\cdot$}}{0},
2394              HB##3##4##5=>\processchemicaltextconstant{HB}{##3##4##5}{\hbox{$\cdot$}}{0},
2395              SB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5},
2396              DB##3##4##5=>\processchemicallinesegment{DB}{##3##4##5},
2397              SB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5},
2398              BB##3##4##5=>\processchemicaldeltalinesegment{SB}{##3##4##5},
2399              BD##3##4##5=>\processchemicaldasheddeltalinesegment{SB}{##3##4##5},
2400              BW##3##4##5=>\processchemicalwavylinesegment{SB}{##3##4##5},
2401              SD##3##4##5=>\processchemicaldashedlinesegment{SB}{##3##4##5},
2402              TB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5}%
2403                           \processchemicallinesegment{DB}{##3##4##5},
2404              CZ##3##4##5=>\processchemicaltextelement{RZ}{##3##4##5}{#1}{0}{},
2405                ZTN##4##5=>\processchemicalsmalltextconstant{ZTN}{##4##5}{\chemicaltextelementnumber}{0},
2406                ZTT##4##5=>\processchemicalsmalltextelement{ZTN}{##4##5}{#1}{0}{},
2407                ZBN##4##5=>\processchemicalsmalltextconstant{ZBN}{##4##5}{\chemicaltextelementnumber}{0},
2408                ZBT##4##5=>\processchemicalsmalltextelement{ZBN}{##4##5}{#1}{0}{},
2409              ZN##3##4##5=>\processchemicaltextconstant{ZN}{##3##4##5}{\chemicaltextelementnumber}{0},
2410              ZT##3##4##5=>\processchemicaltextelement{ZN}{##3##4##5}{#1}{0}{},
2411            Z##2##3##4##5=>\processchemicaltextelement{Z}{##2##3##4##5}{#1}{0}
2412                             {l,l,t,r,r,r,b,l},
2413            \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}}
2414
2415\def\executechemicalTHREE[#1]%
2416  {\setchemicalname THREE
2417   %
2418   \setchemicalmaximum      3
2419   \setchemicaldistance   289
2420   \setchemicalsubstitute 952
2421   %
2422   \setchemicalrotation 1  1    0      0     -1   -1    0      0      1
2423   \setchemicalrotation 2 -0.5 -0.866 -0.866  0.5  0.5  0.866  0.866 -0.5
2424   \setchemicalrotation 3 -0.5  0.866  0.866  0.5  0.5 -0.866 -0.866 -0.5
2425   %
2426   \setchemicalangle 1   0  90 180 270
2427   \setchemicalangle 2 120 210 300  30
2428   \setchemicalangle 3 240 330  60 150
2429   %
2430   \setchemicaltranslate 1 -1000     0
2431   \setchemicaltranslate 2     0  1000
2432   \setchemicaltranslate 3  1000     0
2433   \setchemicaltranslate 4     0 -1000
2434   %
2435   \setchemicallinesegment   B   577     0  -289  -500
2436   \setchemicallinesegment  SB   352  -130   -64  -370
2437   \setchemicallinesegment -SB   352  -130  -289  -500
2438   \setchemicallinesegment +SB   577     0   -64  -370
2439   \setchemicallinesegment DB1   327   -87   -89  -327
2440   \setchemicallinesegment DB2   377  -172   -39  -413
2441   \setchemicallinesegment   R   577     0  1077     0
2442   \setchemicallinesegment  -R   577     0  1010   250
2443   \setchemicallinesegment  +R   577     0  1010  -250
2444   \setchemicallinesegment ER1   577    50  1077    50
2445   \setchemicallinesegment ER2   577   -50  1077   -50
2446   \setchemicallinesegment  SR   837     0  1077     0
2447   \setchemicallinesegment -SR   802   130  1010   250
2448   \setchemicallinesegment +SR   802  -130  1010  -250
2449   \setchemicallinesegment DR1   837    50  1077    50
2450   \setchemicallinesegment DR2   837   -50  1077   -50
2451   %
2452   \setchemicaltextelement   Z   577     0
2453   \setchemicaltextelement  RZ  1177     0
2454   \setchemicaltextelement -RZ  1097   300
2455   \setchemicaltextelement +RZ  1097  -300
2456   \setchemicaltextelement CRZ  1077     0
2457   %
2458   \def\processchemical[##1##2##3##4]%
2459     {\processaction
2460        [##1##2##3##4]
2461        [    ROT##4=>\processchemicalrotation{##4},
2462             MOV##4=>\processchemicaltranslate{##4},
2463             SUB##4=>\processchemicalsubstitute{##4},
2464             ADJ##4=>\processchemicaldistance{##4},
2465             -RZ##4=>\processchemicaltextelement{-RZ}{##4}{#1}{3}
2466                       {l,t,r, l,r,l, r,b,l, r,l,r},
2467             +RZ##4=>\processchemicaltextelement{+RZ}{##4}{#1}{3}
2468                       {l,r,b, r,r,l, r,l,t, l,l,r},
2469             -SB##4=>\processchemicallinesegment{-SB}{##4},
2470             +SB##4=>\processchemicallinesegment{+SB}{##4},
2471             -SR##4=>\processchemicallinesegment{-SR}{##4},
2472             +SR##4=>\processchemicallinesegment{+SR}{##4},
2473             CRZ##4=>\processchemicaltextelement{CRZ}{##4}{#1}{0}
2474                       {},
2475           DB##3##4=>\processchemicallinesegment{DB}{##3##4},
2476           DR##3##4=>\processchemicallinesegment{DR}{##3##4},
2477           RZ##3##4=>\processchemicaltextelement{RZ}{##3##4}{#1}{3}
2478                       {l,r,r, t,r,l, r,l,l, b,l,r},
2479           ER##3##4=>\processchemicallinesegment{ER}{##3##4},
2480           SB##3##4=>\processchemicallinesegment{SB}{##3##4},
2481           SR##3##4=>\processchemicallinesegment{SR}{##3##4},
2482           -R##3##4=>\processchemicallinesegment{-R}{##3##4},
2483           +R##3##4=>\processchemicallinesegment{+R}{##3##4},
2484         B##2##3##4=>\processchemicallinesegment{B}{##2##3##4},
2485         R##2##3##4=>\processchemicallinesegment{R}{##2##3##4},
2486         Z##2##3##4=>\processchemicaltextelement{Z}{##2##3##4}{#1}{0}{},
2487         \s!unknown=>\unknownchemical{##1##2##3##4}]}}
2488
2489\def\executechemicalFOUR[#1]%
2490  {\setchemicalname FOUR
2491   %
2492   \setchemicalmaximum      4
2493   \setchemicaldistance   500
2494   \setchemicalsubstitute   0
2495   %
2496   \setchemicalrotation 1  1  0  0 -1 -1  0  0  1
2497   \setchemicalrotation 2  0 -1 -1  0  0  1  1  0
2498   \setchemicalrotation 3 -1  0  0  1  1  0  0 -1
2499   \setchemicalrotation 4  0  1  1  0  0 -1 -1  0
2500   %
2501   \setchemicalangle 1   0  90 180 270
2502   \setchemicalangle 2  90 180 270   0
2503   \setchemicalangle 3 180 270   0  90
2504   \setchemicalangle 4 270   0  90 180
2505   %
2506   \setchemicaltranslate 1 -1000     0
2507   \setchemicaltranslate 2     0  1000
2508   \setchemicaltranslate 3  1000     0
2509   \setchemicaltranslate 4     0 -1000
2510   %
2511   \setchemicallinesegment   B  500  500  500 -500
2512   \setchemicallinesegment  SB  500  240  500 -240
2513   \setchemicallinesegment -SB  500  240  500 -500
2514   \setchemicallinesegment +SB  500  500  500 -240
2515   \setchemicallinesegment DB1  450  240  450 -240
2516   \setchemicallinesegment DB2  550  240  550 -240
2517   \setchemicallinesegment  EB  360  300  360 -300
2518   \setchemicallinesegment   R  500  500  854  854
2519   \setchemicallinesegment  -R  500  500  500 1000
2520   \setchemicallinesegment  +R  500  500 1000  500
2521   \setchemicallinesegment ER1  465  535  819  889
2522   \setchemicallinesegment ER2  535  465  889  819
2523   \setchemicallinesegment  SR  684  684  854  854
2524   \setchemicallinesegment -SR  500  760  500 1000
2525   \setchemicallinesegment +SR  760  500 1000  500
2526   \setchemicallinesegment DR1  649  719  819  889
2527   \setchemicallinesegment DR2  719  649  889  819
2528   %
2529   \setchemicaltextelement   Z  500  500
2530   \setchemicaltextelement  RZ  925  925
2531   \setchemicaltextelement -RZ  500 1100
2532   \setchemicaltextelement +RZ 1100  500
2533   \setchemicaltextelement CRZ 1038 1038
2534   %
2535   \setchemicaltextelement  ZN  350  350
2536   %
2537   \def\processchemical[##1##2##3##4]%
2538     {\processaction
2539        [##1##2##3##4]
2540        [    PB:##4=>\beginchemicalpicture{##4},
2541             PE????=>\endchemicalpicture,
2542             ROT##4=>\processchemicalrotation{##4},
2543             SUB##4=>\processchemicalsubstitute{##4},
2544             ADJ##4=>\processchemicaldistance{##4},
2545             MOV##4=>\processchemicaltranslate{##4},
2546             -RZ##4=>\processchemicaltextelement{-RZ}{##4}{#1}{4}
2547                       {b,l,t,r, l,t,r,b, t,r,b,l, r,b,l,t},
2548             +RZ##4=>\processchemicaltextelement{+RZ}{##4}{#1}{4}
2549                       {l,t,r,b, t,r,b,l, r,b,l,t, b,l,t,r},
2550             -SB##4=>\processchemicallinesegment{-SB}{##4},
2551             +SB##4=>\processchemicallinesegment{+SB}{##4},
2552             -SR##4=>\processchemicallinesegment{-SR}{##4},
2553             +SR##4=>\processchemicallinesegment{+SR}{##4},
2554             CRZ##4=>\processchemicaltextelement{CRZ}{##4}{#1}{0}{},
2555           ZN##3##4=>\processchemicaltextconstant{ZN}{##3##4}{\chemicaltextelementnumber}{0},
2556           ZT##3##4=>\processchemicaltextelement{ZN}{##3##4}{#1}{0}{},
2557           DB##3##4=>\processchemicallinesegment{DB}{##3##4},
2558           DR##3##4=>\processchemicallinesegment{DR}{##3##4},
2559           EB##3##4=>\processchemicallinesegment{EB}{##3##4},
2560           ER##3##4=>\processchemicallinesegment{ER}{##3##4},
2561           RZ##3##4=>\processchemicaltextelement{RZ}{##3##4}{#1}{4}
2562                       {lb,lt,rt,rb, lt,rt,rb,lb, rt,rb,lb,lt, rb,lb,lt,rt},
2563           SB##3##4=>\processchemicallinesegment{SB}{##3##4},
2564           SR##3##4=>\processchemicallinesegment{SR}{##3##4},
2565           -R##3##4=>\processchemicallinesegment{-R}{##3##4},
2566           +R##3##4=>\processchemicallinesegment{+R}{##3##4},
2567         B##2##3##4=>\processchemicallinesegment{B}{##2##3##4},
2568         R##2##3##4=>\processchemicallinesegment{R}{##2##3##4},
2569         Z##2##3##4=>\processchemicaltextelement{Z}{##2##3##4}{#1}{0}{},
2570         \s!unknown=>\unknownchemical{##1##2##3##4}]}}
2571
2572\def\executechemicalFIVE[#1]%
2573  {\setchemicalname FIVE
2574   %
2575   \setchemicalmaximum       5
2576   \setchemicaldistance    688
2577   \setchemicalsubstitute 1226
2578   %
2579   \setchemicalrotation 1  1      0      0     -1     -1      0      0      1
2580   \setchemicalrotation 2  0.309 -0.951 -0.951 -0.309 -0.309  0.940  0.951  0.309
2581   \setchemicalrotation 3 -0.809 -0.588 -0.588  0.809  0.809  0.588  0.588 -0.809
2582   \setchemicalrotation 4 -0.809  0.588  0.588  0.809  0.809 -0.588 -0.588 -0.809
2583   \setchemicalrotation 5  0.309  0.951  0.951 -0.309 -0.309 -0.951 -0.951  0.309
2584   %
2585   \setchemicalangle 1   0  90 180 270
2586   \setchemicalangle 2  72 162 252 342
2587   \setchemicalangle 3 144 234 324  54
2588   \setchemicalangle 4 216 306  36 126
2589   \setchemicalangle 5 288  18 108 198
2590   %
2591   \setchemicaltranslate 1 -1376     0
2592   \setchemicaltranslate 2  -425  1304
2593   \setchemicaltranslate 3  1113   809
2594   \setchemicaltranslate 4  1113  -809
2595   \setchemicaltranslate 5  -425 -1304
2596   %
2597   \setchemicallinesegment   A 1188  500 1188 -500
2598   \setchemicallinesegment   B  688  500  688 -500
2599   \setchemicallinesegment   S -263  808  688 -500
2600   \setchemicallinesegment  SS -116  606  541 -298
2601   \setchemicallinesegment -SS -263  808  541 -298
2602   \setchemicallinesegment +SS -116  606  688 -500
2603   \setchemicallinesegment  SB  688  240  688 -240
2604   \setchemicallinesegment -SB  688  240  688 -500
2605   \setchemicallinesegment +SB  688  500  688 -240
2606   \setchemicallinesegment DB1  638  240  638 -240
2607   \setchemicallinesegment DB2  738  240  738 -240
2608   \setchemicallinesegment  EB  548  340  548 -340
2609   \setchemicallinesegment   R  688  500 1093  794
2610   \setchemicallinesegment  -R  688  500  688 1000
2611   \setchemicallinesegment  +R  688  500 1163  345
2612   \setchemicallinesegment ER1  659  540 1064  834
2613   \setchemicallinesegment ER2  727  460 1122  754
2614   \setchemicallinesegment  SR  898  653 1093  794
2615   \setchemicallinesegment -SR  688  760  688 1000
2616   \setchemicallinesegment +SR  935  420 1163  345
2617   \setchemicallinesegment DR1  869  693 1064  834
2618   \setchemicallinesegment DR2  927  613 1122  754
2619   %
2620   \setchemicaltextelement   Z  688  500
2621   \setchemicaltextelement  RZ 1188  863
2622   \setchemicaltextelement -RZ  688 1100
2623   \setchemicaltextelement +RZ 1258  315
2624   \setchemicaltextelement CRZ 1323  947
2625   %
2626   \setchemicalcircsegment   C -36 36 590 72 475 -345
2627   \setchemicalcircsegment  CC -72  0 590 72 182 -561
2628   %
2629   \setchemicaltextelement  ZN  468  350
2630   \setchemicaltextelement  RN  860  625 % 1.25 Z
2631   \setchemicaltextelement  RTN 785  728 % .12 / 103 75
2632   \setchemicaltextelement  RBN 935  522
2633   %
2634   \def\processchemical[##1##2##3##4]%
2635     {\processaction
2636        [##1##2##3##4]
2637        [ FRONT????=>{\executechemicalFIVEFRONT[#1]},
2638             PB:##4=>\beginchemicalpicture{##4},
2639             PE????=>\endchemicalpicture,
2640             ROT##4=>\processchemicalrotation{##4},
2641             SUB##4=>\processchemicalsubstitute{##4},
2642             ADJ##4=>\processchemicaldistance{##4},
2643             MOV##4=>\processchemicaltranslate{##4},
2644             -RZ##4=>\processchemicaltextelement{-RZ}{##4}{#1}{5}
2645                       {b,l,t,r,r, l,t,r,r,l, t,r,r,l,l, r,b,l,t,r},
2646             +RZ##4=>\processchemicaltextelement{+RZ}{##4}{#1}{5}
2647                       {l,t,r,r,b, t,r,r,l,l, r,r,l,l,r, b,l,l,r,r},
2648             -SB##4=>\processchemicallinesegment{-SB}{##4},
2649             +SB##4=>\processchemicallinesegment{+SB}{##4},
2650             -SR##4=>\processchemicallinesegment{-SR}{##4},
2651             +SR##4=>\processchemicallinesegment{+SR}{##4},
2652             -RD##4=>\processchemicaldashedlinesegment{-R}{##4},
2653             +RD##4=>\processchemicaldashedlinesegment{+R}{##4},
2654             -RB##4=>\processchemicaldeltalinesegment{-R}{##4},
2655             +RB##4=>\processchemicaldeltalinesegment{+R}{##4},
2656             CRZ##4=>\processchemicaltextelement{CRZ}{##4}{#1}{0}{},
2657             RTN##4=>\processchemicaltextconstant{RTN}{##4}{\chemicaltextelementnumber}{0},
2658             RTT##4=>\processchemicaltextelement{RTN}{##4}{#1}{0}{},
2659             RBN##4=>\processchemicaltextconstant{RBN}{##4}{\chemicaltextelementnumber}{0},
2660             RBT##4=>\processchemicaltextelement{RBN}{##4}{#1}{0}{},
2661             -SS##4=>\processchemicallinesegment{-SS}{##4},
2662             +SS##4=>\processchemicallinesegment{+SS}{##4},
2663             CCD##4=>\processchemicaldottsegment{CC}{##4},
2664           SS##3##4=>\processchemicallinesegment{SS}{##3##4},
2665           RD##3##4=>\processchemicaldashedlinesegment{R}{##3##4},
2666           RB##3##4=>\processchemicaldeltalinesegment{R}{##3##4},
2667           ZN##3##4=>\processchemicaltextconstant{ZN}{##3##4}{\chemicaltextelementnumber}{0},
2668           ZT##3##4=>\processchemicaltextelement{ZN}{##3##4}{#1}{0}{},
2669           RN##3##4=>\processchemicaltextconstant{RN}{##3##4}{\chemicaltextelementnumber}{0},
2670           RT##3##4=>\processchemicaltextelement{RN}{##3##4}{#1}{0}{},
2671           AU##3##4=>\processchemicaluparrowsegment{A}{##3##4},
2672           AD##3##4=>\processchemicaldownarrowsegment{A}{##3##4},
2673           CC##3##4=>\processchemicalcircsegment{CC}{##3##4},
2674           CD##3##4=>\processchemicaldottsegment{C}{##3##4},
2675           DB##3##4=>\processchemicallinesegment{DB}{##3##4},
2676           DR##3##4=>\processchemicallinesegment{DR}{##3##4},
2677           EB##3##4=>\processchemicallinesegment{EB}{##3##4},
2678           ER##3##4=>\processchemicallinesegment{ER}{##3##4},
2679           RZ##3##4=>\processchemicaltextelement{RZ}{##3##4}{#1}{5}
2680                       {l,l,r,r,r, l,r,r,b,l, r,r,b,l,t, r,l,l,t,r},
2681           SB##3##4=>\processchemicallinesegment{SB}{##3##4},
2682           SR##3##4=>\processchemicallinesegment{SR}{##3##4},
2683           -R##3##4=>\processchemicallinesegment{-R}{##3##4},
2684           +R##3##4=>\processchemicallinesegment{+R}{##3##4},
2685         B##2##3##4=>\processchemicallinesegment{B}{##2##3##4},
2686         C##2##3##4=>\processchemicalcircsegment{C}{##2##3##4},
2687         R##2##3##4=>\processchemicallinesegment{R}{##2##3##4},
2688         S##2##3##4=>\processchemicallinesegment{S}{##2##3##4},
2689         Z##2##3##4=>\processchemicaltextelement{Z}{##2##3##4}{#1}{0}{},
2690         \s!unknown=>\unknownchemical{##1##2##3##4}]}}
2691
2692\def\executechemicalSIX[#1]%
2693  {\setchemicalname SIX
2694   %
2695   \setchemicalmaximum       6
2696   \setchemicalsubstitute 1375
2697   \setchemicaldistance    866
2698   %
2699   \setchemicalrotation 1  1    0   0 -1     -1    0    0      1
2700   \setchemicalrotation 2  0.5 -0.866 -0.866 -0.5 -0.5  0.866  0.866  0.5
2701   \setchemicalrotation 3 -0.5 -0.866 -0.866  0.5  0.5  0.866  0.866 -0.5
2702   \setchemicalrotation 4 -1    0      0      1    1    0      0     -1
2703   \setchemicalrotation 5 -0.5  0.866  0.866  0.5  0.5 -0.866 -0.866 -0.5
2704   \setchemicalrotation 6  0.5  0.866  0.866 -0.5 -0.5 -0.866 -0.866  0.5
2705   %
2706   \setchemicalangle 1   0  90 180 270
2707   \setchemicalangle 2  60 150 240 330
2708   \setchemicalangle 3 120 210 300  30
2709   \setchemicalangle 4 180 270   0  90
2710   \setchemicalangle 5 240 330  60 150
2711   \setchemicalangle 6 300  30 120 210
2712   %
2713   \setchemicaltranslate 1 -1732     0
2714   \setchemicaltranslate 2  -866  1500
2715   \setchemicaltranslate 3   866  1500
2716   \setchemicaltranslate 4  1732     0
2717   \setchemicaltranslate 5   866 -1500
2718   \setchemicaltranslate 6  -866 -1500
2719   %
2720   \setchemicallinesegment    A 1386   500 1386 -500
2721   \setchemicallinesegment    S    0  1000  866 -500
2722   \setchemicallinesegment   SS  125   783  741 -283
2723   \setchemicallinesegment  -SS    0  1000  741 -283
2724   \setchemicallinesegment  +SS  125   783  866 -500
2725   \setchemicallinesegment    B  866   500  866 -500
2726   \setchemicallinesegment   SB  866   240  866 -240
2727   \setchemicallinesegment  -SB  866   240  866 -500
2728   \setchemicallinesegment  +SB  866   500  866 -240
2729   \setchemicallinesegment  DB1  816   240  816 -240
2730   \setchemicallinesegment  DB2  916   240  916 -240
2731   \setchemicallinesegment   EB  726   340  726 -340
2732   \setchemicallinesegment    R  866   500 1299  750
2733   \setchemicallinesegment   -R  866   500  866 1000
2734   \setchemicallinesegment   +R  866   500 1299  250
2735   \setchemicallinesegment  ER1  841   543 1274  793
2736   \setchemicallinesegment  ER2  891   457 1324  707
2737   \setchemicallinesegment   SR 1091   630 1299  750
2738   \setchemicallinesegment  -SR  866   740  866 1000
2739   \setchemicallinesegment  +SR 1091   370 1299  250
2740   \setchemicallinesegment  DR1 1066   673 1274  793
2741   \setchemicallinesegment  DR2 1116   588 1324  707
2742   \setchemicallinesegment MID1    0  1000 -150  200
2743   \setchemicallinesegment MID2    0 -1000 -150 -200
2744   \setchemicallinesegment MIDS1   0  1000 -180    0
2745   \setchemicallinesegment MIDS2   0 -1000 -180    0
2746   %
2747   \setchemicalcircsegment   C -30 30 700 60 600 -346
2748   \setchemicalcircsegment  CC -60  0 700 60 350 -606
2749   %
2750   \setchemicaltextelement    Z  866  500
2751   \setchemicaltextelement   RZ 1386  800
2752   \setchemicaltextelement  -RZ  866 1100
2753   \setchemicaltextelement  +RZ 1386  200
2754   \setchemicaltextelement  CRZ 1524  880
2755   \setchemicaltextelement MIDZ -150    0
2756   %
2757   \setchemicaltextelement  ZN   589 350
2758   \setchemicaltextelement  RN  1083 625  % 1.25 Z
2759   \setchemicaltextelement  RTN 1008 755  % .12 / 130 75
2760   \setchemicaltextelement  RBN 1158 495
2761   %
2762   \def\processchemical[##1##2##3##4##5]%
2763     {\processaction
2764        [##1##2##3##4##5]
2765        [    FRONT????=>{\executechemicalSIXFRONT[#1]},
2766               MID????=>\processchemicallinesegment{MID}{1????},
2767              MIDS????=>\processchemicallinesegment{MIDS}{1????},
2768              MIDZ????=>\processchemicaltextelement{MIDZ}{1????}{#1}{0}{},
2769             PB:##4##5=>\beginchemicalpicture{##4##5},
2770                PE????=>\endchemicalpicture,
2771             ROT##4##5=>\processchemicalrotation{##4##5},
2772             SUB##4##5=>\processchemicalsubstitute{##4##5},
2773             ADJ##4##5=>\processchemicaldistance{##4##5},
2774             MOV##4##5=>\processchemicaltranslate{##4##5},
2775             -RZ##4##5=>\processchemicaltextelement{-RZ}{##4##5}{#1}{6}
2776                       {b,l,l,t,r,r, l,l,r,r,r,l, t,r,r,b,l,l, r,r,l,l,l,r},
2777             +RZ##4##5=>\processchemicaltextelement{+RZ}{##4##5}{#1}{6}
2778                       {l,t,r,r,b,l, r,r,r,l,l,l, r,b,l,l,t,r, l,l,l,r,r,r},
2779             -SB##4##5=>\processchemicallinesegment{-SB}{##4##5},
2780             +SB##4##5=>\processchemicallinesegment{+SB}{##4##5},
2781             -SR##4##5=>\processchemicallinesegment{-SR}{##4##5},
2782             +SR##4##5=>\processchemicallinesegment{+SR}{##4##5},
2783             -RD##4##5=>\processchemicaldashedlinesegment{-R}{##4##5},
2784             +RD##4##5=>\processchemicaldashedlinesegment{+R}{##4##5},
2785             -RB##4##5=>\processchemicaldeltalinesegment{-R}{##4##5},
2786             +RB##4##5=>\processchemicaldeltalinesegment{+R}{##4##5},
2787             CRZ##4##5=>\processchemicaltextelement{CRZ}{##4##5}{#1}{0}{},
2788             -SS##4##5=>\processchemicallinesegment{-SS}{##4##5},
2789             +SS##4##5=>\processchemicallinesegment{+SS}{##4##5},
2790             CCD##4##5=>\processchemicaldottsegment{CC}{##4##5},
2791RTN##4##5=>\processchemicaltextconstant{RTN}{##4##5}{\chemicaltextelementnumber}{0},
2792RTT##4##5=>\processchemicaltextelement{RTN}{##4##5}{#1}{0}{},
2793RBN##4##5=>\processchemicaltextconstant{RBN}{##4##5}{\chemicaltextelementnumber}{0},
2794RBT##4##5=>\processchemicaltextelement{RBN}{##4##5}{#1}{0}{},
2795           SS##3##4##5=>\processchemicallinesegment{SS}{##3##4##5},
2796           RD##3##4##5=>\processchemicaldashedlinesegment{R}{##3##4##5},
2797           RB##3##4##5=>\processchemicaldeltalinesegment{R}{##3##4##5},
2798           ZN##3##4##5=>\processchemicaltextconstant{ZN}{##3##4##5}{\chemicaltextelementnumber}{0},
2799           ZT##3##4##5=>\processchemicaltextelement{ZN}{##3##4##5}{#1}{0}{},
2800RN##3##4##5=>\processchemicaltextconstant{RN}{##3##4##5}{\chemicaltextelementnumber}{0},
2801RT##3##4##5=>\processchemicaltextelement{RN}{##3##4##5}{#1}{0}{},
2802           AU##3##4##5=>\processchemicaluparrowsegment{A}{##3##4##5},
2803           AD##3##4##5=>\processchemicaldownarrowsegment{A}{##3##4##5},
2804           CD##3##4##5=>\processchemicaldottsegment{C}{##3##4##5},
2805           CC##3##4##5=>\processchemicalcircsegment{CC}{##3##4##5},
2806           DB##3##4##5=>\processchemicallinesegment{DB}{##3##4##5},
2807           EB##3##4##5=>\processchemicallinesegment{EB}{##3##4##5},
2808           ER##3##4##5=>\processchemicallinesegment{ER}{##3##4##5},
2809           RZ##3##4##5=>\processchemicaltextelement{RZ}{##3##4##5}{#1}{6}
2810                       {l,l,t,r,r,b, l,r,r,r,l,l, r,r,b,l,l,t, r,l,l,l,r,r},
2811           SB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5},
2812           SR##3##4##5=>\processchemicallinesegment{SR}{##3##4##5},
2813           DR##3##4##5=>\processchemicallinesegment{DR}{##3##4##5},
2814           -R##3##4##5=>\processchemicallinesegment{-R}{##3##4##5},
2815           +R##3##4##5=>\processchemicallinesegment{+R}{##3##4##5},
2816         B##2##3##4##5=>\processchemicallinesegment{B}{##2##3##4##5},
2817         C##2##3##4##5=>\processchemicalcircsegment{C}{##2##3##4##5},
2818         R##2##3##4##5=>\processchemicallinesegment{R}{##2##3##4##5},
2819         S##2##3##4##5=>\processchemicallinesegment{S}{##2##3##4##5},
2820         Z##2##3##4##5=>\processchemicaltextelement{Z}{##2##3##4##5}{#1}{0}{},
2821            \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}
2822
2823\def\executechemicalSEVEN[#1]% incomplete !
2824  {\setchemicalname SEVEN
2825   %
2826   \setchemicalmaximum        7
2827   \setchemicalsubstitute     -
2828   \setchemicaldistance    1038
2829   %
2830   \setchemicalrotation 1  .623  .782 - - - - - -
2831   \setchemicalrotation 2 -.223  .975 - - - - - -
2832   \setchemicalrotation 3 -.901  .434 - - - - - -
2833   \setchemicalrotation 4 -.901 -.434 - - - - - -
2834   \setchemicalrotation 5 -.223 -.975 - - - - - -
2835   \setchemicalrotation 6  .623 -.782 - - - - - -
2836   \setchemicalrotation 7     1     0 - - - - - -
2837   %
2838   \setchemicalangle 1       0 - - -
2839   \setchemicalangle 2  51.429 - - -
2840   \setchemicalangle 3 102.857 - - -
2841   \setchemicalangle 4 154.286 - - -
2842   \setchemicalangle 5 205.714 - - -
2843   \setchemicalangle 6 257.143 - - -
2844   \setchemicalangle 7 308.571 - - -
2845   %
2846   \setchemicaltranslate 1 - -
2847   \setchemicaltranslate 2 - -
2848   \setchemicaltranslate 3 - -
2849   \setchemicaltranslate 4 - -
2850   \setchemicaltranslate 5 - -
2851   \setchemicaltranslate 6 - -
2852   \setchemicaltranslate 7 - -
2853   %
2854   \setchemicallinesegment   B 1038 500 1038 -500
2855   \setchemicallinesegment  SB 1038 240 1038 -240
2856   \setchemicallinesegment -SB 1038 240 1038 -500
2857   \setchemicallinesegment +SB 1038 500 1038 -240
2858   %
2859   \setchemicaltextelement Z 1038 500
2860   %
2861   \def\processchemical[##1##2##3##4##5]%
2862     {\processaction
2863        [##1##2##3##4##5]
2864        [    PB:##4##5=>\beginchemicalpicture{##4##5},
2865                PE????=>\endchemicalpicture,
2866            %ROT##4##5=>\processchemicalrotation{##4},
2867            %SUB##4##5=>\processchemicalsubstitute{##4##5},
2868            %ADJ##4##5=>\processchemicaldistance{##4##5},
2869            %MOV##4##5=>\processchemicaltranslate{##4##5},
2870             -SB##4##5=>\processchemicallinesegment{-SB}{##4##5},
2871             +SB##4##5=>\processchemicallinesegment{+SB}{##4##5},
2872           SB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5},
2873         B##2##3##4##5=>\processchemicallinesegment{B}{##2##3##4##5},
2874         Z##2##3##4##5=>\processchemicaltextelement{Z}{##2##3##4##5}{#1}{0}{},
2875            \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}
2876
2877\def\executechemicalEIGHT[#1]% incomplete !
2878  {\setchemicalname EIGHT
2879   %
2880   \setchemicalmaximum       8
2881   %\setchemicalsubstitute 1307
2882   \setchemicaldistance    1207
2883   %
2884   \setchemicalrotation 1  .707  .707 - - - - - -
2885   \setchemicalrotation 2     0     1 - - - - - -
2886   \setchemicalrotation 3 -.707  .707 - - - - - -
2887   \setchemicalrotation 4    -1     0 - - - - - -
2888   \setchemicalrotation 5 -.707 -.707 - - - - - -
2889   \setchemicalrotation 6    0     -1 - - - - - -
2890   \setchemicalrotation 7  .707 -.707 - - - - - -
2891   \setchemicalrotation 8     1     0 - - - - - -
2892   %
2893   \setchemicalangle 1  45 - - -
2894   \setchemicalangle 2  90 - - -
2895   \setchemicalangle 3 135 - - -
2896   \setchemicalangle 4 180 - - -
2897   \setchemicalangle 5 225 - - -
2898   \setchemicalangle 6 270 - - -
2899   \setchemicalangle 7 315 - - -
2900   \setchemicalangle 8   0 - - -
2901   %
2902   \setchemicaltranslate 1 -2414     0
2903   \setchemicaltranslate 2 -1706  1706
2904   \setchemicaltranslate 3     0  2414
2905   \setchemicaltranslate 4  1706  1706
2906   \setchemicaltranslate 5  2414     0
2907   \setchemicaltranslate 6  1706 -1706
2908   \setchemicaltranslate 7     0 -2414
2909   \setchemicaltranslate 8 -1706 -1706
2910   %
2911   \setchemicallinesegment    B 1207 500 1207 -500
2912   \setchemicallinesegment   SB 1207 240 1207 -240
2913   \setchemicallinesegment  -SB 1207 240 1207 -500
2914   \setchemicallinesegment  +SB 1207 500 1207 -240
2915   %
2916   \setchemicaltextelement    Z 1207 500
2917   %
2918   \def\processchemical[##1##2##3##4##5]%
2919     {\processaction
2920        [##1##2##3##4##5]
2921        [    PB:##4##5=>\beginchemicalpicture{##4##5},
2922                PE????=>\endchemicalpicture,
2923            %SUB##4##5=>\processchemicalsubstitute{##4##5},
2924             ADJ##4##5=>\processchemicaldistance{##4##5},
2925             MOV##4##5=>\processchemicaltranslate{##4##5},
2926             -SB##4##5=>\processchemicallinesegment{-SB}{##4##5},
2927             +SB##4##5=>\processchemicallinesegment{+SB}{##4##5},
2928           SB##3##4##5=>\processchemicallinesegment{SB}{##3##4##5},
2929         B##2##3##4##5=>\processchemicallinesegment{B}{##2##3##4##5},
2930         Z##2##3##4##5=>\processchemicaltextelement{Z}{##2##3##4##5}{#1}{0}{},
2931            \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}
2932
2933\def\executechemicalFIVEFRONT[#1]%
2934  {\executechemicalFIVE[]%
2935   %
2936   \setchemicalname FIVEFRONT
2937   %
2938   \setchemicallinesegment  -R 688 500 688 100
2939   \setchemicallinesegment  +R 688 500 688 900
2940   %
2941   \setchemicaltextelement -RZ   0 -1300
2942   \setchemicaltextelement +RZ   0  1300
2943   %
2944   \def\processchemical[##1##2##3##4]%
2945     {\def\chemicalrotation{2}%
2946      \processaction
2947        [##1##2##3##4]
2948        [    -RZ##4=>\processchemicalunrotatedtextelement{Z}{-RZ}{##4}{#1}{5}
2949                       {,,,,, t,t,t,t,t},
2950             +RZ##4=>\processchemicalunrotatedtextelement{Z}{+RZ}{##4}{#1}{5}
2951                       {,,,,, b,b,b,b,b},
2952             -SB##4=>\processchemicallinesegment{-SB}{##4},
2953             +SB##4=>\processchemicallinesegment{+SB}{##4},
2954           SB##3##4=>\processchemicallinesegment{SB}{##3##4},
2955           -R##3##4=>\processchemicalunrotatedlinesegment{t}{-R}{##3##4},
2956           +R##3##4=>\processchemicalunrotatedlinesegment{b}{+R}{##3##4},
2957           BB##3##4=>\processchemicalzlinesegment{B}{##3##4},
2958         R##2##3##4=>\processchemicalunrotatedlinesegment{t}{-R}{##2##3##4}%
2959                     \processchemicalunrotatedlinesegment{b}{+R}{##2##3##4},
2960         B##2##3##4=>\processchemicallinesegment{B}{##2##3##4},
2961         Z##2##3##4=>\processchemicaltextelement{Z}{##2##3##4}{#1}{0}{},
2962         \s!unknown=>\unknownchemical{##1##2##3##4}]}}
2963
2964\def\executechemicalSIXFRONT[#1]%
2965  {\executechemicalSIX[]%
2966   %
2967   \setchemicalname SIXFRONT
2968   %
2969   \setchemicallinesegment -R 866 500 866 100
2970   \setchemicallinesegment +R 866 500 866 900
2971   %
2972   \setchemicaltextelement -RZ 0 -1300
2973   \setchemicaltextelement +RZ 0  1300
2974   %
2975   \def\processchemical[##1##2##3##4]%
2976     {\def\chemicalrotation{2}%
2977      \processaction
2978        [##1##2##3##4]
2979        [    -RZ##4=>\processchemicalunrotatedtextelement{Z}{-RZ}{##4}{#1}{6}
2980                       {,,,,,, t,t,t,t,t,t},
2981             +RZ##4=>\processchemicalunrotatedtextelement{Z}{+RZ}{##4}{#1}{6}
2982                       {,,,,,, b,b,b,b,b,b},
2983             -SB##4=>\processchemicallinesegment{-SB}{##4},
2984             +SB##4=>\processchemicallinesegment{+SB}{##4},
2985           SB##3##4=>\processchemicallinesegment{SB}{##3##4},
2986           -R##3##4=>\processchemicalunrotatedlinesegment{t}{-R}{##3##4},
2987           +R##3##4=>\processchemicalunrotatedlinesegment{b}{+R}{##3##4},
2988           BB##3##4=>\processchemicalzlinesegment{B}{##3##4},
2989         R##2##3##4=>\processchemicalunrotatedlinesegment{t}{-R}{##2##3##4}%
2990                     \processchemicalunrotatedlinesegment{b}{+R}{##2##3##4},
2991         B##2##3##4=>\processchemicallinesegment{B}{##2##3##4},
2992         Z##2##3##4=>\processchemicaltextelement{Z}{##2##3##4}{#1}{0}{},
2993        \s!unknown=>\unknownchemical{##1##2##3##4}]}}
2994
2995% 1  :    0
2996% 2  : -115
2997% 3* : -195
2998% 3  : -165
2999% 4  : -245
3000
3001\def\executechemicalCARBON[#1]%
3002  {\setchemicalname CARBON
3003   %
3004   \setchemicalmaximum    4
3005   \setchemicaldistance   0
3006   \setchemicalsubstitute 0
3007   %
3008   \setchemicalrotation 1   1      0      0     -1     -1      0      0      1
3009   \setchemicalrotation 2  -0.423 -0.906 -0.906  0.423  0.423  0.906  0.906 -0.423
3010   \setchemicalrotation 3  -0.966 -0.259 -0.259  0.966  0.966  0.259  0.259 -0.966
3011   \setchemicalrotation 3* -0.966  0.259  0.259  0.966  0.966 -0.259 -0.259 -0.966
3012   \setchemicalrotation 4  -0.423  0.906  0.906  0.423  0.423 -0.906 -0.906 -0.423
3013   %
3014   \setchemicalangle 1     0  90 180 270
3015   \setchemicalangle 2   115 205 295  25
3016   \setchemicalangle 3   165 255 345  75
3017   \setchemicalangle 3*  195 285  15 105
3018   \setchemicalangle 4   245 335  65 155
3019   %
3020   \setchemicaltranslate 1 -1500     0
3021   \setchemicaltranslate 2     0  1500
3022   \setchemicaltranslate 3  1500     0
3023   \setchemicaltranslate 4     0 -1500
3024   %
3025   \setchemicallinesegment B1   500 0  1000 0
3026   \setchemicallinesegment B2   300 0  1000 0
3027   \setchemicallinesegment B3   500 0  1000 0
3028   \setchemicallinesegment B4   300 0  1000 0
3029   %
3030   \setchemicaltextelement  Z  1100 0
3031   %
3032   \setchemicalcircsegment  C  0 360 500 360 0  -500
3033   %
3034   \def\processchemical[##1##2##3##4##5]%
3035     {\processaction
3036        [##1##2##3##4##5]
3037        [      MIR????=>\setchemicalmirror{3},
3038              -MIR????=>\resetchemicalmirror{3},
3039              *MIR????=>\togglechemicalmirror{3},
3040                CB????=>\processlocalchemicals{B,C,Z},
3041                 C????=>\processchemicalcircsegment{C}{1????},
3042               -ROT##5=>\reversechemical{ROT}{##5}{3,4,1,2},
3043             ROT##4##5=>\processchemicalrotation{##4##5},
3044             MOV##4##5=>\processchemicaltranslate{##4##5},
3045           CB##3##4##5=>\processlocalchemicals
3046                          {ROT##3,C,B,Z2..4,
3047                           MOV##3,*MIR,-ROT##3,C,B,Z2..4},
3048         B##2##3##4##5=>\processprivatechemicallinesegment{B}{##2##3##4##5},
3049         Z##2##3##4##5=>\processchemicaltextelement{Z}{##2##3##4##5}{#1}{4}
3050                          {l,t,r,b, t,r,b,l, r,b,l,t, b,l,t,r},
3051            \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}
3052
3053% 1:   45      2:  -90      3: -225
3054% 4:  -45      5: -135      6: -270
3055
3056\newif\ifNEWMANstagger  \NEWMANstaggertrue
3057
3058\def\executechemicalNEWMANSTAGGER%
3059  {\NEWMANstaggertrue\executechemicalNEWMAN}
3060
3061\def\executechemicalNEWMANECLIPSE%
3062  {\NEWMANstaggerfalse\executechemicalNEWMAN}
3063
3064\def\executechemicalNEWMAN[#1]%
3065  {\setchemicalname NEWMAN
3066   %
3067   \setchemicalmaximum    6
3068   \setchemicaldistance   0
3069   \setchemicalsubstitute 0
3070   %
3071   \ifNEWMANstagger
3072     \setchemicalrotation 1  0.707  0.707  0.707 -0.707 -0.707 -0.707 -0.707  0.707
3073     \setchemicalrotation 2  0     -1     -1      0      0      1      1      0
3074     \setchemicalrotation 3 -0.707  0.707  0.707  0.707  0.707 -0.707 -0.707 -0.707
3075   \else
3076     \setchemicalrotation 1  .866 -.5   -.5   -.866 -.866  .5    .5    .866
3077     \setchemicalrotation 2 -.259  .966  .966  .259  .259 -.966 -.966 -.259
3078     \setchemicalrotation 3 -.5   -.866 -.866  .5    .5    .866  .866 -.5
3079   \fi
3080   \setchemicalrotation 4  0.707 -0.707 -0.707 -0.707 -0.707  0.707  0.707  0.707
3081   \setchemicalrotation 5 -0.707 -0.707 -0.707  0.707  0.707  0.707  0.707 -0.707
3082   \setchemicalrotation 6  0      1      1      0      0     -1     -1      0
3083   %
3084   \ifNEWMANstagger
3085     \setchemicalangle 1 315  45 135 225
3086     \setchemicalangle 2  90 180 270   0
3087     \setchemicalangle 3 225 315  45 135
3088   \else
3089     \setchemicalangle 1  30 120 210 300
3090     \setchemicalangle 2 255 345  75 165
3091     \setchemicalangle 3 120 210 300  30
3092   \fi
3093   \setchemicalangle 4  45 135 225 315
3094   \setchemicalangle 5 135 225 315  45
3095   \setchemicalangle 6 270   0  90 180
3096   %
3097   \setchemicaltranslate 1 -1500     0
3098   \setchemicaltranslate 2     0  1500
3099   \setchemicaltranslate 3  1500     0
3100   \setchemicaltranslate 4     0 -1500
3101   %
3102   \setchemicallinesegment B1    0 0  1000 0
3103   \setchemicallinesegment B2    0 0  1000 0
3104   \setchemicallinesegment B3    0 0  1000 0
3105   \setchemicallinesegment B4  500 0  1000 0
3106   \setchemicallinesegment B5  500 0  1000 0
3107   \setchemicallinesegment B6  500 0  1000 0
3108   %
3109   \setchemicaltextelement  Z 1100 0
3110   %
3111   \setchemicalcircsegment  C 0 360 500 360 0 -500
3112   %
3113   \def\processchemical[##1##2##3##4]%
3114     {\processaction
3115        [##1##2##3##4]
3116        [STAGGER????=>{\executechemicalNEWMANSTAGGER[#1]},
3117         ECLIPSE????=>{\executechemicalNEWMANECLIPSE[#1]},
3118               B????=>\processlocalchemicals{B1..6},
3119              CB????=>\processlocalchemicals{B1..6,C,Z1..6},
3120               C????=>\processchemicalcircsegment{C}{1????},
3121              ROT##4=>\processchemicalrotation{##4},
3122              MOV##4=>\processchemicaltranslate{##4},
3123          B##2##3##4=>\processprivatechemicallinesegment{B}{##2##3##4},
3124          Z##2##3##4=>\ifNEWMANstagger
3125                        \processchemicaltextelement{Z}{##2##3##4}{#1}{6}
3126                          {l,t,r,l,r,b, l,r,l,r,r,l, r,b,l,r,l,t, r,l,r,l,l,r}%
3127                      \else
3128                        \processchemicaltextelement{Z}{##2##3##4}{#1}{6}
3129                          {l,r,t,t,r,b, t,b,r,r,b,l, r,l,b,b,l,t, b,t,l,l,t,r}%
3130                      \fi,
3131          \s!unknown=>\unknownchemical{##1##2##3##4}]}}
3132
3133\def\executechemicalCHAIR[#1]% smaller
3134  {\setchemicalname CHAIR
3135   %
3136   \setchemicalmaximum 6
3137   %
3138   \setchemicallinesegment  B1  1600  800  2800 -800
3139   \setchemicallinesegment  B2  2800 -800   800    0
3140   \setchemicallinesegment  B3   800    0 -1600 -800
3141   \setchemicallinesegment  B4 -1600 -800 -2800  800
3142   \setchemicallinesegment  B5 -2800  800  -800    0
3143   \setchemicallinesegment  B6  -800    0  1600  800
3144   %
3145   \setchemicallinesegment +R1  1600  800  1600  1600
3146   \setchemicallinesegment +R2  2800 -800  2800 -1600
3147   \setchemicallinesegment +R3   800    0   800   800
3148   \setchemicallinesegment +R4 -1600 -800 -1600 -1600
3149   \setchemicallinesegment +R5 -2800  800 -2800  1600
3150   \setchemicallinesegment +R6  -800    0  -800  -800
3151   %
3152   \setchemicallinesegment -R1  1600  800  2350  522 % 750 278
3153   \setchemicallinesegment -R2  2800 -800  3493 -400
3154   \setchemicallinesegment -R3   800    0  1329 -600 % 528 600
3155   \setchemicallinesegment -R4 -1600 -800 -2350 -522 % 750 278
3156   \setchemicallinesegment -R5 -2800  800 -3493  400
3157   \setchemicallinesegment -R6  -800    0 -1329  600 % 528 600
3158   %
3159   \setchemicaltextelement +RZ1  1600  1800
3160   \setchemicaltextelement +RZ2  2800 -1800
3161   \setchemicaltextelement +RZ3   800  1000
3162   \setchemicaltextelement +RZ4 -1600 -1800
3163   \setchemicaltextelement +RZ5 -2800  1800
3164   \setchemicaltextelement +RZ6  -800 -1000
3165   %
3166   \setchemicaltextelement -RZ1  2538  453 % 200 lang
3167   \setchemicaltextelement -RZ2  3666 -300
3168   \setchemicaltextelement -RZ3  1460 -750
3169   \setchemicaltextelement -RZ4 -2538 -453
3170   \setchemicaltextelement -RZ5 -3666  300
3171   \setchemicaltextelement -RZ6 -1460  750
3172   %
3173   \def\processchemical[##1##2##3##4##5]%
3174     {\def\chemicalrotation{1}%
3175      \processaction
3176        [##1##2##3##4##5]
3177        [      B????=>\processlocalchemicals{B1,B2,B3,B4,B5,B6},
3178              -R????=>\processlocalchemicals{-R1,-R2,-R3,-R4,-R5,-R6},
3179              +R????=>\processlocalchemicals{+R1,+R2,+R3,+R4,+R5,+R6},
3180            B##2????=>{\getchemicallinesegment[0][B##2]},
3181          -RZ##4????=>{\getchemicalfixedtextelement[-RZ##4][1][##4][l,l,tc,r,r,bc][#1]},
3182          +RZ##4????=>{\getchemicalfixedtextelement[+RZ##4][1][##4][c][#1]},
3183           -R##3????=>{\getchemicallinesegment[0][-R##3]},
3184           +R##3????=>{\getchemicallinesegment[0][+R##3]},
3185          \s!unknown=>\unknownchemical{##1##2##3##4##5}]}}
3186
3187\def\executechemicalarrow#1#2[#3]%
3188  {\dogetcommalistelement1\from#3\to\toptext
3189   \dogetcommalistelement2\from#3\to\bottext
3190   \def\dochemicaltext##1%
3191     {\dosetsubscripts%
3192      $\@@dochemicalstyle{\@@localchemicalformat\strut##1}$%
3193      \doresetsubscripts}%
3194   \doifelse\@@chemicallocation\v!intext
3195     {#1{\dochemicaltext\toptext}}%
3196     {\setbox\chemicalsymbols=\hbox
3197        {\box\chemicalsymbols
3198         \vbox{\halign{##\cr
3199           \hbox to 3em{\hss\dochemicaltext{\toptext}\hss}\cr
3200           #2%
3201           \hbox to 3em{\hss\dochemicaltext{\bottext}\hss}\cr}}}}}
3202
3203\def\executechemicalGIVES
3204  {\executechemicalarrow
3205     {\chemicalsinglepicturearrow}% nodig
3206     {\rightarrowfill\cr}}
3207
3208\def\executechemicalEQUILIBRIUM
3209  {\executechemicalarrow
3210     {\chemicaldoublepicturearrow}%  nodig
3211     {\rightarrowfill\cr\leftarrowfill\cr}}
3212
3213\def\executechemicalMESOMERIC
3214  {\executechemicalarrow
3215     {\chemicalsinglepicturearrow}%  nodig
3216     {$\leftarrow\hskip-1em$\rightarrowfill\cr}}
3217
3218\def\executechemicalsign#1[#2]%
3219  {\doifelse\@@chemicallocation\v!intext
3220     {\dosetsubscripts
3221      $\@@dochemicalstyle{\@@localchemicalformat#1}$%
3222      \doresetsubscripts}
3223     {\setbox\chemicalsymbols\hbox
3224        {\box\chemicalsymbols
3225         \dosetsubscripts
3226         $\@@dochemicalstyle{\@@localchemicalformat#1}$%
3227         \doresetsubscripts}}}
3228
3229\def\executechemicalPLUS
3230  {\executechemicalsign{+}}
3231
3232\def\executechemicalMINUS
3233  {\executechemicalsign{-}}
3234
3235\def\executechemicalEQUAL
3236  {\executechemicalsign{=}}
3237
3238\def\executechemicalSPACE[#1]%
3239  {\doifnot\@@chemicallocation\v!intext
3240     {\setbox\chemicalsymbols\hbox
3241        {\box\chemicalsymbols
3242         \quad}}}
3243
3244\def\executechemicalCHEM[#1]%
3245  {\doifnot\@@chemicallocation\v!intext
3246     {\setbox\chemicalsymbols\hbox
3247        {\box\chemicalsymbols
3248         $\@@dochemicalstyle{\@@localchemicalformat#1}$}}}
3249
3250\def\executechemicalTEXT[#1]%
3251  {\doifnot\@@chemicallocation\v!intext
3252     {\setbox\chemicalsymbols\hbox
3253        {\box\chemicalsymbols#1}}}
3254
3255%\def\executechemicalLOW[#1]%
3256%  {\setlowsubscripts}
3257%
3258%\def\executechemicalHIGH[#1]%
3259%  {\sethighsubscripts}
3260
3261\def\putchemicalrule#1#2#3#4%
3262  {\ifcase\chemicaldrawingmode
3263     \putrule from {#1} {#2} to {#3} {#4}
3264   \or
3265     \psline(#1,#2)(#3,#4)%
3266   \or
3267     \bgroup
3268     \!!counta=#1\!!countb=#2\!!countc=#3\!!countd=#4\relax
3269     \global\MPdrawingdonetrue
3270     \setchemicalattributes
3271     \startMPdrawing
3272       x1 := \MPdivten[\the\!!counta]u ;
3273       y1 := \MPdivten[\the\!!countb]u ;
3274       x2 := \MPdivten[\the\!!countc]u ;
3275       y2 := \MPdivten[\the\!!countd]u ;
3276       draw z1--z2 ;
3277     \stopMPdrawing
3278     \egroup
3279   \fi}
3280
3281\def\executechemicalcomplex#1%
3282  {\bgroup
3283   \putchemicalrule {0} {-\@@chemicalbottom}     {0}  {\@@chemicaltop}%
3284   \putchemicalrule {0}  {\@@chemicaltop}    {#1150}  {\@@chemicaltop}%
3285   \putchemicalrule {0} {-\@@chemicalbottom} {#1150} {-\@@chemicalbottom}%
3286   \egroup}
3287
3288\def\executechemicalOPENCOMPLEX[#1]%
3289  {\executechemicalcomplex+\ignorespaces
3290   \executechemicalSPACE[]}
3291
3292\def\executechemicalCLOSECOMPLEX[#1]%
3293  {\executechemicalSPACE[]%
3294   \executechemicalcomplex-\ignorespaces}
3295
3296% nog niet door midden as!
3297
3298\def\executechemicalverticalsymbol#1#2%
3299  {\executechemicalTEXT
3300     [$\left#1\relax
3301       \dimen0=\@@chemicalunit
3302       \scratchcounter=\@@chemicaltop
3303       \advance\scratchcounter by \@@chemicalbottom
3304       \dimen0=\scratchcounter\dimen0
3305       \vcenter to \dimen0{}
3306       \dimen2=\@@chemicalunit
3307       \dimen2=\@@chemicalright\dimen0
3308       \vcenter{\leftskip1em\hsize\dimen2\relax\strut#2\strut}%
3309       \right.$]}%
3310
3311\def\executechemicalUPARROW[#1]%
3312  {\executechemicalverticalsymbol\uparrow{#1}}
3313
3314\def\executechemicalDOWNARROW[#1]%
3315  {\executechemicalverticalsymbol\downarrow{#1}}
3316
3317\def\executechemicalUPDOWNARROW[#1]%
3318  {\executechemicalverticalsymbol\updownarrow{#1}}
3319
3320\let\setchemicalattributes\relax
3321
3322\setupchemical
3323  [\c!width=0,
3324   \c!height=0,
3325   \c!left=0,
3326   \c!right=0,
3327   \c!top=0,
3328   \c!bottom=0,
3329   \c!bodyfont=\the\bodyfontsize,
3330   \c!resolution=\outputresolution,
3331   \c!scale=\v!medium,
3332   \c!size=\v!medium,
3333   \c!textsize=\v!big,
3334   \c!frame=\v!off,
3335   \c!axis=\v!off,
3336   \c!state=\v!start,
3337   \c!style=\rm,
3338   \c!location=,
3339   \c!option=,
3340   \c!offset=LOW,
3341   \c!alternative=1,
3342   \c!color=,
3343   \c!rulethickness=,
3344   \c!rulecolor=,
3345   \c!factor=1]
3346
3347% Tijdelijk plaatsen we deze extra macro's hier.
3348%
3349% mathontop: \mtop {} {}
3350% textontop: \ttop {} {}
3351
3352\def\putontop#1#2%
3353  {\vbox
3354     {\halign
3355        {\strut\hss##\hss\cr
3356         #1\cr
3357         #2\cr}}}
3358
3359\def\ttop#1#2%
3360  {\putontop{\tx#1}{#2}}
3361
3362\def\mtop#1#2%
3363  {\vbox
3364     {\offinterlineskip
3365      \halign
3366        {\hss##\hss\cr
3367         $\scriptscriptstyle#1$\cr
3368         \noalign{\vskip.5ex}%
3369         $#2$\cr}}}
3370
3371\def\ctop#1#2%
3372  {\vbox
3373     {\offinterlineskip
3374      \halign
3375        {\hss##\hss\cr
3376         $\@@dochemicalstyle{\@@localchemicalformat\scriptscriptstyle#1}$\cr
3377         \noalign{\vskip.5ex}%
3378         $\@@dochemicalstyle{\@@localchemicalformat#2}$\cr}}}
3379
3380%D Here are a couple of goodies:
3381%D
3382%D \startitemize
3383%D \item styles hooked into \CONTEXT\ style mechanism
3384%D \item support for color and rulethickness (mp mode only)
3385%D \item position tracking
3386%D \stopitemize
3387
3388\let\@@chemicalrulecolor\empty
3389\let\@@chemicalcolor    \empty
3390
3391\def\setchemicalattributes
3392  {\scratchdimen\@@chemicalrulethickness
3393   \def\chemicalattributes
3394     {withpen pencircle scaled \the\scratchdimen\space
3395      withcolor }%
3396   \doifelsenothing\@@chemicalrulecolor
3397     {\edef\chemicalattributes{\chemicalattributes black}}
3398     {\edef\chemicalattributes{\chemicalattributes \MPcolor{\@@chemicalrulecolor}}}%
3399   \startMPdrawing
3400     drawoptions (\chemicalattributes) ;
3401   \stopMPdrawing}
3402
3403\unexpanded\def\@@dochemicalcolor
3404  {\dousecolorparameter\@@chemicalcolor}
3405
3406\unexpanded\def\@@dochemicalstyle
3407  {\dousestyleparameter\@@chemicalstyle}
3408
3409\setupchemical
3410  [\c!rulethickness=\linewidth,
3411   \c!rulecolor=,
3412   \c!color=]
3413
3414\def\cpos#1#2%
3415  {\iftrialtypesetting
3416     #2%
3417   \else
3418     \bgroup
3419     \globalpushmacro\dowithchemical
3420     \gdef\dowithchemical##1{\hpos{#1}{##1}\globalpopmacro\dowithchemical}%
3421     #2%
3422     \egroup
3423  \fi}
3424
3425\protect \endinput
3426
3427% \startchemical[axis=on,frame=yes]
3428%     \chemical[SIX,ROT2,B,R36,RZ6][CH_3]
3429%  	\chemical[PB:RZ3,ONE,Z05,SB5,EP37,PE][O,H]
3430% \stopchemical
3431
3432% \startchemical[size=big,scale=small,axis=on,frame=yes,factor=1.5]
3433%     \chemical[SIX,ROT2,B,R36,RZ6][CH_3]
3434%  	\chemical[PB:RZ3,ONE,Z05,SB5,EP37,PE][O,H]
3435% \stopchemical
3436
3437% \startchemical[size=big,scale=medium,axis=on,frame=yes,factor=1.5]
3438%     \chemical[SIX,ROT2,B,R36,RZ6][CH_3]
3439%  	\chemical[PB:RZ3,ONE,Z05,SB5,EP37,PE][O,H]
3440% \stopchemical
3441
3442% \startc