[tex-eplain] turning off indexing

Oleg Katsitadze olegkat at gmail.com
Sun Nov 18 17:09:27 CET 2007


On Thu, Nov 15, 2007 at 01:20:46PM -0500, John Frampton wrote:
> I don't like all that writing to the index file going on every time I run 
> Tex.

For each defined index (\defineindex{N}) I've added a \ifNdx switch
which turns off any writing to the corresponding index file, see the
attached patch.

> And I certainly don't want to see all the reports of reading the .tmp 
> file.

As Karl suggested, using etex avoids .tmp file altogether.  However,
making \Ndxfalse disable the processing which needs the .tmp file
might be a bad idea, after all (see below), especially since it's easy
to avoid the .tmp file problem with etex (etex is ubiquitous nowadays).

> To this point, I've just used \idx and \sidx, so the following hack 
> kills the writing and .tmp file use (but does not stop opening the .idx 
> file for writing).
>
> \def\noindex{%
>    \let\idx\relax
>    \def\sidx##1{\@getoptionalarg\relax}%
> }
>
> Am I missing something?

All indexing commands take initial optional argument (the one which
modifies index terms in some way), so in general redefinitions should
take care of that, too.  Apart from this, I see several problems with
this approach as a general solution.

First, indexing commands disabled in this way do not produce whatsits
from the \write command, which can considerably affect page-breaking.
This might or might not be important for a draft run, depending on a
situation.

Second, it's not possible to disable index writing _and_ typeset the
proof index terms in the margin, which I imagine might be useful.

Next, these redefinitions don't do any sanity checks of the arguments,
especially important for the first optional argument.  (There is also
much more involved when processing arguments with special symbols.)

So, I suggest that \Ndxfalse only disables opening the index file and
writing of the indexing terms, and leaves all other processing in
place.

The downside to this is that the .tmp file mess remains, but as I
said, etex avoids this, and I have the impression that etex is now the
standard.

Another note -- to compensate for the missing whatsits from `real'
\write, I use `\write-1{}' which writes a newline to the log file.
This makes the log untidy, but the line-breaking will be the same as
with indexing enabled.

For testing, the patched eplain.tex can be downloaded from

  http://tug.org/eplain/misc/eplain.tex

Of course, any comments and suggestions are welcome.

Best,
Oleg

P.S.  The patch also includes a minor bug fix -- in \@idxwrite when
\indexproofingtrue, I was adding \allowhyphens in vertical mode, too,
which could cause spurious whitespace.
-------------- next part --------------
--- xeplain.tex	13 Sep 2007 16:46:05 +0300	1.46
+++ xeplain.tex	18 Nov 2007 17:38:32 +0200	
@@ -2082,6 +2082,11 @@
 \outer\def\defineindex#1{%
   \def\@idxprefix{#1}%
   %
+  % Define a switch to control opening and writing of the index file
+  % for this prefix.
+  \expandafter\innernewif\csname if\@idxprefix dx\endcsname
+  \csname \@idxprefix dxtrue\endcsname
+  %
   % Define the indexing commands for this prefix. 
   \for\@idxcmd:=,marked,submarked,name%
                 \extraidxcmdsuffixes\do
@@ -2145,35 +2150,38 @@
 %
 % \@idxwrite{TERM}{PAGENO} writes a general index entry for TERM on page
 % PAGENO to the index file `\@idxprefix indexfile'.  We open the stream
-% as `\indexfilebasename.\@idxprefix dx' if it isn't already open.
+% as `\indexfilebasename.\@idxprefix dx' if it isn't already open.  We
+% only write out the index term if this has not been disabled with
+% \csname\@idxprefix dxfalse\endcsname.
 %
 \let\indexfilebasename = \jobname
 %
 \def\@idxwrite#1#2{%
-  % Be sure the file is opened.
-  \csname if@\@idxprefix indexfileopened\endcsname \else
-    \expandafter\immediate\openout\csname @\@idxprefix indexfile\endcsname =
-      \indexfilebasename.\@idxprefix dx
-    \expandafter\global\csname @\@idxprefix indexfileopenedtrue\endcsname
-  \fi
-  %
-  % Save the index term.
-  \def\temp{#1}%
-  %
-  % Write the index term and page number.
-  \edef\@wr{%
-    \expandafter\write\csname @\@idxprefix indexfile\endcsname{%
-      \string\indexentry
-      {\sanitize\temp}%
-      {\noexpand#2}%
+  \csname if\@idxprefix dx\endcsname
+    % Be sure the file is opened.
+    \@openidxfile
+    %
+    % Save the index term.
+    \def\temp{#1}%
+    %
+    % Write the index term and page number.
+    \edef\@wr{%
+      \expandafter\write\csname @\@idxprefix indexfile\endcsname{%
+        \string\indexentry
+        {\sanitize\temp}%
+        {\noexpand#2}%
+      }%
     }%
-  }%
-  \@wr
+    \@wr
+  \else
+    % Produce a whatsit anyway, to ensure consistent page-breaking.
+    \write-1{}%
+  \fi
   % 
   % Marginalize the index term, if desired.
   % (the \allowhyphens allows `infinitesimal' in \sidx{Infinitesimal}infinitesimal 
   % to be hyphenated.
-  \ifindexproofing \insert\@indexproof{\indexproofterm{#1}}\allowhyphens\fi
+  \ifindexproofing \insert\@indexproof{\indexproofterm{#1}}\ifhmode\allowhyphens\fi\fi
   %
   % We just appended at least one non-discardable item (namely, the
   % whatsit from the \write) to the current list.  So in case glue comes
@@ -2186,6 +2194,14 @@
   \ifsilentindexentry \expandafter\ignorespaces\fi
 }%
 %
+\def\@openidxfile{%
+  \csname if@\@idxprefix indexfileopened\endcsname \else
+    \expandafter\immediate\openout\csname @\@idxprefix indexfile\endcsname =
+      \indexfilebasename.\@idxprefix dx
+    \expandafter\global\csname @\@idxprefix indexfileopenedtrue\endcsname
+  \fi
+}%
+%
 %
 % If this conditional is true, we output the index terms on the page
 % where they occur.


More information about the tex-eplain mailing list