## LaTeX forum ⇒ General ⇒ Is it possible to create an index without the \index{} command?

LaTeX specific issues not fitting into one of the other forums of this category.
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

### Is it possible to create an index without the \index{} command?

I know how to make a nice index with LaTeX, but it is tedious. Until there's a better way that I'm unaware of, we must indicate each word that we want to get into the index, using the command \index{<word>}. For example :
\RequirePackage[l2tabu,orthodox]{nag}\documentclass[11pt,twoside]{book}\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}\usepackage{imakeidx}\indexsetup{othercode=\small}\makeindex[program=makeindex,columns=2,intoc=true] \begin{document} \chapter{Funky title 1}Some weird text with an indexed word : word1\index{word1}.  Bla bla blabla. \newpage \chapter{Hilarious title 2}More funny text here, with some indexed words : word1\index{word1} and word2\index{word2}.  Blabla bla bla. \cleardoublepage\printindex\end{document}

This indexing method is boring, and laborious in a large book. So is it possible to code the following idea instead ?

You define the list of all the *exact* words you want to see in the index, for example :
index_list = {word1, word2, ...}

Then LaTeX could read that list (using some package or some code that I don't know), and create an index of the occurrence of all the pages in your document that have the exact same words.

I know that this may create a large number of pages in the index, for a single word that is often used. Maybe we could ask LaTeX to show the first page only, for each chapter (or section), or something more convenient. Notice that this idea doesn't ask us to use the \index{} command at all.

This idea may have many limitations, or constraints, since we may want to use some sub-indexing (like \index{cake!chocolate}), and may have problems with words that have accents (like \index{ecole@école}, in French).

Is this idea doable in LaTeX? Is there a special package that may do this?

Stefan Kottwitz
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Hi Cham,

quick and easy way: for day keyword foo, create a macro \foo that contains the word plus an \index command. Then use \foo in the text. One benefit is, that you can add formatting whenever you decide. The construction of \foo with \index could be done via another macro to save typing and to have consistency.

Another approach would be using xesearch, that requires XeLaTeX.

I think there's no ready-to-use package.

Because of the latter I think, it's not work the effort, since auto generated indexes would be not as good as human made indexes. Good indexing is a professional work.

Stefan

Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm
I don't understand your suggestion. Can you give an explicit example using the MWE code above ?

What I would like to do, is to build the index without using the command \index{}. Just tell LaTeX a list of words that need to be indexed, at the beginning of the code or in the preamble. I suspect this isn't possible. Or it may imply alot of complicated coding to tell LaTeX what to do with the list.

Is there other packages that is able to create an index?

Stefan Kottwitz
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Both of my suggestions involve \index, but once in the macro, not a hundred times in the main document body.

Without \index, it is not possible, somewhere it must be placed.

Stefan

Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm
Then what are the advantages of your suggestion? You still need to warp the words in the text with a command. This is the long process I want to get rid.

I guess that the macro could be something like \idx{word}, instead of typing word\index{word}.

Stefan Kottwitz
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Old way:

Some text \index{keyword}keyword ... text ... \index{keyword}keyword

Suggested way:

Some text \keyword ... text ... \keyword

Not so bad, also seen the fact that now you have a macro to even add glossary entries or formatting. \keyword would be defined so that it contains \index plus \xspace at the end.

Stefan

Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm
How your macro would work for words with accents, like "école" or "café" ? (old way : \index{ecole@école}) Or if you need to index a sub word, like \index{gateau@gâteau!chocolat} ?

Stefan Kottwitz
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Internally, the macro would use école. But you are also right, the macro cannot contain accented characters, so the macro name would be \ecole.

Definitions like


or something like with \foreach in TikZ, or forloop

\foreach \key in {keyword,école,other,...} {  \idx{key} }

Stefan

Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm
Stefan Kottwitz wrote:

Stefan, this would still pose a problem for words with accents. For example ; "école" inside \newcommand*{\idx}[1]{\index{#1}{#1}} will not print the "é" or will not print it at the proper place in the index.

Also, we can't use sub-index entries with these macros, like \index{walking!zombie} (sorry for the stupid example!).

I suspect there's no solution and that we still need to make the index in the old standard way.

Stefan Kottwitz
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Special characters can be treated in an index and is just an indexing topic. And for a keyword that goes too sub index, one needs a different macro. Anyway, the solution you look for is pretty impossible (how should it guess sub index or main index) and may produce a big pile of index entries anyway that's possibly not human usable.

Btw. any perl or other script program could parse a LaTeX file and insert \index entries anywhere following a word list in this script.

Stefan