Debian Codegraph @

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

raw
1 %
2 % Copyright (C) 1998-2024 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/esindex
8 %
9
10 \documentclass[a4paper]{ltxguide}
11
12 \usepackage[english,spanish]{babel}
13 \spanishdatedel
14 \usepackage[utf8]{inputenc}
15 \usepackage[T1]{fontenc}
16
17 \title{\textsf{esindex}\\\large 1.8\quad 2024-04-27}
18
19 \author{Javier Bezos}
20
21 \raggedright
22 \parskip=.8ex
23 \advance\oddsidemargin-.7cm
24 \advance\textwidth1.8cm
25 \addtolength{\textheight}{3.5cm}
26 \addtolength{\topmargin}{-2cm}
27
28 \usepackage{xcolor,bera}
29
30 \definecolor{notes}{rgb}{.75, .3, .3}%
31
32 \makeatletter
33 \def\@begintheorem#1#2{%
34 \list{}{}%
35 \global\advance\@listdepth\m@ne
36 \item[{\sffamily\bfseries\color{notes}\MakeUppercase{#1}}]}%
37 \makeatother
38 \newtheorem{warning}{Warning}
39 \newtheorem{note}{Note}
40 \newtheorem{example}{Example}
41
42 \begin{document}
43
44 \vspace*{1cm}
45 {\fontsize{48}{48}\selectfont \color{notes}{esindex}\par}
46 {\LARGE Generating automatically sort keys for \textit{MakeIndex}
47 with \LaTeX\par}
48 \vspace*{1ex}
49 Version 1.8 (2024-04-27)\par
50 \texttt{https://github.com/jbezos/esindex}\par
51 Javier Bezos (\texttt{http://www.texnia.com})
52
53 \vspace*{6ex}
54
55 {\small\itshape Please, report any issues you find in
56 \texttt{https://github.com/jbezos/esindex/issues}.\par}
57
58 This package defines the command \verb|\esindex|, which adds sort keys
59 to the index entries for you. Although originally a specifically Spanish
60 tool (so part of the documentation is in Spanish), the idea behind this
61 package may be applied to other languages, and tools to adapt it are
62 provided. They are explained below, section 2.
63
64 So,
65 \begin{verbatim}
66 \esindex{cañón}
67 \end{verbatim}
68 is equivalent to
69 \begin{verbatim}
70 \index{can^^ffon@cañón}
71 \end{verbatim}
72
73 \verb|\index| is not touched at all (except if requested with the package
74 option \verb|replaceindex|).
75
76 As you can see, the package generates the sort key within \TeX{}
77 itself, which has a number of advantages (and some disadvantages, of
78 course).
79
80 Version 1.5 provides tools for other languages and adds support for
81 \textsf{luatex} and \textsf{xetex}.
82
83 Version 1.6 adds a package option -- with \verb|babel| the `actual' value
84 (ie, the text to be printed in the index) is wrapped with
85 \verb|\foreignlanguage| if the current language is not the main one
86 (this replacement comes after \verb|\esindexactual|). Actually, the
87 macro is \verb|\esindexlanguage|, which by default is `let' to the
88 \textsf{babel} macro.
89
90 Version 1.7 (besides fixing a bug with xe/lua) adds multilevel
91 comparisons (up to three levels, ie, primary, secondary and tertiary).
92 For example:
93 \begin{verbatim}
94 \esindexreplacesub{å}{a}{2}%
95 \esindexreplacesub{à}{a}{1}%
96 \end{verbatim}
97 creates a two-level key sorting \verb|à| before \verb|å|. For a
98 three-level key use \verb|\esindexreplacesubsub| (with 4 arguments). With
99 \verb|\esindexexpandkeys| the three levels are expanded. (Internally,
100 with the definitions above the key for \verb|ràpid| is
101 \verb|rapid^^Ar1pid|.)
102
103 (Version 1.8 is just a bug fix.)
104
105 \section{Spanish}
106
107 Este paquete ha sido diseñado para facilitar la escritura de índices
108 correctamente alfabetizados en castellano. Su principal orden es
109 \verb|\esindex|, que convierte a una forma adecuada su argumento. Así
110 por ejemplo,
111 \begin{verbatim}
112 \esindex{cañón}
113 \end{verbatim}
114 equivale a
115 \begin{verbatim}
116 \index{can^^ffon@cañón}
117 \end{verbatim}
118 No es necesario usar \textsf{babel} salvo, lógicamente, si los acentos
119 están escritos en forma de abreviaciones (\verb|'a|, \verb|'e|, etc.)
120 en lugar de con los caracteres reales. En este último caso, el paquete
121 utiliza ciertas órdenes internas de \textsf{babel}, por lo que no puedo
122 garantizar su funcionamiento correcto con versiones distintas a las 3.6
123 a 3.27. En caso de que \textsf{esindex} sea incompatible con futuras
124 versiones de \textsf{babel} (lo cual no es realmente probable)
125 intentaré adaptarlo en el menor tiempo posible.
126
127 Salvo el carácter \verb|actual| (normalmente \verb|@|) se pueden usar
128 todos los caracteres especiales de \textit{MakeIndex}. Se pueden
129 aplicar convenciones diferentes a las normales, pero en este caso hacen
130 falta ajustes adicionales en caso de que los modificados sean
131 \verb|actual|, \verb|encap|, \verb|level| o \verb|quote|. En ese caso
132 basta con indicar los caracteres que hay que usar como opciones de
133 paquete. Por ejemplo, si para \verb|quote| decidimos usar \verb|$| en
134 nuestro archivo \verb|.ist| particular, tendríamos que llamar al
135 paquete del siguiente modo:
136 \begin{verbatim}
137 \usepackage[quote=$]{esindex}
138 \end{verbatim}
139
140 Es importante observar que, a diferencia de la opción para alemán de
141 \textit{MakeIndex}, el uso de \verb|"| en abreviaciones como \verb|"u|
142 es completamente legítimo, ya que el paquete reconoce tal combinación y
143 la trata aparte. Lo mismo vale para \verb|'| o \verb|~| en caso de que
144 se usaran como carácter especial. Es decir
145 \begin{verbatim}
146 \esindex{{"!`}Cig"ue'nas{"!}|textbf}
147 \end{verbatim}
148 equivale a
149 \begin{verbatim}
150 \index{{"!`}Ciguen^^ffas{"!}@{"!`}Cig\"ue\~nas{"!}|textbf}
151 \end{verbatim}
152
153 Sin embargo, el uso del carácter \verb|quote| ante \verb|encap| o
154 \verb|level| no se detecta a menos que el grupo esté encerrado entre
155 llaves. Por ejemplo, en lugar de \verb/\esindex{Pleca: "|}/ debe
156 escribirse \verb/\esindex{Pleca: {"|}}/. (En realidad en este caso
157 podría haberse usado \verb|\index|. Es tan sólo un ejemplo.)
158
159 Aunque el hecho de que \verb|@| no se pueda usar en \verb|\esindex|
160 hace que todavía algunas entradas se tengan que hacer a mano, la mayor
161 parte del trabajo se ve considerablemente simplificado.
162
163 Finalmente, hay que señalar que con este paquete no se crea en el
164 índice una entrada propia para la palabras que empiezan por eñe, sino
165 que tan sólo se añaden al final de la ene. En el rarísimo caso de que
166 hubiera palabras que empiezan por eñe habría que modificar el archivo
167 \verb|.ind| a mano o bien redefinir de algún modo las entradas
168 generadas.
169
170 La versión 1.3 elimina una incompatibilidad con recientes versiones de
171 \LaTeX{} y añade nuevas funciones:
172 \begin{itemize}
173 \item Opción de paquete \verb|ignorespaces|: al formar la clave de
174 ordenación se suprimen los espacios, de forma que:
175 $$\mbox{adentro} < \mbox{a donde} = \mbox{adonde}.$$
176 \item Opción de paquete \verb|replaceindex|: el comportamiento de
177 \verb|\index| se reemplaza por el de \verb|\esindex|, aunque en este
178 caso no es posible introducir entradas que no se adapten a lo
179 requerido por \verb|\esindex|.
180 \item La orden \verb|\ignorewords| da
181 una lista de palabras separadas por comas que no se cuentan en la
182 ordenación. Por ejemplo, con \verb|\ignorewords{de}| tendríamos:
183 $$\mbox{pino albar} < \mbox{pino laricio} < \mbox{pino de montaña}.$$
184 Distingue la caja, por lo que las formas con mayúsculas hay que darlas
185 explícitamente, si hicieran falta.
186 \end{itemize}
187
188 Algunas funciones adicionales son:
189 \begin{itemize}
190 \item La lista de tókenes \verb|\everyesindex| permite dar definiciones
191 locales para establecer el comportamiento de otras órdenes. Por
192 ejemplo:
193 \begin{verbatim}
194 \everyesindex{\renewcommand\emph[1]{#1}}
195 \end{verbatim}
196 elimina de la clave esa orden. Con:
197 \begin{verbatim}
198 \everyesindex{\renewcommand\emph[1]{#1'}}
199 \end{verbatim}
200 la entrada en cursiva iría detrás de la redonda, si la hubiera. Es una
201 técnica que se puede emplear en otros casos para reajustar el orden de
202 entradas idénticas.
203
204 \item La orden \verb|\esindexsort| permite predefinir claves asociadas
205 a entradas concretas, para ajustar su ordenación (lo que normalmente se
206 consigue añadiendo texto adicional para que \textsf{makeindex} lo tenga
207 en cuenta). Estas correspondencias deben darse antes de la aparición
208 del primer \verb|\esindex| con ese término, y las claves se procesan
209 posteriormente con \verb|ignorespaces|, \verb|\ignorewords| y
210 \verb|\everyesindex|, si están activadas. Por ejemplo:
211 \begin{verbatim}
212 \esindexsort{adonde}{adonde'1}
213 \esindexsort{adónde}{adonde'2}
214 \esindexsort{a donde}{a donde'7}
215 \esindexsort{a dónde}{a donde'8}
216 \end{verbatim}
217 daría el orden \emph{adonde, adónde, a donde, a dónde}, con
218 \verb|ignorespaces|, o bien \emph{a donde, a dónde,} [probablemente
219 otros términos], \emph{adonde, adónde}, sin \verb|ignorespaces|.
220 \end{itemize}
221
222 \section{Other languages}
223
224 First, you very likely want to ignore de Spanish specific settings with
225 the package option \verb|nospanish|. What \verb|\esindex| does is the
226 following:
227
228 \begin{enumerate}
229 \item Replacements set by \verb|\esindexsort|. See an example above.
230
231 \item \verb|\esindexreplace| in \verb|\everyesindex|. See an example
232 below.
233
234 \item Replacements by \LaTeX{} (protected) expansion, including
235 redefinitions in \verb|\everyesindex| and, in Spanish, \verb|\`|,
236 \verb|\"| and \verb|\~|. You may force protected expansion at any point
237 inside \verb|\everyesindex| with \verb|\esindexexpandkey|. In addition,
238 the sort key is stored in \verb|\esindexkey|, which can be manipulated
239 directly.
240
241 \item Removal of words listed in \verb|\ignoredwords| (maybe not the
242 logical place, but real life is not always logical). For example, with
243 \verb|\ignorewords{de,la}| the words “de” and “la” (preceded and
244 followed by spaces) are removed from the key.
245
246 \item Removal of spaces if \verb|ignorespaces|. Very often this is
247 similar to the \verb|-l| option of \textit{MakeIndex}.
248
249 \item Replacement of `actual' as set by \verb|\esindexactual|, but
250 still based on the original \verb|\esindex| argument, without changes.
251 For example, with:
252 \begin{verbatim}
253 \esindexactual{Felipe II}{Felipe II, \textit{rey de España}}
254 \end{verbatim}
255 just write \verb|\esindex{Felipe II}| (as many times as you want), and
256 the entry will show “Felipe II, \textit{rey de España}” (the sort key
257 is still based on “Felipe II”, of course).
258
259 \end{enumerate}
260
261 Do you find it chaotic? Well, you are right. After all this package was
262 for Spanish indexes with some readjustments for it to be adapted to
263 other languages. A general solution deserves another package. Feel free
264 to create one based on this package (MIT license), if you like.
265
266 Here is an example of an \verb|\everyesindex|. Like other
267 \verb|\every...|'s, it is a token register:
268 \begin{verbatim}
269 \everyesindex{%
270 \renewcommand\"[1]{#1e}%
271 \renewcommand\textit[1]{#1}%
272 \esindexexpandkey
273 \esindexreplace{ä}{ae}%
274 \esindexreplace{ü}{ue}%
275 \esindexreplace{ö}{oe}}
276 \end{verbatim}
277
278 What it does is:
279 \begin{enumerate}
280 \item Redefines \verb|\textit| so that it is removed to build the key.
281 With \verb|\everyesindex{\renewcommand\textit[1]{#1'}}| italics would
282 be sorted after upright.
283
284 \item Redefines \verb|\"|. Of course, this only works correctly if used
285 for this precise expansion.
286
287 \item Applies the previous changes with a protected expansion.
288
289 \item Make a direct replacement of some characters.
290
291 \end{enumerate}
292 Note there is a pattern: first flatten the key by removing macros, and
293 then the resulting unmarked text is processed to replace some chars.
294
295 Remember these changes are not shown -- they are used by
296 \textit{MakeIndex} to sort the entries. Note also replacements can be
297 made language dependent with the appropriate test (eg, with
298 \textsf{iflang}).
299
300 As a convenience tool, \verb|\esindexlastchar| is \verb|^^ff| or
301 \verb|^^^^ffff| (\verb|^^^^^^10ffff| in \textsf{luatex}), depending on
302 the engine.
303
304 You can play with \textsf{lua} inside \verb|\everyesindex|, too. For
305 example, to convert at once things like \textit{2,3-dimetilfenol} to
306 \textit{dimetilfenol}:
307 \begin{verbatim}
308 \everyesindex{
309 \directlua{
310 token.set_macro('esindexkey',
311 string.gsub([[\esindexkey]], '^[-0-9,]+', ''))
312 }}
313 \end{verbatim}
314
315 It is just the concept (for example, it fails if the key contains
316 \verb|]]|).
317
318 \section{Final remarks}
319
320 Indexing has many subtleties. Recommended readings are:
321 \begin{itemize}
322 \item \textit{Guidelines for Alphabetical Arrangement of Letters and
323 Sorting of Numerals and Other Symbols},
324 \verb|https://www.niso.org/sites/default/files/2017-08/tr03.pdf|
325 \item \textit{Guidelines for Indexes and Related Information Retrieval
326 Devices},
327 \verb|https://www.niso.org/sites/default/files/2017-08/tr02.pdf|
328 \item \textit{Unicode Collation Algorithm},
329 \verb|https://unicode.org/reports/tr10/|,
330 \item \textit{Unicode Locale Data Markup Language (LDML)}, part 5,
331 \textit{Collation},
332 \verb|http://www.unicode.org/reports/tr35/tr35-collation.html|.
333 \end{itemize}
334
335 There are at least 3 tasks, from \LaTeX{} to a suitable key (eg,
336 \verb|$\delta$| to \verb|delta| or whatever you want), collating these
337 keys, and generate the formated index in a form \LaTeX{}
338 understands.\footnote{There can be also sub-tasks. For example, the
339 last task is best split in two sub-tasks, namely, first generate a
340 sorted list of terms, and then format them, but unfortunately, most
341 \texttt{ist} styles output a formatted list. We also need to format and
342 collapse locators and so on.} With \textsf{makeindex} these 3 steps are
343 intermingled, and so does \textsf{esindex}. This is another reason why
344 a general solution deserves a completely new package. However, with
345 some patience you can do many useful things with \textsf{esindex}, even
346 sorting words in non-Latin scripts (at least, with the most basic
347 rules).
348
349 \end{document}
350
351 MIT License
352 -----------
353
354 Permission is hereby granted, free of charge, to any person obtaining a
355 copy of this software and associated documentation files (the
356 "Software"), to deal in the Software without restriction, including
357 without limitation the rights to use, copy, modify, merge, publish,
358 distribute, sublicense, and/or sell copies of the Software, and to
359 permit persons to whom the Software is furnished to do so, subject to
360 the following conditions:
361
362 The above copyright notice and this permission notice shall be included
363 in all copies or substantial portions of the Software.
364
365 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
366 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
367 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
368 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
369 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
370 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
371 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.