summaryrefslogtreecommitdiff
path: root/support/ochem/ochem.sty
blob: 5fbb09445730d8ae9fb3c91a9843cb250c066af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
%
% OCHEM.STY  - Stilfile zum Erzeugen von chemischen Formeln in LaTeX
% (c) 1993-1996,1999-2000 by Ingo Kloeckl
%
% 11.09.1993  error handling improved
% 09.12.1993  neue befehle fuer orbitallappen und geb. bindungen
% 04.10.1994  griechische symbole in texten
% 14.02.1996  environment ochem ersetzt durch \ochem-Befehl
% 15.02.1996  supermini eingefuehrt, die gfbox in htshow... geloescht
% 20.09.1996  zentrierungsmoeglichkeit durch ochem als \hbox, wertet nun
%               bounding box info aus.
% 21.09.1996  Trennung zwischen fixen und gleitfaehigen Objekten, verursachen
%               nun keine Verwirrungen mehr.
% 20.10.1996  Korrekte Bestimmung der BBox (/erg), npr ok
% 21.10.1996  Verbesserung BBox der Glasgeraete
% -------------------
% 22.03.1999  Version 3 beta release: schema compiler in Perl 
% 11.04.1999  Version 3 consolidation
% 02.05.1999  fshow (PS command) removed due to interference with MetaPost
% 09.01.2000  new bond shapes >> and >. and b
% 19.01.2000  new bond shape ~
% 19.04.2000  undesired spaces inhibited (thanks to B. Seckinge)
% 10.04.2001  option 'separate' added to easily produce EPS figures
%

\newcommand{\chemversion}{OCHEM Version 3-0e 2001-04-10 }
\typeout{package \chemversion}
\typeout{(c) 1993-1996, 1999 -- 2001 Ingo Kloeckl}

\RequirePackage[dvips]{color}
\RequirePackage{verbatim}
\RequirePackage{ifthen}

\newboolean{separate}\setboolean{separate}{false}
\DeclareOption{separate}{%
  \setboolean{separate}{true}
  \newwrite\verb@chemnames
  \immediate\openout\verb@chemnames \jobname.names
}
\ProcessOptions\relax

