| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2018 by Justin Finnerty <[email protected]> |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified under the conditions of |
| 6 |
% the LaTeX Project Public License, either version 1.3 of this license |
| 7 |
% or (at your option) any later version. The latest version of this |
| 8 |
% license is in: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% and version 1.3 or later is part of all distributions of LaTeX version |
| 13 |
% 2005/12/01 or later. |
| 14 |
% |
| 15 |
% \fi |
| 16 |
% |
| 17 |
% \iffalse |
| 18 |
%<*driver> |
| 19 |
\ProvidesFile{chemsec.dtx} |
| 20 |
%</driver> |
| 21 |
%<package>\NeedsTeXFormat{LaTeX2e}[1994/06/01] |
| 22 |
%<package>\ProvidesPackage{chemsec} |
| 23 |
%<*package> |
| 24 |
[2018/02/01 v1.12 .dtx chemsec file] |
| 25 |
%</package> |
| 26 |
%<package>\RequirePackage{ifthen}[1994/06/01] |
| 27 |
%<*driver> |
| 28 |
\documentclass{ltxdoc} |
| 29 |
\usepackage{chemsec}[2018/02/01] |
| 30 |
\EnableCrossrefs |
| 31 |
\CodelineIndex |
| 32 |
\RecordChanges |
| 33 |
\begin{document} |
| 34 |
\DocInput{chemsec.dtx} |
| 35 |
\PrintChanges |
| 36 |
\PrintIndex |
| 37 |
\end{document} |
| 38 |
%</driver> |
| 39 |
% \fi |
| 40 |
% |
| 41 |
% \CheckSum{418} |
| 42 |
% |
| 43 |
% \CharacterTable |
| 44 |
% {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 |
| 45 |
% 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 |
| 46 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 47 |
% Exclamation \! Double quote \" Hash (number) \# |
| 48 |
% Dollar \$ Percent \% Ampersand \& |
| 49 |
% Acute accent \' Left paren \( Right paren \) |
| 50 |
% Asterisk \* Plus \+ Comma \, |
| 51 |
% Minus \- Point \. Solidus \/ |
| 52 |
% Colon \: Semicolon \; Less than \< |
| 53 |
% Equals \= Greater than \> Question mark \? |
| 54 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 55 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 56 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 57 |
% Right brace \} Tilde \~} |
| 58 |
% |
| 59 |
% |
| 60 |
% \changes{v1.0}{1996/06/05}{Initial version} |
| 61 |
% |
| 62 |
% \GetFileInfo{chemsec.dtx} |
| 63 |
% |
| 64 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 65 |
% |
| 66 |
% |
| 67 |
% \title{The \textsf{chemsec} package\thanks{This document |
| 68 |
% corresponds to \textsf{chemsec}~\fileversion, dated \filedate.}} |
| 69 |
% \author{Justin Finnerty \\ \textsf{[email protected]}} |
| 70 |
% |
| 71 |
% \maketitle |
| 72 |
% |
| 73 |
% \section{Abstract} |
| 74 |
% |
| 75 |
% A cross-reference system designed for an arbitrary set of items. |
| 76 |
% Generates a document-order set of consecutive number labels that can |
| 77 |
% be cross-referenced anywhere in the document. The motivating example |
| 78 |
% is labeling chemical structures in a scientific document. |
| 79 |
% |
| 80 |
% \section{Usage} |
| 81 |
% |
| 82 |
% This package solves the problem of providing a sequence of numeric |
| 83 |
% labels to represent entities in a document. The motivating example is |
| 84 |
% labels for chemical structures in a scientific document. In such a |
| 85 |
% document you want the full chemical name and a label to appear in the |
| 86 |
% typeset document for each chemical structure the first time the |
| 87 |
% structure is referenced in the document text. Subsequent references to |
| 88 |
% the structure should only use the label. These labels should form a |
| 89 |
% numeric sequence, with the first chemical structure being labeled |
| 90 |
% \textbf{1}, the second \textbf{2} and so on. |
| 91 |
% |
| 92 |
% These labels share similar features to numeric bibliographic reference |
| 93 |
% styles, both use numbers to represent something, the numbers form a |
| 94 |
% single sequence starting from one and incrementing as references or |
| 95 |
% structures appear in the document. Furthermore these labels or |
| 96 |
% citations can appear in multiple places in the text but must retain a |
| 97 |
% single unique numeric label. |
| 98 |
% |
| 99 |
% However there are a couple of differences to a bibliography. Firstly |
| 100 |
% the name of the chemical structure generally appears where it is first |
| 101 |
% used in the document along with its label rather than in a |
| 102 |
% bibliography or footnote. Secondly it is common to use a single |
| 103 |
% numeric label for closely related structures, appending a sub-label to |
| 104 |
% denote individual structures, usually lower-case letters. For example |
| 105 |
% we might have ``\textsf{methyl acetate (\textbf{1a})}'' and |
| 106 |
% ``\textsf{ethyl acetate (\textbf{1b})}'' being specific examples of an |
| 107 |
% ``\textsf{acetic acid ester (\textbf{1})}'' structure. Lastly, you may |
| 108 |
% need to separate the logical and actual first occurrence of a label, |
| 109 |
% allowing use of labels in abstracts and captions before a defining |
| 110 |
% macro call that sets the actual number of the label in the main |
| 111 |
% document sequence. |
| 112 |
% |
| 113 |
% The solution presented here uses keys to identify structures, in a |
| 114 |
% similar way to the BibTeX, with a special format that allows |
| 115 |
% associating related structures to an exemplar structure. This is |
| 116 |
% achieved by using keys that contain an exclamation mark |
| 117 |
% (|main-key!sub-key|) to separate the key for an exemplar structure |
| 118 |
% from a sub-key for the related structures. Following our example above |
| 119 |
% we might have keys |acetate!methyl|, |acetate!ethyl| and |acetate| as |
| 120 |
% the keys for ``methyl acetate'', ``ethyl acetate'' and ``acetic acid |
| 121 |
% ester'' respectively. Using such keys with this package would |
| 122 |
% automatically give the labels ``\textsf{\textbf{1a}}'', |
| 123 |
% ``\textsf{\textbf{1b}}'' and ``\textsf{\textbf{1}}''. Alternatively |
| 124 |
% in chemistry we want the sub-labels to be more meaningful, for example |
| 125 |
% denoting isomeric structures or an abbreviation for different |
| 126 |
% substituents. This package allows you to manually provide such a more |
| 127 |
% meaningful sub-label for each sub-key, for example leading to |
| 128 |
% ``\textsf{methyl acetate (\textbf{1-Me})}'' and ``\textsf{ethyl |
| 129 |
% acetate (\textbf{1-Et})}'' and ``\textsf{acetic acid ester |
| 130 |
% (\textbf{1})}'' in the output document. |
| 131 |
|
| 132 |
% However, using sub-keys is entirely optional and you can write a |
| 133 |
% complete document without using the sub-key feature. Keys with |
| 134 |
% sub-keys can be freely mixed in a document with keys that do not have |
| 135 |
% sub-keys. We suggest you generally want to provide an exemplar key |
| 136 |
% without sub-key for each set of keys which have sub-keys. This allows |
| 137 |
% you to refer in the document to the group of related chemicals as well |
| 138 |
% as the specific structures, ``\textsf{acetic acid ester |
| 139 |
% (\textbf{1})}'' in our example above. Hopefully the most difficult |
| 140 |
% part of using the \textsf{chemsec} package is choosing keys for your |
| 141 |
% structures. |
| 142 |
% |
| 143 |
% \subsection{Known Issues} |
| 144 |
% |
| 145 |
% \subsection{Capitalization of names} |
| 146 |
% |
| 147 |
% The package cannot capitalize the name of an entity, for example if an |
| 148 |
% entity name appears at the beginning of a sentence. For example the |
| 149 |
% capitalization of a chemical name requires parsing and understanding |
| 150 |
% the complete chemical nomenclature, something well beyond the scope of |
| 151 |
% this package. It is also hard to automatically detect when |
| 152 |
% capitalization should occur. Currently, the solutions are to avoid |
| 153 |
% using the macros that might produce entity names at the start of a |
| 154 |
% sentence or to manually type the entity name and use a macro that only |
| 155 |
% outputs a label. A possible future extension of this package may allow |
| 156 |
% the specification of two names for a compound, one capitalized and one |
| 157 |
% not, as well as macros to select between them. |
| 158 |
% |
| 159 |
% \subsubsection{Failure to issue warning} |
| 160 |
% |
| 161 |
% \emph{Note} that any labeling issue arising from this package is |
| 162 |
% always resolved when the document is processed twice in a row. It is |
| 163 |
% therefore recommended that, after making an edit, the user always |
| 164 |
% processes the document twice to ensure correct labeling. |
| 165 |
% |
| 166 |
% The user should get a warning if the for some reason the labels |
| 167 |
% typeset in the document are incorrect and the document processing |
| 168 |
% needs to be repeated. This can happen when using a macro that |
| 169 |
% requests the value of a label but does not set it. These macros use |
| 170 |
% current values or values set in the \textsl{aux} file. If the values |
| 171 |
% from the \textsl{aux} file need to be used they may either not be present |
| 172 |
% or differ from values set later in the document. When this happens |
| 173 |
% the user should get a warning message, however a number of issues may |
| 174 |
% prevent this and it is always recommended to process the document twice |
| 175 |
% after editing to ensure the correct labeling. |
| 176 |
% |
| 177 |
% Known cases of failure to get a warning message are: |
| 178 |
% \begin{itemize} |
| 179 |
% \item Use of macros before the document begins, for example in the |
| 180 |
% \textsf{abstract} environment, may fail to issue a warning about |
| 181 |
% incorrect labels. (I think this is due to the boolean variable that |
| 182 |
% signals an error being reset at the beginning of the document.) |
| 183 |
% \item Automatic sub-labels. Currently we cannot check to see if |
| 184 |
% sub-labels change during document processing. This is because |
| 185 |
% sub-labels are stored as text rather than numbers and text comparison |
| 186 |
% is surprisingly difficult in LaTeX. |
| 187 |
% \item User-defined sub-labels. We do not detect if a user-defined |
| 188 |
% sub-label is defined after a request for the sub-label. This is only |
| 189 |
% an issue the first time a document is processed or when a |
| 190 |
% |\DefineChemical| macro command is added to the document. |
| 191 |
% \end{itemize} |
| 192 |
% |
| 193 |
% \subsection{Defining structure names and sub-labels} |
| 194 |
% |
| 195 |
% \DescribeMacro{\DefineChemical} You define the names and optional |
| 196 |
% sub-label of a compound or entity using the |\DefineChemical| |
| 197 |
% \marg{key} \marg{name} \marg{sub-label} macro. This command does not |
| 198 |
% display any output in the document nor does it define the first part |
| 199 |
% of the label. This means you can define all the chemicals used in the |
| 200 |
% document in a single place rather than as they appear in the document. |
| 201 |
% The list can even be placed in a separate file included in the main |
| 202 |
% file, facilitating the reuse of keys and names in other documents. No |
| 203 |
% matter where this macro is placed in the document the \textsf{chemsec} |
| 204 |
% package will use the information wherever needed. |
| 205 |
% |
| 206 |
% Leaving the \marg{sub-label} argument empty for a |main!sub| key turns |
| 207 |
% on automatic sub-labeling for this key. By default this generates |
| 208 |
% sequential alphabetic labels for each |sub| key with the same |main| |
| 209 |
% key for which there is no user defined sub-label. This means that you |
| 210 |
% can manually supply labels for some |main!sub| keys and also have |
| 211 |
% |main!sub| keys without a defined label. This is advanced usage and |
| 212 |
% this package does not check to see if the automatically generated |
| 213 |
% labels match any of the user-defined labels. |
| 214 |
% |
| 215 |
% The \textsl{name} parameter can contain many LaTeX formatting |
| 216 |
% commands, including the use of |$$| math-mode. |
| 217 |
% |
| 218 |
% \subsection{\textsf{ChemCite} Macros} |
| 219 |
% |
| 220 |
% The package provides a range of macros that tailor what information |
| 221 |
% about a structure is output into the typeset document. These are the |
| 222 |
% |ChemCite| family of macros. All of these macros can have a ``|*|'' |
| 223 |
% (star) suffix. This suffix indicates this use of the macro should act |
| 224 |
% as a cross-reference for the label and not as a possible defining |
| 225 |
% reference. This means that the star form can be used in abstracts, |
| 226 |
% captions and anywhere in the document you need to use a label where it |
| 227 |
% might appear before it appears in the main document text where you |
| 228 |
% want the numeric label to be defined. |
| 229 |
% |
| 230 |
% \DescribeMacro{\ChemCite\marg{key}} Output the label for the given |
| 231 |
% key. If this is the first time the key is used and the non-star form |
| 232 |
% is used the full name precedes the label, with a star no full name is used. For example |
| 233 |
% |\ChemCite{acetate!methyl}| could give ``methyl acetate (\textbf{1a})'' |
| 234 |
% the first time it appeared and ``\textbf{1a}'' elsewhere. |
| 235 |
% The non-star form also sets the value of the numeric label at the |
| 236 |
% point it first appears in the document. The star form uses in order; |
| 237 |
% the current label if defined or a value stored in the \textsl{aux} |
| 238 |
% file from the previous time the document was processed or a |
| 239 |
% dummy value. The star form also never outputs the full name. For example |
| 240 |
% |\ChemCite*{acetate!methyl}| could give ``\textbf{1a}'' if it can |
| 241 |
% determine the labels or output a dummy value ``\textbf{0??}'' (or |
| 242 |
% less likely ``\textbf{0a}'' or ``\textbf{1??}''). |
| 243 |
% |
| 244 |
% \DescribeMacro{\ChemFCite\marg{key}} This macro always displays the |
| 245 |
% structure name as well as the label for the given key. The |F| is a |
| 246 |
% mnemonic for \textsf{full}, indicating the full entry of the name and |
| 247 |
% label is always used. For example |\ChemFCite{acetate!methyl}| would |
| 248 |
% give ``methyl acetate (\textbf{1a})'' the first time it appeared as well |
| 249 |
% as elsewhere. The non-star form also |
| 250 |
% sets the value of the numeric label at the point it first appears in |
| 251 |
% the document. The star form uses in order; the current label if |
| 252 |
% defined or a value stored in the \textsl{aux} file from the previous |
| 253 |
% time the document was processed or a dummy value. For example |
| 254 |
% |\ChemFCite*{acetate!methyl}| could give ``methyl acetate |
| 255 |
% (\textbf{1a})'' if it can determine the labels or output a dummy value |
| 256 |
% ``?? (\textbf{0??})'' or similar. |
| 257 |
% |
| 258 |
% \DescribeMacro{\ChemSCite\marg{key}} In counterpoint to the |
| 259 |
% |\ChemFCite| macro, this always only outputs the label for the given |
| 260 |
% key. The |S| is a mnemonic for \textsf{short}, indicating the short |
| 261 |
% entry of just the label is always used. For example |
| 262 |
% |\ChemSCite{acetate!methyl}| would give ``\textbf{1a}'' the first time |
| 263 |
% it appeared as well as ``\textbf{1a}'' elsewhere. The non-star form |
| 264 |
% also sets the value of the numeric label at the point it first appears |
| 265 |
% in the document. The star form uses in order; the current label if |
| 266 |
% defined or a value stored in the \textsl{aux} file from the previous |
| 267 |
% time the document was processed or a dummy value. For example |
| 268 |
% |\ChemSCite*{acetate!methyl}| could give ``\textbf{1a}'' if it can |
| 269 |
% determine the labels or output a dummy value ``\textbf{0??}'' (or less |
| 270 |
% likely ``\textbf{0a}'' or ``\textbf{1??}''). |
| 271 |
% |
| 272 |
% \DescribeMacro{\ChemMFCite\marg{key}} This macro always displays the |
| 273 |
% structure name of the main part of the key with the label for the |
| 274 |
% given key. The |MF| is a mnemonic for \textsf{main full} or |
| 275 |
% \textsf{mixed full}, indicating the full entry of the \textit{main} |
| 276 |
% (exemplar) name is used with the label and sub-label for the key. For |
| 277 |
% example |\ChemMFCite{acetate!methyl}| would give ``acetic acid ester |
| 278 |
% (\textbf{1a})'' wherever it was used. The non-star form also sets the |
| 279 |
% value of the numeric label at the point it first appears in the |
| 280 |
% document. The star form uses in order; the current label if defined or |
| 281 |
% a value stored in the \textsl{aux} file from the previous time the |
| 282 |
% document was processed or a dummy value. For example |
| 283 |
% |\ChemMFCite*{acetate!methyl}| could give ``acetic acid ester |
| 284 |
% (\textbf{1a})'' if it can determine the labels or output a dummy value |
| 285 |
% ``?? (\textbf{0??})'' or similar. |
| 286 |
% |
| 287 |
% \DescribeMacro{\ChemMSCite\marg{key}} This macro always displays just |
| 288 |
% the label from the main part of the key. The |MS| is a mnemonic for |
| 289 |
% \textsf{main short} or \textsf{mixed short}, indicating the short |
| 290 |
% entry of just the \textit{main} (exemplar) label for the key. For |
| 291 |
% example |\ChemMSCite{acetate!methyl}| would give ``\textbf{1}'' |
| 292 |
% wherever it was used. While this macro always gives exactly the same |
| 293 |
% result as |\ChemSCite| with just the main part of a key |
| 294 |
% (e.g. |\ChemSCite{acetate}|), it is included here because it allows |
| 295 |
% the document writer to include more context in the document as it is |
| 296 |
% being written. The non-star form also sets the value of the numeric |
| 297 |
% label at the point it first appears in the document. The star form |
| 298 |
% uses in order; the current label if defined or a value stored in the |
| 299 |
% \textsl{aux} file from the previous time the document was processed or |
| 300 |
% a dummy value. For example |\ChemMSCite*{acetate!methyl}| could give |
| 301 |
% ``\textbf{1}'' if it can determine the label or output a dummy value |
| 302 |
% ``\textbf{0}''. |
| 303 |
% |
| 304 |
% \DescribeMacro{\NoCite\marg{key}} This macro outputs nothing in the |
| 305 |
% document but sets the numeric value of the label for the key in the |
| 306 |
% document ordered sequence. |
| 307 |
% |
| 308 |
% \subsection{Possible Future extensions} |
| 309 |
% |
| 310 |
% \DescribeMacro{\ChemEntityTable} Output a table of entity names, |
| 311 |
% labels and keys. This is intended to be used for creating a useful |
| 312 |
% reference table when creating and editing a document rather than for |
| 313 |
% final output. |
| 314 |
% |
| 315 |
% \subsection{Internal macros that control style} |
| 316 |
% |
| 317 |
% Style macros can be overridden by the user to control the style of the |
| 318 |
% label and accompanying text. |
| 319 |
% |
| 320 |
% \DescribeMacro{\ChemLabelStyle} Internal macro that formats a |
| 321 |
% label. It is used by the other two style macros for this purpose. |
| 322 |
% Users may redefine this macro to change the label formatting. |
| 323 |
% |
| 324 |
% \DescribeMacro{\ChemFullLabelStyle} Internal macro used to format a |
| 325 |
% label and its full name text. Users may redefine this macro to change |
| 326 |
% the name and label formatting, particularly when you wish to format |
| 327 |
% the label and sub-label separately. |
| 328 |
% |
| 329 |
% \DescribeMacro{\ChemShortLabelStyle} Internal macro used to formats a |
| 330 |
% label without name text. Users may redefine this macro to change the |
| 331 |
% name and label formatting, particularly when you wish to format the |
| 332 |
% label and sub-label separately. |
| 333 |
% |
| 334 |
% \DescribeMacro{\ChemMainCounterStyle} Internal macro that converts the |
| 335 |
% counter used for main key label into a number or letter. The default |
| 336 |
% implementation uses |\arabic| to generate a number. Users may redefine |
| 337 |
% this macro to output letters instead of numbers. |
| 338 |
% |
| 339 |
% \DescribeMacro{\ChemSubCounterStyle} Converts the counter used for the |
| 340 |
% sub-key label into a number or letter. The default implementation uses |
| 341 |
% |\alph| to generate a letter. Users may redefine this macro to output |
| 342 |
% numbers instead of letters. |
| 343 |
% |
| 344 |
% \section{Design brief} |
| 345 |
% |
| 346 |
% This section contains a description of what this package sets out to |
| 347 |
% achieve. |
| 348 |
% The package should be able to consistently label an entity throughout |
| 349 |
% the document based on a user-defined key. The label can be either a |
| 350 |
% consecutive number or a user-defined label. These labels can be |
| 351 |
% combined with a sub-label, which can also be consecutive or |
| 352 |
% user-defined. |
| 353 |
% |
| 354 |
% When sub-labels are used a user-supplied key and sub-key are |
| 355 |
% required. Any entity associated with the key without a sub-key is |
| 356 |
% considered to be a generic entity for any entities defined with the |
| 357 |
% same key and a sub-key. |
| 358 |
% |
| 359 |
% \subsection{Limits} |
| 360 |
% |
| 361 |
% \begin{itemize} |
| 362 |
% \item The package can provide consecutive labels or user-defined |
| 363 |
% labels but not both. |
| 364 |
% |
| 365 |
% \item Unless user-defined labels are used, consecutive labels are |
| 366 |
% numeric for labels and alphabetic for sub-labels. |
| 367 |
% |
| 368 |
% \item The package can provide only a single set of consecutive labels. |
| 369 |
% |
| 370 |
% \item The package can provide consecutive sub-labels or user-defined |
| 371 |
% sub-labels but not both for each label. |
| 372 |
% \end{itemize} |
| 373 |
% |
| 374 |
% \subsection{Actions} |
| 375 |
% |
| 376 |
% \begin{itemize} |
| 377 |
% \item The first time the |\ChemCite| macros appear in the latex document |
| 378 |
% with a given key is where the consecutive number label for the key |
| 379 |
% is defined (unless user-defined label are being used). |
| 380 |
% |
| 381 |
% \item Using macros |\ChemCite*| provides the label without defining the |
| 382 |
% consecutive number label. This allows the label to appear, for |
| 383 |
% example in a table, abstract or figure, before the desired defining |
| 384 |
% location of the label. |
| 385 |
% |
| 386 |
% \item The names of entities can be defined anywhere in the document |
| 387 |
% and appear in a user-controlled manner. |
| 388 |
% |
| 389 |
% \item The basic macros typeset the entity name and label at the first |
| 390 |
% defining reference position and only the label in other places. |
| 391 |
% |
| 392 |
% \item A range of advanced macros allow greater control over the |
| 393 |
% display of the entity name and label. For example the user can |
| 394 |
% output a label and sub-label but use the name of the generic entity. |
| 395 |
% A chemistry example of this with ``ethyl acetate (1b)'' and its |
| 396 |
% generic entity ``acetic acid ester (1)'' appearing as ``\dots{}gives |
| 397 |
% the second acetic acid ester (1b)\dots{}''. |
| 398 |
% |
| 399 |
% \item The label will be typeset in a particular, user configurable, |
| 400 |
% style. The label should be consistently formatted, even in |
| 401 |
% math-mode. |
| 402 |
% |
| 403 |
% \item The label can be used transparently by other packages. For |
| 404 |
% example it can be used with the \textsf{psfrag} package to inject |
| 405 |
% the correct labels into figures at documentation preparation time |
| 406 |
% rather than having to recreate new figures whenever the label |
| 407 |
% numbering changes. |
| 408 |
% |
| 409 |
% \end{itemize} |
| 410 |
% |
| 411 |
% \section{Package options} |
| 412 |
% |
| 413 |
% The package has two options. Both options are intended to be used |
| 414 |
% when debugging the package or its usage. Control of the style used |
| 415 |
% when typesetting names and labels is optionally done manually by |
| 416 |
% redefining the style control macros described elsewhere. |
| 417 |
% |
| 418 |
% \begin{description} |
| 419 |
% \item[|draft|] Output structure/entity key as a superscript before |
| 420 |
% any name and/or label output. This can be useful during document |
| 421 |
% preparation. |
| 422 |
% \item[|debug|] Output extra information in the processing log to do |
| 423 |
% with the operation of the package and turn on |draft| mode. |
| 424 |
% \end{description} |
| 425 |
% |
| 426 |
% \section{Implementation} |
| 427 |
% |
| 428 |
% The package creates a virtual mapping of keys to a name and a |
| 429 |
% label. The key is stored as |Main!Sub| if the key has a sub-key. This |
| 430 |
% mapping is stored into the \textsf{aux} file where it is read at the |
| 431 |
% start of each document processing. If the mapping is altered during |
| 432 |
% processing the user gets a warning to reprocess the document, similar |
| 433 |
% to other automatically created indices. |
| 434 |
% |
| 435 |
% The package has several sets of macros. The public macros are used to |
| 436 |
% define the key to name mapping and to lookup and output the names and |
| 437 |
% labels based on the key during document processing. One set of |
| 438 |
% internal macros defines the style used to display the name and |
| 439 |
% labels. These macros can be redefined by the user. A second set of |
| 440 |
% internal macros controls the definition and management of the map |
| 441 |
% data. A third set controls logging information and extra output that |
| 442 |
% might be used during testing. |
| 443 |
% |
| 444 |
% This uses a simple first cited first numbered algorithm to generate a |
| 445 |
% unique sequential label for a set of compounds. It relies on a set of |
| 446 |
% chemical definitions that can appear anywhere in the text and are |
| 447 |
% stored in the ``aux'' file at program termination and read in at |
| 448 |
% program start up. |
| 449 |
% |
| 450 |
% Note on programming style. All the functions are declared using LaTeX |
| 451 |
% commands unless using TeX functions |edef|, |gdef| and |xdef| were |
| 452 |
% required. The public functions have been defined using LaTeX2e's |
| 453 |
% |DeclareRobustCommand*{}|. |
| 454 |
% |
| 455 |
% \StopEventually{} |
| 456 |
% |
| 457 |
% \subsection{Output Style Macros} |
| 458 |
% |
| 459 |
% \begin{macro}{\ChemLabelStyle} \marg{label} The default implementation |
| 460 |
% formats the label in a sloping bold font. |
| 461 |
% \begin{macrocode} |
| 462 |
\DeclareRobustCommand*{\ChemLabelStyle}[1]{% |
| 463 |
\textsl{\bfseries{}#1}} |
| 464 |
% \end{macrocode} |
| 465 |
% \end{macro} |
| 466 |
% |
| 467 |
% \begin{macro}{\ChemFullLabelStyle} |
| 468 |
% \marg{full name} \marg{main label} \marg{sub-label} Formats the full |
| 469 |
% entity name and label. The default implementation does not format |
| 470 |
% the entity name, simply forwarding the argument as-is. The default |
| 471 |
% implementation appends the sub-key label to the main label and uses |
| 472 |
% the |\ChemLabelStyle| to format them together. |
| 473 |
% \begin{macrocode} |
| 474 |
\DeclareRobustCommand*{\ChemFullLabelStyle}[3]{% |
| 475 |
\ifthenelse{\equal{}{#3}}{% |
| 476 |
#1 (\ChemLabelStyle{#2})% |
| 477 |
}{% |
| 478 |
#1 (\ChemLabelStyle{#2#3})% |
| 479 |
}% |
| 480 |
}% |
| 481 |
% \end{macrocode} |
| 482 |
% \end{macro} |
| 483 |
% |
| 484 |
% \begin{macro}{\ChemShortLabelStyle} |
| 485 |
% \marg{main label} \marg{sub-label} Formats the labels when they |
| 486 |
% appear without the entity name. The default implementation appends |
| 487 |
% the sub-key label to the main label and uses the |\ChemLabelStyle| |
| 488 |
% to format them together. |
| 489 |
% \begin{macrocode} |
| 490 |
\DeclareRobustCommand*{\ChemShortLabelStyle}[2]{% |
| 491 |
\ifthenelse{\equal{}{#2}}{% |
| 492 |
\ChemLabelStyle{#1}% |
| 493 |
}{% |
| 494 |
\ChemLabelStyle{#1#2}% |
| 495 |
}% |
| 496 |
}% |
| 497 |
% \end{macrocode} |
| 498 |
% \end{macro} |
| 499 |
% |
| 500 |
% \begin{macro}{\ChemMainCounterStyle}\marg{counter} |
| 501 |
% Converts the counter used for the main key label into a number or |
| 502 |
% letter. The default implementation uses |\arabic| to generate a |
| 503 |
% number. |
| 504 |
% \begin{macrocode} |
| 505 |
\DeclareRobustCommand*{\ChemMainCounterStyle}[1]{% |
| 506 |
\arabic{#1}} |
| 507 |
% \end{macrocode} |
| 508 |
% \end{macro} |
| 509 |
% |
| 510 |
% \begin{macro}{\ChemSubCounterStyle}\marg{counter} |
| 511 |
% Converts the counter used for the sub-key label into a number or |
| 512 |
% letter. The default implementation uses |\alph| to generate a |
| 513 |
% letter. |
| 514 |
% \begin{macrocode} |
| 515 |
\DeclareRobustCommand*{\ChemSubCounterStyle}[1]{% |
| 516 |
\alph{#1}} |
| 517 |
% \end{macrocode} |
| 518 |
% \end{macro} |
| 519 |
% |
| 520 |
% \subsection{Macros for Debugging and Draft Output} |
| 521 |
% |
| 522 |
% Several macros are defined to implement the |draft| and |debug| |
| 523 |
% package options. When these options are not used these macros fall |
| 524 |
% back on default implementations that mostly do nothing. These macros |
| 525 |
% are redefined when the options are used. |
| 526 |
% |
| 527 |
% \begin{macro}{\CN@DEBUG} |
| 528 |
% Internal macro used to suppress debugging messages when not |
| 529 |
% debugging. This is redefined if the |debug| package option is used |
| 530 |
% to output debugging messages in the processing log. |
| 531 |
% \begin{macrocode} |
| 532 |
\makeatletter |
| 533 |
\gdef\CN@DEBUG #1#2{} |
| 534 |
% \end{macrocode} |
| 535 |
% \end{macro} |
| 536 |
% \begin{macro}{\CN@WARN} |
| 537 |
% Internal macro used to output errors and warnings as information |
| 538 |
% messages when not debugging. This is redefined if the |debug| option |
| 539 |
% is used to promote these messages to warning messages in the |
| 540 |
% processing log. |
| 541 |
% \begin{macrocode} |
| 542 |
\gdef\CN@WARN #1#2{\PackageInfo{#1}{#2}} |
| 543 |
% \end{macrocode} |
| 544 |
% \end{macro} |
| 545 |
% \begin{macro}{\CN@DRAFT} |
| 546 |
% Internal macro used to suppress draft only output when not in draft |
| 547 |
% mode. This is redefined if the |debug| or |draft| option is used to |
| 548 |
% add superscript text in the output document. |
| 549 |
% \begin{macrocode} |
| 550 |
\gdef\CN@DRAFT #1{} |
| 551 |
% \end{macrocode} |
| 552 |
% \end{macro} |
| 553 |
% |
| 554 |
% \subsection{Options for Debugging and Draft Output} |
| 555 |
% |
| 556 |
% The package has several options to help with using the package. |
| 557 |
% |
| 558 |
% \begin{itemize} |
| 559 |
% \item The \textsf{debug} option generates more error and warning |
| 560 |
% messages as well as outputting draft data. It does this by redefining |
| 561 |
% the |\CN@DEBUG|, |\CN@WARN| and |\CN@DRAFT| macros. |
| 562 |
% \begin{macrocode} |
| 563 |
\DeclareOption{debug}{% |
| 564 |
\gdef\CN@DEBUG #1#2{\PackageInfo{#1}{#2}}% |
| 565 |
\gdef\CN@WARN #1#2{\PackageWarning{#1}{#2}}% |
| 566 |
\gdef\CN@DRAFT #1{$^{[#1]}$}% |
| 567 |
} |
| 568 |
% \end{macrocode} |
| 569 |
% \item The \textsf{draft} option outputs some draft data. It does this |
| 570 |
% by redefining the |\CN@DRAFT| macro. |
| 571 |
% \begin{macrocode} |
| 572 |
\DeclareOption{draft}{% |
| 573 |
\gdef\CN@DRAFT #1{$^{[#1]}$}% |
| 574 |
} \ProcessOptions |
| 575 |
% \end{macrocode} |
| 576 |
% \end{itemize} |
| 577 |
% |
| 578 |
% \subsection{Counters} |
| 579 |
% |
| 580 |
% Several counters are used internally for generating the label |
| 581 |
% values. They should not be manually altered by the user. |
| 582 |
% |
| 583 |
% \begin{itemize} |
| 584 |
% \item |CN@MaxLabelIndex| tracks the maximum label index. |
| 585 |
% \begin{macrocode} |
| 586 |
\newcounter{CN@MaxLabelIndex} |
| 587 |
\setcounter{CN@MaxLabelIndex}{0} |
| 588 |
% \end{macrocode} |
| 589 |
% \item |CN@LabelIndex| is the number of the current label. |
| 590 |
% \begin{macrocode} |
| 591 |
\newcounter{CN@LabelIndex} |
| 592 |
% \end{macrocode} |
| 593 |
% \item |CN@SubLabelIndex| is the number of the current sub-key label |
| 594 |
% \begin{macrocode} |
| 595 |
\newcounter{CN@SubLabelIndex} |
| 596 |
% \end{macrocode} |
| 597 |
% \end{itemize} |
| 598 |
% |
| 599 |
% \subsection{Internal Variables} |
| 600 |
% |
| 601 |
% \begin{itemize} |
| 602 |
% \item |\CN@@label| is a dummy value used when no label is found for a |
| 603 |
% particular key. This is a guard value for erroneous usage. |
| 604 |
% \begin{macrocode} |
| 605 |
\expandafter\def\csname CN@@label\endcsname{999} |
| 606 |
% \end{macrocode} |
| 607 |
% \item |\CN@@name| is a dummy name used when no name is found for a |
| 608 |
% particular key. This is a guard value for erroneous usage. |
| 609 |
% \begin{macrocode} |
| 610 |
\expandafter\def\csname CN@@name\endcsname{X} |
| 611 |
% \end{macrocode} |
| 612 |
% \item |\CN@@sublabel| is a dummy sub-label used when no label is found |
| 613 |
% for a particular key/sub-key. This is a guard value for erroneous |
| 614 |
% usage. |
| 615 |
% \begin{macrocode} |
| 616 |
\expandafter\def\csname CN@@sublabel\endcsname{X} |
| 617 |
% \end{macrocode} |
| 618 |
% \item |CN@KeyFound| is a boolean to signal whether the key was found |
| 619 |
% in the key list. Failure to be found indicates that this is the first |
| 620 |
% time this key was cited. |
| 621 |
% \begin{macrocode} |
| 622 |
\newboolean{CN@KeyFound} |
| 623 |
% \end{macrocode} |
| 624 |
% \item |CN@ScanList| is a boolean to signal whether the key was found |
| 625 |
% in the last loop of the map scan. |
| 626 |
% \begin{macrocode} |
| 627 |
\newboolean{CN@ScanList} |
| 628 |
% \end{macrocode} |
| 629 |
% \item |CN@Star| is a boolean that signals that a macro was called |
| 630 |
% using the star form of the command. This alters |CN@getLabel| and |
| 631 |
% |CN@getSubLabel| to use predefined labels (if any) instead of labels |
| 632 |
% defined in the regular document flow. |
| 633 |
% \begin{macrocode} |
| 634 |
\newboolean{CN@Star} |
| 635 |
\setboolean{CN@Star}{false} |
| 636 |
% \end{macrocode} |
| 637 |
% \item |CN@Warning| is a boolean that signals that the document has |
| 638 |
% possible incorrect labels and needs to be reprocessed. This is |
| 639 |
% similar to other places where LaTeX generates warnings |
| 640 |
% for automatically generated labels. |
| 641 |
% \begin{macrocode} |
| 642 |
\newboolean{CN@Warning} |
| 643 |
\setboolean{CN@Warning}{false} |
| 644 |
\AtEndDocument{% |
| 645 |
\ifthenelse{\boolean{CN@Warning}}{% |
| 646 |
\PackageWarningNoLine{chemsec}{Chemsec-label(s) were used before they were |
| 647 |
defined or were never defined. Rerun to get chemsec-labels right. If |
| 648 |
this warning message persists check that all names and labels have been |
| 649 |
defined in the text}% |
| 650 |
}{%else |
| 651 |
% do nothing |
| 652 |
}%end if |
| 653 |
}%end def |
| 654 |
% \end{macrocode} |
| 655 |
% \end{itemize} |
| 656 |
% |
| 657 |
% \subsection{Internal Macros} |
| 658 |
% |
| 659 |
% \begin{macro}{\CN@mainpartofkey} |
| 660 |
% Splits the representation of a key as |Main!Sub|, returning only the |
| 661 |
% |Main| part. |
| 662 |
% \begin{macrocode} |
| 663 |
\gdef\CN@mainpartofkey (#1!#2){#1} |
| 664 |
% \end{macrocode} |
| 665 |
% \end{macro} |
| 666 |
% |
| 667 |
% \begin{macro}{\CN@MainKey} |
| 668 |
% Acts as a driver macro for |\CN@mainpartofkey| macro. |
| 669 |
% \begin{macrocode} |
| 670 |
\gdef\CN@MainKey (#1){\CN@mainpartofkey(#1!)}% |
| 671 |
% \end{macrocode} |
| 672 |
% \end{macro} |
| 673 |
% |
| 674 |
% \begin{macro}{\CN@definenewchemical}\marg{main!sub |
| 675 |
% key}\marg{name}\marg{sub-label} |
| 676 |
% Associate a key with a chemical name and sub-label. The instances of |
| 677 |
% this macro written in the \textsf{aux} file are what define the |
| 678 |
% current mapping of key to names and sub-labels. There is a check to |
| 679 |
% make sure the key is unique but there is no check that the sub-label |
| 680 |
% is unique. |
| 681 |
% |
| 682 |
% This macro is the main macro that creates the table of key name and |
| 683 |
% labels that is used by the other macros to generate output in the |
| 684 |
% document. |
| 685 |
% \begin{macrocode} |
| 686 |
\DeclareRobustCommand*{\CN@definenewchemical}[3]{%key, name, label |
| 687 |
% check for previous definition of name |
| 688 |
\ifcsname CN@#1@label\endcsname%ifdef |
| 689 |
% previous definition, do nothing |
| 690 |
\CN@DEBUG{chemsec}{Attempt to redefine key "#1" ignored.}% |
| 691 |
\else% |
| 692 |
% label not defined |
| 693 |
\CN@DEBUG{chemsec}{Defining new compound with key "#1". Name is "#2", sub-label is "#3".}% |
| 694 |
\expandafter\gdef\csname CN@#1@label\endcsname{0}% |
| 695 |
\expandafter\gdef\csname CN@#1@name\endcsname{#2}% |
| 696 |
\ifthenelse{\equal{#3}{-}}{%if no sub-label |
| 697 |
}{%else |
| 698 |
\ifthenelse{\equal{#3}{}}{%if no sub-label |
| 699 |
}{%else |
| 700 |
\expandafter\gdef\csname CN@#1@sublabel\endcsname{#3}% |
| 701 |
}%end if |
| 702 |
}%end if |
| 703 |
\fi% |
| 704 |
}% |
| 705 |
% \end{macrocode} |
| 706 |
% \end{macro} |
| 707 |
% |
| 708 |
% \begin{macro}{\CN@defineLabelUsed} \marg{main!sub key} \marg{label |
| 709 |
% index} Associate a label with a |main| key. The instances of this |
| 710 |
% macro written in the \textsf{aux} file are what define the mapping |
| 711 |
% of key to label used to typeset a label before a macro call that |
| 712 |
% defines the position of the key in document order, and hence its |
| 713 |
% true label. |
| 714 |
% \begin{macrocode} |
| 715 |
\DeclareRobustCommand*{\CN@defineLabelUsed}[2]{%key, label |
| 716 |
% check for previous definition of name |
| 717 |
\ifcsname CN@#1@labelUsed\endcsname%ifdef |
| 718 |
\CN@DEBUG{chemsec}{Attempt to redefine label for key "#1" ignored.}% |
| 719 |
\else |
| 720 |
% label not defined |
| 721 |
\expandafter\gdef\csname CN@#1@labelUsed\endcsname{#2}% |
| 722 |
\CN@DEBUG{chemsec}{defineLabelUsed: Presetting label of key "#1" to "#2" -> "\csname CN@#1@labelUsed\endcsname"}% |
| 723 |
\fi% |
| 724 |
} |
| 725 |
% \end{macrocode} |
| 726 |
% \end{macro} |
| 727 |
% |
| 728 |
% \begin{macro}{\CN@defineSublabelUsed} \marg{main!sub key} |
| 729 |
% \marg{label value} |
| 730 |
% Associate a sublabel with a |main!sub| key. The instances of this macro written in |
| 731 |
% the \textsf{aux} file are what define the mapping of key to sublabel |
| 732 |
% used to typeset a sublabel before a macro call that defines the position |
| 733 |
% of the key in document order, and hence its true sublabel. |
| 734 |
% \begin{macrocode} |
| 735 |
\DeclareRobustCommand*{\CN@defineSublabelUsed}[2]{%key, sublabel |
| 736 |
% check for previous definition of name |
| 737 |
\ifcsname CN@#1@sublabelUsed\endcsname%ifdef |
| 738 |
\CN@DEBUG{chemsec}{Attempt to redefine sublabel for key "#1" ignored.}% |
| 739 |
\else |
| 740 |
% label not defined |
| 741 |
\expandafter\gdef\csname CN@#1@sublabelUsed\endcsname{#2}% |
| 742 |
|
| 743 |
\CN@DEBUG{chemsec}{defineLabelUsed: Presetting sublabel of key "#1" to "#2" -> "\csname CN@#1@sublabelUsed\endcsname"}% |
| 744 |
\fi% |
| 745 |
} |
| 746 |
% \end{macrocode} |
| 747 |
% \end{macro} |
| 748 |
% |
| 749 |
% \begin{macro}{\CN@GetFullName} |
| 750 |
% Check that a name is defined for the given key. If no name exists |
| 751 |
% then check using only the |Main| part of a |Main!Sub| key. If still no |
| 752 |
% name is found then output ``|??|'' and print an error message to the |
| 753 |
% processing log. |
| 754 |
% \begin{macrocode} |
| 755 |
\DeclareRobustCommand*{\CN@GetFullName}[1]{% |
| 756 |
\ifcsname CN@#1@name\endcsname%if name |
| 757 |
% use my own name |
| 758 |
\csname CN@#1@name\endcsname% |
| 759 |
\else% |
| 760 |
\ifcsname CN@\CN@MainKey(#1)@name\endcsname%if main key name |
| 761 |
% Use main key name |
| 762 |
\csname CN@\CN@MainKey(#1)@name\endcsname% |
| 763 |
\else% |
| 764 |
\CN@WARN{chemsec}{Attempt to find name for key "#1" failed.}% |
| 765 |
\setboolean{CN@Warning}{true}% |
| 766 |
??% |
| 767 |
\fi%endif main |
| 768 |
\fi%endif full key |
| 769 |
}% |
| 770 |
% \end{macrocode} |
| 771 |
% \end{macro} |
| 772 |
% |
| 773 |
% \begin{macro}{\CN@GetLabel} |
| 774 |
% Check that a label is defined for the given key. If no label exists |
| 775 |
% then check using only the |Main| part of a |Main!Sub| key. If still |
| 776 |
% no label is found then if the star form is used output the value of |
| 777 |
% the label from the previous time the document was processed |
| 778 |
% (actually the value from |\CN@defineLabelUsed| calls in the |
| 779 |
% \textsl{aux} file) or |0| (zero). If the not a star form then the |
| 780 |
% label is calculated by incrementing the |
| 781 |
% \textsf{CN\@{}MaxLabelIndex}. This also writes a call to |
| 782 |
% |\CN@defineLabelUsed| in the \textsl{aux} for the next processing |
| 783 |
% run. |
| 784 |
% \begin{macrocode} |
| 785 |
\DeclareRobustCommand*{\CN@GetLabel}[3]{% key, foundbool, |
| 786 |
% indexcount |
| 787 |
\setboolean{#2}{true}% |
| 788 |
\CN@DEBUG{chemsec}{GetLabel: looking for '#1'}% |
| 789 |
\setcounter{#3}{\csname CN@#1@label\endcsname}% |
| 790 |
\CN@DEBUG{chemsec}{GetLabel: Label count is \arabic{#3}}% |
| 791 |
\CN@DEBUG{chemsec}{GetLabel: Star form is {\ifCN@Star true\else false\fi}}% |
| 792 |
\ifthenelse{\value{#3} = 0}{% |
| 793 |
%% label has NOT been defined |
| 794 |
\CN@DEBUG{chemsec}{GetLabel: No local label for key '#1' is defined.}% |
| 795 |
\ifthenelse{\boolean{CN@Star}}{% |
| 796 |
%% Star form means can only use predefined value |
| 797 |
\ifcsname CN@#1@labelUsed\endcsname% have predefined value |
| 798 |
\CN@DEBUG{chemsec}{GetLabel: Predefined label for key '#1' is \csname CN@#1@labelUsed\endcsname.}% |
| 799 |
\setcounter{#3}{\csname CN@#1@labelUsed\endcsname}% |
| 800 |
\else% no predefined, set warning |
| 801 |
\setboolean{CN@Warning}{true}% |
| 802 |
\CN@DEBUG{chemsec}{GetLabel: No predefined label for key '#1'.}% |
| 803 |
\fi% |
| 804 |
}{% |
| 805 |
%% Non-star form means calculate value |
| 806 |
\CN@DEBUG{chemsec}{GetLabel: MaxLabelIndex is \arabic{CN@MaxLabelIndex}}% |
| 807 |
\stepcounter{CN@MaxLabelIndex}% |
| 808 |
\CN@DEBUG{chemsec}{GetLabel: Increment MaxLabelIndex to \arabic{CN@MaxLabelIndex}}% |
| 809 |
\expandafter\xdef\csname CN@#1@label\endcsname{\arabic{CN@MaxLabelIndex}}% |
| 810 |
\write\@auxout{\string\CN@defineLabelUsed{#1}{\csname CN@#1@label\endcsname}}% |
| 811 |
\setcounter{#3}{\csname CN@#1@label\endcsname}% |
| 812 |
\setboolean{#2}{false}% |
| 813 |
%% Check that @labelUsed matches @label or set @Warning |
| 814 |
\ifcsname CN@#1@labelUsed\endcsname% |
| 815 |
\ifthenelse{\equal{\csname CN@#1@labelUsed\endcsname}{\csname CN@#1@label\endcsname}}{% predefined label matches label - do nothing |
| 816 |
}{% predefined does not match. |
| 817 |
\CN@DEBUG{chemsec}{GetLabel: Local label does not match predefined label} |
| 818 |
\setboolean{CN@Warning}{true}% |
| 819 |
}% |
| 820 |
\fi |
| 821 |
}% |
| 822 |
}{%else |
| 823 |
% do nothing |
| 824 |
}%end if def to 0 |
| 825 |
\CN@DEBUG{chemsec}{GetLabel: Result counter \arabic{#3}}% |
| 826 |
}%end def |
| 827 |
% \end{macrocode} |
| 828 |
% \end{macro} |
| 829 |
% |
| 830 |
% \begin{macro}{\CN@GetSubLabel} |
| 831 |
% Check that a sublabel is defined for the given key. If the star form |
| 832 |
% is used output the value of the label from the previous time the |
| 833 |
% document was processed (actually the value from |
| 834 |
% |\CN@defineSubLabelUsed| calls in the \textsl{aux} file) or |??|. If |
| 835 |
% not a star form and no sublabel exists then try and calculate a |
| 836 |
% value based on the number of keys having the same |Main| part of the |
| 837 |
% |Main!Sub| key. This also writes a call to |\CN@defineSubLabelUsed| |
| 838 |
% in the \textsl{aux} for the next processing run. |
| 839 |
% \begin{macrocode} |
| 840 |
\DeclareRobustCommand*{\CN@GetSubLabel}[3]{% key, found?, return-element |
| 841 |
\setboolean{#2}{true}% |
| 842 |
\CN@DEBUG{chemsec}{GetSubLabel: looking for sublabel of '#1'}% |
| 843 |
\ifthenelse{\equal{\CN@MainKey(#1)}{#1}}{%if a main key |
| 844 |
\CN@DEBUG{chemsec}{GetSubLabel: '#1' is a main key .: no sublabel}% |
| 845 |
\xdef#3{}% |
| 846 |
}{%else |
| 847 |
\ifcsname CN@#1@sublabel\endcsname%if defined |
| 848 |
\CN@DEBUG{chemsec}{GetSubLabel: Sublabel previously defined as '\csname |
| 849 |
CN@#1@sublabel\endcsname'}% |
| 850 |
\xdef#3{\csname CN@#1@sublabel\endcsname}% |
| 851 |
\else% else need to define sublabel |
| 852 |
\setboolean{#2}{false}% |
| 853 |
\ifthenelse{\boolean{CN@Star}}{% |
| 854 |
% Star form means can only use predefined value |
| 855 |
\ifcsname CN@#1@sublabelUsed\endcsname% have predefined value |
| 856 |
\CN@DEBUG{chemsec}{GetSubLabel: Predefined sublabel for key '#1' is \csname CN@#1@sublabelUsed\endcsname.}% |
| 857 |
\xdef#3{\csname CN@#1@sublabelUsed\endcsname}% |
| 858 |
\else% no predefined, set warning |
| 859 |
\setboolean{CN@Warning}{true}% |
| 860 |
\CN@DEBUG{chemsec}{GetSubLabel: No predefined sublabel for key |
| 861 |
'#1'.}% |
| 862 |
\xdef#3{??}% |
| 863 |
\fi% |
| 864 |
}{% |
| 865 |
\CN@DEBUG{chemsec}{GetSubLabel: Sublabel not previously defined}% |
| 866 |
\ifcsname CN@\CN@MainKey(#1)@sublabel\endcsname%if |
| 867 |
% main key def |
| 868 |
\setcounter{CN@SubLabelIndex}{\csname CN@\CN@MainKey(#1)@sublabel\endcsname}% |
| 869 |
\else% |
| 870 |
\setcounter{CN@SubLabelIndex}{0}% |
| 871 |
\fi% |
| 872 |
\CN@DEBUG{chemsec}{GetSubLabel: Highest label for these keys is |
| 873 |
\arabic{CN@SubLabelIndex}.}% |
| 874 |
\stepcounter{CN@SubLabelIndex}% |
| 875 |
\expandafter\xdef\csname CN@\CN@MainKey(#1)@sublabel\endcsname{\arabic{CN@SubLabelIndex}}% |
| 876 |
\expandafter\xdef\csname CN@#1@sublabel\endcsname{\ChemSubCounterStyle{CN@SubLabelIndex}}% |
| 877 |
\write\@auxout{\string\CN@defineSublabelUsed{#1}{\csname CN@#1@sublabel\endcsname}}% |
| 878 |
\CN@DEBUG{chemsec}{GetSubLabel: Sublabel now defined as '\csname |
| 879 |
CN@#1@sublabel\endcsname'}% |
| 880 |
\xdef#3{\csname CN@#1@sublabel\endcsname}% |
| 881 |
}% |
| 882 |
\fi%end if |
| 883 |
}%end if |
| 884 |
}% enddef |
| 885 |
% \end{macrocode} |
| 886 |
% \end{macro} |
| 887 |
% |
| 888 |
% \begin{macro}{\CN@RealCite} |
| 889 |
% Search for the label and sublabel for a given key. |
| 890 |
% \begin{macrocode} |
| 891 |
\DeclareRobustCommand*{\CN@RealCite}[4]{%key, |
| 892 |
% found, index-counter, |
| 893 |
% sub |
| 894 |
\CN@DRAFT{#1}% |
| 895 |
\CN@DEBUG{chemsec}{In RealCite}% |
| 896 |
\setcounter{#3}{0}% |
| 897 |
\setcounter{CN@SubLabelIndex}{0}% |
| 898 |
\setboolean{#2}{false}% |
| 899 |
\xdef#4{}% |
| 900 |
\CN@DEBUG{chemsec}{Real: calling GetLabel for '\CN@MainKey(#1)', the main |
| 901 |
part of '#1'}% |
| 902 |
\CN@GetLabel{\CN@MainKey(#1)}{#2}{#3}% |
| 903 |
\CN@DEBUG{chemsec}{Real: calling GetSubLabel for "#1"}% |
| 904 |
\CN@GetSubLabel{#1}{CN@ScanList}{#4}% |
| 905 |
}%end def |
| 906 |
% \end{macrocode} |
| 907 |
% \end{macro} |
| 908 |
% |
| 909 |
% \begin{macro}{\NoCite} |
| 910 |
% Search for the label and sublabel for a given key without producing |
| 911 |
% any output. This can be used to define the label associated with a |
| 912 |
% key without anything being typeset in the document. |
| 913 |
% \begin{macrocode} |
| 914 |
\DeclareRobustCommand*{\NoCite}[1]{% |
| 915 |
\CN@RealCite{#1}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 916 |
} |
| 917 |
% \end{macrocode} |
| 918 |
% \end{macro} |
| 919 |
% |
| 920 |
% \begin{macro}{\CN@ChemCite} |
| 921 |
% Output name, label and sublabel for a given key. The name is output |
| 922 |
% only if |CN@KeyFound| is \textsf{false} which occurs the first time |
| 923 |
% a key is cited. |
| 924 |
% \begin{macrocode} |
| 925 |
\DeclareRobustCommand*{\CN@ChemCite}[1]{% |
| 926 |
% \CN@DEBUG{chemsec}{in Chemcite}% |
| 927 |
\CN@RealCite{#1}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 928 |
% \CN@DEBUG{chemsec}{Cite: called Real}% |
| 929 |
\ifthenelse{\boolean{CN@KeyFound}}{% |
| 930 |
% \CN@DEBUG{chemsec}{Cite: key found, use Short}% |
| 931 |
\ChemShortLabelStyle{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 932 |
}{%else |
| 933 |
% \CN@DEBUG{chemsec}{Cite: key not found, use Long}% |
| 934 |
\ChemFullLabelStyle{\CN@GetFullName{#1}}{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 935 |
}% |
| 936 |
}% |
| 937 |
% \end{macrocode} |
| 938 |
% \end{macro} |
| 939 |
% |
| 940 |
% \begin{macro}{\CN@ChemFCite} |
| 941 |
% Output name, label and sublabel for a given key. The name is always |
| 942 |
% output. |
| 943 |
% \begin{macrocode} |
| 944 |
\DeclareRobustCommand*{\CN@ChemFCite}[1]{% |
| 945 |
% \CN@DEBUG{chemsec}{in ChemFullCite}% |
| 946 |
\CN@RealCite{#1}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 947 |
% \CN@DEBUG{chemsec}{Cite: called Real}% |
| 948 |
\ChemFullLabelStyle{\CN@GetFullName{#1}}{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 949 |
}% |
| 950 |
% \end{macrocode} |
| 951 |
% \end{macro} |
| 952 |
% |
| 953 |
% \begin{macro}{\CN@ChemSCite} |
| 954 |
% Output label and sublabel for a given key. The name is never output. |
| 955 |
% \begin{macrocode} |
| 956 |
\DeclareRobustCommand*{\CN@ChemSCite}[1]{% |
| 957 |
% \CN@DEBUG{chemsec}{in ChemShortCite}% |
| 958 |
\CN@RealCite{#1}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 959 |
% \CN@DEBUG{chemsec}{SCite: called Real}% |
| 960 |
\ChemShortLabelStyle{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 961 |
}% |
| 962 |
% \end{macrocode} |
| 963 |
% \end{macro} |
| 964 |
% |
| 965 |
% \begin{macro}{\CN@ChemMFCite} |
| 966 |
% Output name associated with the |Main| part of the |Main!Sub| key as |
| 967 |
% well as the label \textit{and} sublabel. |
| 968 |
% \begin{macrocode} |
| 969 |
\DeclareRobustCommand*{\CN@ChemMFCite}[1]{% |
| 970 |
% \CN@DEBUG{chemsec}{in ChemMainFullCite}% |
| 971 |
\CN@RealCite{\CN@MainKey(#1)}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 972 |
% \CN@DEBUG{chemsec}{Cite: called Real}% |
| 973 |
\ChemFullLabelStyle{\CN@GetFullName{\CN@MainKey(#1)}}{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 974 |
}% |
| 975 |
% \end{macrocode} |
| 976 |
% \end{macro} |
| 977 |
% |
| 978 |
% \begin{macro}{\CN@ChemMSCite} |
| 979 |
% Output the label for the |Main| part of the |Main!Sub| key. |
| 980 |
% \begin{macrocode} |
| 981 |
\DeclareRobustCommand*{\CN@ChemMSCite}[1]{% |
| 982 |
% \CN@DEBUG{chemsec}{in ChemMainShortCite}% |
| 983 |
\CN@RealCite{\CN@MainKey{#1}}{CN@KeyFound}{CN@LabelIndex}{\CN@SubLabel}% |
| 984 |
% \CN@DEBUG{chemsec}{SCite: called Real}% |
| 985 |
\ChemShortLabelStyle{\ChemMainCounterStyle{CN@LabelIndex}}{\CN@SubLabel}% |
| 986 |
}% |
| 987 |
% \end{macrocode} |
| 988 |
% \end{macro} |
| 989 |
% |
| 990 |
% \begin{macro}{\CN@ChemCiteStar} |
| 991 |
% Set |CN@Star| boolean before calling base |\CN@ChemCite|. |
| 992 |
% \begin{macrocode} |
| 993 |
\DeclareRobustCommand*{\CN@ChemCiteStar}[1]{% |
| 994 |
% \CN@DEBUG{chemsec}{in Chemcite}% |
| 995 |
\setboolean{CN@Star}{true}% |
| 996 |
\CN@ChemCite{#1}% |
| 997 |
\setboolean{CN@Star}{false}% |
| 998 |
} |
| 999 |
% \end{macrocode} |
| 1000 |
% \end{macro} |
| 1001 |
% |
| 1002 |
% \begin{macro}{\CN@ChemFCiteStar} |
| 1003 |
% Set |CN@Star| boolean before calling base |\CN@ChemFCite|. |
| 1004 |
% \begin{macrocode} |
| 1005 |
\DeclareRobustCommand*{\CN@ChemFCiteStar}[1]{% |
| 1006 |
% \CN@DEBUG{chemsec}{in ChemFullCite}% |
| 1007 |
\setboolean{CN@Star}{true}% |
| 1008 |
\CN@ChemFCite{#1}% |
| 1009 |
\setboolean{CN@Star}{false}% |
| 1010 |
}% |
| 1011 |
% \end{macrocode} |
| 1012 |
% \end{macro} |
| 1013 |
% |
| 1014 |
% \begin{macro}{\CN@ChemSCiteStar} |
| 1015 |
% Set |CN@Star| boolean before calling base |\CN@ChemSCite|. |
| 1016 |
% \begin{macrocode} |
| 1017 |
\DeclareRobustCommand*{\CN@ChemSCiteStar}[1]{% |
| 1018 |
% \CN@DEBUG{chemsec}{in ChemShortCite}% |
| 1019 |
\setboolean{CN@Star}{true}% |
| 1020 |
\CN@ChemSCite{#1}% |
| 1021 |
\setboolean{CN@Star}{false}% |
| 1022 |
}% |
| 1023 |
% \end{macrocode} |
| 1024 |
% \end{macro} |
| 1025 |
% |
| 1026 |
% \begin{macro}{\CN@ChemMFCiteStar} |
| 1027 |
% Set |CN@Star| boolean before calling base |\CN@ChemMFCite|. |
| 1028 |
% \begin{macrocode} |
| 1029 |
\DeclareRobustCommand*{\CN@ChemMFCiteStar}[1]{% |
| 1030 |
% \CN@DEBUG{chemsec}{in ChemMainFullCite}% |
| 1031 |
\setboolean{CN@Star}{true}% |
| 1032 |
\CN@ChemMFCite{#1}% |
| 1033 |
\setboolean{CN@Star}{false}% |
| 1034 |
}% |
| 1035 |
% \end{macrocode} |
| 1036 |
% \end{macro} |
| 1037 |
% |
| 1038 |
% \begin{macro}{\CN@ChemMSCiteStar} |
| 1039 |
% Set |CN@Star| boolean before calling base |\CN@ChemMSCite|. |
| 1040 |
% \begin{macrocode} |
| 1041 |
\DeclareRobustCommand*{\CN@ChemMSCiteStar}[1]{% |
| 1042 |
% \CN@DEBUG{chemsec}{in ChemMainShortCite}% |
| 1043 |
\setboolean{CN@Star}{true}% |
| 1044 |
\CN@ChemMSCite{#1}% |
| 1045 |
\setboolean{CN@Star}{false}% |
| 1046 |
}% |
| 1047 |
% \end{macrocode} |
| 1048 |
% \end{macro} |
| 1049 |
% |
| 1050 |
% \subsection{Public Interface Macros} |
| 1051 |
% |
| 1052 |
% \begin{macro}{\ChemCite} |
| 1053 |
% Delegate to |\CN@ChemCiteStar| or |\CN@ChemCite| depending on |
| 1054 |
% whether ``|*|'' was used. \changes{1.10}{1999/12/10}{This version |
| 1055 |
% provides star forms of the standard commands (except for |
| 1056 |
% |NoCite|). The star forms use in order; the current label if defined |
| 1057 |
% or a value stored in the \textsl{aux} file from the previous time |
| 1058 |
% the document was processed if defined or a dummy value. As these |
| 1059 |
% files are read in before the document, but in order they should |
| 1060 |
% provide the author with greater flexibility in defining the |
| 1061 |
% numbering order. Either the author should define a sublabel for all |
| 1062 |
% compounds using the (no-longer) optional sublabel field to disable |
| 1063 |
% auto-numbering or use the |NoCite| and |Chem?Cite*| commands to get |
| 1064 |
% the desired numbering.} |
| 1065 |
% \begin{macrocode} |
| 1066 |
\DeclareRobustCommand*{\ChemCite}{% |
| 1067 |
\@ifstar{\CN@ChemCiteStar}{\CN@ChemCite}% |
| 1068 |
} |
| 1069 |
% \end{macrocode} |
| 1070 |
% \end{macro} |
| 1071 |
% |
| 1072 |
% \begin{macro}{\ChemFCite} |
| 1073 |
% Delegate to |\CN@ChemFCiteStar| or |\CN@ChemFCite| depending on |
| 1074 |
% whether ``|*|'' was used. |
| 1075 |
% \begin{macrocode} |
| 1076 |
\DeclareRobustCommand*{\ChemFCite}{% |
| 1077 |
\@ifstar{\CN@ChemFCiteStar}{\CN@ChemFCite}% |
| 1078 |
}% |
| 1079 |
% \end{macrocode} |
| 1080 |
% \end{macro} |
| 1081 |
% |
| 1082 |
% \begin{macro}{\ChemSCite} |
| 1083 |
% Delegate to |\CN@ChemSCiteStar| or |\CN@ChemSCite| depending on |
| 1084 |
% whether ``|*|'' was used. |
| 1085 |
% \begin{macrocode} |
| 1086 |
\DeclareRobustCommand*{\ChemSCite}{% |
| 1087 |
\@ifstar{\CN@ChemSCiteStar}{\CN@ChemSCite}% |
| 1088 |
}% |
| 1089 |
% \end{macrocode} |
| 1090 |
% \end{macro} |
| 1091 |
% |
| 1092 |
% \begin{macro}{\ChemMFCite} |
| 1093 |
% Delegate to |\CN@ChemMFCiteStar| or |\CN@ChemMFCite| depending on |
| 1094 |
% whether ``|*|'' was used. |
| 1095 |
% \begin{macrocode} |
| 1096 |
\DeclareRobustCommand*{\ChemMFCite}{% |
| 1097 |
\@ifstar{\CN@ChemMFCiteStar}{\CN@ChemMFCite}% |
| 1098 |
}% |
| 1099 |
% \end{macrocode} |
| 1100 |
% \end{macro} |
| 1101 |
% |
| 1102 |
% \begin{macro}{\ChemMSCite} |
| 1103 |
% Delegate to |\CN@ChemMSCiteStar| or |\CN@ChemMSCite| depending on |
| 1104 |
% whether ``|*|'' was used. |
| 1105 |
% \begin{macrocode} |
| 1106 |
\DeclareRobustCommand*{\ChemMSCite}{% |
| 1107 |
\@ifstar{\CN@ChemMSCiteStar}{\CN@ChemMSCite}% |
| 1108 |
}% |
| 1109 |
% \end{macrocode} |
| 1110 |
% \end{macro} |
| 1111 |
% |
| 1112 |
% \begin{macro}{\DefineChemical}\marg{main!sub key}\marg{name}\marg{label} |
| 1113 |
% Associate a key with a chemical name and sub-label by inserting a |
| 1114 |
% |\CN@definenewchemical| macro call into the \textsf{aux} file. |
| 1115 |
% \begin{macrocode} |
| 1116 |
\DeclareRobustCommand*{\DefineChemical}[3]{% |
| 1117 |
\CN@definenewchemical{#1}{#2}{#3}% |
| 1118 |
\write\@auxout{\string\CN@definenewchemical{#1}{#2}{#3}}% |
| 1119 |
}%end def |
| 1120 |
% \end{macrocode} |
| 1121 |
% \end{macro} |
| 1122 |
% \begin{macrocode} |
| 1123 |
\makeatother |
| 1124 |
% \end{macrocode} |
| 1125 |
% |
| 1126 |
% \Finale |
| 1127 |
\endinput |