The package indextools ∗
Mạeul Rouquette
†from Enrico Gregorio’s work
Contents
1 Introduction 2
2 Package usage 3
3 Specific package commands 5 4 If something goes wrong 8
5 Hints 10
5.1 Conflicts. . . 10
5.1.1 Two columm typesetting and index prologue . . 10
5.1.2 Classmemoir . . . 12
5.1.3 Packageshowidx . 12 5.1.4 Packagefancyhdr . 13 5.1.5 Packagecombine . 13 5.2 Packagebidi . . . 13
5.3 Index layout customisation 13 5.4 Index page customisation 13 5.5 Index location customi- sation . . . 15
5.6 Using theshowidxpackage 16 5.7 Index List sectioning cus- tomisation . . . 16
6 Implementation 17 6.1 Incompatibilities and emulation . . . 18
6.2 \makeindex . . . 19
6.3 \index. . . 22
6.4 \printindex . . . 23
6.5 ‘innnote’ and ‘notenum- ber’ options . . . 29
Abstract
This package is a fork of the imakeidx package. The original authors of imakeidx were Claudio Beccari and Enrico Gregorio; the first author withdrew his availability as a maintainer in 2013. The second author de- clined some upgrade suggestions to remove some incompatibilities with cer- tain packages that are particularly important with critical editions dealing with languages that are being written from right to left. Therefore this fork, namedindextools, was created by Mạeul Rouquette, who acknowledges the work of the two preceding authors thanking them for the excellent package they created; nevertheless this fork was necessary in order to let other users benefit from its functionalities very useful in the field of humanities.
We hope that one day, only one package will be provided. The differences with theimakedixare:
∗Version number v1.5.1; last revision 2015/11/22.
†maieul at maieul dot net
• the name;
• the compatibility with packagebidi;
• this documentation.
This package replaces and extends the functionalities ofimakeidx, therefore it MUST not be loaded at the same time as imakeidx. Some controls are implemented to avoid these situations; if loading of indextools is required afterimakeidxis already loaded, it does not get loaded; at the same time, if it gets loaded, it sets a suitable macro so thatimakeidxcan’t be loaded after indextools.
This package exploits the\write18facility of modern TEX system distri- butions that allows to run system commands while typesetting a document written with the LATEX mark up. By so doing, the index or indices, that are usually typeset at the very end of the document, are possibly split and sorted so as to include them in the document itself. This process has some minor limitations: it’s impossible to start an index before all other pages have been ejected.
For support, please open issues on:
https://github.com/maieul/indextools
1 Introduction
It’s been some years now that the typesetting engine of the TEX system is just pdftex; the original Knuthian tex is still corrected by D. E. Knuth himself, but is frozen, according to his will; it is still distributed by every TEX distribution, but in practicepdftex, xetex or luatex are the most used interpreters and typesetting engines of most macro packages.
This programpdftex was originally born with the facility of producing either a pdf output file, as its name suggests, or a dvi file. Since then it has been enriched with many upgrades, also with regard to the evolution of the PDF language itself.
It also incorporates the extensions ofε-TEX and has the ability to open a shell so as to run system commands with their arguments. The same is true forxetex and luatex.
This facility, since the TEX Live 2010 distribution, is official, but is sort of restricted, in the sense that the TEX system configuration file contains a list of
“safe” system commands that can be run bypdftex; presently the only program relevant for this package ismakeindex. This precaution is necessary in order to avoid running malicious code. Other programs can be run, though, but it’s necessary to expressly tellpdftex that it can do so; this authorisation is given by means of a suitable program option, as explained below.
This package will exploit this facility in order to run a perl script that is capable of splitting a raw index file into different chunks and to run themakeindex orxindy TEX system programs so as to sort and format the index entries according to a specified index style file. Once the shell is terminated, the typesetting program resumes its work and possibly prints the various formatted indices produced in
previous steps. In this way the document indices are always synchronous with their document and no further typesetting runs are necessary.
In order to reach this goal, it is necessary that at least the restrictedwrite18 facility is enabled; if the TEX distribution in use does not enable this restricted fea- ture by default, it is necessary to enable the typesetting engine to run such facility;
depending on the distribution and the shell editor that is being used to work on a specific document, it is necessary to add--shell-escape(or--enable-write18 for MiKTEX) to the command with which the typesetting program is launched, possibly through the shell editor. This applies to all threepdftex,xetex, andluatex typesetting engines.
If LuaLATEX is used andluatexis version 0.42 to 0.66, it’s impossible to distinguish whether the restricted shell escape is active or not, so the automatic procedure will be tried anyway, unless disabled with thenoautomaticpackage option. With version 0.68 or later, the behaviour is the same as with the other engines.
2 Package usage
This package is invoked as usual by means of a\usepackagecommand:
\usepackage[hoptionsi]{indextools}
The availablehoptionsiconsist in a comma separated list of the following op- tions:
makeindex in order to use themakeindex sorting and formatting engine; this op- tion is the default and is mutually exclusive with the next option.
xindy in order to use thexindy sorting and formatting engine;texindyis an alias forxindyand actually it’s the scripttexindywhich is called by this package.
Nevertheless if the realxindy is desired, in order to avoid the settings made up by texindy, so as to add xindy the command line specific settings, it is possible to specify the optiontruexindy; the user is then responsible to set up thexindy engine with the suitable command line options.
noautomatic disables the automatic splitting of the raw index files and running of the system programs; this option might be used to save time when one knows for sure that the index files are already OK and do not need to be refreshed. Actually the time spent in splitting, sorting and formatting is so short that this option might be useful only when very lengthy indices are being processed.
nonewpage inhibits the new page command to be issued when using an article type document class and multiple indices are being typeset. We don’t see why someone would use multiple indices in an article (except possibly for package documentations, which usually provide a macro index and a list of changes).
quiet suppresses all messages about manual index processing.
original uses the class-provided theindex environment for typesetting the in- dices; it is implicitly set if the document class option twocolumnhas been specified.
afterindex allows to use\index command after\printindex. If this case, the index will be printed only on the secund run.
innote adds a mark for content indexed in note. The standard mark is an italic
‘n’ added after the page number. You can redefine the\innnotecommand to modify the standard mark. The default value is:
\providecommand{\innote}[1]{#1\textit{n}}
notenumber adds the note number for content indexed in note. The stan- dard marks is a ‘n.’ followed by the note number. You can redefine
\innnotenumberto modify the standard mark. The default value is:
\providecommand{\innotenumber}[2]{#2n.~#1}
splitindex calls thesplitindexscript by Markus Kohm, which is included in every TEX Live distribution since 2009. With this option all index entries, which are written in one raw index file, are successively split into all the requested index files; in this way there is virtually no limit on the number of indices that is possible to create for a particular document.
The last described option deserves an explanation. LATEX can write on a limited number of files during a run, and some of theseoutput streamsare already reserved (among these: aux files, toc files, lof files, lot files, plus several other ones). When more than one index is produced, there’s the risk to run off the number of writable files, because normallyindextoolsreserves an output stream for each index. So the splitindexoption comes to rescue: with it onlyone raw index file is written out.
At the first\printindex command, the programsplitindex is called; it splits the large index file into as many parts as the number of requested indices; after this, makeindexorxindy can do their job. In this way only one output stream is needed during the LATEX run.
When should you apply this option, then? With one index it’s useless, you should begin to consider it for two or more indices and definitely use it if you get the error message
! No room for a new \write
Apart from this case, with or without it, the results are the same. See section 4 to see what files are written during the LATEX run with or without the option.
3 Specific package commands
As it is customary when just one index is produced, the standard LATEX facilities, i.e. the commands \makeindex, \index, and \printindex must be used. This package redefines them so as to produce multiple indices and defines some other commands. The first three of the following commands may be used only in the preamble.
\makeindex with the syntax:
\makeindex[hkey-valuesi]
wherehkey-valuesiis a comma separated list of key-value assignments of the form:key=value; the available keys are the following:
name is the symbolic name for an index; if this key is not specified, it de- faults to the value of the\jobnamecontrol sequence, in other words the name of the current main .tex file, i.e., the file that \inputs and/or
\includes all the files of the complete document. This symbolic name is necessary only when doing multiple indices and is used with the\index command to point to the right index.
Example:name=nameidx
title is the title that is typeset at the beginning of the specific index; if not specified, the\indexnamevalue is used.
Example:title=Index of names.
program is the name of the system program that is used to sort and format an index; valid choices aremakeindex,xindy, ortexindy, plustruexindy. If not specified the program specified among the package options is used.
If no option is specified,makeindex is used. In order to usexindy, it’s necessary to callpdflatex with the shell escape command line option.
Example:program=xindy.
options is the list of options to be passed to the sorting and formatting pro- gram; this list is a balanced text of program options, separated with the syntax required by the sorting and formatting program. For ex- ample, in order to use a different makeindex sorting and formatting stylemystyle.ist and avoiding any message in the screen output, write options=-s mystyle.
noautomatic is a boolean key that defaults tofalse; you can set it totrueby simply listing its key in the key-value list, without necessarily specifying the=truepart. If specified the index sorting program won’t be called during the typesetting run for this particular index.
intoc is a boolean variable that defaults tofalse; if you want to set ittrue you must simply list this key in the key-value list, with no need of specifying the=truepart. By setting this key totruean entry for this particular index is put in the table of contents.
columns accepts an integer representing the number of columns in the index;
this is silently ignored if the original or the twocolumn options are
set; the number can even be1. Example:columns=3
columnsep accepts a dimension representing the separation between index columns; the default is35pt as in the standard classes.
Example:columnsep=15pt
columnseprule is a boolean option; if it is set, a rule will appear between the index columns.
\indexsetup with the syntax:
\indexsetup{hkey-valuesi}
where again hkey-valuesi is a comma separated list of key=value assign- ments; the available keys are:
level whose acceptable values are sectioning commands such as\chapteror
\chapter*. Actually any command with an argument will do and will receive the index title as its argument. The default is\chapter*or, if the class doesn’t provide chapters,\section*. If you specify\chapter so as to override the default starred command \chapter*, the index title goes directly to the table of contents; in this case do not specify theintocoption.
toclevel whose acceptable value is a sectioning command name such as sectionto indicate the level at which we want the indices appear in the table of contents.
noclearpage is a boolean option; when set, no \clearpage will be issued between indices. You might want to set it in order to have a ‘chapter of indices’; in this case you are responsible for setting the right value of the above keys. For example
\indexsetup{level=\section*,toclevel=section,noclearpage}
...
\chapter*{Indices}
\printindex
\printindex[names]
\printindex[objects]
See more on this subject in section5
firstpagestyle whose acceptable value is a page style, default plain. You might want to set it toemptyor some other page style defined by the class or by yourself. This keyword is disabled when the packagefancyhdr is loaded; any definition or choice of page styles must be done before typesetting the indices.
headers which takes two values: the left and right marks. You might want to use this for disabling automatic uppercasing, by saying, for example, headers={\indexname}{\indexname}; notice that these values should always be a pair of balanced braced texts. Don’t use these keys if you usefancyhdr.
othercode whose acceptable value is arbitrary TEX code that will be executed at the beginning of index entries typesetting. For example you might want to change here the setting of \parskip.
\splitindexoptions must have as its argument the command line option to splitindex; this might be necessary on some systems. The default is -m "", because we want it only for splitting the large index file into its components which are later processed by this package. See thesplitindex documentation for other options.
\index with the syntax:
\index[hnamei]{hentryi}
insertshentryiin the raw index file namedhnamei; if only one raw index file is being built in order to split it in different index files by means ofsplitindex, thehentryiis listed in the specific slit index file with namehnamei; if no name is specified, thishentryiis added to the default index with name\jobname. The hentryi should be written according to the particular syntax of the sorting and formatting program.
\indexprologue with the syntax:
\indexprologue[hspacingi]{htexti}
is used to define somehtextito go between the index header and the entries;
thehspacingishould be a vertical space command such as \vspace{36pt}
(default is \bigskip), controlling the spacing between the prologue and the index proper. The command affects only the next index produced by
\printindexand is best placed just before this command. Please read ahead for further information on the use of this command.
\printindex with the syntax:
\printindex[hnamei]
is used to typeset the particular index named hnamei; if no optional ar- gument is specified, the default index with name \jobname.indis typeset.
Actually this command activates all the mechanism of closing the output to the raw index file, shelling out, possibly calling thesplitindexscript in order to divide the single raw file generated by the typesetting engine into dis- tinct raw files according to the default or specifiedhnameis for each index, calling the sorting and formatting program on each of these split raw files (unless inhibited by anoautomatic option; in which case a warning is issued in order to remember the typesetter that this particular index has not been processed), producing the sorted and formatted .ind files, and eventually inputs and typesets these formatted files. Deep breath.
Let’s see an example. The sequence of commands ...
\usepackage{indextools}
...
\makeindex[title=Concept index]
\makeindex[name=persons,title=Index of names,columns=3]
...
\begin{document}
...
...relativity\index{relativity}...
...
... Einstein\index[persons]{Einstein, Albert}...
...
And this is the end of the story.
\printindex
\indexprologue{\small In this index you’ll find only famous people’s names}
\printindex[persons]
\end{document}
will produce two indices. Entries for either index must be typed as shown above.
The prologue will be printed (full text width) only in the “Index of names”, which will be typeset in three columns.
When the original option is set, maybe implicitly because of twocolumn,
\indexsetupand the keyscolumns,columnsepandcolumnseprulefor\makeindex have no effect. Please read more on this matter further on.
4 If something goes wrong
Sinceindextoolsrelies on good cooperation between package options and command line options for the LATEX run, in some cases it may happen that the indices are not correctly built or built at all.
If you use onlymakeindex and TEX Live 2010 or later, then you shouldn’t need anything special, sincemakeindex is among the safe programs allowed to be called during a LATEX run, be itlatex,pdflatex,xelatex, orlualatex.
When the options splitindex, xindy, texindy or truexindy are speci- fied (globally or locally), the LATEX run should be called with the unrestricted --shell-escape(which is--enable-write18for MiKTEX) typesetting program option or thenoautomaticoption should be specified when loadingindextools.
Let’s look at a couple of examples. In both we suppose that the document mybook.texdefines two indices through
\makeindex[...]
\makeindex[name=secondary,...]
where...denotes possible options excluding name.
First of all we examine the case whenindextoolsis calledwithoutsplitindex. Two files called mybook.idx and secondary.idx will be written during the LATEX run. At the corresponding \printindex command, makeindex will act on
\makeindex
\makeindex[name=secondary]
withoutsplitindex withsplitindex (at\begin{document})
mybook.idx mybook.idx secondary.idx
(at\printindex)
mybook.ind mybook-mybook.idx mybook.ilg mybook-secondary.idx secondary.ind mybook-mybook.ind secondary.ilg mybook-mybook.ilg
mybook-secondary.ind mybook-secondary.ilg Table 1: Files written during a LATEX run
each of them producing the files mybook.ind, mybook.ilg, secondary.ind and secondary.ilg. The.indfiles contain the relevanttheindexenvironments with alphabetised entries, while in the.ilgfiles makeindex will write its log. You can check inmybook.logwhether the makeindex run has been executed by searching for a line
runsystem(makeindex <...>)...executed
where <...> stands for the rest of the command line in the particular case. If this line is not present, then makeindex has not been called; this happens when you didn’t specify the shell escape command line option for the LATEX run or the restricted shell escape is not active; also, of course, if you set the noautomatic option for the index.
When using splitindex, the situation is different. During the LATEX run, only a large index file called mybook.idx file gets written; the first \printindex command will call splitindex (unrestricted shell escape must be active), which will produce the two partial index files mybook-mybook.idx and mybook-secondary.idx. These two files will be processed bymakeindexproducing the four filesmybook-mybook.ind,mybook-mybook.ilg,mybook-secondary.ind andmybook-secondary.ilg. The line
runsystem(splitindex <...>)...executed
inmybook.logwill tell that the splitting has been done (see later on if this doesn’t seem true). In table1you can see what files are produced when the first two lines are in the preamble.
Everything is the same when usingtexindy for alphabetising, except that, by default, it doesn’t write.ilgfiles. If you want them, addoptions=-t hnamei.ilg
to the relevant\makeindexcommand, in our example it should be
\makeindex[...,options=-t mybook.ilg]
\makeindex[name=secondary,...,options=-t secondary.ilg]
The name of the.ilgfilemust be specified. Remember, though, thatxindy .ilg files may turn out to be very large.
When something different from expected appears to take place, check also the time stamps of the produced files; if they are older thanmybook.log, it means that they have not been written in the last run. The most common case is that you forgot to activate the shell escape feature (which is not necessary with TEX Live 2010 or later, provided you use onlymakeindex).
Another cause of malfunction might be a wrong option passed to makeindex, texindy orsplitindex. For example, if you specify a style option formakeindex such asoptions=-s mystyle.istand the style file is missing or its name is mistyped, the run of makeindex will result in mybook.log, but it will be aborted and the TEX program has no control over this process. In this case the.ilgand.indfiles will not be produced and you can spot the problem by checking the time stamps.
On some systems a message such as Index file mystyle.ist not found
Usage: makeindex [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num]
may appear on the screen, but often this window gets closed before you realize you have a problem. The time stamp is the best clue to detect such problems.
Shell hackers may be able to redirect the stderr stream to a file, but this requires skills that can’t be explained here, because they require tens of different tricks, depending on what method is used to start a LATEX run. From the command line, assumingbash, it would be something like
pdflatex --shell-escape mybook.tex 2>latex-errors
If shell hackers know a way to access the exit status of the called program, we’d be glad to implement a supplementary check.
5 Hints
Actually this package reaches two goals: (a) it typesets the indices of a specific document in just one run, and (b) it lets the author/typesetter produce documents with multiple indices.
5.1 Conflicts
5.1.1 Two columm typesetting and index prologue
As it has been already mentioned, it is possible to use the command\indexprologue to write some text before the index proper gets typeset; an optional space may be used in place of the default one-line spacing between the index title, the prologue and the index body.
This facility relies on a particular feature of themulticolsenvironment, that indextoolsuses to instruct the typesetting program to typeset the index with a specified number of balanced columns. The choice ofmulticolshas been made because it balances the columns in the last page; the declaration\twocolumdoes not perform the same way, and, if used, it makes\printindex typeset the index in two-column mode with an unbalanced last column.
In the previous sections it has been clearly stated that any configuration of the way indextools typesets the indices is bypassed if the option original has been specified either explicitly or implicitly. It is implicitly specified if the option twocolumnis specified in the class declaration statement.
Why? Because if two column typesetting is desired for the whole document, it is not clear if the index has to be typeset in one column within each column of the document, or if it should be typeset in two column mode after a\onecolumn command is being issued; the results are not the same: with the former method the columns remain unbalanced, while the latter has balanced columns. Furthermore the\onecolumcommand forces a page break; without the\onecolumncommand if the index is treated as a chapter, there is a page break, while if it is configured to be typeset as a section there is no forced page break. With this plethora of combinations we decided to avoid any configuration of the index typesetting and left the decision to the user. This requires the user to practice some ingenuity in order to obtain what he expects.
First of all the user shall not specify thetwocolumnoption to the class. Secondly the user asks for the use ofindextoolsand sets up the single or multiple\makindex commands. thirdly he loads all other packages required for his document; possibly he uses also geometry in order to specify a specific page layout. He shall specify the\twocolumndeclaration after the above has been completed, in any case after the indextools package has been loaded and the single or multiple \makeindex commands are configured.
A good example might be this one:
\documentclass[a4paper,11pt]{book}
\usepackage{indextools}
\indexsetup{level=\section*,toclevel=section,noclearpage}
\makeindex[title=Index of places,columns=1]
\twocolumn
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[italian,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,margin={1in,1in},binding=3mm]{geometry}
\usepackage[english]{varioref}
\usepackage[hang]{caption}
\begin{document}
...
\indexprologue{This index lists all the residences where Lady Esther lived during the time span described in the book.}
\printindex
\end{document}
In this way the index is typeset as a “section”, not as a “chapter”, in one column mode within the two column document style; the indicated prologue is typeset between the index title “Index of places” and the start of the index proper.
On the opposite the following code:
\documentclass[a4paper,11pt]{book}
\usepackage{indextools}
\makeindex[title=Index of places,columns=2]
\twocolumn
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[italian,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,margin={1in,1in},binding=3mm]{geometry}
\usepackage[english]{varioref}
\usepackage[hang]{caption}
\begin{document}
...
\onecolumn
\indexprologue{This index lists all the residences where Lady Esther lived during the time span described in the book.}
\printindex
\end{document}
produces an index typeset as a “chapter”, starting on a new page; it is typeset in two balanced columns. The prologue is typeset where it should. The ingenious reader can experiment mixing the various settings used in these two examples in order to find out what benefits or disadvantages one can obtain with settings that are not physically impossible, but that may be aesthetically conflicting with one another.
5.1.2 Class memoir
The first public version of this package was not compatible with thememoirclass.
Since version 1.1 it is; however, one has to keep in mind that all index processing is done with the methods of the present package, andnotwithmemoir’s; however the syntax used is the same and there should be no problem. There is an interaction betweenmemoirandshowidxthat required special attention. See below about using showidx.
5.1.3 Packageshowidx
Up to version 1.1 this package did not allow to use it together with theshowidx package; now it is, provided thatshowidx is loaded before indextools. See below more information on usingshowidx.
5.1.4 Packagefancyhdr
When using package fancyhdrsome inconveniences did show up; now we believe we have detected the causes and we implemented the necessary corrections1.
5.1.5 Packagecombine
Apparently there might be some conflicts with packagecombine, because this pack- age redefines the contents of \jobname; we tried to control this behaviour, and made the necessary patches, but it is still necessary to load this packageindextools beforepackagecombine.
5.2 Package bidi
A strange conflict was discovered between packagesimakeidx andbidi, in order to lethyperrefredefine some internal macros so as to have index hyperlinks properly executed. This implies that the “index” package be loaded beforehyperref; on the oppositebidi(for bidirectional writing, needed for typesetting Arabic and Hebrew scripts, among other ones)must be loaded afterhyperrefand redefines some hyper commands that have influence on the indexing package; therefore after loading bidi the previous redefinitions are lost. A solution was found by modifying the definition of the environmenttheindexand delaying its definition to the execution of\begin{document}. This is the main reason of this fork so thatindextoolsmay be loaded, as most packages normally do, beforehyperref.
5.3 Index layout customisation
If you redefine yourself thetheindexenvironment, please remember not to number the chapter or section that introduces the index if you ask for theintoc option;
either use the commands \chapter* or the \section*respectively and the in- tocoption or don’t use this option and redefine your theindexenvironment with numbered chapter or section commands, that will put the index titles directly into the table of contents. See below the effect of the\backmatter declaration.
You may use theidxlayoutpackage by Thomas Titz, which offers many functions for index typesetting customisation and is compatible with our package; remem- ber to load idxlayoutafter indextools. This package has a similar function to our
\indexprologue, called \setindexprenote; howeveridxlayout doesn’t reset the index prologue, which must be declared anew or disabled with\noindexprenote before the next\printindexcommand. In any case take into serious consideration what is being said hereafter about customisation.
5.4 Index page customisation
The same, more or less, holds true if you customise your headings;indextoolscan deal with standard settings, but it generally cannot deal with personal styles and
1Thanks to Mạeul Rouquette who, before creating this fork, spotted the problems and sug- gested some patches.
customisations. This is why if you loadfancyhdr, some of the\indexsetupsettings may be disabled.
When you make any kind of customisation, remember that there are several classes, or personal settings, or features that may render your customisation very difficult to handle. Typically:
• There are classes where the normal usable highest sectioning command, dis- regarding\part, is not\chapter, but\section; for example classesarticle, scrartcl.
• Sectioning commands come in two varieties: starred and unstarred; the for- mer ones are not numbered and do not produce any entry in the headings and in the table of contents; the latter ones may behave differently according to the next item.
• There are some classes (for example book, scrbook, menoir,. . . ) that have the special “sectioning” declarations \frontmatter, \mainmatter, and
\backmatterwhich modify how the unstarred sectioning commands behave for what concerns the heading and the table of contents entries.
For what concerns indices, these are generally typeset at the document end.
This means that the\backmatterdeclaration may be in force; in this case unstarred sectioning commands are not numbered but they produce normal headings and table of contents entries.
• Heading entries are used by the output routine paging algorithm in such a way as to extract the left or the right part from suitable “marks”; for the even (left) pages the required information is extracted from the \topmark or\firstmark, while for the odd (right) pages they are extracted from the
\botmark. Generally speaking, the even page heading refers to\leftmark and odd page headings refer to \rightmark; these are the two commands that extract the correct part from the suitable marks. But when you use the headersoption value, you specify two brace balanced strings that are loaded through\markbothas the left and right part of the current mark.
• The contents of the marks may be very varied; they are generally made up of two brace balanced strings, which in turn may contain other brace balanced strings that may be used in different ways by the selected page style and by the page style definitions of the macros\chaptermarks,\sectionmarks, and\subsectionmarksthat may interfere with personal customisations.
• Remember also that things change in an obvious way when one side typeset- ting is chosen; all pages are treated as if they were odd ones; therefore any customisation must take into account also this aspect.
The above list has not been written down for discouraging customisations of any kind: simply it recalls what must be taken care of in order to create one’s customisation in a proper way.
The above list explains why we disabled the commands tied to the\indexsetup keysheadingsandfirstpagestylewhen packagefancydris being used; you may even set up these keys, but if thefancyhdr package has been loaded, we disable their action; this implies that any fancy customisation must be done before starting to print any index.
Theintocoption must also be used with care, as well as the starred or unstarred sectioning commands for thelevel andtocleveloption values. They must be chosen according to what the possible\backmatterdeclaration sets up, in order to avoid double entries in the table of contents; the\backmattersettings may also influence the way heading information is being used, and this makes it even more stringent to set up any index page style customisation before starting to print any index.
Therefore if by chance you get double entries into the table of contents, elimi- nate theintocoption from your calls; your class, packages, and settings are already taking care of it.
The packagetocbibindshould be loaded with thenoindex option, otherwise it would interfere with our redefinition of theindex.
If you redefine your theindexenvironment by means of other packages, pay attention that these redefine a realtheindex environment with this very name;
if they create an environment with a different name,indextoolscan’t take care of the indices production (in particular the TEX system programmakeindexcreates a sorted and formatted.indfile that refers explicitly to thetheindexenvironment), and it can’t take care of the table of contents entry and of the position of the hyper link anchors needed to navigate your document by means of hyper links.
5.5 Index location customisation
Some packages might want to use the facilities of indextools to offer customised index commands, where the entry location is not expressed by a page number, but by an other reference value (for example: line number, entry number, etc.).
These packages may use the low-level command\indtl@wrindexentrywhich takes three arguments:
1. The index name.
2. The entry.
3. The location number.
For example \indtl@wrindexentry{names}{Charles}{26} adds to the index namesthe valueCharleswith the location reference26.
In simpler words, the new command \indtl@wrindexentry is of interest mainly to package and class authors; it is not to be used by the “normal” user, who, on the opposite, if interested in referencing the index entries on some location counter different from the page one, is urged to refer to the classes and packages that implement this facility;eledmac should be one of these packages. Matter of fact this addition to theindextoolspackage was contributed by Mạeul Rouquette, the author and maintainer of eledmac.
5.6 Using the showidx package
If you want to make use of theshowidxfacilities, remember to load that package beforeindextools; remember also to disable or comment out the call toshowidxwhen you typeset the final version of your document. This constraint is due to the fact thatshowidx redefines several internal commands, some of which have to receive theindextoolsdefinition in order to perform as described in this documentation.
At the same time if the memoirclass is being used, remember that this class simulates theshowidxpackage and has its own commands to enable or disable the printing of the index entries into the margin of the document; the default setting is with the\hideindexmarkscommand in force; but if the user wants to write his index entries in the margin he has to issue the declaration\showindexmarksjust after begin document, in any case before the part of the source file(s) he wants to be marked with the index entries in the margin.
5.7 Index List sectioning customisation
Use freely the options and the key values in order to reach the desired results, but you are advised to prepare in advance the styles for composing the various indices in a proper way; for example, if you use a titled style for the index, where the index sections are distinguished with a bold face title or alphabetic letter, you have to set up a.istfile, such asmyindexstyle.ist, made up like this:
headings_flag 1
heading_prefix "\\par\\penalty-50\\textbf{"
heading_suffix "}\\\\\*\~\\\\\*"
symhead_positive "Symbols"
symhead_negative "symbols"
numhead_positive "Numbers"
numhead_negative "numbers"
delim_0 ",\~"
where the numeric and non alphabetic entries have different titles. But, say, you are making also an index where the entries are file names, and for some names only the extension is entered; the extensions start with a dot, so the sorting program will sort these names at the beginning of the sorted index file, but you won’t like to have a title such as “Symbols”; you probably prefer to have a title such as
“Extensions”; therefore you have to prepare a different index style file, such as this one:
headings_flag 1
heading_prefix "\\par\\penalty-50\\textbf{"
heading_suffix "}\\\\\*\~\\\\\*"
symhead_positive "Extensions"
symhead_negative "extensions"
numhead_positive "Numbers"
numhead_negative "numbers"
delim_0 ",\~"
This done, besides requiring the use of this package, you have to declare the
\makeindex command with the necessary options; pay a particular attention to the options that involve the index symbolic name, the index title, the index style, the fact that the index titles shall appear in the table of contents, and if you are preparing an e-book, you probably would like to hyper link both the page numbers and the index titles to the proper locations. The typesetting program will do everything for you but be careful not to confuse it with illogical index entries.
Especially with multiple indices it is important that you are consistent in putting the right information in the right index and with a consistent mark-up.
Define yourself appropriate macros so that, for example, personal names are con- sistently typeset, say, in caps and small caps and are entered into a specific index;
you may even create one command to typeset the name in the document and replicate the same name in the index.
Of course there is no program that can decide at your place what and where to index each piece of information; this is a task for humans. Soooooo. . .
HAPPY TEXING!
6 Implementation
The heading to the file is in common with the documentation file, and has already been taken care of. But we require the xkeyval package, in order to handle the key-value lists.
Notice that in order to create a specific name space so as to avoid possible conflicts with other packages, all the commands defined in this package are prefixed with the stringindtl@.
1\RequirePackage{xkeyval}
We define the various options and their defaults. After \ProcessOptions, we set anyway the original option if the document class has been given the twocolumnoption, which is incompatible withmulticol. We define also an internal alias for\immediate\write18, a rudimentary check for the typesetting engine and a macro for modifying the command line call tosplitindex. Thexpatchis requested;
at the moment none if its features are used, but it callsetoolbox, whose facilities are used here; while future extensions will benefit from the extended patched com- mands, that strongly enrich the performances of the main packageetoolbox.
2\DeclareOption{xindy}{\def\indtl@progdefault{texindy}}
3\DeclareOption{texindy}{\def\indtl@progdefault{texindy}}
4\DeclareOption{truexindy}{\def\indtl@progdefault{truexindy}}
5\DeclareOption{makeindex}{\def\indtl@progdefault{makeindex}}
6\newif\ifindtl@disableautomatic
7\DeclareOption{noautomatic}{\indtl@disableautomatictrue}
8\newif\ifindtl@nonewpage
9\DeclareOption{nonewpage}{%
10 \indtl@nonewpagetrue\indtl@disableautomatictrue
11}
12\newif\ifindtl@splitindex
13\DeclareOption{splitindex}{\indtl@splitindextrue}
14\newif\ifindtl@original
15\DeclareOption{original}{\indtl@originaltrue}
16\DeclareOption{quiet}{\AtEndOfPackage{%
17 \let\indtl@finalmessage\@gobble
18 \let\indtl@splitindexmessage\relax}}
19\newif\ifindtl@afterindex
20\DeclareOption{afterindex}{\indtl@afterindextrue}
21
22\newif\ifindtl@innote
23\DeclareOption{innote}{\indtl@innotetrue}
24
25\newif\ifindtl@notenumber
26\DeclareOption{notenumber}{\indtl@notenumbertrue}
27
28\ExecuteOptions{makeindex}
29\ProcessOptions\relax
30
31\if@twocolumn\indtl@originaltrue\fi
32\def\indtl@exec{\immediate\write18}
33\def\indtl@engine{(pdf)latex}
34\RequirePackage{ifxetex,ifluatex}
35\ifxetex\def\indtl@engine{xelatex}\fi
36\ifluatex % luatex doesn’t have \(pdf)shellescape
37 \def\indtl@engine{lualatex}
38 \ifnum\luatexversion<68
39 \chardef\indtl@shellescape\@ne % no way to know the value
40 \else
41 \RequirePackage{pdftexcmds} % provides \pdf@shellescape
42 \chardef\indtl@shellescape\pdf@shellescape
43 \fi
44 \let\indtl@exec\pdf@system
45\fi
46\RequirePackage{xpatch}
47\edef\indtl@splitindexoptions{-m \string"\string"}
48\def\splitindexoptions#1{\g@addto@macro\indtl@splitindexoptions{ #1}}
49\@onlypreamble\splitindexoptions
6.1 Incompatibilities and emulation
While experimenting we found out that some classes or packages are either in- compatible with this one, or must be faked in order to pretend they have been loaded.
There is a serious incompatibility with thememoirclass. In factsmemoirputs all index entries in the main.auxfile and extracts them to the various raw index files at\end{document}time. This means that no raw index file output stream has been defined, and therefore this package can’t close it; moreover it can’t typeset the indices before\end{document}because they are not yet available. Therefore
ifmemoiris the active class, we will hijack its index mechanism replacing it with ours.
On the opposite we pretend that packagemakeidxor packagemultindhave been loaded, so thathyperref can play with their commands, that are substantially the same as those used here. By so doing those packages are inhibited from being loaded after this one. We do the same with the forked originalimakeidx package so that ifimakeidxis loaded before,indextoolsis not loaded, but an error message is issued; otherwise we fake the fact thatimakeidxhas already been loaded so that it does not get reloaded.
50\@namedef{[email protected]}{3000/12/31}
51\@ifpackageloaded{multind}
52 {\PackageError{indextools}{Incompatible package ‘multind’ loaded}
53 {This package is incompatible with multind, don’t load both.%
54 \MessageBreak\@ehc}}
55 {\@namedef{[email protected]}{3000/12/31}}
56
57\@ifpackageloaded{imakeidx}
58 {\PackageError{indextools}{Incompatible package ‘imakeidx’ loaded}
59 {This package is incompatible with imakeidx, don’t load both.%
60 \MessageBreak\@ehc}}
61 {\@namedef{[email protected]}{3000/12/31}}
At the same time we redefine some commands defined by makeidx and we de- fine the default English names for the \see and \seealso commands. We use
\providecommandso that, if makeidxhas already been loaded, we do not redefine things that have already been defined.
62\providecommand*\see[2]{\emph{\seename} #1}
63\providecommand*\seealso[2]{\emph{\alsoname} #1}
64\providecommand*\seename{see}
65\providecommand*\alsoname{see also}
6.2 \makeindex
From here on, some commands are duplicated; this depends on the fact that the behavior must be different when usingsplitindexor not. The memory occupied by the useless commands will be cleared at the end of package.
66\providecommand*\makeindex{} % to use \renewcommand safely
67\renewcommand{\makeindex}[1][]{\indtl@makeindex{#1}}
68% \@onlypreamble\makeindex % Already in latex.ltx
This package implementation of\makeindexsets default values for the keys, then evaluates its argument (which is the optional argument to\makeindex) and calls two other macros. After that we have to reset the defaults.
69\def\indtl@makeindex#1{%
70 \edef\indtl@name{\jobname}%
71 \edef\indtl@jobname{\jobname}%
72 \def\indtl@title{\indexname}%
73 \edef\indtl@program{\indtl@progdefault}%
74 \let\indtl@options\space
75 \KV@indtl@noautomaticfalse\KV@indtl@intocfalse
76 \setkeys{indtl}{#1}%
77 \ifindtl@splitindex\KV@indtl@noautomaticfalse\fi
78 \indtl@build\indtl@name
79 \indtl@startidx\indtl@name
80 \indtl@resetdefaults
81}
Here are the keys. As usual, theindtl@prefix is used to distinguish anything that is being defined in this package, even the keys.
82\define@key{indtl}{name}{\def\indtl@name{#1}}
83\define@key{indtl}{title}{\def\indtl@title{#1}}
84\define@choicekey{indtl}{program}[\indtl@val\indtl@nr]
85 {makeindex,xindy,texindy,truexindy}{%
86 \ifcase\indtl@nr\relax
87 \def\indtl@program{makeindex}%
88 \or
89 \def\indtl@program{texindy}%
90 \or
91 \def\indtl@program{texindy}%
92 \or
93 \def\indtl@program{xindy}%
94 \fi}
95\define@key{indtl}{options}{\def\indtl@options{ #1 }}
96\define@boolkey{indtl}{noautomatic}[true]{}
97\define@boolkey{indtl}{intoc}[true]{}
98\define@key{indtl}{columns}{\def\indtl@columns{#1}}
99\define@key{indtl}{columnsep}{\def\indtl@columnsep{#1}}
100\define@boolkey{indtl}{columnseprule}[true]{}
101\def\indtl@resetdefaults{%
102 \def\indtl@options{ }%
103 \def\indtl@columns{2}\def\indtl@columnsep{35\p@}%
104 \KV@indtl@columnseprulefalse
105 \KV@indtl@intocfalse\KV@indtl@noautomaticfalse}
106\indtl@resetdefaults
The control sequence \indtl@build defines a control sequence to hold the setup for an index to be used when the index is sorted and printed
107\def\indtl@build#1{%
108 \toks@{}%
109 \indtl@dokey\indtl@title
110 \indtl@dokey\indtl@program
111 \indtl@dokey\indtl@options
112 \indtl@dokey\indtl@columns
113 \indtl@dokey\indtl@columnsep
114 \ifKV@indtl@noautomatic
115 \addto@hook\toks@{\KV@indtl@noautomatictrue}%
116 \else
117 \addto@hook\toks@{\KV@indtl@noautomaticfalse}%
118 \fi
119 \ifKV@indtl@intoc
120 \addto@hook\toks@{\KV@indtl@intoctrue}%
121 \else
122 \addto@hook\toks@{\KV@indtl@intocfalse}%
123 \fi
124 \ifKV@indtl@columnseprule
125 \addto@hook\toks@{\KV@indtl@columnsepruletrue}%
126 \else
127 \addto@hook\toks@{\KV@indtl@columnseprulefalse}%
128 \fi
129 \expandafter\edef\csname indtl@set@#1\endcsname{\the\toks@}%
130}
Comand \indtl@dokey receives as argument the text of the values assigned to certain keys, and adds them to the options token list.
131\def\indtl@dokey#1{%
132 \expandafter\addto@hook\expandafter\toks@\expandafter{%
133 \expandafter\def\expandafter#1\expandafter{#1}}}
Command \indtl@startidx defines the output stream(s); the macro with suffixsplit is used whensplitindex is not enabled, the one with suffix uniqueis used otherwise. In the case of many indices, the symbolic name for an index named
‘pippo’ is\pippo@idxfilecorresponding to the filepippo.idx. When splitindex is enabled, the only output stream is called \@indexfile as in standard LATEX, corresponding to\jobname.idx.
134\def\indtl@startidxsplit#1{%
135 \if@filesw
136 \def\index{\@bsphack
137 \@ifnextchar [{\@index}{\@index[\indtl@jobname]}}
138 \expandafter\newwrite\csname #1@idxfile\endcsname
139 \immediate\openout \csname #1@idxfile\endcsname #1.idx\relax
140 \typeout{Writing index file #1.idx}%
141 \fi}
We define a switch which is set to true when a \makeindex command is given:
withsplitindexwe open only one stream.
142\newif\ifindtl@startedidx
143\def\indtl@startidxunique#1{%
144 \if@filesw
145 \ifindtl@startedidx\else
146 \newwrite\@indexfile
147 \immediate\openout\@indexfile\[email protected]%
148 \global\indtl@startedidxtrue
149 \fi
150 \def\index{\@bsphack
151 \@ifnextchar [{\@index}{\@index[\indtl@jobname]}}
152 \expandafter\let\csname #1@idxfile\endcsname\@empty
153 \typeout{Started index file #1}%
154 \fi}
6.3 \index
Provide a default definition for\index; when a \makeindex command is given and LATEX is writing on auxiliary files,\index will be redefined, as seen before.
When index files are written,\indexalways calls\@index. Some code is borrowed frommemoir.cls, but heavily modified. We want\@wrindexto be defined with two arguments, so that hyperref can hook into it just like it does with the similar commands defined by the old packagesmultindandindex.
155\renewcommand{\index}[2][]{\@bsphack\@esphack}
156\def\@index[#1]{%
157 \@ifundefined{#1@idxfile}%
158 {\PackageWarning{indextools}{Undefined index file ‘#1’}%
159 \begingroup
160 \@sanitize
161 \indtl@nowrindex}%
162 {\edef\@idxfile{#1}%
163 \begingroup
164 \@sanitize
165 \@wrindex\@idxfile}}
166\def\indtl@nowrindex#1{\endgroup\@esphack}
Command\@wrindexmust be duplicated; we have to call it the same as usual in order to supporthyperref. But the real name will be given at the end. We have to define a switch to allow the use of theshowidxfacilities. We define also a helper macro so as to do the right thing so as to show the index file name to which a certain index entry is going to be written; the idea is to prefix the index entry with the actual name of the specific index, except in the case or the default index, where the name is set to\jobname. Since the control sequence is a primitive command, its value cannot be directly compared in the \ifx sense to the current macro represented by argument#1. Therefore we need a further helper control sequence
\indtl@jobnamethat contains the value assigned to\jobname.
We must also take care of the case where the user wants to print the index entries in the margin while working on the document. This implies testing for the package showidxbeing already loaded; but this is not sufficient, because the memoirclass simulates the showidx package and the test would result to be true even if the user did not load that package, but uses thememoirclass.
Therefore we use the same boolean used bymemoir, testing in advance so as not redefining it; then we use it to let the showidx true or simulated macros do their job, but we also take care of resetting the switch default value to false at begin document time if thememoirclass is being used.
167\@ifundefined{showindexmarks}{\newif\ifshowindexmark}{}
168\@ifpackageloaded{showidx}{\showindexmarktrue}{\showindexmarkfalse}
169\newcommand\indtl@showidxentry[2]{%
170 \ifshowindexmark
171 \@showidx{\ifdefequal{\indtl@jobname}{#1}{}{[#1]\space}#2}%
172 \fi}
173\newcommand\indtl@wrindexentrysplit[3]{%
174 \expandafter\protected@write\csname#1@idxfile\endcsname{}%
175 {\string\indexentry{#2}{#3}}%
176}
177\newcommand\indtl@wrindexentryunique[3]{%
178 \protected@write\@indexfile{}%
179 {\string\indexentry[#1]{#2}{#3}}%
180}
181\def\indtl@wrindexsplit#1#2{%
182\indtl@wrindexentrysplit{#1}{#2}{\thepage}%
183\endgroup\indtl@showidxentry{#1}{#2}%
184 \@esphack%
185}
186\def\indtl@wrindexunique#1#2{%
187\indtl@wrindexentryunique{#1}{#2}{\thepage}%
188\endgroup\indtl@showidxentry{#1}{#2}%
189 \@esphack%
190 }
6.4 \printindex
Compilation of the indices is disabled if -shell-escape has not been given or the restricted mode is not active; in this case we emit a warning. X E TEX has \shellescape instead of \pdfshellescape, so we take care of this (hop- ing that users or packages don’t define a \shellescape command). In any case we define an internal version of this command. In the case of luatex we can’t emit the proper messages if luatex is not version 0.68 or later. The conditional
\ifKV@indtl@noautomaticis defined by\define@boolkeyabove.
191\def\indtl@shellwarn{}
192\ifdefined\indtl@shellescape % luatex
193\else
194 \@ifundefined{shellescape}
195 {\let\indtl@shellescape\pdfshellescape} % pdftex
196 {\let\indtl@shellescape\shellescape} % xetex
197\fi
198\ifnum\indtl@shellescape=\z@
199 \let\KV@indtl@noautomaticfalse\KV@indtl@noautomatictrue
200 \KV@indtl@noautomatictrue
201 \def\indtl@shellwarn{\MessageBreak or call \indtl@engine\space with
202 -shell-escape}
203\fi
Do the same ifnoautomatic has been given as an option.
204\ifindtl@disableautomatic
205 \let\KV@indtl@noautomaticfalse\KV@indtl@noautomatictrue
206 \KV@indtl@noautomatictrue
207\fi
Now we set up thetheindex environment. If theoriginal option is set, we simply patch the class definition in order to call the macro that does the work related to the table of contents. Otherwise we define a newtheindexenvironment,
based on the standard, but using, if the number of columns is greater than one, the multicolsenvironment. Users needing a different setup can use the\indexsetup command. Before doing so, though, we need to disable certain features if the packagefancyhdris loaded sometimes before the\begin{documentstatement, be it before or after loadingindextools. If that package is loaded we have to patch the definition of the environment theindex, because its default commands interfere with those defined here that work perfectly when fancyhdr is not loaded. This patching could be defined further on, but if it remains close to what has to be patched, it’s easier to understand it’s operation.
We make this redefinition at the begining of the document, to prevent redef- inition by other packages, like bidi. This point is where indextools and imakeidx diverge.
208\newif\ifindtl@fancyhdr
209\AtBeginDocument{%
210 \@ifpackageloaded{fancyhdr}{\indtl@fancyhdrtrue}{\indtl@fancyhdrfalse}%
211 \ifindtl@original
212 \expandafter\def\expandafter\theindex\expandafter{\expandafter
213 \indtl@maybeaddtotoc\theindex}
214 \else
215 \renewenvironment{theindex}
216 {\indtl@maybeaddtotoc
217 \indtl@indexlevel{\indexname}%
218 \ifindtl@fancyhdr\else%
219 \indtl@indexheaders%
220 \thispagestyle{\indtl@firstpagestyle}%
221 \fi%
222 \ifnum\indtl@columns>\@ne
223 \columnsep \indtl@columnsep
224 \ifx\indtl@idxprologue\relax
225 \begin{multicols}{\indtl@columns}
226 \else
227 \begin{multicols}{\indtl@columns}[\indtl@idxprologue]
228 \fi
229 \else
230 \indtl@idxprologue
231 \fi
232 \global\let\indtl@idxprologue\relax
233 \parindent\z@
234 \parskip\z@ \@plus .3\p@\relax
235 \columnseprule \ifKV@[email protected]\p@\else\z@\fi
236 \raggedright
237 \let\item\@idxitem
238 \indtl@othercode}
239 {\ifnum\indtl@columns>\@ne\end{multicols}\fi
240 }
241\fi
242}
243\ifindtl@original
244\else
245 \global\let\indtl@idxprologue\relax
246 \RequirePackage{multicol}
247\fi
The command \indexsetup may be used to customize some aspects of index formatting.
248\def\indtl@indexlevel{%
249 \@ifundefined{chapter}{\section}{\chapter}*}
250\define@key{indtlindex}{level}{\def\indtl@indexlevel{#1}}
251\def\indtl@toclevel{%
252 \@ifundefined{chapter}{section}{chapter}}
253\define@key{indtlindex}{toclevel}{\def\indtl@toclevel{#1}}
254\define@boolkey{indtlindex}{noclearpage}[true]{\let\indtl@clearpage\relax}
255\def\indtl@indexheaders{%
256 \@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}}
257\define@key{indtlindex}{headers}{\def\indtl@indexheaders{\markboth#1}}
258\def\indtl@firstpagestyle{plain}
259\define@key{indtlindex}{firstpagestyle}{\def\indtl@firstpagestyle{#1}}
260\let\indtl@othercode\relax
261\define@key{indtlindex}{othercode}{\def\indtl@othercode{#1}}
262\newcommand{\indexsetup}[1]{%
263 \ifindtl@original\else\setkeys{indtlindex}{#1}\fi}
264\@onlypreamble\indexsetup
The command\indexprologuesets the internal version which is always\let to\relaxduring\begin{theindex}.
265\newcommand{\indexprologue}[2][\bigskip]{%
266 \long\gdef\indtl@idxprologue{{#2\par}#1}}
Now we provide the relevant\printindexmacros by transferring the real job to a secondary macro\indtl@putindexafter due checks and messages.
267\providecommand*{\printindex}{}
268\renewcommand*{\printindex}[1][\indtl@jobname]{%
269 \@ifundefined{#1@idxfile}{\indtl@error{#1}}{\indtl@putindex{#1}}}
270
271\def\indtl@error#1{%
272 \def\@tempa{#1}\def\@tempb{\indtl@jobname}%
273 \ifx\@tempa\@tempb
274 \let\indtl@optarg\@empty
275 \else
276 \def\indtl@optarg{[#1]}%
277 \fi
278 \PackageError{indextools}
279 {Misplaced \protect\printindex\indtl@optarg}
280 {You are not making this index, as no appropriate
281 \protect\makeindex\MessageBreak
282 command has been issued in the preamble.}}
We define a command to do a \cleardoublepage if the optionopenright is active (in classes where twoside is meaningful). In case \chapter is defined but
not\if@openright, we assume that the class wants “open right”.
283\def\indtl@clearpage{%
284 \@ifundefined{chapter}
285 {\clearpage} % article and similar classes
286 {\@ifundefined{if@openright}
287 {\cleardoublepage}
288 {\if@openright
289 \cleardoublepage
290 \else
291 \clearpage
292 \fi}
293 }}
We need a helper macro to do a check in order to avoid a loop and the hook where to insert the table of contents related stuff.
294\def\indtl@check@indexname{\indexname}
295\providecommand*\indtl@maybeaddtotoc{}
Two helper macros for preparing the final messages to the user.
296\def\indtl@finalmessage#1{%
297 \expandafter\edef\csname indtl@message#1\endcsname
298 {\indtl@program\indtl@options#1.idx}
299 \AtEndDocument{\PackageWarning{indextools}{%
300 Remember to run \indtl@engine\space again after calling\MessageBreak
301 ‘\@nameuse{indtl@message#1}’\indtl@shellwarn\@gobble}}}
302\def\indtl@splitindexmessage{%
303 \AtEndDocument{\PackageWarningNoLine{indextools}{%
304 Remember to run \indtl@engine\space again after calling\MessageBreak
305 ‘splitindex’ and processing the indices\indtl@shellwarn}}}
Here is a helper macro for deciding whether to call the external utility or to issue a final message. In \indtl@makeindexname we put the name of the only program allowed by default (makeindex). If the list is updated, we can supplement the list here, maybe defining a list macro; for now this is sufficient. The temporary switch\if@tempswais set to true if automatic processing is possible, so that the main macro can take the appropriate action.
306 \def\indtl@makeindexname{makeindex}
307 \def\indtl@decide{%
308 \@tempswafalse
309 \ifindtl@splitindex % splitindex is not "safe"
310 \ifnum\indtl@shellescape=\@ne\@tempswatrue\fi
311 \else
312 \ifx\indtl@program\indtl@makeindexname % nor is texindy
313 \ifnum\indtl@shellescape=\tw@\@tempswatrue\fi
314 \fi
315 \ifnum\indtl@shellescape=\@ne\@tempswatrue\fi
316 \fi
317 \ifKV@indtl@noautomatic
318 \@tempswafalse
319 \fi}
We define a macro that close a specified index file and run in.
320\newcommand{\indtl@closeandrundidxsplit}[1]{%
321 \immediate\closeout\csname #1@idxfile\endcsname
322 \let\indtl@indexname\indexname % keep \indexname
323 \@nameuse{indtl@set@#1}\indtl@decide
324 \if@tempswa % we can call the external program
325 \indtl@exec{\indtl@program\indtl@options#1.idx}%
326 \else
327 \indtl@finalmessage{#1}%
328 \fi
329}
We define a macro that close the general index file and run in.
330\newcommand{\indtl@closeandrundidxunique}{%
331 \immediate\closeout\@indexfile
332 \indtl@exec{splitindex \indtl@splitindexoptions\space\[email protected]}%
333 \global\indtl@splitdonetrue
334}
We now define the main macro that puts the specified index file into the document and possibly orders to add the index title to the table of contents. It is duplicated as usual. The argument#1is the specific symbolic name of the index. In partic- ular if the intoc option has been specified, the hook \indtl@maybeaddtotoc is defined in such a way that the relevant information is added to thetocfile. The
\phantomsectioncommand is necessary when usinghyperref; here it is hidden as argument to\@nameuse, so it is equivalent to\relaxand does nothing ifhyperref has not been loaded.
335\def\indtl@putindexsplit#1{%
336 \ifindtl@nonewpage\else
337 \indtl@clearpage
338 \fi
339 \ifindtl@afterindex%
340 \AtEndDocument{%
341 \indtl@clearpage%
342 \indtl@closeandrundidxsplit{#1}%
343 \indltl@afterindexMessage%
344 }%
345 \else%
346 \indtl@closeandrundidxsplit{#1}%
347 \fi
348 \ifKV@indtl@intoc
349 \def\indtl@maybeaddtotoc{\@nameuse{phantomsection}%
350 \addcontentsline{toc}{\indtl@toclevel}{\indtl@title}}%
351 \else
352 \def\indtl@maybeaddtotoc{}%
353 \fi
354 \ifx\indtl@title\indtl@check@indexname\else
355 \def\indexname{\indtl@title}%
356 \fi
357 \@input@{#1.ind}
358 \let\indexname\indtl@indexname % restore \indexname
359}
360
361\newif\ifindtl@splitdone
362\def\indtl@putindexunique#1{%
363 \ifindtl@nonewpage\else
364 \indtl@clearpage
365 \fi
366 \let\indtl@indexname\indexname % keep \indexname
367 \@nameuse{indtl@set@#1}\indtl@decide
368 \if@tempswa % we can call the external program
369 \ifindtl@splitdone\else
370 \ifindtl@afterindex
371 \AtEndDocument{%
372 \indtl@clearpage%
373 \indtl@closeandrundidxunique%
374 \indltl@afterindexMessage%
375 }
376 \else
377 \indtl@closeandrundidxunique
378 \fi
379 \fi
380 \else
381 \ifindtl@splitdone\else
382 \indtl@splitindexmessage\global\indtl@splitdonetrue
383 \fi
384 \fi
385 \if@tempswa % we can call the external program
386 \indtl@exec{\indtl@program\indtl@options\indtl@jobname-#1.idx}%
387 \fi
388 \ifKV@indtl@intoc
389 \def\indtl@maybeaddtotoc{\@nameuse{phantomsection}%
390 \addcontentsline{toc}{\indtl@toclevel}{\indtl@title}}%
391 \else
392 \def\indtl@maybeaddtotoc{}%
393 \fi
394 \ifx\indtl@title\indtl@check@indexname\else
395 \def\indexname{\indtl@title}%
396 \fi
397 \@input@{\indtl@jobname-#1.ind}
398 \let\indexname\indtl@indexname % restore \indexname
399}
A warning message when using ‘afterindex’ option.
400\newcommand{\indltl@afterindexMessage}{%
401 \PackageWarning{indextools}{You use the ‘afterindex’ option.
402 \MessageBreak That means you use \string\index\space commands after \string\printindex\space command.
403 \MessageBreak Consequently, the index may be not ok at the first run.
404 }%
405}