Debian Codegraph @

texmf-dist/doc/latex/gindex/gindex.tex

raw
1 %
2 % Copyright (C) 2019 Javier Bezos http://www.texnia.com
3 %
4 % This file may be distributed and/or modified under the conditions of
5 % the MIT License. A version can be found at the end of this file.
6 %
7 % Repository: https://github.com/jbezos/gindex
8 %
9
10 \documentclass[a4paper]{ltxguide}
11
12 \title{\textsf{gindex}\\\large Version 0.2}
13
14 \author{Javier Bezos\\\texttt{http://www.texnia.com}}
15
16 \date{2019-10-07}
17
18 \raggedright
19 \parskip=.8ex
20 \advance\oddsidemargin-.7cm
21 \advance\textwidth2cm
22 \addtolength{\textheight}{3.5cm}
23 \addtolength{\topmargin}{-2cm}
24
25 \usepackage{xcolor,bera}
26
27 \definecolor{notes}{rgb}{.75, .3, .3}%
28
29 \makeatletter
30 \def\@begintheorem#1#2{%
31 \list{}{}%
32 \global\advance\@listdepth\m@ne
33 \item[{\sffamily\bfseries\color{notes}\MakeUppercase{#1}}]}%
34 \makeatother
35 \newtheorem{warning}{Warning}
36 \newtheorem{note}{Note}
37 \newtheorem{example}{Example}
38
39 \begin{document}
40
41 \vspace*{1cm}
42 {\fontsize{48}{48}\selectfont \color{notes}{gindex}\par}
43 {\LARGE Formatting indexes with \LaTeX\par}
44 \vspace*{1ex}
45 Version 0.2 (2019-10-07)\par
46 \texttt{https://github.com/jbezos/gindex}\par
47 Javier Bezos (\texttt{http://www.texnia.com})\par
48
49 \vspace*{6ex}
50
51 This package works in conjunction with a \textit{\bfseries g}eneric
52 \verb|ist| file, which provides a way to \textit{\bfseries g}enerate
53 the format of index entries from within \LaTeX. With standard classes,
54 it works out of the box with some predefined values, which you can (and
55 in fact should) redefine with |\renewcommand|.
56
57 Note it is version 0.2. Changes of the existing features are unlikely
58 to happen (but who knows), but new features, on the other hand, will be
59 added in the near future.
60
61 What it does is to generate blocks like this for each first-level entry:
62 \begin{verbatim}
63 \setcounter{indexsubitems}{2}% The number of subitems
64 \indexitem{blah1}{1}%
65 \indexsubitem{subblah1}{3}%
66 \indexsubitem{subblah2}{5}%
67 \indexnoitem{}{}% Usually dummy
68 \end{verbatim}
69
70 As you can see, when |\indexitem| is executed, you know the number of
71 subitems, which is necessary for some styles. Subsubitems are allowed,
72 but not counted. Only subitems are counted.
73
74 The default values are:
75 \begin{verbatim}
76 \newcommand\indexitem[2]{\item #1\ifx\\#2\\\else, #2\fi}
77 \newcommand\indexsubitem[2]{\subitem #1\ifx\\#2\\\else, #2\fi}
78 \newcommand\indexsubsubitem[2]{\subsubitem #1\ifx\\#2\\\else, #2\fi}
79 \end{verbatim}
80 For example, to replace the comma by a quad:
81 \begin{verbatim}
82 \renewcommand\indexitem[2]{\item #1\ifx\\#2\\\else\quad #2\fi}
83 \end{verbatim}
84
85 It is guaranteed that these command can take up to 5 arguments. If you
86 define |\indexitem| with all of them, the parameters in the previous
87 example will be:
88 \begin{enumerate}
89 \item |blah1|
90 \item |1|
91 \item |\indexsubitem|
92 \item |subblah1|
93 \item |3|
94 \end{enumerate}
95 This explains the line |\indexnoitem{}{}| above, which by default does
96 nothing. By inspecting the third parameter you decide how to format the
97 current parameter (of course, in most cases you must emit it again at
98 the end of your definition of |\indexitem|). See the example below.
99
100 There is a tool to define the most usual entry format, which is uesd in
101 the following way:
102 \begin{verbatim}
103 \renewcommand\indexitem[2]{%
104 \indexitemhang{0pt}% First line left margin
105 {10pt}% Second, third... lines left margin
106 {}% After entry if no locator
107 {: }% Entry-locator separator
108 {#1}% Entry
109 {#2}}% Locator
110 \end{verbatim}
111
112 Other macros are:
113 \begin{itemize}
114 \item \verb|\indexpreamble|, executed just after
115 \verb|\begin{theindex}| (\verb|\relax| by default).
116 \item \verb|\indexpostamble|, executed before
117 \verb|\end{theindex}| (\verb|\relax| by default).
118 \item \verb|\indexskip|, which is \verb|\indexspace| by default,
119 with similar purpose.
120 \item \verb|\indexheading|, which is added by |gindexh.ist| but no by
121 |gindex.ist|, is defined as follows:
122 \begin{verbatim}
123 \newcommand\indexheading[1]{%
124 {\bfseries\hfil
125 \MakeUppercase{#1}%
126 \hfil}%
127 \nopagebreak}
128 \end{verbatim}
129 \item \verb|\indexrangesep|, which by default is |-|.
130 \item \verb|\indexpagessep|, which by default is |, |.
131 \end{itemize}
132
133 Remember to set the style to |gindex| when running \textsf{makeindex}:
134 \begin{verbatim}
135 makeindex -s gindex yourfile
136 \end{verbatim}
137 Or if you want |\indexheading|'s to be included:
138 \begin{verbatim}
139 makeindex -s gindexh yourfile
140 \end{verbatim}
141
142 Note also there is usually no need to run \textsf{makeindex} to fine
143 tune the format.
144
145 \begin{example}
146 With the following definitions, items and subitems are typeset, as
147 usual, as separate paragraphs. However, if the item has no locator,
148 and there is exactly one subitem, they are joined with a comma as
149 separator (the code is somewhat low-level):
150 \begin{verbatim}
151 \renewcommand\indexitem[5]{%
152 \def\next{%
153 \indexitemhang{0pt}{20pt}{:}{, }{#1}{#2}%
154 #3{#4}{#5}}%
155 \ifnum\value{indexsubitems}=1\relax
156 \ifx\\#2\\%
157 \def\next{%
158 \indexitemhang{0pt}{20pt}{:}{, }{#1, #4}{#5}}%
159 \fi
160 \fi
161 \next}
162
163 \renewcommand\indexsubitem[2]{%
164 \indexitemhang{0pt}{40pt}{}{, }{--- #1}{#2}}
165 \end{verbatim}
166 \end{example}
167
168 If an item starts with |\indexspecial|, what follows replaces the
169 current item.
170 \begin{example}
171 With |gindex.ist|, you can generate your own headings. If you are sure
172 there is nothing before |a '''| and |l '''| (actually, it can be
173 anything provided it is sorted at the right place), the following two
174 entries will ``group'' the items under two headings.
175 \begin{verbatim}
176 \index{a '''@\indexspecial\indexheading{a-k}}
177 \index{l '''@\indexspecial\indexheading{l-z}}
178 \end{verbatim}
179 \end{example}
180
181
182
183 \section{Internals}
184
185 The |ind| files is generated by |gindex.ist| with generic macros like:
186 \begin{verbatim}
187 \addindexitem{bla1}{1}
188 \addindexsubitem{subbla1}{3}
189 \addindexsubitem{subbla2}{5}
190 \end{verbatim}
191 What \textsf{gindex} does is to convert them to the above format. Some
192 parameters should be cuntomized in the |ist| file, however. These are:
193 \begin{verbatim}
194 headings_flag 0
195 actual '@'
196 quote '"'
197 level '!'
198 page_precedence "rRnaA"
199 keyword "\\indexentry"
200 \end{verbatim}
201 As to |headings_flag|, its value is |-1| with |gindexh| and the
202 recommended way to deal with case is with |\indexheading|
203
204 \end{document}
205
206 MIT License
207 -----------
208
209 Permission is hereby granted, free of charge, to any person obtaining a
210 copy of this software and associated documentation files (the
211 "Software"), to deal in the Software without restriction, including
212 without limitation the rights to use, copy, modify, merge, publish,
213 distribute, sublicense, and/or sell copies of the Software, and to
214 permit persons to whom the Software is furnished to do so, subject to
215 the following conditions:
216
217 The above copyright notice and this permission notice shall be included
218 in all copies or substantial portions of the Software.
219
220 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
221 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
222 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
223 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
224 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
225 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
226 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.