diff options
Diffstat (limited to 'support/splint/tex/gindex.sty')
-rw-r--r-- | support/splint/tex/gindex.sty | 164 |
1 files changed, 140 insertions, 24 deletions
diff --git a/support/splint/tex/gindex.sty b/support/splint/tex/gindex.sty index 9d8ed2d334..2a449d343b 100644 --- a/support/splint/tex/gindex.sty +++ b/support/splint/tex/gindex.sty @@ -1,4 +1,4 @@ -% Copyright 2012-2020, Alexander Shibakov +% Copyright 2012-2024, Alexander Shibakov % This file is part of SPLinT % % SPLinT is free software: you can redistribute it and/or modify @@ -18,19 +18,7 @@ % set up the list of unindexable terms -\ifx\unindexable\UNDEFINED - \def\unindexable{{$\TeXx$}{$\TeXa$}{$\TeXb$}{$\TeXf$}{$\TeXao$}{$\TeXfo$}}% -\else - \expandafter\def\expandafter\unindexable\expandafter - {\unindexable{$\TeXx$}{$\TeXa$}{$\TeXb$}{$\TeXf$}{$\TeXao$}{$\TeXfo$}}% -\fi - -\def\TeXx{\hbox{\let\_\UL\tt\TeX\_}} -\def\TeXa{\hbox{\tt\TeX\rm(a)}} -\def\TeXb{\hbox{\tt\TeX\rm(b)}} -\def\TeXf{\hbox{\tt\TeX\rm(f)}} -\def\TeXao{\hbox{\tt\TeX\rm(ao)}} -\def\TeXfo{\hbox{\tt\TeX\rm(fo)}} +\newwrite\gindex % macros to determine if the current term is indexable @@ -66,9 +54,21 @@ \def\s@t@nd@xable#1\end{\aftergroup\yyfirstoftwo} +\def\makeunindexable#1{% + \expandafter\m@keunindexable\expandafter{\unindexable}{#1}% +} + +\def\m@keunindexable#1#2{% + \def\unindexable{#1#2}% +} + +\def\makeunindexablex#1{% + {\edef\unindexable{#1}\expandafter}\expandafter\makeunindexable\expandafter{\unindexable}% +} + % \Cee\ index entry (produced by \CWEAVE\ and typeset directly from the file) -\def\I#1, #2.{% +\def\Ii#1, #2.{% \makeoneindexentry{#1}{#1}{#2}{\setxreflistplain}{\filterxrefsplain}% } @@ -124,7 +124,17 @@ #3{#2}% \par }{% - \toksg{#1}% + \checkforthree#1\end{% + \toksg{#1}% + }{% + \the\toksg\toksg{}% set the index section header + \let\defypreamble\empty + \let\defypostamble\defypostambleshowcs + \hangindent\inxhangindent\noindent\strut\ninercs#1:% + \hskip0pt plus2em\penalty1000\hskip0pt plus-2em\relax\kern\inxaiskip + #3{#2}% + \par + }% }% } @@ -146,6 +156,11 @@ \yystringempty{#2}{\yyfirstoftwo}{\yysecondoftwo}% } +\def\checkforthree#1#2#3\end{% + \yystringempty{#3}{\yyfirstoftwo}{\yysecondoftwo}% +} +% if the term is unindexable, only collect the definitions (i.e. references enclosed in \[ and \]) + \def\filterdefs#1#2{% #1{}{}, #2, \[]{}% the last empty braces are not necessary but this way % both \f@lterdefs and \f@lterdefsplain can be defined @@ -331,6 +346,13 @@ \def\idxentry{{\def\_{\char`\_}\hbox{\tt$\langle$\the\toksa$\rangle_{\rm f}$}}}% }% +\def\termfsscstring#1{% flex sate names + \numberstocharsandspaces#1\end + \let\optstrextra\optstrextraesc + \expandafter\nameproc\expandafter{\the\toksa}\with\parsebin + \def\idxentry{{\def\_{\char`\_}\hbox{\flexsnstyle{\the\toksa}}}}% +}% + \def\termstring#1{% \numberstocharsandspaces#1\end \let\optstrextra\optstrextraesc @@ -366,6 +388,55 @@ }% }% +\def\termtrivial#1{% trivial index entry for debugging purposes + % can also be used as a starting point for other index processors + \def\idxentry{% + {\rm index entry goes here}% + }% +}% + +% the raw/direct macros below should be used sparingly because they potentially introduce +% style inconsistencies while outputting index terms; a special scheme can be designed to counter +% that ... or one can just be careful; in addition, \termdirect relies on the exact number of expansions +% (2) undergone by the entry's contents; +% of the two options, \termraw is probably preferable as it does not pass any volatile information +% (such as expandable sequences) in the index entries and thus allows much more elaborate and +% safe setup of index terms; the only advantage of the \termdirect variation is the lack of global +% assignments (the \termraw changes the \indexterms array); indices by their nature are global +% so this should be a secondary consideration in the majority of cases. + +\def\termdirect#1{% + \def\idxentry{% + {\t@rmdirect#1}% + }% +}% + +\def\t@rmdirect#1\end\toksa#2\eatone{#2} + +\let\vend\relax % the delimeter to let the indexing script know that this is a raw entry + +% here is an example of the \termdirect macros in action: +% +% the entry setup below is a bit elaborate since parts of the entry must be passed in a safe way +% in case it contains dangerous characters like _ +% \toksa{\noexpand\tt{\noexpand\rm(}#1{\noexpand\rm)}\noexpand\charstocharsx#2\end}% +% the \noexpand's above are necessary to block the final expansion by \write +% the assignment below would also work; note the '0 ' which is required to stop the expansion +% of \romannumeral which is part of \charstonumberse; in this case \vend can be left undefined +% \toksa{\end0 \noexpand\noexpand\noexpand\vend(#1)#2\noexpand\noexpand\noexpand\vend\eatone}% + +% the setup above works with the following indexing command +%\ridxentry{\termdirect}{\the\toksa}{#2}% + +\def\termraw#1{% raw entry, shows terms saved in a global array, #1 is the index into the array + \numberstocharsandspaces#1\end + \def\idxentry{% + {\let\parsernamespace\empty\getmidstackcs\indexterms{\the\toksa}}% + }% +}% + +\setnulstack{indexterms} % the array for the terms processed by \termraw + \expandafter\def\csname acharswitch:index\endcsname{% correct reserved \TeX\ characters a la CWEB verbatim %$\%\\ % unaffected %\#\ % these never appear @@ -403,12 +474,23 @@ \def\indexseparator#1#2{% \vskip.3\baselineskip - \centerline{\csname index domain translation [#1]\endcsname}% + \centerline{% + \toksa\expandafter\expandafter\expandafter + {\expandafter\yyfirstofthree\romannumeral0\csname index domain translation [#1]\endcsname}% + \toksb\expandafter\expandafter\expandafter + {\expandafter\yysecondofthree\romannumeral0\csname index domain translation [#1]\endcsname}% + \toksc\expandafter\expandafter\expandafter + {\expandafter\yythirdofthree\romannumeral0\csname index domain translation [#1]\endcsname}% + \the\toksc + \edef\next{\write\cont{%\noexpand\noexpand\noexpand\eatone{\noexpand\meaning\noexpand\ZZ}% + \noexpand\noexpand\noexpand\YY{\the\toksa}{2}{\secno}% write to contents file + {\noexpand\the\pageno}{\the\toksb}}}\next % \YY{title}{depth}{sec}{page}{ss} + }% \vskip.3\baselineskip } -\expandafter\def\csname index domain translation [F]\endcsname{{\sc FLEX INDEX}} -\expandafter\def\csname index domain translation [T]\endcsname{{\sc\TeX\ INDEX}} +\expandafter\def\csname index domain translation [F]\endcsname{{\noexpand\flex\ index}{flex index}{F{\sc LEX INDEX}}} +\expandafter\def\csname index domain translation [T]\endcsname{{\noexpand\TeX\ index}{TeX index}{\TeX\ {\sc INDEX}}} \def\indexsection#1{% \vskip.3\baselineskip @@ -429,11 +511,21 @@ \def\otherlangindexseparator{% \enddoublecols \vskip.8\baselineskip - \centerline{B{\sc ISON}, F{\sc LEX, AND} \TeX\ {\sc INDICES}}% + \centerline{\otherlangindexheader + \edef\next{\write\cont{%\noexpand\noexpand\noexpand\eatone{\noexpand\meaning\noexpand\ZZ}% + \noexpand\noexpand\noexpand\YY{\noexpand\noexpand\noexpand\bison\ index}{2}{\secno}% write to contents file + {\noexpand\the\pageno}{bison Index}}}\next % \ZZ{title}{depth}{sec}{page}{ss} + }% \vskip.5\baselineskip \begindoublecols } +\def\otherlangindexheader{% + B{\sc ISON}, F{\sc LEX, AND} \TeX\ {\sc INDICES}% +} + +%\def\otherlangindexseparator{} + % general index entries (generated by bindx.pl) \def\GI#1#2#3#4.{% raw index entries (standard format, with no page references) @@ -485,13 +577,32 @@ \def\inxaiskip{.5em} \def\inxicgap{5pt} +\ifx\unindexable\UNDEFINED + \def\unindexable{{$\TeXx$}{$\TeXa$}{$\TeXb$}{$\TeXf$}{$\TeXao$}{$\TeXfo$}{$\BZ$}}% +\else + \expandafter\def\expandafter\unindexable\expandafter + {\unindexable{$\TeXx$}{$\TeXa$}{$\TeXb$}{$\TeXf$}{$\TeXao$}{$\TeXfo$}{$\BZ$}}% +\fi + +\def\idxsafe{% redefine some control sequences to behave safely in the index + \def\TeXx{\hbox{\let\_\UL\tt\TeX\_}} + \def\TeXa{\hbox{\tt\TeX\rm(a)}} + \def\TeXb{\hbox{\tt\TeX\rm(b)}} + \def\TeXf{\hbox{\tt\TeX\rm(f)}} + \def\TeXao{\hbox{\tt\TeX\rm(ao)}} + \def\TeXfo{\hbox{\tt\TeX\rm(fo)}} + \def\BZ{\hbox{\tt BZ}} +} + \def\inxmod{% new indexing macro - \write\cont{} % ensure that the contents file isn't empty - \write\cont{\catcode `\noexpand\@=12\relax} % \makeatother - \closeout\cont % the contents information has been fully gathered + \closeout\exampletable + \termindexfalse + \idxsafe + \closeout\gindex \message{Index:} \medskip \eightpoint\raggedright + \emergencystretch=.1em % for especially tight cases \fnotesstart=2 \fnotesspan=1 \noofcolumns=3 @@ -504,10 +615,14 @@ \expandafter\let\expandafter\acharswitch\csname acharswitch:index\endcsname \let\texlexer\texlexerindex \let\*=\lapstar + \let\I\Ii % make \CWEAVE\ generated entries typeset in our style \begindoublecols \readindex - \otherlangindexseparator \readgindex + \write\cont{}% ensure that the contents file isn't empty + \write\cont{\catcode `\noexpand\@=12\relax}% \makeatother + \closeout\cont % the contents information has been fully gathered + \enddoublecols } \newread\trygindex @@ -517,6 +632,7 @@ \ifeof\trygindex \else \closein\trygindex + \otherlangindexseparator \input \jobname.gdy \fi } |