% user command for chem font setting
\newcommand{\chemfont}[1]
 {\renewcommand{\chemfontname}{#1}}
% default font is sans serif
\newcommand{\chemfontname}{\sffamily}

%
% Erzeugt gleitfaehiges Reaktionsschema mit ldf. Nummer und Labelmoeglichkeit
% \begin{schema[*]}
%   \ochem, \caption, \label...
% \end{schema[*]}
%
\@ifundefined{chapter}
  {\newcounter{schema}
   \renewcommand{\theschema}{\arabic{schema}}}
  {\newcounter{schema}[chapter]
   \renewcommand{\theschema}{\thechapter--\arabic{schema}}}
\newcommand{\fps@schema}{htbp}
\newcommand{\ftype@schema}{5}
\newcommand{\ext@schema}{lor}
\newcommand{\fnum@schema}{\schemaname~\theschema}
\newcommand{\schemaname}{Schema}
\newcommand{\lorname}{Die Reaktionsschemata}
\newcommand{\l@schema}{\@dottedtocline{1}{1.5em}{2.3em}}

\newcommand{\tableofschemes}
 {\@restonecolfalse
  \if@twocolumn\@restonecoltrue\onecolumn\fi
  \chapter*{\lorname\@mkboth{\lorname}{\lorname}}
  {\parindent\z@\@starttoc{lor}}
  \if@restonecol\twocolumn\fi
 }

\newenvironment{schema}
 {\@float{schema}}
 {\end@float}
\newenvironment{schema*}
 {\@dblfloat{schema}}
 {\end@dblfloat}

%
%  open .chm output file for chemistry environments and install
%  font for chemical text
%
\newwrite\verb@chem
\immediate\openout\verb@chem \jobname.chm

\AtBeginDocument
 {{\chemfontname\immediate\write\verb@chem{font(\string"
  \string\usefont\string{\f@encoding\string}\string{\f@family\string}
		 \string{\f@series\string}\string{\f@shape\string}
  \string\fontsize\string{\f@size\string}\string{\f@baselineskip\string}\string\selectfont
  \string")}}
  \ifthenelse{\boolean{separate}}{\pagestyle{empty}}{}
 }

\AtEndDocument
 {\immediate\closeout\verb@chem
  \ifthenelse{\boolean{separate}}{\immediate\closeout\verb@chemnames}{}
 }

%
%  chemistry environment for placing scheme descriptions in
%  use #1 as name of TeX fragment (-> #1.ctx)
%
\newcounter{chemcnt}

\newenvironment{chemistry}[1][\arabic{chemcnt}]
 {\ifthenelse{\boolean{separate}}{\newpage}{}%
  \ifthenelse{\boolean{separate}}{\immediate\write\verb@chemnames{#1}}{}%
  \InputIfFileExists{#1.ctx}{}{\typeout{ochem: cannot find #1.ctx}}%
  \immediate\write\verb@chem{schema(\string"#1.ctx\string")}%
  \@bsphack
  \let\do\@makeother\dospecials
  \catcode`\^^M\active \catcode`\^^I=12
  \def\verbatim@processline{%
    \immediate\write\verb@chem{\the\verbatim@line}}%
  \verbatim@start}
 {\@esphack
  \immediate\write\verb@chem{endschema}%
  \stepcounter{chemcnt}}

\newenvironment{chemspecial}
 {\@bsphack
  \let\do\@makeother\dospecials
  \catcode`\^^M\active \catcode`\^^I=12
  \def\verbatim@processline{%
    \immediate\write\verb@chem{\the\verbatim@line}}%
  \verbatim@start}
 {\@esphack
 }


%
% ------------------------------------------
%    auxiliary functions and macros
% ------------------------------------------
%
\special{!
  /\par {} def
  /posx 10 dict def
  posx begin
    /c -.5 def   /bl 0 def   /b -.5 def   /br  -1 def
    /r -1  def   /tr -1 def  /t -.5 def   /tl  0 def   /l 0  def
  end 
  /posy 10 dict def
  posy begin
    /c  -.5 def  /bl 0 def   /b  0 def    /br  0  def
    /r  -.5 def  /tr  -1 def /t  -1 def   /tl -1 def   /l -.5 def
  end 
  % x y pos text ftshow -
  /ftshow { /t exch def cvn /p exch def gs translate 
	   t stringwidth exch posx p get mul exch posy p get mul moveto 
	   t show gr} def
  %
  %  abbreviations
  %
  /tr { translate } def
  /sc { scale }def
  /ro { rotate } def
  /l { lineto } def
  /s { stroke } def
  /m { moveto } def
  /np { newpath } def
  /gs { gsave } def
  /gr { grestore } def
  %
  %  different bond types
  %  phi x y len s0..s12
  %
  /sb__ { currentlinewidth .7 mul setlinewidth } def
  /b0 {  /bl exch def gsave translate rotate 
	 newpath 0 0 moveto bl 0 lineto stroke 
	 grestore } def
  /b1 {  /bl exch def gsave translate rotate 
	 gsave 1 setgray
	   newpath lw lw 1.5 mul moveto bl lw 2 mul sub 0 rlineto stroke
	   newpath lw lw -1.5 mul moveto bl lw 2 mul sub 0 rlineto stroke 
	 grestore
	 currentlinewidth 2 mul setlinewidth 
	 newpath 0 0 moveto bl 0 lineto stroke 
	 grestore } def
  /b2 {  /bl exch def gsave translate rotate 
	 newpath 0 lw -.5 mul moveto bl bw -.5 mul lineto 0 bw rlineto 
	 0 lw .5 mul lineto closepath fill 
	 grestore } def
  /b3 {  /bl exch def gsave translate rotate 
	 newpath 0 lw -.5 mul moveto bl bw -.5 mul lineto 0 bw rlineto 
	 0 lw .5 mul lineto closepath clip 
	 [ bd dup ] 0 setdash bw setlinewidth
	 newpath 0 0 moveto bl 0 lineto stroke  
	 grestore } def
  /b4 {  /bl exch def gsave translate rotate 
	 newpath 0 bw -.15 mul moveto bl bw -.15 mul lineto 
	 0 bw .3 mul rlineto 0 bw .15 mul lineto closepath clip 
	 [ bd dup ] 0 setdash bw setlinewidth
	 newpath 0 0 moveto bl 0 lineto stroke
	 grestore } def
  /b5 {  /bl exch def gsave translate rotate 
	 newpath 0 bw .5 mul moveto bl 0 rlineto 0 bw -.5 mul moveto bl 0 rlineto stroke 
	 grestore } def
  /b6 {  /bl exch def gsave translate rotate 
	 newpath 0 0 moveto bl 0 rlineto stroke 
	 sb__ .1 bl mul bw  moveto .8 bl mul 0 rlineto stroke 
	 grestore } def
  /b7 {  /bl exch def gsave translate rotate 
	 newpath 0 0 moveto bl 0 rlineto stroke 
	 sb__ .1 bl mul bw neg moveto .8 bl mul 0 rlineto stroke 
	 grestore } def
  /b8 {  /bl exch def gsave translate rotate 
	 newpath 0 0 moveto bl 0 rlineto stroke 
	 sb__  .1 bl mul bw neg moveto .8 bl mul 0 rlineto 
	 .1 bl mul bw moveto .8 bl mul 0 rlineto stroke 
	 grestore } def
  /b9 {  /bl exch def gsave translate rotate 
	 currentlinewidth 2 mul setlinewidth 1 setlinecap
	 newpath 0 0 moveto bl 0 lineto stroke 
	 grestore } def
  /b10 { /bl exch def gsave translate rotate 
	 newpath 0 0 moveto bl 0 rlineto stroke 
	 newpath bl 0 moveto bw neg bw neg rlineto 0 bw dup add rlineto closepath fill 
	 grestore } def
  /b11 { /bl exch def  gsave translate rotate 
	 newpath 0 0 moveto bl 0 rlineto stroke 
	 newpath 0 0 moveto bw bw neg rlineto 0 bw dup add rlineto closepath fill 
	 grestore } def
  /b12 { pop pop pop pop} def
  /b13 { /bl exch def gsave translate rotate 
	 newpath 0 bw -.5 mul moveto bl lw -.5 mul lineto 0 lw rlineto 
	 0 bw .5 mul lineto closepath fill 
	 grestore } def
  /b14 { /bl exch def gsave translate rotate 
	 newpath 0 bw -.5 mul moveto bl lw -.5 mul lineto 0 lw rlineto 
	 0 bw .5 mul lineto closepath clip 
	 [ bd dup ] 0 setdash bw setlinewidth
	 newpath 0 0 moveto bl 0 lineto stroke  
	 grestore } def
  /b15 { /bl exch def gsave translate rotate 
	 bw setlinewidth 1 setlinecap
	 newpath 0 0 moveto bl 0 lineto stroke 
	 grestore } def
  /b16 { /bl exch def gsave translate rotate 
         newpath 0 0 moveto 
         3 dict begin
           /n bl bw 2 mul div cvi 1 add def
           /blt bl n div def
           /bwt bw bl blt div mul .5 mul def
           n {bwt 0.3 mul bw
              bwt 0.7 mul bw neg
              bwt 0 rcurveto} repeat
         end
         stroke 
	 grestore } def
    
  %
  % arrow types
  % len phi x y ar0..ar7
  %
  /ar0 { gsave translate rotate 0 0 moveto 0 lineto stroke grestore} def
  /ar1 { gsave translate rotate 0 0 moveto dup 0 lineto stroke newpath 0 moveto aw neg dup rlineto
	  0 aw dup add rlineto closepath fill grestore} def
  /ar2 { gsave translate rotate 0 0 moveto 0 lineto stroke newpath 0 0 moveto aw aw rlineto
	  0 aw dup add neg rlineto closepath fill grestore} def
  /ar3 { gsave translate rotate 0 aw 2 div moveto dup 0 rlineto 0 aw -.5 mul moveto dup 0 rlineto stroke 
	  newpath aw 2 div moveto aw neg aw rlineto 0 aw neg rlineto closepath fill newpath
	  0 aw -.5 mul moveto aw 0 rlineto 0 aw neg rlineto closepath fill grestore} def
  /ar4 { gsave translate rotate 0 0 moveto dup 0 lineto stroke newpath 0 moveto aw neg dup rlineto
	  0 aw dup add rlineto closepath fill newpath 0 0 moveto aw aw lineto
	  0 aw -2 mul rlineto closepath fill grestore} def
  /ar5 { gsave translate rotate 0 0 moveto dup 0 lineto stroke newpath dup 0 moveto aw neg dup rlineto
	  0 aw dup add rlineto closepath fill newpath 2 div dup aw moveto aw -2 mul dup
	  rlineto aw neg moveto aw dup add dup rlineto stroke grestore} def
  /ar6 { gsave translate rotate 0 0 moveto dup 0 lineto stroke newpath 0 0 moveto aw aw rlineto
	  0 aw dup add neg rlineto closepath fill newpath 2 div dup aw moveto aw -2 mul dup
	  rlineto aw neg moveto aw dup add dup rlineto stroke grestore} def
  % phi x y arrow tip
  /atip { gsave translate rotate 
	  /maw aw 2 div def
	  newpath 0 0 moveto maw neg maw rlineto 0 maw -2 mul rlineto closepath fill
	  grestore } def
  %
  % marker types: size x y m<type>
  %
  /slw { .035 setlinewidth }def
  /m0 { gsave translate slw dup scale 0 0 .5 0 360 arc closepath stroke
	grestore } def
  /m1 { gsave translate slw dup scale 0 0 .5 0 360 arc closepath fill
	grestore } def
  /m2 { gsave translate slw dup scale -.5 -.5 moveto 1 0 rlineto 0 1 rlineto
	  -1 0 rlineto closepath stroke
	grestore } def
  /m3 { gsave translate slw dup scale -.5 -.5 moveto 1 0 rlineto 0 1 rlineto
	  -1 0 rlineto closepath fill
	grestore } def
  /m4 { gsave translate slw dup scale 0 -.5 moveto .5 0 lineto 0 .5 lineto
	  -.5 0 lineto closepath stroke
	grestore } def
  /m5 { gsave translate slw dup scale 0 -.5 moveto .5 0 lineto 0 .5 lineto
	  -.5 0 lineto closepath fill
	grestore } def
  /m6 { gsave translate slw dup scale -.5 -.5 moveto 1 0 rlineto -.5 1 rlineto
	  closepath stroke
	grestore } def
  /m7 { gsave translate slw dup scale -.5 -.5 moveto 1 0 rlineto -.5 1 rlineto
	  closepath fill
	grestore } def
  /m8 { gsave translate slw dup scale -.5 0 moveto 1 0 rlineto 
	  0 -.5 moveto 0 1 rlineto stroke
	grestore } def
  /m9 { gsave translate slw dup scale -.5 -.5 moveto .5 .5 lineto
	  -.5 .5 moveto .5 -.5 lineto stroke
	grestore } def
  /m10 { gsave translate slw dup scale -.5 -.5 moveto .5 .5 lineto
	  -.5 .5 moveto .5 -.5 lineto 0 -.5 moveto 0 .5 lineto stroke
	grestore } def
  /m11 { } def
}