[texhax] Index and Glossary?

Niall Mansfield texhax at uit.co.uk
Fri Dec 9 12:59:01 CET 2005


  > So if I want to have the word "latex" in my index and
  > glossary I have to mark the work latex with a \index{latex} at each
  > place it occurs in the text.
  > Is there a package ...

Forget about a package.  Instead, define macros/commands for all the
words that you'll want indexed.  The following are progessively more
sophisticated approaches you can take.  (I've written several books in
LaTeX, and indexed others, and the following has worked well.  For short
documents, approaches (1) and (2) would probably be enough.)

1. One-off simple definition

	\newcommand{\latex}{\index{latex}latex}

   and then in your text you use \latex{} throughout.

	I am a great fan of the \latex{} system because it lets you define ...

   (Note the {} -- otherwise you won't get a space after the word.)


2. More complex formatting

   By defining and using a consistent command instead of literal
   words, you can easily enhance the formatting of the text item and/
   or the index term, and maybe make the command shorter to type as
   well..  What I actually use is:

	\newcommand{\ltx}{\LaTeX\index{\LaTeX}}

   Another example is where you know that the index entry needs to be qualified in
   some way, or cross-referenced.  E.g.

	\newcommand{\disp}{DISPLAY\index{DISPLAY environment variable}{\index{environment variable, DISPLAY}}}

   This gives you consistent index entries with almost no effort.


3. Making it easier

   I define commands to make it easier to define other index commands:

	\newcommand{\ixo}[1]{\index{#1}}  % index only
	\newcommand{\ixb}[1]{\ixo{#1}#1}  % index before text item
	\newcommand{\ixa}[1]{#1\ixo{#1}}  % index after text item

   The before/after stuff is a consideration near punctuation.  E.g. there's
   a difference between

	jumped over lazy dog\index{dog}.

   and

	jumped over lazy \index{dog}dog.

   The first one gives you unwanted space before the period.  The
   second is the correct one.  Using my commands I'd have written this
   as:

	jumped over lazy \ixb{dog}.

   (In fact, if I was writing a dog book, I'd have created a macro right at the beginning:

	\newcommand{\dog}{\ixb{dog}}

   and then in the text used:

	jumped over lazy \dog.


4. Automating the automating

   For very large works, you can automate the macro definitions.  E.g. I use

	\definequad{envvar}{\sf}{}{!environment variable}

   which I've defined, which in turn defines several different but related macros.  E.g.

	 \envvarxb{DISPLAY}  % indexes the term ("before" - see above) and includes it in the text
	 \envvarxa{DISPLAY}  % indexes the term ("after") and includes it in the text
	 \envvarnx{DISPLAY}  % no index, but included in the text
	 \envvarxo{DISPLAY}  % index entry only

   but my mechanism for this is messy so I haven't included it.  However, I mention
   it because if you use some consistent system like this it makes indexing (and
   writing) relatively fast and easy.


-------------------------------------------------------------
Niall Mansfield
    UIT Cambridge Ltd.
    PO Box 145                          email: nmm at uit.co.uk
    Cambridge CB4 1GQ,  England		tel: +44 1223 302 041
-------------------------------------------------------------




More information about the texhax mailing list