[comp.text.tex] LaTeX Indexing

jtc@van-bc.wimsey.bc.ca (J.T. Conklin) (06/09/90)

I have just finished the Administrator's Guide for our product, but
need help with creating an index before I can send it off to the
printers.

I have set up macros like \code{}, and \file{}, which format the text
in boldfacs and slant to give the reader visual cues about the nature
(program or datafile) of what is being discussed in the text.

	\newcommand{\code}[1]{{\bf #1}}

I then tried adding an \index{} in the \code{} definition, since we
want the reader to be able to find the location of discussion about
one of the programs in our package in the index.

	\newcommand{\code}[1]{{\bf #1}\index{#1}}

This works fine, except that some of the \code{} macros start sentances,
and that Capitalized entry is indexed.  I tried using \lowercase{},
but it isn't evaluated until the index is printed.

	\newcommand{\code}[1]{{\bf #1}\index{\lowercase{#1}}}

I looked all through the TeXbook and the LaTeXbook, and didn't find
something like \eval{}, so I'm kind of stuck.  I sent out our drafts
by hand editing the *.idx file, but I don't want to have to do that
all the time.

Any help would be appreciated.

Thank you,

	--jtc

jtkohl@MIT.EDU (John T Kohl) (06/10/90)

I had a similar problem with underscores appearing in function names and
indexes, and screwing up the sort order.

My solution was a bit contorted, and might be of use to you.  Perhaps
some \expandafters will get the \lowercase evaluated at the right time?

Here's what I did to fix the underscore problem, and
some macros that use the fix:
---- cut here ---
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  fixunder.sty functions.sty
# Wrapped by jtkohl@lycus on Sun Jun 10 12:29:38 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fixunder.sty' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fixunder.sty'\"
else
echo shar: Extracting \"'fixunder.sty'\" \(1799 characters\)
sed "s/^X//" >'fixunder.sty' <<'END_OF_FILE'
X% fixunder.sty,  31 May 1990, John T. Kohl
X%
X% The contents of this file are in the public domain.
X%
X%
X% play games with _ to make it active and to provide a reasonable _
X% character (from \tt in most cases), and a discretionary word-break point.
X
X%
X% Some \makeunder... macros for convenience in setting catcodes.
X%
X\def\makeunderactive{\catcode`\_=\active\relax}
X\def\makeunderother{\catcode`\_=12\relax}
X\def\makeunderletter{\catcode`\_=11\relax}
X\def\makeundernormal{\catcode`\_=8\relax}
X\makeunderother
X\def\cctwlunder{_}
X
X%
X% The hair here is to allow things like \index to work reasonably with
X% the new definition of underscore when the argument to index is part of
X% a macro replacement and as such gets tokenized before \index is
X% evaluated.
X% [in the normal case at top-level, \index{foo_bar} works since \index
X% does some hair to make _ into a reasonable character code, and \index
X% does NOT use a macro expansion.  If you have something like
X% \def\foo#1#2{\index{#1} bar #2}
X% then \foo{baz_quux}{frobnitz} will result in baz_quux getting
X% tokenized BEFORE \foo is expanded, so that the catcode hair in \index
X% is to no avail.]
X%
X% \underrealfalse declares that you want to replace with the \tt _;
X% \underrealtrue declares that you want to replace with \char95 (ASCII _).
X%
X% for things like \index which write things out to files, set
X% \underrealfalse before evaluating the \index macro, and what actually
X% gets written to the file is an _, rather than something like
X% {\leavemode \kern... } (the typical definition of \_).
X%
X% the above example would then be
X% \def\foo#1#2{\underrealfalse\index{#1}\underrealtrue bar #2}
X%
X
X\newif\ifunderreal
X\underrealfalse
X\makeunderactive
X\def_{\ifunderreal\cctwlunder\else\leavevmode {\tt \cctwlunder}\discretionary{}{}{}\fi}
X\let\_=_
END_OF_FILE
if test 1799 -ne `wc -c <'fixunder.sty'`; then
    echo shar: \"'fixunder.sty'\" unpacked with wrong size!
fi
# end of 'fixunder.sty'
fi
if test -f 'functions.sty' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'functions.sty'\"
else
echo shar: Extracting \"'functions.sty'\" \(1397 characters\)
sed "s/^X//" >'functions.sty' <<'END_OF_FILE'
X%
X% definitions related to function declarations/displays
X%
X\ifx\undefined\@psfonts
X\def\argfont{\tt}
X\else
X\font\argfont = c-bol
X\hyphenchar\argfont = -1
X\fi
X\let\funcfont=\bf
X\newcount\argc@ount
X%
X% funcdecl is used as \begin{funcdecl}{funcname}{return type}{firstline}
X%
X% see fixunder.sty for comments on why the \underrealtrue & \underrealfalse
X% stuff is here.
X\newenvironment{funcdecl}[3]{\underrealtrue\index{#1}\underrealfalse%
X\argc@ount=0\begin{tabbing}
X#2 \\
X{\bf #1}(\= \+ #3%
X}{)
X\end{tabbing}
X}
X\newcommand{\docomm@}{\ifnum\argc@ount >0, \\\fi}
X\newcommand{\funcvoid}{\argc@ount=0}
X\newcommand{\funcin}{\docomm@\argc@ount=0{\sl /* IN */}\\}
X\newcommand{\funcinout}{\docomm@\argc@ount=0{\sl /* INOUT */}\\}
X\newcommand{\funcout}{\docomm@\argc@ount=0{\sl /* OUT */}\\}
X\newcommand{\funcarg}[2]{\docomm@#1 {\argfont #2}\advance\argc@ount by1}
X\newcommand{\funcparam}[1]{{\argfont #1}}
X\newcommand{\funcfuncarg}[2]{\docomm@#1 {\argfont #2}(\= \+ \argc@ount=0}
X\newcommand{\funcendfuncarg}{), \- \\ \argc@ount=0}
X\newcommand{\libname}[1]{{\argfont #1}}
X\newcommand{\globalname}[1]{{\argfont #1}}
X\newcommand{\ptsto}{->\discretionary{}{}{}}
X\newcommand{\datatype}[1]{{\bf #1}}
X\newcommand{\filename}[1]{{\sl #1\/}}
X
X\newcommand{\funcname}[1]{\underrealtrue\index{#1}\underrealfalse{\funcfont #1}()}
X\newcommand{\funcnamenoparens}[1]{\underrealtrue\index{#1}\underrealfalse{\funcfont #1}}
END_OF_FILE
if test 1397 -ne `wc -c <'functions.sty'`; then
    echo shar: \"'functions.sty'\" unpacked with wrong size!
fi
# end of 'functions.sty'
fi
echo shar: End of shell archive.
exit 0
--
John Kohl <jtkohl@ATHENA.MIT.EDU> or <jtkohl@MIT.EDU>
Digital Equipment Corporation/Project Athena
(The above opinions are MINE.  Don't put my words in somebody else's mouth!)

piet@cs.ruu.nl (Piet van Oostrum) (06/11/90)

In article <486@van-bc.wimsey.bc.ca>, jtc@van-bc (J.T. Conklin) writes:

 |					  I tried using \lowercase{},
 |but it isn't evaluated until the index is printed.
 |
 |	\newcommand{\code}[1]{{\bf #1}\index{\lowercase{#1}}}
 |
\uppercase and \lowercase are strange beasts, as they are not expandable
(evaluation is a non-TeX term), this means that they only do something when
they are processed in TeX's ``stomach'', i.e. when they are about to be
processed as output. The converted token list is then again read as input.
So in this case the following will probably work:

\lowercase{\index{#1}}

I don't know why Knuth choose this way rather than making them expandable.
-- 
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31-30-531806   Uucp:   uunet!mcsun!ruuinf!piet
Telefax:   +31-30-513791   Internet:  piet@cs.ruu.nl   (*`Pete')