Debian Codegraph @

texmf-dist/doc/latex/idxcmds/idxcmds_en.tex

raw
1 % arara: pdflatex
2 % arara: biber
3 % arara: pdflatex
4 % arara: pdflatex
5 % --------------------------------------------------------------------------
6 % the IDXCMDS package
7 %
8 % create commands for adding formatted index entries
9 %
10 % --------------------------------------------------------------------------
11 % Clemens Niederberger
12 % Web: http://www.mychemistry.eu/forums/forum/idxcmds/
13 % E-Mail: [email protected]
14 % --------------------------------------------------------------------------
15 % Copyright 2012-2015 Clemens Niederberger
16 %
17 % This work may be distributed and/or modified under the
18 % conditions of the LaTeX Project Public License, either version 1.3
19 % of this license or (at your option) any later version.
20 % The latest version of this license is in
21 % http://www.latex-project.org/lppl.txt
22 % and version 1.3 or later is part of all distributions of LaTeX
23 % version 2005/12/01 or later.
24 %
25 % This work has the LPPL maintenance status `maintained'.
26 %
27 % The Current Maintainer of this work is Clemens Niederberger.
28 % --------------------------------------------------------------------------
29 % The idxcmds package consists of the files
30 % - idxcmds.sty
31 % - idxcmds_en.tex, idxcmds_en.pdf
32 % - README
33 % --------------------------------------------------------------------------
34 % If you have any ideas, questions, suggestions or bugs to report, please
35 % feel free to contact me.
36 % --------------------------------------------------------------------------
37 \documentclass[load-preamble,add-index,scrartcl={DIV10}]{cnltx-doc}
38 \usepackage[utf8]{inputenc}
39 \usepackage{idxcmds}
40 \setcnltx{
41 package = {idxcmds} ,
42 authors = Clemens Niederberger ,
43 email = [email protected] ,
44 url = http://www.mychemistry.eu/forums/forum/idxcmds/ ,
45 abstract = {%
46 create commands for adding formatted index entries%
47 } ,
48 add-cmds = {
49 newidxcmd,newsubidxcmd,newsubmainidxcmd
50 } ,
51 add-silent-cmds = {
52 acr,environ,file,hsnbg,KOMAScript,scientist,test,@ifstar,
53 cmd,cmd@base,cmd@idx,cmd@nostar,cmd@star,
54 indexentry
55 } ,
56 index-setup = { othercode=\footnotesize,noclearpage } ,
57 makeindex-setup = { columns=3, columnsep=1em , intoc , title=Package Index }
58 }
59 \usepackage{imakeidx}
60 \makeindex[name=environments,title=Index of Environments,intoc,columns=2]
61 \makeindex[name=\jobname-examples,title=Index of Examples,intoc,columns=3]
62
63 \usepackage[
64 backend=biber,
65 style=cnltx,
66 sortlocale=en_US,
67 indexing=cite,
68 useprefix]{biblatex}
69 \addbibresource{cnltx.bib}
70
71 \defbibheading{bibliography}{\addsec{References}}
72 \usepackage{csquotes}
73
74 \usepackage[biblatex]{embrac}[2012/06/29]
75 \ChangeEmph{[}[,.02em]{]}[.055em,-.08em]
76 \ChangeEmph{(}[-.01em,.04em]{)}[.04em,-.05em]
77
78 % \setidxcmds{idx-cmd=\index[\jobname-examples]}
79
80 \newidxcmd[{\index[\jobname-examples]}]\acr{\textsc{#1}}
81 \newidxcmd[{\index[environments]}]\environ{\texttt{#1}}[ (Environment)]
82 \newidxcmd[{\index[\jobname-examples]}]\scientist{\textsf{#1}}
83 \newsubmainidxcmd[{\index[\jobname-examples]}]\file{\textsf{#1}}
84 \newsubidxcmd[{\index[\jobname-examples]}]\test{Test}{\textcolor{red}{#1}}
85 \newsubidxcmd*[{\index[\jobname-examples]}]\hsnbg{\scientist[Heisenberg]{Werner Heisenberg}}{#1}
86
87 \begin{document}
88
89 \section{Licence and Requirements}\label{sec:license}
90 \license
91
92 \idxcmds\ loads and needs the the packages \pkg{etoolbox}~\cite{pkg:etoolbox},
93 \pkg{pgfopts}~\cite{pkg:pgfopts} and \pkg{ltxcmds}~\cite{pkg:ltxcmds}.
94
95 \section{Motivation}
96 When working on a larger document and designing and writing the macros for
97 various bits and pieces I was going to use I found myself repeatedly writing
98 the same kind of macros again and again that had some kind of semantic
99 meaning, maybe some markup definitions that also created an index entry and
100 had a star form for omitting the index entry. They all had more or less the
101 following structure:
102
103 \begin{sourcecode}
104 \makeatletter
105 \newcommand*\cmd{\@ifstar\cmd@star\cmd@nostar}
106 \newcommand*\cmd@star[1]{\cmd@base{#1}}
107 \newcommand*\cmd@nostar[1]{\cmd@base{#1}\cmd@idx{#1}}
108 \newcommand*\cmd@base[1]{\textit{#1}}
109 \newcommand*\cmd@idx[1]{\index{#1@\cmd@base{#1}}}
110 \makeatother
111 \end{sourcecode}
112
113 After having copied and pasted this code for the fourth time I thought: you
114 should have a command that does this for you. That was when \cs{newidxcmd}
115 was born. This command soon enough got some extensions, \eg, giving
116 the commands thus defined an optional argument that allowed specifying the
117 sorting. It wasn't long before I realized that I might want to use this
118 \cs{newidxcmd} again in other documents which was when I wrote the first
119 draft of this package.
120
121 I added other commands, \cs{newsubmainidxcmd} and \cs{newsubidxcmd}, which I
122 didn't (and still don't) really use or need but of which I thought they could
123 be useful for others, and here we are.
124
125 \section{Usage}\label{sec:usage}
126 \subsection{Available Commands}
127 \idxcmds\ provides these commands:
128 \begin{commands}
129 \command{newidxcmd}[\oarg{index cs}\marg{cs}\marg{formatting specs}\oarg{append}]
130 Defines a command \meta{cs} that formats its argument according to
131 \meta{formatting specs} and creates an index entry with \meta{index cs}
132 that gets \meta{append} appended. Refer to the argument of \meta{cs}
133 in \meta{formatting specs} with \code{\#1}.
134
135 Also defines a command \cs*{\meta{cs}idx} that allows to only create an
136 index entry. See section~\ref{sec:command:usage:newidxcmd} for examples
137 and further description of its functionality. Default for \meta{index cs}
138 is \cs{index}.
139 \command{newsubidxcmd}[\sarg\oarg{index cs}\marg{cs}\marg{main
140 entry}\marg{form. specs}\oarg{append}]
141 Defines a command \meta{cs} that formats its argument according to
142 \meta{form. specs} and creates an index sub-entry to \meta{main entry}
143 with \meta{index cs} that gets \meta{append} appended. Refer to the
144 argument of \meta{cs} in \code{form.\@ specs} with \code{\#1}.
145
146 Also defines a command \cs*{\meta{cs}idx} that allows to only create an
147 index entry. See section~\ref{sec:command:usage:newsubidxcmd} for further
148 description of its functionality. Default for \meta{index cs} is
149 \cs*{index}.
150 \command{newsubmainidxcmd}[\oarg{index cs}\marg{cs}\marg{form. specs}\oarg{append}]
151 Defines a command \meta{cs} that formats its argument according to
152 \meta{form. specs} and creates an index sub-entry to a main entry with
153 \meta{index cs} that gets \meta{append} appended. Refer to the argument
154 of \meta{cs} in \meta{form. specs} with \code{\#1}.
155
156 Also defines a command \cs*{\meta{cs}idx} that allows to only create an
157 index entry. The main entry is specified at use time. See
158 section~\ref{sec:command:usage:newsubmainidxcmd} for examples and further
159 description of its functionality. Default for \meta{index cs} is
160 \cs*{index}.
161 \end{commands}
162
163 The commands \meta{cs} defined this way are robust but their formatting
164 argument is not placed in a group. Keep this in mind when you use
165 \cs*{bfseries} or something in a definition. \meta{cs} will be defined using
166 \pkg{etoolbox}' \cs*{newrobustcmd} which means an error will be thrown if
167 \meta{cs} is already defined.
168
169 Of course these commands cannot cover all possible use cases for index entries
170 but that is not the intention of this package, anyway.
171
172 \subsection{Command Usage}\label{sec:command:usage}
173 \subsubsection{\cs*{newidxcmd}}\label{sec:command:usage:newidxcmd}
174 The command \cs{newidxcmd}\Marg{\cs*{foo}}\marg{formatting specs} will define
175 a new command \cs*{foo} with the following syntax:
176 \begin{commands}
177 \command*{foo}[\sarg\marg{text}]
178 format \meta{text} according to specifications, no index entry.
179 \command*{foo}[\oarg{sort idx}\marg{text}\oarg{append}]
180 format \meta{text} according to specifications, add formatted index
181 entry, sorted according to \meta{sort idx} or, if the optional argument
182 is left out, sorted according to \meta{text}. \meta{append} is added to
183 the index entry if the trailing optional argument is used (this can be
184 useful for instance for getting formatted page numbers).
185 \command*{fooidx}[\oarg{sort idx}\marg{text}\oarg{append}]
186 add formatted index entry, sorted according to \meta{sort idx} or, if the
187 optional argument is left out, sorted according to \meta{text}.
188 \meta{append} is added to the index entry if the trailing optional
189 argument is used.
190 \end{commands}
191
192 Let's see an example:
193 \begin{example}
194 % in the preamble, probably:
195 % \newidxcmd{\acr}{\textsc{#1}}
196 % \newidxcmd[{\index[environments]}]{\environ}{\texttt{#1}}[ (Environment)]
197 % \newidxcmd{\scientist}{\textsf{#1}}
198 \acr{cd}, \acr{id}
199
200 \environ{center}, \environ{flushleft}
201
202 \scientist*{Albert Einstein}, \scientist[Heisenberg]{Werner Heisenberg}
203 \end{example}
204 You will find these examples in the index of examples or the index of
205 environments, respectively. The second set of examples shows the purpose of
206 the first optional argument: if you have several indexes --~like this
207 documentation has for demonstration purposes~-- you might need to specify the
208 index command used\footnote{This document uses
209 \pkg{imakeidx}~\cite{pkg:imakeidx} for this purpose.}. If you want to prove
210 if the example worked: \scientist*{Albert Einstein} should not be found in the
211 index and \scientist*{Werner Heisenberg} should be sorted under
212 \emph{Heisenberg}. Both \environ*{center} and \environ*{flushleft} ahould be
213 found in the examples index.
214
215 Now let's disect the example a bit. The uses of \cs*{acr}\Marg{cd},
216 \cs*{scientist}\sarg\Marg{Albert Einstein} and \cs*{environ}\Marg{center} will
217 essentially expand to
218 \begin{sourcecode}
219 % \acr{cd} =>
220 \textsc{cd}\index{cd@\textsc{cd}}
221 % and in \jobname.idx =>
222 \indexentry{cd@\textsc {cd}}{3}
223
224 % \scientist*{Albert Einstein} =>
225 \textsf{Albert Einstein}
226
227 % \environ{center} =>
228 \texttt{center}\index[environments]{center@\texttt{center} (Environment)}
229 % and in examples.idx =>
230 \indexentry{center@\texttt {center} (Environment)}{3}
231 \end{sourcecode}
232
233 \subsubsection{\cs*{newsubidxcmd}}\label{sec:command:usage:newsubidxcmd}
234 The command \cs{newsubidxcmd}\sarg\Marg{\cs*{foo}}\marg{main entry}\marg{form.
235 specs} will define a new command \cs*{foo} with the same syntax as
236 \cs{newidxcmd} does. However, \cs{newsubidxcmd} has an additional argument
237 that specifies the main index entry this group of sub entries belongs to. For
238 the unstarred variant this argument can be some arbitrary main entry. For the
239 starred variant it demands a command plus argument defined by \cs{newidxcmd}
240 as argument.
241
242 \begin{example}
243 % preamble:
244 % \newsubidxcmd{\test}{Test}{\textcolor{red}{#1}}
245 % \newsubidxcmd*{\hsnbg}{\scientist[Heisenberg]{Werner Heisenberg}}{#1}
246 \scientist[Heisenberg]{Werner Heisenberg} was born in
247 \hsnbg[Wuerzburg]{W\"urzburg (Germany)}. He worked as a
248 professor in \hsnbg{Leipzig (Germany)}. And this is a
249 \test{test}.
250 \end{example}
251
252 \subsubsection{\cs*{newsubmainidxcmd}}\label{sec:command:usage:newsubmainidxcmd}
253 The command \cs{newsubmainidxcmd}\Marg{\cs*{foo}}\marg{form. specs} will define
254 a new command \cs*{foo} similar to \cs{newsubidxcmd} but where the main
255 index entry is specified for every use case in the running text. \cs*{foo}
256 will have the following syntax:
257 \begin{commands}
258 \command*{foo}[\sarg\marg{text}]
259 format \meta{text} according to specifications, no index entry.
260 \command*{foo}[\oarg{sort idx}\marg{text}\marg{main entry}\oarg{append}]
261 format \meta{text} according to specifications, add formatted index
262 sub-entry to the main index entry \meta{main entry}, sorted according to
263 \meta{sort idx} or, if the optional argument is left out, sorted
264 according to \meta{text}. \meta{append} is added to the index entry if
265 the trailing optional argument is used (this can be useful for instance
266 for getting formatted page numbers).
267 \command*{fooidx}[\oarg{sort idx}\marg{text}\marg{main entry}\oarg{append}]
268 add formatted index sub-entry to the main index entry \meta{main entry},
269 sorted according to \meta{sort idx} or, if the optional argument is left
270 out, sorted according to \meta{text}. \meta{append} is added to the
271 index entry if the trailing optional argument is used.
272 \end{commands}
273
274 \begin{example}
275 % in the preamble, probably:
276 % \newsubmainidxcmd{\file}{\textsf{#1}}
277 \file{article}{classes} is a standard \LaTeX{} class.
278 \file{scrartcl}{KOMA-Script@\KOMAScript} is part of the \KOMAScript{} bundle.
279 \file*{test} is a dummy.
280 \end{example}
281
282 \subsection{Options}
283 \idxcmds\ has the following options -- either setable as package option or with
284 the setup command \cs{setidxcmds}\marg{options} which takes a comma separated
285 list of options:
286 \begin{options}
287 \keyval{sort-sep}{symbol}\Default{@}
288 set makeindex symbol to separate the index into sorting and typesetting
289 part as specified in the index style file.
290 \keyval{sub-sep}{symbol}\Default{!}
291 set makeindex symbol to add a sub entry as specified in the index style
292 file.
293 \keyval{idx-cmd}{cs}\Default{\cs*{index}}
294 \sinceversion{0.2b}The default indexing command that is used by \idxcmds.
295 \end{options}
296
297 % \end{document}
298
299 \printbibliography
300
301 % \section{Implementation}
302 % In the following code the lines 1--32 have been omitted. They only repeat the
303 % license statement which has already been mentioned in
304 % section~\ref{sec:license}.
305
306 % \implementation[linerange={33-1000},firstnumber=33]
307
308
309 \printindex[\jobname-examples]
310
311 \printindex[environments]
312
313 % \indexprologue{\noindent
314 % This index has some peculiar entries in addition to the ones you would
315 % normally expect. But actually they are the corresponding entries to the
316 % examples shown in section~\ref{sec:usage}.%
317 % }
318 % \printindex
319
320 \end{document}