Path: utzoo!attcan!uunet!snorkelwacker!bloom-beacon!bloom-beacon.mit.edu!jtkohl From: jtkohl@MIT.EDU (John T Kohl) Newsgroups: comp.text.tex Subject: Re: LaTeX Indexing (underscore frobbing) Message-ID: Date: 10 Jun 90 16:30:23 GMT References: <486@van-bc.wimsey.bc.ca> Sender: news@athena.mit.edu (News system) Organization: MIT Project Athena Lines: 135 In-Reply-To: jtc@van-bc.wimsey.bc.ca's message of 8 Jun 90 18:47:25 GMT 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 '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 or Digital Equipment Corporation/Project Athena (The above opinions are MINE. Don't put my words in somebody else's mouth!)