Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The .ilg file is fulll of errors, and no \index command is accepted.

This is makeindex, version 2.15 [TeX Live 2011] (kpathsea + Thai support).
Scanning input file thesis.idx...
!! Input index error (file = thesis.idx, line = 1):
   -- Illegal page number \thepage.
...
   -- Illegal page number \thepage.
!! Input index error (file = thesis.idx, line = 28):
   -- Illegal page number \thepage.
done (0 entries accepted, 28 rejected).
Nothing written in thesis.ind.
Transcript written in thesis.ilg.

There is issued \makeindex before document, and the \printindex command is redefined (and issued at the end after \bibliography).

\let\my@prnt@nd@x\printindex
\renewcommandx\printindex{%
  \cleardoublepage%
  \addcontentsline{toc}{chapter}{\indexname}%
  \my@prnt@nd@x%
}

The .idx file has these lines (among others):

...
\indexentry{oscila\textcommabelow tie,~ecua\textcommabelow tie}{\thepage }
\indexentry{natural~numbers}{\thepage }
\indexentry{category,!balanced~definition}{\thepage }
...

For some reasons, in the class .dtx, i have redefined \protected@write which seems to be used by \@wrindex.

% \begin{macro}{\protected@write}
% \begin{macro}{\protected@write@immediate}
% \begin{macro}{\immediateaddtocontents}
% \begin{macro}{\addtocontentsline}
%    \begin{macrocode}
% redefine \protected@write to use \protected@write@immediate below
\long\def\protected@write#1#2#3{\protected@write@immediate#1{#3}[#2]}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Code borrowed from `multitoc.dtx' CTAN /macros/latex/contrib/ms %%
%%% Copyright [1998..1999]  Martin Schr\"oder. All rights reserved. %%
% \write with appropriate handling of |\protect| and |\thepage|; args:
% an output stream, some text to write, and some initialization code.
\newcommandx*\protected@write@immediate[3][3]{%
  \begingroup
    \let\thepage\relax
    #3%
    \let\protect\string
    \edef\reserved@a{\immediate\write#1{#2}}%
    \reserved@a
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi%
}
%%%                                                                 %%
%%%                                                                 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}

There is only a blank page after the bibilography, and usually i had all index entries in the following page, but nothing is generated; appreciate any help or fix on this. Thank s.

share|improve this question
3  
It's a really bad idea to redefine \protected@write to begin with. Of course, if you declare \let\thepage\relax, \thepage becomes unexpandable and will be written literally in the file. It's quite unclear why you want to make all writes \immediate: it's a plainly wrong thing to do. –  egreg May 31 '12 at 15:58
    
that's it, a simple backup/restore \TeXnique has resolved it. –  sjbiaga May 31 '12 at 18:22

1 Answer 1

There should be very good reasons why you want to make all writes \immediate. It's usually a wrong thing to do, for many reasons. Here's one.

Suppose you want to produce a table of contents, which is a quite common thing in LaTeX documents. Suppose your depth of listing in the TOC is at least 1, so that sections are included. Suppose that a section title is found when TeX hasn't yet finished a page, but when it completes its tasks connected with this action, it realizes that the section title must be moved to the next page.

Here is the problem: the entry for the TOC in the auxiliary file will already have been written. And it will be wrong, off by one.

With a delayed write, the entry would be written only when the section title actually appears in a page. Therefore, doing all writes \immediate is plainly wrong; the same situation would appear for the index, as TeX might find an entry to index in a line that will eventually end up in the next page.

If you read the documentation of multitoc, you'll see that the code for \immediateaddtocontents (that uses \protected@write@immediate) was for adding something without the page number. That's why Martin Schröder does \let\thepage\relax: the token \thepage becomes unexpandable and will be written literally to an auxiliary file (and successively used macros will gobble it).

For index production it must be expandable, otherwise you'll get (as you indeed do) \thepage in the .idx file, which is pretty useless: you're losing the association between the entry and the page number. But it's not sufficient to remove that instruction: the write operation must not be immediate.


By the way, there is a much simpler way to make all write operations immediate:

\let\@@write\write
\def\write{\immediate\@@write}

(a double \immediate prefix is equivalent to one).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.