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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
% \iffalse meta-comment
%
% Copyright (C) Johannes Fink
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{corridx}
%<package> [2005/05/05 v1.0 Chemical Index]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{corridx}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
\DocInput{corridx.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
% {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
% 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
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
%
% \changes{v1.0}{2005/05/05}{Initial version}
%
% \GetFileInfo{corridx.sty}
%
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
% \DoNotIndex{\@ne}
% \DoNotIndex{\advance,\begingroup,\catcode,\closein}
% \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
% \DoNotIndex{\bgroup,\egroup,\newcommand}
% \DoNotIndex{\ifx,\fi}
% \DoNotIndex{\let}
%
% \title{The \textsf{corridx} package
% \thanks{This document corresponds to \textsf{corridx}~\fileversion,
% dated \filedate.}}
% \author{Johannes Fink\\ \texttt{fink@unileoben.ac.at}}
%
% \maketitle
%
% \begin{abstract}
%
% The package introduces a sort entry for chemical names that are
% preceded by numbers and other prefixes to ensure a correct
% ordering in the index.
%
% \end{abstract}
%
% \section{Introduction}
%
% Chemical Names often have preceding numbers or other prefiexes
% that do not contribute to the alphabetic sorting of the respective
% index entry. This drawback can be circumvented by introducing sort
% keys into the index entry. Such as
% \verb"\index{dimethylbenzene@1,3-Dimethylbenzene}". The
% \textit{corridx} package does this automatically.
%
% Previously a Pascal program entitled \textit{CorrIdx} was used as a
% preprocessor for the \textit{makeindex} program to insert these
% key entries into the index entry.
%
% Now a \LaTeX\space macro package is available. This package includes all the
% necessary modifications directly in the |*.idx| file.
%
%
%
% \subsection{Clashes}
% The package |corridx| has a different approach
% in comparison to the package |index| and will
% not work with this package and maybe also with
% other similar packages.
% A package error
% is forced when the package |index| is loaded.
% The package works together with |makeidx|.
%
% \section{Usage}
%
% \subsection{Predefined Index Types}
%
% There are always the forms |\ia| and |\noia|, |\ib| and |\noib|,
% |\ic| and |\noic|, |\ig| and |\noig|.
% The |\no..| form places an index in the |*.idx| file, whereas the |\i.| form places both text and
% index.
%
% \DescribeMacro{\ia}
% The command |\ia| (index acronym) is used as
% |\ia{1,2-butanediol}{1,2-BD}|
% and places in the text "1,2-butanediol (1,2-BD)"
% and in the index |*.idx|
% \newline
% |\indexentry{acr bd@1,2-BD!\nopagebreak 1,2-Butanediol}{1}|
%
% \DescribeMacro{\ic}
% % The command |\ic| is used as |\ic{1,2-butanediol}| and places in the text
% "1,2-butanediol" and in the index |*.idx| \newline
% |\indexentry{chem butanediol@1,2-Butanediol}{1}|.
%
% \DescribeMacro{\ib}
% The command |\ib| (\textbf{both} acronym and chemical index )
% is used as \newline |\ib{1,2-butanediol}{1,2-BD}| and places in
% the text
% "1,2-butanediol (1,2-BD)" and in the index |*.idx|
%
% \begin{verbatim}
% \indexentry{chem butanediol@\begin{crrdxchem}1,2-Butanediol\end{crrdxachem}}{1}
% \indexentry{acr bd@1,2-BD\nopagebreak!\begin{crrdxacr}1,2-Butanediol\end{crrdxacr}}{1}
% \end{verbatim}
%
% \DescribeMacro{\ig}
% |\ig| (index general) places both in the index and the text, The macro has two arguments,
% the first being optional.
% The first optional argument is appended in the index to the second
% and is suppressed in the text for |\ig|.
% |\ig[!unsaturated]{polyester}| places in the text "polyester" and
% in the index
% |\indexentry{gen polyester@Polyester!unsaturated}{2}|.
% To use |\ig| with one argument, |\ig{polyester}| places places in the text "polyester"
% and in the index |*.idx| |\indexentry{gen polyester@Polyester}{2}|
%
% \StopEventually{\PrintIndex}
%
% \subsection{Define Yourself an Index Entry Type}
% The index entry is structured by several variables to have freedom
% in the output. A typical definition of an index looks like
%
% \begin{verbatim}
% \newcommand{\myindex}[x]{%
% \bgroup%
% \def\crrdx@key@prefix{keyprefix}%
% % here is the key inserted
% \def\crrdx@key@ostfix{keypostfix}%
% \def\crrdx@sep@@{@separator@}%
% \def\crrdx@entry@prefix{entryprefix}%
% % here is the entry inserted,
% % with the first letter capitalized
% \def\crrdx@entry@postfix{entrypostfix}%
% \def\crrdx@fmt@page{formatpage}%
% \def\crrdx@sfc@prerun{\crrdx@sfc@prerun@default}
% \def\crrdx@key@prerun{\crrdx@key@prerun@default}
% \crrdx@fmt@index@entry{thekey}{thecapitalizedentry}%
% \egroup%
% \end{verbatim}
% In the foregoing definition we give the variables in the order as
% they are placed by the macro \verb"\crrdx@fmt@index@entry".
% There are more macros to be defined by the user, as are really
% necessary in most cases, but this kind of structuring may be
% helpful to achieve the desired result more easily.
%
% Look for the definitions of \verb"\noia", \verb"\noic",
% \verb"\noig" to have a feeling how to use the variables.
%
% \subsection{Auxiliary Commands}
%
%
% \DescribeMacro{\crrdxformatpage} This macro sets a postfix in the index
% entry for page formatting. Use the command \newline
% \verb"\crrdxformatpage{chem}{|textit}" \newline to get in the chemical
% index the page number in italic. To make the page number for a
% chemical index in boldface, place the command
% \verb"\crrdxformatpage{chem}{|textbf}". This holds for all subsequent
% entries, if placed in the main text. However, you can redefine the
% environment |figure|, by including the |\crrdxformatpage| command to
% get a special page formatting only there.
%
% For example, the definition
% \begin{verbatim}
% \renewenvironment{figure}%
% {\@float{figure}\crrdxformatpage{chem}{|textit}}%
% {\end@float}%
% \end{verbatim}
% causes chemical index entries to be \textit{italic} only in the figure environment,
% of course, if switched off outside.
% Do not use |\ic| within the caption, but use |\noic| outside the caption.
%
% Similarly use the commands \newline |\crrdxformatpage{acr}{}| and \newline |\crrdxformatpage{gen}{}|,
% or \newline \verb"\crrdxformatpage{gen}{|textbf}".
%
% You can also use your own defined formats.
%
% \DescribeMacro{crrdxenvchem} \DescribeMacro{crrdxenvacr} We define empty environments that can be later used
% for special settings in the index. For example, you can define some characters as active there.
% In my personal copy I use to define this environment
% \verb"\selectlanguage{chemical}".
% The \verb"chemical" package is not available from the \LaTeX\space mirrors.
% You can download it from \verb"http://www.unileoben.ac.at/~fink/papers/welcome.html"
% somewhat downwards, in the \LaTeX section.
%
% \subsection{Index Sectioning}
%
% \begin{macro}{\sectioncrrdx}
% This macro can be used to place an index heading that is included without
% numbering into the table of contents. Example:
%\begin{verbatim*}
%\index{acr @\sectioncrrdx{Acronyms}\swallow|swallow}%
%\index{chem @\sectioncrrdx{Chemicals}\swallow|swallow}%
%\index{gen @\sectioncrrdx{General}\swallow|swallow}%
%\end{verbatim*}
% |\swallow| ensures that no comma and page number will come into the entry.
% Take care to place the section entry at the top of the other entries,
% by placing one space more behind \verb*+chem +, etc. than in the other
% related entries.
% \end{macro}
%
% \section{Implementation}
% \subsection{Main Entries}
%
% \begin{macro}{\ic}
% |\ic{1,2-chemname}| places |1,2-chemname| in the text and
% places an index entry, formatted as |chem chemname@1,2-chename|.
% \begin{macrocode}
\newcommand{\ic}[1]{\begin{crrdxchem}#1\end{crrdxchem}\noic{#1}}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\noic}
% |\noic{1,2-chemname}| places an index entry, formatted as \newline
% |chem chemname@1,2-chename|.
% We encapsule the whole macro by grouping.
% \begin{macrocode}
\newcommand{\noic}[1]{%
\bgroup%
\def\crrdx@key@prefix{chem }%
\def\crrdx@key@ostfix{}%
\def\crrdx@sep@@{@}%
\def\crrdx@entry@prefix{\string\begin{crrdxchem}}%
\def\crrdx@entry@postfix{\string\end{crrdxchem}}%
\def\crrdx@fmt@page{\crrdx@fmtpage@chem}%
\def\crrdx@sfc@prerun{\crrdx@sfc@prerun@default}%
\def\crrdx@key@prerun{\crrdx@key@prerun@default}%
\crrdx@fmt@index@entry{#1}{#1}%
\egroup%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ia} This is the acronym entry.
% It places the acronym in the text and in the index
% \begin{macrocode}
\newcommand{\ia}[2]{#1 \mbox{(#2)}\noia{#1}{#2}}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\noia} This places the acronym in the index.
% \begin{macrocode}%
\newcommand{\noia}[2]{%
\bgroup%
\def\crrdx@key@prefix{acr }%
\def\crrdx@key@ostfix{}%
\def\crrdx@sep@@{@}%
\def\crrdx@entry@prefix{#2\string\nopagebreak!\string\begin{crrdxacr}}%
\def\crrdx@entry@postfix{\string\end{crrdxacr}}%
\def\crrdx@fmt@page{\crrdx@fmtpage@acr}%
\def\crrdx@sfc@prerun{\crrdx@sfc@prerun@default}%
\def\crrdx@key@prerun{\crrdx@key@prerun@default}%
\crrdx@fmt@index@entry{#2}{#1}%
\egroup%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ib \noib}
% |\ib| and |\noib| are macros to place both a chemical index and an
% acronym. |\ib| places both the index and the text, whereas |\noib|
% places only both index entries. The macros have two arguments,
% e.g., |\ib{1,2-chemname}{CN}|.
% \begin{macrocode}
\newcommand{\noib}[2]{\noic{#1}\noia{#1}{#2}}%
\newcommand{\ib}[2]{\ic{#1}\noia{#1}{#2}}%
% \end{macrocode}
% \end{macro}
% |\ig| and |\noig| are macros to place a general index.
% \begin{macro}{\ig}
% \begin{macrocode}
\newcommand{\ig}[2][]{%
#2%
\noig[#1]{#2}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\noig}
% This macro formats a general index entry.
% \begin{macrocode}
\newcommand{\noig}[2][]{%
\bgroup%
\def\crrdx@key@prefix{gen }%
\def\crrdx@key@ostfix{}%
\def\crrdx@sep@@{@}%
\def\crrdx@entry@prefix{}%
\def\crrdx@entry@postfix{#1}%
\def\crrdx@fmt@page{\crrdx@fmtpage@gen}%
\def\crrdx@sfc@prerun{\crrdx@sfc@prerun@default}%
\def\crrdx@key@prerun{\crrdx@key@prerun@default}%
\crrdx@fmt@index@entry{#2}{#2}%
\egroup%
}%
% \end{macrocode}
% \end{macro}
%
% \subsection{Auxiliary Commands}
% \begin{macro}{\crrdxformatpage} This macro set a postfix for page formatting.
% \begin{macrocode}
\newcommand{\crrdxformatpage}[2]{\@namedef{crrdx@fmtpage@#1}{#2}}%
\crrdxformatpage{chem}{\@empty}%
\crrdxformatpage{acr}{\@empty}%
\crrdxformatpage{gen}{\@empty}%
% \end{macrocode}
% \end{macro}
% The |makeindex| program describes the following
% commands for page formatting:
% \begin{verbatim}
% \providecommand{\ii}[1]{{\it#1}}%
% \providecommand{\bb}[1]{{\bf#1}}%
% \end{verbatim}
% e.g., for index boldface pagenumber as last entry in the
% |\index| command \verb"|bb".
% However we not use this type,
% we use rather%
% \verb"|textit}" or \verb"|textbf".
% \begin{environment}{crrdxchem} We define an empty environment that can be later used
% for special chemical language settings.
% \begin{macrocode}
\newenvironment{crrdxchem}{}{}%
% \end{macrocode}
% \end{environment}
% \begin{environment}{crrdxacr} We define an empty environment that can be later used
% for special settings for acronyms.
% \begin{macrocode}
\newenvironment{crrdxacr}{}{}%
% \end{macrocode}
% \end{environment}
%
% \subsection{Formatting the Key}
%
% \begin{macro}{\crrdx@key} This macro scans the entry and removes
% every non-letter character. The key is placed in the index
% before the |@| as sorting aid.
% \begin{macrocode}
\newcommand{\crrdx@key}[1]{%
\crrdx@key@prerun%
\edef\crrdx@key@temp{#1}%
\edef\crrdx@key@var{\@empty}%
\let\end\@empty%
\expandafter\crrdx@key@loop\crrdx@key@temp\end%
}%
% \end{macrocode}
% \begin{macrocode}
\newcommand{\crrdx@key@loop}[1]{%
\let\next=\crrdx@key@loop%
\ifx#1\end\let\next=\relax\fi%
\ifcat\noexpand#1a\lowercase{\edef\crrdx@key@var{\crrdx@key@var#1}}\fi%
\next}%
% \end{macrocode}
% The following text formats are skipped in the key:
% \begin{macrocode}
\newcommand{\crrdx@key@prerun@default}%
{%
\renewcommand{\textrm}[1]{{\noexpand\textrm{##1}}}%
\renewcommand{\textbf}[1]{{\noexpand\textbf{##1}}}%
\renewcommand{\textsf}[1]{{\noexpand\textsf{##1}}}%
\renewcommand{\texttt}[1]{{\noexpand\texttt{##1}}}%
\renewcommand{\textmd}[1]{{\noexpand\textmd{##1}}}%
\renewcommand{\textit}[1]{{\noexpand\textit{##1}}}%
\renewcommand{\textsc}[1]{{\noexpand\textsc{##1}}}%
\renewcommand{\textsl}[1]{{\noexpand\textsl{##1}}}%
\renewcommand{\textup}[1]{{\noexpand\textup{##1}}}%
\def~{\string~}%
}%
% \end{macrocode}
% If you want to skip a normal text in the key, then format it as |\textup|.
% \subsection{Formatting the Entry}
% \end{macro}
% \begin{macro}{\crrdx@sfc@prerun}
% After scanning the key, we want to use the formats again
% with a different expansion than when doing the key.
% \begin{macrocode}
\newcommand{\crrdx@sfc@prerun@default}%
{%
\renewcommand{\textrm}{\string\textrm}%
\renewcommand{\textbf}{\string\textbf}%
\renewcommand{\textsf}{\string\textsf}%
\renewcommand{\texttt}{\string\texttt}%
\renewcommand{\textmd}{\string\textmd}%
\renewcommand{\textit}{\string\textit}%
\renewcommand{\textsc}{\string\textsc}%
\renewcommand{\textsl}{\string\textsl}%
\renewcommand{\textup}{\string\textup}%
\def~{\string~}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\crrdx@fmt@index@entry}
% This macro formats the input into the index.
% \begin{macrocode}
\newcommand{\crrdx@fmt@index@entry}[2]{%
\crrdx@key{#1}%
\crrdx@sfc{#2}%
\edef\crrdx@fmt@index@entry@var{%
\crrdx@key@prefix%
\crrdx@key@var%
\crrdx@key@ostfix%
\crrdx@sep@@%
\crrdx@entry@prefix%
\crrdx@sfc@var%
\crrdx@entry@postfix%
\crrdx@fmt@page}%
\index{\crrdx@fmt@index@entry@var}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\crrdx@sfc@loop}
% We want to capitalize the first letter automatically. We start to declare the loop
% used in |\crrdx@sfc|.
% We scan the entry to find the first letter. This we are capitalizing
% and then we switch to scan what is left over from |#1|.
% \begin{macrocode}
\newcommand{\crrdx@sfc@loop}[1]{%
\crrdx@sfc@prerun%
\let\next=\crrdx@sfc@loop%
\ifx#1\end\let\next=\relax\fi%
\ifcat\noexpand#1a%
% \end{macrocode}
% A letter is found
% \begin{macrocode}
\uppercase{\edef\crrdx@sfc@var{\crrdx@sfc@var#1}}%
% \end{macrocode}
% make it uppercase.
% We scan now the rest what is left over in |#1| and add it to the |\crrdx@sfc@var|.
% \begin{macrocode}
\let\next=\crrdx@sfc@loop@leftover%
\else%
\edef\crrdx@sfc@var{\crrdx@sfc@var#1}%
\fi%
\next}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\crrdx@sfc@loop@leftover} Collects the stack |#1| after finding a letter.
% \begin{macrocode}
\newcommand{\crrdx@sfc@loop@leftover}[1]{%
\let\next=\crrdx@sfc@loop@leftover%
\ifx#1\end\let\next=\relax\fi%
\edef\crrdx@sfc@var{\crrdx@sfc@var#1}%
\next%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\crrdx@sfc} This is the main macro to \textbf{S}et the \textbf{F}irst letter as \textbf{C}apital, i.e.,
% what is behind the |@| in the |\index| command.
% We presume that before a possible space in the entry there is a letter
% that can be capitalized.
% \begin{macrocode}
\newcommand{\crrdx@sfc}[1]{%
\edef\crrdx@sfc@var{\@empty}%
\let\end\@empty%
\crrdx@split{#1}%
\expandafter\crrdx@sfc@loop\crrdx@beforespace\end%
\ifx\crrdx@afterspace\@empty\else%
\edef\crrdx@sfc@var{\crrdx@sfc@var\space\crrdx@afterspace}%
\fi%
}%
% \end{macrocode}
% \end{macro}
% Scanning the loop, normally spaces are lost. Therefore we split the
% entry when a space is there at the first space and glue it together in the final part of
% |\crrdx@sfc|.
% \begin{macrocode}
\def\crrdx@ss#1 #2\stop{\edef\crrdx@beforespace{#1}\edef\crrdx@afterspace{#2}}%
% \end{macrocode}
% \begin{macrocode}
\newcommand{\crrdx@split}[1]{%
\edef\test{\@empty}%
% \end{macrocode}
% We test for no space there with a space and |\test| as last entry.
% \begin{macrocode}
\crrdx@ss#1 \test\stop%
\ifx\crrdx@afterspace\test%
% \end{macrocode}
% there is no space%
% \begin{macrocode}
\edef\crrdx@beforespace{#1}\edef\crrdx@afterspace{\@empty}%
\else%
% \end{macrocode}
% there is a space
% \begin{macrocode}
\crrdx@ss#1\stop%
\fi%
}%
% \end{macrocode}
%
% \subsection{Index Sectioning}
% We use here |providecommand| because it may be defined in some classes too
% (at least in classes that I developed for personal use).
%
% \begin{macro}{\swallow} Swallows the next item (no operation)
% \begin{macrocode}
\providecommand\swallow[1]{\relax}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\sectioncrrdx} Makes an index, added to
% table of contents at level 1 (section) without number.
% \begin{macrocode}
\providecommand{\sectioncrrdx}[1]%
{\section*{#1}\addcontentsline{toc}{section}{#1}}%
% \end{macrocode}
% \end{macro}
%
% \subsection{Clashes Check}
% \begin{macrocode}
\AtBeginDocument{ \@ifpackageloaded{index}%
{\PackageError{corridx}%
{This package is not compatible with package index}{}}}%
% \end{macrocode}
%
%
% \PrintChanges
% \Finale
\endinput
|