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

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

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

Postby Cham » Thu Dec 07, 2017 9:27 pm

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 :
  1. \RequirePackage[l2tabu,orthodox]{nag}
  2. \documentclass[11pt,twoside]{book}
  3. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  4. \usepackage{imakeidx}
  5. \indexsetup{othercode=\small}
  6. \makeindex[program=makeindex,columns=2,intoc=true]
  7.  
  8. \begin{document}
  9.  
  10. \chapter{Funky title 1}
  11. Some weird text with an indexed word : word1\index{word1}. Bla bla blabla.
  12.  
  13. \newpage
  14.  
  15. \chapter{Hilarious title 2}
  16. More funny text here, with some indexed words : word1\index{word1} and word2\index{word2}. Blabla bla bla.
  17.  
  18. \cleardoublepage
  19. \printindex
  20. \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 :
  1. 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?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Dec 08, 2017 12:39 am

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
Site admin

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Dec 08, 2017 2:14 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?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Dec 08, 2017 2:18 pm

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
Site admin

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Dec 08, 2017 2:24 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}.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Dec 08, 2017 2:31 pm

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
Site admin

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Dec 08, 2017 2:36 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} ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Dec 08, 2017 3:30 pm

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

  1. \newcommand*{\idx}[1]{\index{#1}{#1}}
  2. \newcommand*{\keyword}{\idx{kexword}}
  3. \newcommand*{\ecole}{\idx{école}}
  4. ...

or something like with \foreach in TikZ, or forloop

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


Stefan
Site admin

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Dec 08, 2017 6:30 pm

Stefan Kottwitz wrote:
  1. \newcommand*{\idx}[1]{\index{#1}{#1}}
  2. \newcommand*{\keyword}{\idx{kexword}}
  3. \newcommand*{\ecole}{\idx{école}}
  4. ...



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.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Dec 08, 2017 8:02 pm

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
Site admin


Return to “General”

Who is online

Users browsing this forum: Baidu [Spider] and 5 guests