summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gatech-thesis/gatech-thesis-index.sty
blob: 61b9cd9d676ec6cf866630ddae255a1e20edf2b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
%% gatech-thesis-index.sty - support code for creating an index
%%   depends on index.sty, so it is not included by default in the
%%   main gatech-thesis.cls (this cuts down on ``extra'' dependencies.
%%   It also depends on the multicol package.
%%
%% Note that index.sty is included in the ``camel'' package if you
%% are using MikTeX.
%%
%% To use this package, all you need do is include
%%   \usepackage{gatech-thesis-index}
%% in your preamble, and 
%%   \gtindex
%% just after your vita section, but within the postliminary environment
%% of your bodytext.  The, the index will be automatically
%% and included in the location specified, and added to the table of
%% contents.  Of course, you need actual index references within your
%% main text like this:
%%   foo\index{foo}
%% Read the index.sty documentation for more info, but basically 
%% gatech-thesis-gloss.sty makes it simple:
%%    1. insert the \usepackage and \gtindex commands into your document
%%    2. sprinkle \index{} citations in your text
%%    3. run ``makeindex'' on the <rootfile>.idx file created
%%       after the first ``latex'' run, like this:
%%         makeindex -s gatech-thesis-index.ist <rootfile>.idx
%%       This will create <rootfile>.ind (the gatech-thesis-index.ist
%%       file is a format specification for the index).  If you want
%%       to customize the index format, copy gatech-thesis-index.ist to
%%       ``myformat.ist'' and change the copy.  Use ``-s myformat.ist'' 
%%       instead of gatech-thesis-index.ist.
%%          You can run the makeindex command at the same time you run `
%%       `bibtex'' for your references and/or glossary.
%%    4. run ``latex'' twice more (the same ``twice more'' needed for
%%       bibtex and gatech-thesis-gloss.sty)
%%
\NeedsTeXFormat{LaTeX2e}[1995/06/01] \ProvidesPackage{gatech-thesis-index}
          [2002/08/08  Index support for gatech-thesis.cls]
\@ifclassloaded{gatech-thesis}{}{
  PackageError{This style can only be used with the gatech-thesis class}
}
\RequirePackage{index}
\RequirePackage{multicol}

\newif\if@proofmode
\@proofmodefalse

\DeclareOption{proofmode}{%
  \if@draft        % This is an internal gatech-thesis variable!
    \@proofmodetrue % this is an internal index.sty variable
  \else
    \PackageWarn{option `proofmode' can't be used in 'final' mode.}
    \@proofmodefalse
  \fi
}
\DeclareOption{showidx}{%
  \if@draft        % This is an internal gatech-thesis variable!
    \@proofmodetrue % this is an internal index.sty variable
  \else
    \PackageWarn{option `showidx' can't be used in 'final' mode.}
    \@proofmodefalse
  \fi
}
\ProcessOptions

\newif\ifindexpage
\indexpagetrue% why use this package if you're not going to USE it?

\if@proofmode
  \proofmodetrue% pass option to index package
\else
  \proofmodefalse% ditto
\fi

\newcommand{\gtindexname}{}
\newcommand{\idxcontentlinestring}{}
\newcommand{\idxpdfbookmarkstring}{}

\newcommand{\setindexstring}[1]{%
  \renewcommand{\gtindexname}{#1}
  \renewcommand{\indexname}{\Makeuppercase{#1}}
  \renewcommand{\idxcontentlinestring}{%
    \texorpdfstring{\Makeuppercase{#1}}{#1}
  }
  \renewcommand{\idxpdfbookmarkstring}{#1}
}
\setindexstring{Index}
% if you want to change the name of the index, do it in the preamble
% once the document begins, it''s too late.
\AtBeginDocument{%
  \newindex{default}{idx}{ind}{Index}
}

\renewenvironment{theindex}{%
  \edef\indexname{\the\@nameuse{idxtitle@\@indextype}}%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \chapter*{\MakeUppercase{\gtindexname}}
  \@mkboth{\scshape\MakeUppercase\indexname}%
          {\scshape\MakeUppercase\indexname}%
  \let\item\@idxitem
  \columnseprule \z@
  \columnsep 35\p@
  \begin{multicols}{2}[%
    \ifx\index@prologue\@empty\else
      \index@prologue
      \bigskip
    \fi]%    
    \parindent\z@
    \parskip\z@ \@plus .3\p@\relax
}{\end{multicols}%
  \if@restonecol
    \onecolumn
  \else
    \clearpage
  \fi
}

\renewcommand{\do@indexpage}{%
  \ifindexpage
    \if@openright\cleardoublepage\else\clearpage\fi 
    % must clear page here, so that phantomsection\addcontentsline is on the correct page
    \phantomsection%
    \addcontentsline{toc}{chapter}{\idxcontentlinestring}
    \settoheight{\gt@tmpa}{A}
    \set@gttocskip{\gt@tmpa}
    {\newlinestretch{1}
     \printindex
    }%
    \newpage
  \fi
}

\newcommand{\gtindex}{\do@indexpage}
\newcommand{\bs}{\symbol{'134}}% print backslash
\newcommand{\gtCom}[1]{\texttt{\bs#1}\index{#1@\texttt{\bs#1}}}
\newcommand{\gtProg}[1]{\texttt{#1}\index{#1@\texttt{#1} program}}