[texhax] Indexing macros on TeXbook

Rodolfo Medina rodolfo.medina at gmail.com
Mon Aug 1 15:43:28 CEST 2016


I'm having a look at the indexing macros from the TeXbook on p.262 and trying
to apply them in pratice.  They seem to work.  What I want to do now is adding
vertical space before a new letter begins, but don't know how.  Here's my
test.tex file:

\def\beginindex{\begingroup
  \parindent=1em \maxdepth=\maxdimen
  \def\par{\endgraf \futurelet\next\inxentry}
  \obeylines \everypar={\hangindent 2\parindent}
  \exhyphenpenalty=10000 \raggedright}
\def\inxentry{\ifx\next\sub \let\next=\subentry
  \else\ifx\next\endindex \let\next=\vfill
  \else\let\next=\mainentry \fi\fi \next}
\def\endindex{\mark{}\break\endgroup}
\let\sub=\indent \newtoks\maintoks \newtoks\subtoks
\def\mainentry#1,{\mark{}\noindent
  \maintoks={#1}\mark{\the\maintoks}#1,}
\def\subentry\sub#1,{\mark{\the\maintoks}\indent
  \subtoks={#1}\mark{\the\maintoks\sub\the\subtoks}#1,}

\def\inxcheck#1\sub#2\end{\def\next{#1}%
  \ifx\next\empty % do nothing if \botmark is null
  \else\noindent #1\continued %
    \def\next{#2}%
    \ifx\next\empty % nothing more if \botmark has no \sub
    \else\let\sub=\continued \indent #2\fi
    \advance\dimen0 by-\prevdepth \kern\dimen0 \fi}
\def\continued{ ({\it continued}\thinspace):\endgraf}

\newwrite\index
\immediate\openout\index=index.idx
Some text on p.1
\vfill\eject
\immediate\write\index{\noexpand\beginindex first entry,
                                            \the\pageno.\endindex}
\immediate\write\index{\noexpand\beginindex second entry,
                                            \the\pageno.\endindex}
\immediate\closeout\index
\newread\testin
  \openin \testin index.ind
  \ifeof\testin
    \closein \testin % file didn't exist
  \else
    \read\testin to \temp
    \ifeof\testin
      \closein \testin % file empty
    \else
      \closein \testin
%\begindoublecolumns
      {\catcode`@=11 
             \input index.ind }
%\enddoublecolumns
    \fi
  \fi
  
\vfill\eject

\end

After processing it with simply `tex test', I execute the following small shell
script to sort entries:

#!/bin/sh

cat index.idx | sort > index.ind

and then process test.tex once again.

Please help whoever can, thanks in advance.

Rodolfo



More information about the texhax mailing list