Debian Codegraph @

texmf-dist/source/latex/chemcompounds/chemcompounds.dtx

raw
1 % \iffalse
2 %%
3 %% File: chemcompounds.dtx Copyright (C) 2005-2007 Stephan Schenk
4 %% $Id: chemcompounds.dtx,v 1.8 2006/12/01 15:21:58 schenk Exp $
5 %%
6 %% Stephan Schenk ([email protected])
7 %%
8 % This program may be distributed and/or modified under the
9 % conditions of the LaTeX Project Public License, either version 1.3
10 % of this license or (at your option) any later version.
11 % The latest version of this license is in
12 % http://www.latex-project.org/lppl.txt
13 %
14 % This package consists of the files chemcompounds.dtx and chemcompounds.ins
15 %
16 %%
17 %% To produce the documentation, do the following:
18 %%
19 %% latex chemcompounds.dtx
20 %% latex chemcompounds.dtx
21 %% makeindex -s gglo.ist -o chemcompounds.gls chemcompounds.glo
22 %% latex chemcompounds.dtx
23 %%
24
25 %<*driver>
26 \ProvidesFile{chemcompounds.dtx}
27 %</driver>
28 %<package>\NeedsTeXFormat{LaTeX2e}
29 %<package>\ProvidesPackage{chemcompounds}
30 %<*package>
31 [2006/12/01 v1.1.3 Dictionary for compound numbering]
32 %</package>
33 %
34 %<*driver>
35 \documentclass{ltxdoc}
36 \GetFileInfo{chemcompounds.dtx}
37 \RecordChanges
38 \begin{document}
39 \DocInput{\filename}
40 \PrintChanges
41 \end{document}
42 %</driver>
43 % \fi
44 %
45 % \CheckSum{198}
46 %
47 % \CharacterTable
48 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
49 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
50 % Digits \0\1\2\3\4\5\6\7\8\9
51 % Exclamation \! Double quote \" Hash (number) \#
52 % Dollar \$ Percent \% Ampersand \&
53 % Acute accent \' Left paren \( Right paren \)
54 % Asterisk \* Plus \+ Comma \,
55 % Minus \- Point \. Solidus \/
56 % Colon \: Semicolon \; Less than \<
57 % Equals \= Greater than \> Question mark \?
58 % Commercial at \@ Left bracket \[ Backslash \\
59 % Right bracket \] Circumflex \^ Underscore \_
60 % Grave accent \` Left brace \{ Vertical bar \|
61 % Right brace \} Tilde \~}
62 %
63 %
64 %
65 % \changes{1.1.3}{2006/12/01}{Updated documentation.}
66 % \changes{1.1.2}{2005/10/24}{Posted on CTAN on 2005/10/24.}
67 % \changes{1.0.0}{2005/07/21}{First version posted on CTAN.}
68 %
69 % \title{The \textsf{chemcompounds} package\thanks{This file describes
70 % version \fileversion\ and has been last revised \filedate.}}
71 % \author{Stephan Schenk\\mail (at) schenk-stephan.de}
72 % \maketitle
73 %
74 % \setcounter{tocdepth}{1}
75 %
76 % \begin{abstract}
77 % The \texttt{\filename} package allows for a simple consecutive numbering of
78 % chemical compounds. Optionally, it is possible to supply a custom name for
79 % each compound. By default the compounds are numbered following the order of
80 % their appearance in the text.
81 % \end{abstract}
82 %
83 % \tableofcontents
84 %
85 % \section{Introduction}
86 %
87 % In chemical publications it is often necessary to consecutively number every
88 % compound mentioned in the text. Although this can be simply accomplished by
89 % manually inserting the corresponding numbers into the text, it is generally
90 % much more tedious work since the numbering scheme tends to change several
91 % times during the evolvement of the manuscript. For this reason it would be
92 % nice to have an automaticism which will take care of every change.
93 %
94 % Being myself a chemist, I've been using the \texttt{chemcono} package by
95 % Stefan Schulz for this purpose quite successfully over several years. This
96 % package creates a library very similar to |thebibliography|. Users can now
97 % refer to entries in the library by a command very similar to |\cite|. Thus,
98 % once you change the library entry every reference to it will be updated
99 % automatically upon running \LaTeX\ on the file. There is only one issue
100 % associated with this package: You get a list of all declared compounds
101 % inside your document wich at least looks odd. I therefore decided to write a
102 % new package \texttt{chemcompounds} described in this document to address
103 % this problem.
104 %
105 % When taking a closer look at the \texttt{chemcono} package, I realised that
106 % the only thing one has to do is to get rid of everything which produces
107 % text. Thus, as a basis I used the mechanism of |\bibitem| and |\cite| in
108 % pretty much the same way as \texttt{chemcono} does by extracting the
109 % corresponding code from |article.cls| and |latex.ltx| but deleting any
110 % unnecessary commands producing output. I also introduced several lines of
111 % code to make the printing of the compound names more customisable.
112 %
113 % Currently, the packages knows two different modes of operation. In
114 % the default |implicit| mode, a compound name is created automatically as a
115 % consecutive number when the compound is referenced for the first time by
116 % |\compound|. Thus, all compounds will be numbered
117 % consecutively in the order they appear in the text. If the automatically
118 % generated name is not appropriate, a custom name can be given to a compound
119 % by means of the |\declarecompound| command described below.
120 %
121 % In |noimplicit| mode names are not generated fully automatically. Instead, for
122 % every compound a |\declarecompound| must be issued. This will again create a
123 % subsequent number and a custom name can be given as an optional argument. The
124 % main difference to |implicit| mode is that thus compounds will be
125 % numbered in the order of the corresponding |\declarecompound| commands rather
126 % than in the order of their appearance in the text.
127 %
128 %
129 % \section{The user interface}
130 %
131 % Because of the way the implementation works, two \LaTeX\ runs are required
132 % to get everything right. This should not be a problem since you have to run
133 % \LaTeX\ twice anyway to get the table of contents and references right. The
134 % package will issue a ``labels have changed'' warning if you have to rerun
135 % \LaTeX. For every unknown compound name the package will issue a warning, too.
136 %
137 % \subsection{Package options}
138 %
139 % \begin{list}{}{\leftmargin=0pt \labelsep=0pt}
140 %
141 % \item
142 % \DescribeMacro{implicit}
143 % This option causes the package to operate in |implicit| mode. This is the
144 % default.
145 %
146 % \item
147 % \DescribeMacro{noimplicit}
148 % This option is the opposite of |implicit| and causes the package to operate in
149 % |noimplicit| mode.
150 %
151 % \end{list}
152 %
153 % \subsection{Assigning and accessing compound names}
154 %
155 % \begin{list}{}{\leftmargin=0pt \labelsep=0pt}
156 %
157 % \item
158 % \DescribeMacro{\declarecompound}
159 % |\declarecompound[|\meta{optional name}|]{|\meta{label}|}|\\
160 % assigns a name to a compound.
161 % If the optional argument is omitted, a consecutive number is automatically
162 % taken as compound name. This command can only occur in the preamble.
163 % A personal recommendation is to keep all |\declarecompound|s together in a
164 % separate file and |\input| this file in the preamble.
165 %
166 % In |implicit| mode, if no optional argument is given, the command does nothing
167 % since the automatic compound name will be generated by |\compound|.
168 %
169 % \item
170 % \DescribeMacro{\compound}
171 % |\compound{|\meta{label1}|,|\meta{label2}|,|\dots|}|\\
172 % prints the name of a compound. If a list of labels is given as argument, a
173 % list of names separated by |\compoundseparator| is created. In |implicit| mode
174 % this command also creates a new compound name if the label is used for the
175 % first time and a custom name has not already been assigned to this compound.
176 %
177 % \item
178 % \DescribeMacro{\compound*}
179 % The starred version works in almost exactly the same way as |\compound|. The
180 % only difference is that it does not create any output at all. However, it
181 % still creates the label in |implicit| mode. It can thus be used to create
182 % ``hidden'' compounds in |implicit| mode. This, i.e., can be useful if some
183 % compounds are depicted in an illustration or scheme which are only later or
184 % even never mentioned in the text but the numbering scheme should take care of
185 % them.
186 %
187 % \item
188 % \DescribeMacro{\compound+}
189 % The version with a '|+|' really prints only the name of a compound. In
190 % |implicit| mode, no label is created. Thus, it is the opposite of the starred
191 % command.
192 %
193 % \end{list}
194 %
195 %
196 %
197 % \subsection{Customization}
198 %
199 % The commands in this section can be used to fine-tune the appearance of the
200 % compound names. In order to change the default behaviour you have to
201 % |\renewcommand| the corresponding commands. The defaults for every command
202 % are given in parentheses.
203 %
204 % \begin{list}{}{\leftmargin=0pt \labelsep=0pt}
205 %
206 % \item
207 % \DescribeMacro{\compoundseparator}
208 % |\compoundseparator| (\verb*<,\penalty\@m\ <)\\
209 % defines the separator in a list of compound names.
210 %
211 % \item
212 % \DescribeMacro{\compoundglobalprefix}
213 % |\compoundglobalprefix| ()\\
214 % defines the prefix for a list of compound names. This will be printed also in
215 % case the list has length one.
216 %
217 % \item
218 % \DescribeMacro{\compoundglobalsuffix}
219 % |\compoundglobalsuffix| ()\\
220 % defines the suffix for a list of compound names. This will be printed also in
221 % case the list has length one.
222 %
223 % \item
224 % \DescribeMacro{\compoundprefix}
225 % |\compoundprefix| ()\\
226 % defines the prefix for every compound.
227 %
228 % \item
229 % \DescribeMacro{\compoundsuffix}
230 % |\compoundsuffix| ()\\
231 % defines the suffix for every compound.
232 %
233 % \item
234 % \DescribeMacro{\compoundstyle}
235 % |\compoundstyle| (|\textbf|)\\
236 % defines the style of each name.
237 %
238 % \item
239 % \DescribeMacro{\printcompound}
240 % |\printcompound|
241 % (|{\compoundprefix}{\compoundstyle{#1}}{\compoundsuffix}|)\\
242 % is used to actually format the name of each compound. If the previous
243 % possibilities are not sufficient to meet your formatting demands the thing
244 % you should redefine is this one.
245 %
246 % \end{list}
247 %
248 %
249 %
250 % \subsection{Examples}
251 %
252 % The following examples using
253 % \begin{verbatim}
254 % \declarecompound{label1}
255 % \declarecompound{label2}
256 % \declarecompound[5b]{label3}
257 % \compound{label1} and \compound{label1,label2,label3}
258 % \end{verbatim}
259 % should clarify the meaning of the above commands. The first two
260 % |\declarecommand|s could be omitted in |implicit| mode.
261 %
262 % \begin{itemize}
263 %
264 % \item
265 % Using the defaults results in \textbf{1} and \textbf{1}, \textbf{2},
266 % \textbf{5b}.
267 %
268 % \item
269 % \begin{verbatim}
270 % \renewcommand{\compoundstyle}{\underbar}
271 % \end{verbatim}
272 % gives \underbar 1 and \underbar 1, \underbar 2, \underbar{5b}.
273 %
274 % \item
275 % \begin{verbatim}
276 % \renewcommand{\compoundseparator}{;}
277 % \end{verbatim}
278 % gives \textbf{1} and \textbf{1}; \textbf{2}; \textbf{5b}.
279 %
280 % \item
281 % \begin{verbatim}
282 % \renewcommand{\compoundglobalprefix}{(}
283 % \renewcommand{\compoundglobalsuffix}{)}
284 % \end{verbatim}
285 % gives (\textbf{1}) and (\textbf{1}, \textbf{2}, \textbf{5b}).
286 %
287 % \item
288 % \begin{verbatim}
289 % \renewcommand{\compoundprefix}{(}
290 % \renewcommand{\compoundsuffix}{)}
291 % \end{verbatim}
292 % gives (\textbf{1}) and (\textbf{1}), (\textbf{2}), (\textbf{5b}).
293 %
294 % \item
295 % \begin{verbatim}
296 % \renewcommand{\compoundglobalprefix}{\textbf{[}}
297 % \renewcommand{\compoundglobalsuffix}{\textbf{]}}
298 % \renewcommand{\compoundprefix}{\ensuremath{\langle}}
299 % \renewcommand{\compoundsuffix}{\ensuremath{\rangle}}
300 % \renewcommand{\compoundstyle}{\emph}
301 % \end{verbatim}
302 % gives \textbf{[}$\langle$\emph{1}$\rangle$\textbf{]} and
303 % \textbf{[}$\langle$\emph{1}$\rangle$,
304 % $\langle$\emph{2}$\rangle$, $\langle$\emph{5b}$\rangle$\textbf{]}.
305 %
306 % \end{itemize}
307 %
308 % \noindent
309 % As shown above customization is not limited solely to parentheses etc.\
310 % but can include formating commands, too.
311 %
312 %
313 %
314 % \StopEventually{}
315 %
316 % \section{The implementation}
317 %
318 %\iffalse
319 %<*package>
320 %\fi
321 %
322 % \subsection{Identification}
323 % The package identifies itself at the top using something like
324 % \iffalse
325 % Identification is already done on top of the file. Thus the following
326 % code should be printed in the documentation but should not be included
327 % in the package.
328 %</package>
329 %<*!package>
330 % \fi
331 % \begin{macrocode}
332 \NeedsTeXFormat{LaTeX2e}
333 \ProvidesPackage{chemcompounds}
334 [\filedate\space \fileversion\space Dictionary for compound numbering]
335 % \end{macrocode}
336 % \iffalse
337 %</!package>
338 %<*package>
339 % \fi
340 %
341 % \subsection{Package options}
342 %
343 % \begin{macro}{\ifchemcompounds@implicit}
344 % \changes{1.1.0}{2005/10/06}{New.}
345 % Define a new boolean variable defining whether |implicit| mode is enabled.
346 % \begin{macrocode}
347 \newif\ifchemcompounds@implicit
348 % \end{macrocode}
349 % \end{macro}
350 %
351 % \begin{macro}{implicit}
352 % \changes{1.1.0}{2005/10/07}{New option.}
353 % \begin{macro}{noimplicit}
354 % \changes{1.1.0}{2005/10/06}{New option.}
355 % The following package options set |ifchemcompounds@implicit| either to true or
356 % false. The default is |implicit| mode.
357 % \begin{macrocode}
358 \DeclareOption{implicit}{\chemcompounds@implicittrue}
359 \DeclareOption{noimplicit}{\chemcompounds@implicitfalse}
360 \ExecuteOptions{implicit}
361 % \end{macrocode}
362 % \end{macro}
363 % \end{macro}
364 %
365 % Process options.
366 % \changes{1.1.0}{2005/10/06}{Added code to process options.}
367 % \begin{macrocode}
368 \ProcessOptions
369 % \end{macrocode}
370 %
371 %
372 % \subsection{User interface}
373 %
374 % The work flow for creating and accessing compound names was borrowed from the
375 % definition of |\bibitem| and |\cite|.
376 %
377 % \begin{macro}{\compoundseparator}
378 % \changes{1.1.0}{2005/10/06}{Changed default value to include trailing
379 % space.}
380 % \begin{macro}{\compoundglobalprefix}
381 % \begin{macro}{\compoundglobalsuffix}
382 % \begin{macro}{\compoundprefix}
383 % \begin{macro}{\compoundsuffix}
384 % \begin{macro}{\compoundstyle}
385 % \begin{macro}{\printcompound}
386 % \changes{1.1.2}{2005/10/18}{New. Previous \cs{@compound}
387 % command.}
388 % The following definitions define the default layout of the names in the text
389 % (no surrounding parentheses, multiple compound names separated by comma,
390 % names in bold face). |\printcompound| defines the way each name is
391 % printed.
392 % \begin{macrocode}
393 \def\compoundseparator{,\penalty\@m\ }
394 \let\compoundglobalprefix\@empty
395 \let\compoundglobalsuffix\@empty
396 \let\compoundprefix\@empty
397 \let\compoundsuffix\@empty
398 \def\compoundstyle{\textbf}
399 \def\printcompound#1{{\compoundprefix}{\compoundstyle{#1}}{\compoundsuffix}}
400 % \end{macrocode}
401 % \end{macro}
402 % \end{macro}
403 % \end{macro}
404 % \end{macro}
405 % \end{macro}
406 % \end{macro}
407 % \end{macro}
408 %
409 % \begin{macro}{\declarecompound}
410 % \changes{1.1.0}{2005/10/07}{Only in preamble.}
411 % This command is used to assign a name to a compound.
412 % It just looks ahead whether an optional argument was given
413 % and calls the appropriate internal command. To avoid problems with the
414 % creation of the labels, this command is only allowed in the preamble.
415 % \begin{macrocode}
416 \def\declarecompound{\@ifnextchar[\@ldeclarecompound\@declarecompound}
417 \@onlypreamble\declarecompound
418 % \end{macrocode}
419 % \end{macro}
420 %
421 % \begin{macro}{\ifchemcompounds@print}
422 % \changes{1.1.2}{2005/10/18}{New.}
423 % Define a new boolean variable indicating whether the starred version of
424 % |\compound| was used.
425 % \begin{macrocode}
426 \newif\ifchemcompounds@print
427 % \end{macrocode}
428 % \end{macro}
429 %
430 % \begin{macro}{\ifchemcompounds@create}
431 % \changes{1.1.3}{2006/12/01}{New.}
432 % Define a new boolean variable indicating whether a label name shall be
433 % created automatically in |implicit| mode.
434 % \begin{macrocode}
435 \newif\ifchemcompounds@create
436 % \end{macrocode}
437 % \end{macro}
438 %
439 % \begin{macro}{\compound}
440 % \changes{1.1.3}{2006/12/01}{Abandon use of \cs{@ifstar} since this breaks
441 % compatibility with amsmath (reported by J. Ryan).}
442 % \changes{1.1.3}{2006/12/01}{Set chemcompounds@create appropriately.}
443 % \changes{1.1.2}{2005/10/18}{Only check for starred version and call internal
444 % command. Functionality moved to \cs{@compound}.}
445 % \changes{1.1.1}{2005/10/11}{Changed label prefix to 'comp'.}
446 % \changes{1.1.0}{2005/10/07}{Changed definition of
447 % \cs{compoundseparator}. Inserted \cs{@createcompoundhook}.}
448 % \changes{1.0.1}{2005/10/05}{Replaced \cs{hbox} by \cs{mbox}
449 % to work around some spacing issues when printing the compound name.}
450 % \begin{macro}{\compound*}
451 % \changes{1.1.2}{2005/10/18}{New.}
452 % \begin{macro}{\compound+}
453 % \changes{1.1.3}{2006/12/01}{New (suggested by J. Hooper).}
454 % This command will finally print the name associated with a compound label.
455 % The starred version just creates the label (in |implicit| mode) without
456 % printing the value.
457 % The command itself just checks whether the starred or plussed version is used,
458 % sets the internal flags appropriately and calls the internal command
459 % |\@compound|.
460 % \begin{macrocode}
461 \DeclareRobustCommand{\compound}{%
462 \chemcompounds@createtrue
463 \chemcompounds@printtrue
464 \@ifnextchar *{\chemcompounds@printfalse\@firstoftwo\@compound}
465 {%
466 \@ifnextchar +{\chemcompounds@createfalse\@firstoftwo\@compound}
467 {\@compound}
468 }
469 }
470 % \end{macrocode}
471 % \end{macro}
472 % \end{macro}
473 % \end{macro}
474 %
475 %
476 %
477 % \subsection{Internal commands}
478 %
479 % \begin{macro}{\@compound}
480 % \changes{1.1.2}{2005/10/18}{New. Previous functionality moved to
481 % \cs{printcompound}.}
482 % This command retrieves the name associated with a compound and prints it
483 % in the text using the previously defined format. The code is a modified
484 % version of the definition of |\cite| in |latex.ltx|.
485 % If this command is invoked by |\compound*|, |\ifchemcompounds@print| will be
486 % false and all output will be suppressed.
487 % \begin{macrocode}
488 \def\@compound#1{%
489 % \end{macrocode}
490 % Print optional prefix to a list of compounds.
491 % \begin{macrocode}
492 \ifchemcompounds@print
493 \compoundglobalprefix
494 \fi
495 % \end{macrocode}
496 % Now loop over every label in the argument list.
497 % \begin{macrocode}
498 \let\@compounda\@empty
499 \@for\@compoundb:=#1\do{%
500 \edef\@compoundb{\expandafter\@firstofone\@compoundb}%
501 % \end{macrocode}
502 % Print separator. Note that it is empty for the first entry and
503 % |\compoundseparator| otherwise.
504 % \begin{macrocode}
505 \ifchemcompounds@print
506 \@compounda
507 \def\@compounda{{\compoundseparator}}%
508 \fi
509 % \end{macrocode}
510 % If compound is undefined, print '\textbf{?}' and raise a warning.
511 % \begin{macrocode}
512 \@ifcompoundundefined{\@compoundb}{%
513 \ifchemcompounds@print
514 \mbox{\reset@font\bfseries ?}%
515 \fi
516 \G@refundefinedtrue
517 \@latex@warning
518 {compound `\@compoundb' on page \thepage\space undefined}%
519 }{%
520 % \end{macrocode}
521 % If compound is known print formatted name.
522 % \begin{macrocode}
523 \ifchemcompounds@print
524 \mbox{\printcompound{\@nameuse{comp@\@compoundb}}}%
525 \fi
526 }%
527 % \end{macrocode}
528 % In |implicit| mode |\@createcompoundhook| will generate a new name if this has
529 % not been done before. In |noimplicit| mode this does nothing.
530 % \begin{macrocode}
531 \@createcompoundhook{\@compoundb}%
532 }%
533 % \end{macrocode}
534 % Print optional suffix to a list of compounds.
535 % \begin{macrocode}
536 \ifchemcompounds@print
537 \compoundglobalsuffix
538 % \end{macrocode}
539 % Although nothing is printed, under certain conditions an additional
540 % space is created. Remove it.
541 % \begin{macrocode}
542 \else
543 \unskip
544 \fi
545 }
546 % \end{macrocode}
547 % \end{macro}
548 %
549 % \begin{macro}{\chemcompounds@counter}
550 % Define a new counter which will be used for generating the compound names.
551 % \begin{macrocode}
552 \newcounter{chemcompounds@counter}
553 % \end{macrocode}
554 % \end{macro}
555 %
556 % \begin{macro}{\chemcompounds@label}
557 % \changes{1.1.1}{2005/10/11}{Changed label prefix to 'comp' since 'c' is
558 % already in use.}
559 % \changes{1.1.0}{2005/10/06}{Labels are now prefixed with 'c' making them
560 % hopefully unique.}
561 % The next command will be used in the |.aux| file and defines a new label for
562 % every compound.
563 % \begin{macrocode}
564 \def\chemcompounds@label{\@newl@bel {comp}}
565 % \end{macrocode}
566 % \end{macro}
567 %
568 % \begin{macro}{\chemcompounds@writelabel}
569 % \changes{1.1.2}{2005/10/18}{Added \cs{ignorespaces}.}
570 % \changes{1.1.1}{2005/10/10}{\cs{noexpand} the label value. Required
571 % for improved robustness.}
572 % \changes{1.1.0}{2005/10/06}{New.}
573 % Write the label and its value to the |aux| file.
574 % \begin{macrocode}
575 \def\chemcompounds@writelabel#1#2{%
576 \if@filesw
577 \begingroup
578 \def\protect{\noexpand}%
579 \immediate\write\@auxout{
580 \string\chemcompounds@label{#1}{#2}
581 }%
582 \endgroup
583 \fi
584 \ignorespaces
585 }
586 % \end{macrocode}
587 % \end{macro}
588 %
589 % \begin{macro}{\@ldeclarecompound}
590 % \changes{1.1.0}{2005/10/06}{Completly rewritten.}
591 % The next command gets called if an additional argument was supplied to
592 % |\declarecompound|. It creates the compound with the given name as soon as
593 % the |aux| file is writeable. This command can only be used in the preamble.
594 % \begin{macrocode}
595 \def\@ldeclarecompound[#1]#2{%
596 \AtBeginDocument{\@createcompound[#1]{#2}}
597 }
598 \@onlypreamble\@ldeclarecompound
599 % \end{macrocode}
600 % \end{macro}
601 %
602 % \begin{macro}{\@declarecompound}
603 % \changes{1.1.0}{2005/10/06}{Completely rewritten.}
604 % In |implicit| mode this command does nothing since default names are created
605 % automatically by |\compound|.
606 % \begin{macrocode}
607 \ifchemcompounds@implicit
608 \let\@declarecompound\@gobble
609 % \end{macrocode}
610 % In |noimplicit| mode this simply creates the compound as soon as
611 % the |aux| file is writeable.
612 % \begin{macrocode}
613 \else
614 \def\@declarecompound#1{%
615 \AtBeginDocument{\@createcompound{#1}}
616 }
617 \fi
618 \@onlypreamble\@declarecompound
619 % \end{macrocode}
620 % This command can only be used in the preamble.
621 % \end{macro}
622 %
623 % \begin{macro}{\@ifcompoundundefined}
624 % \changes{1.1.1}{2005/10/11}{Changed label prefix to 'comp'.}
625 % \changes{1.1.0}{2005/10/06}{New.}
626 % Test whether a compound has already been defined by testing the associated
627 % label.
628 % \begin{macrocode}
629 \def\@ifcompoundundefined#1{%
630 \@ifundefined{comp@#1}
631 }
632 % \end{macrocode}
633 % \end{macro}
634 %
635 % \begin{macro}{\@createcompound}
636 % \changes{1.1.0}{2005/10/06}{New.}
637 % This command is used to create a new compound name. It just looks ahead
638 % whether an optional argument was given and calls the appropriate command.
639 % \begin{macrocode}
640 \def\@createcompound{%
641 \@ifnextchar[\@@lcreatecompound\@@createcompound
642 }
643 % \end{macrocode}
644 % \end{macro}
645 %
646 % \begin{macro}{\@@createcompound}
647 % \changes{1.1.0}{2005/10/06}{New.}
648 % If a compound name has not yet been created this command increments
649 % |chemcompounds@counter| and takes the new value as the compound name.
650 % The new compound name is written to the |aux| file and a flag is set to
651 % indicate that a name for this compound has already been created.
652 % \begin{macrocode}
653 \def\@@createcompound#1{%
654 \@ifnotcompoundcreated{#1}{%
655 \stepcounter{chemcompounds@counter}%
656 \chemcompounds@writelabel{#1}{\the\value{chemcompounds@counter}}
657 \@compoundcreated{#1}%
658 }%
659 }
660 % \end{macrocode}
661 % \end{macro}
662 %
663 % \begin{macro}{\@@lcreatecompound}
664 % \changes{1.1.0}{2005/10/06}{New.}
665 % This command creates a compound name from the first parameter and writes it
666 % to the |aux| file. A flag is set to indicate that a name for this compound has
667 % already been created.
668 % \begin{macrocode}
669 \def\@@lcreatecompound[#1]#2{%
670 \chemcompounds@writelabel{#2}{#1}
671 \@compoundcreated{#2}%
672 }
673 % \end{macrocode}
674 % \end{macro}
675 %
676 % \begin{macro}{\@compoundcreated}
677 % \changes{1.1.1}{2005/10/11}{Changed label prefix to 'compc'.}
678 % \changes{1.1.0}{2005/10/06}{New.}
679 % Set a flag indicating that the compound name has been created. This is done by
680 % defining an appropriate label in |implicit| mode.
681 % \begin{macrocode}
682 \ifchemcompounds@implicit
683 \def\@compoundcreated#1{%
684 \global\@namedef{compc@#1}{}%
685 }
686 % \end{macrocode}
687 % In |noimplicit| mode this is unnecessary, thus just gobble the argument.
688 % \begin{macrocode}
689 \else
690 \let\@compoundcreated\@gobble
691 \fi
692 % \end{macrocode}
693 % \end{macro}
694 %
695 % \begin{macro}{\@ifnotcompoundcreated}
696 % \changes{1.1.1}{2005/10/11}{Changed label prefix to 'compc'.}
697 % \changes{1.1.0}{2005/10/07}{New.}
698 % Check whether a new compound name has already been created.
699 % In |implicit| mode existence of the corresponding label (flag) is checked.
700 % If it does not exist, the code given as the second argument is executed.
701 % \begin{macrocode}
702 \ifchemcompounds@implicit
703 \def\@ifnotcompoundcreated#1#2{%
704 \@ifundefined{compc@#1}{#2}{}%
705 }
706 % \end{macrocode}
707 % In |noimplicit| mode the label (flag) is unused and a new name will always be.
708 % created. Therefore just execute the code given as second argument.
709 % \begin{macrocode}
710 \else
711 \let\@ifnotcompoundcreated\@secondoftwo
712 \fi
713 % \end{macrocode}
714 % \end{macro}
715 %
716 % \begin{macro}{\@createcompoundhook}
717 % \changes{1.1.3}{2006/12/01}{Implicit definition now checks for
718 % chemcompounds@create}
719 % \changes{1.1.0}{2005/10/07}{New.}
720 % This command gets called everytime a compound name is printed.
721 % In |implicit| mode this command creates a new compound name if
722 % |\ifchemcompounds@create| is true. The |\compound+| command sets
723 % this boolean to false.
724 % \begin{macrocode}
725 \ifchemcompounds@implicit
726 \def\@createcompoundhook#1{%
727 \ifchemcompounds@create
728 \@createcompound{#1}%
729 \fi
730 }
731 % \end{macrocode}
732 % In |noimplicit| mode this is unnecessary. Therefore just gobble the argument.
733 % \begin{macrocode}
734 \else
735 \let\@createcompoundhook\@gobble
736 \fi
737 % \end{macrocode}
738 % \end{macro}
739 %
740 % \begin{macrocode}
741 \endinput
742 % \end{macrocode}
743 %
744 %\iffalse
745 %</package>
746 %\fi
747 %
748 % \Finale