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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
%%
%% Enhanced index generation for Hyperlatex
%% Version 1.0
%% Jan 27 1998
%%
%% Copyright (C) 1998 Sebastian Erdmann <serdmann@cs.tu-berlin.de>
%%
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License as
%% published by the Free Software Foundation; either version 2 of
%% the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but without any warranty; without even the implied warranty of
%% merchantability or fitness for a particular purpose. See the
%% GNU General Public License for more details.
%%
%% A copy of the GNU General Public License is available on the
%% World Wide Web at "http://www.gnu.org/copyleft/gpl.html". You
%% can also obtain it by writing to the Free Software Foundation,
%% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
% CUSTOMIZATION
\newcommand{\HlxBeginIndexDir}{} % inserted before index directory
\newcommand{\HlxIndexDirActive}[1]{#1} % formatting of letters which
% appear in the index
\newcommand{\HlxIndexDirInactive}[1]{#1} % formatting of letters which
% do not appear in the index
\newcommand{\HlxIndexDirSep}{ } % separator between letters in
% the index directory
\newcommand{\HlxEndIndexDir}{} % inserted after index directory
\newcommand{\HlxIdxSymbols}{Symbols} % directory entry for non-alpha-
% betic characters
\newcommand{\HlxIdxNumbers}{Numbers} % directroy entry for numbers
% Grammar of index entries (reverse-engineered from makeindex(1); not
% yet fully implemented):
%
% entry ::= spec
% | spec '|' format
% | spec '|' 'see' '{' string '}'
%
% spec ::= part
% | part '!' part
% | part '!' part '!' part
%
% part ::= string
% | string '@' string
%
% format ::= '('
% | ')'
% | string
% | '(' string
%
% string ::= string char
% | char
%
% char ::= <any character except NUL, |, !, }, and @>
% | '"' <any character except NUL>
\HlxEval{
(put 'htmlprintindex 'hyperlatex 'hyperlatex-se-format-printindex)
(put 'index 'hyperlatex 'hyperlatex-se-format-index)
(put 'cindex 'hyperlatex 'hyperlatex-se-format-index)
(defun hyperlatex-se-format-index ()
"Adds an index entry."
(let ((opt (hyperlatex-single-line (hyperlatex-parse-optional-argument)))
(arg (hyperlatex-single-line (hyperlatex-parse-required-argument)))
(label (hyperlatex-drop-label)))
(if hyperlatex-final-pass
()
(if (string-match "^\\(.*\\)@\\(.*\\)$" arg)
(progn
(setq opt (substring arg (match-beginning 1) (match-end 1)))
(setq arg (substring arg (match-beginning 2) (match-end 2)))))
(setq hyperlatex-index
(cons (list (if opt opt arg) arg hyperlatex-node-number label)
hyperlatex-index)))))
; From makeindex(1):
;
; Numbers are always sorted in numeric order. Letters are first
; sorted without regard to case; when words are identical, the
; uppercase version precedes its lowercase counterpart.
;
; A special symbol is defined here to be any character not appearing
; in the union of digits and the English alphabetic characters.
; Patterns starting with special symbols precede numbers, which
; precede patterns starting with letters. As a special case, a string
; starting with a digit but mixed with non-digits is considered to be
; a pattern starting with a special character.
(defun hyperlatex-se-index-compare (a b)
(let* ((au (upcase (car a)))
(bu (upcase (car b)))
(a0 (aref au 0))
(b0 (aref bu 0)))
(cond
;; a is a number
((and (<= ?0 a0) (<= a0 ?9) (string-match "^[0-9]+$" au))
(cond
((and (<= ?0 b0) (<= b0 ?9) ; b is a number
(string-match "^[0-9]+$" bu))
(< (string-to-number au)
(string-to-number bu)))
((and (<= ?A b0) (<= b0 ?Z)) t) ; b0 is alphabetic
(t nil))) ; b0 is a symbol
;; a0 is alphabetic
((and (<= ?A a0) (<= a0 ?Z))
(cond
((and (<= ?A b0) (<= b0 ?Z)) ; b0 is alphabetic
(or (string< au bu)
(and (string= au bu)
(string< (car a) (car b)))))
(t nil))) ; b0 is a digit or symbol
;; a0 is a symbol
(t
(cond
((and (<= ?0 b0) (<= b0 ?9)) t) ; b0 is a digit
((and (<= ?A b0) (<= b0 ?Z)) t) ; b0 is alphabetic
(t (string< ; b0 is a symbol
(car a) (car b))))))))
(defun hyperlatex-se-insert-url (href name text)
(insert hyperlatex-meta-< "A")
(if href
(progn
(setq href (number-to-string (+ href hyperlatex-label-number)))
(insert " HREF="
hyperlatex-meta-dq "#" href hyperlatex-meta-dq)))
(if name
(progn
(setq name (number-to-string (+ name hyperlatex-label-number)))
(insert " NAME="
hyperlatex-meta-dq name hyperlatex-meta-dq)))
(insert hyperlatex-meta-> text hyperlatex-meta-< "/A" hyperlatex-meta->))
(defun hyperlatex-se-format-printindex ()
(if (not hyperlatex-final-pass)
()
(setq hyperlatex-index
(sort hyperlatex-index 'hyperlatex-se-index-compare))
(let ((indexelts hyperlatex-index)
(used-chars (make-vector 256 nil))
(toc-num 0)
(symbol-num 1)
(number-num 2)
(char-num 3)
(prev-num -1)
this-num
this-char)
;;
;; insert index body
;;
(insert "\\begin{description}\n")
(while indexelts
(setq this-char (aref (upcase (car (car indexelts))) 0))
;;
;; determine entry type (numeric, alphabetic, symbol)
;;
(cond ((and (<= ?0 this-char) (<= this-char ?9)
(string-match "^[0-9]+$" (car (car indexelts))))
(setq this-num number-num))
((and (<= ?A this-char) (<= this-char ?Z))
(setq this-num (+ (- this-char ?A) char-num)))
(t
(setq this-num symbol-num)))
;;
;; insert entry
;;
(if (= prev-num this-num)
(insert "\\\\")
(aset used-chars this-num t)
(let ((keyname this-char))
(cond ((= this-num symbol-num)
(setq keyname "\\HlxIdxSymbols"))
((= this-num number-num)
(setq keyname "\\HlxIdxNumbers")
(if (= prev-num symbol-num)
(insert "\\xml{p}"))))
(insert "\\item[")
(hyperlatex-se-insert-url toc-num this-num keyname)
(insert "]\n")
(setq prev-num this-num)))
(insert (format "\\xlink{%s}{%s}\n"
(nth 1 (car indexelts))
(hyperlatex-gen-url (nth 2 (car indexelts))
(nth 3 (car indexelts)))))
(setq indexelts (cdr indexelts)))
(insert "\\end{description}\n")
;;
;; insert index directory
;;
(goto-char hyperlatex-command-start)
(insert "\\HlxBeginIndexDir{}")
(let ((sep "")
(name toc-num))
(if (aref used-chars symbol-num)
(progn
(insert sep "\\HlxIndexDirActive{")
(hyperlatex-se-insert-url symbol-num name "\\HlxIdxSymbols")
(insert "}")
(setq sep "\\HlxIndexDirSep{}")
(setq name nil)))
(if (aref used-chars number-num)
(progn
(insert sep "\\HlxIndexDirActive{")
(hyperlatex-se-insert-url number-num name "\\HlxIdxNumbers")
(insert "}")
(setq sep "\\HlxIndexDirSep{}")
(setq name nil)))
(setq this-char ?A)
(setq this-num char-num)
(while (<= this-char ?Z)
(if (aref used-chars this-num)
(progn
(insert sep "\\HlxIndexDirActive{")
(hyperlatex-se-insert-url this-num name
(char-to-string this-char))
(insert "}")
(setq name nil))
(insert sep "\\HlxIndexDirInactive{" this-char "}"))
(setq sep "\\HlxIndexDirSep{}")
(setq this-char (1+ this-char))
(setq this-num (1+ this-num))))
(insert "\\HlxEndIndexDir{}\n")
(goto-char hyperlatex-command-start)))
;; allocate label numbers
(setq hyperlatex-label-number (+ hyperlatex-label-number 29)))
}% end \HlxEval
|