home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume23 / texindex / part01 next >
Encoding:
Text File  |  1991-09-23  |  7.8 KB  |  317 lines

  1. Newsgroups: comp.sources.misc
  2. From: ib09@rz.uni-karlsruhe.de (Thomas Koenig)
  3. Subject:  v23i006:  texindex - generate index for LaTeX', Part01/01
  4. Message-ID: <1991Sep22.201218.21826@sparky.imd.sterling.com>
  5. X-Md4-Signature: fbb6fd82a6b8a8afe622068d4812596b
  6. Date: Sun, 22 Sep 1991 20:12:18 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: ib09@rz.uni-karlsruhe.de (Thomas Koenig)
  10. Posting-number: Volume 23, Issue 6
  11. Archive-name: texindex/part01
  12. Environment: UNIX
  13.  
  14. This is texindex, a little utility for formatting LaTeX - generated
  15. *.idx (indexentry) - files into *.ind - files ready for inclusion
  16. as an index.
  17.  
  18. It is written as a UNIX shell script, using the utilities expand, sed, sort,
  19. uniq and awk (old style).
  20.  
  21. It has the following features:
  22.  
  23.       - parts enclosed in brackets [...] will be enclosed in \verb+...+
  24.     in the *.ind - file
  25.  
  26.       - entries consisting of several words will be rotated.  If, for
  27.         example, you have \index{foo bar} in your *.tex file,
  28.     you'll find both "\item foo bar <page>" and 
  29.     "\item bar \subitem foo <page>" in your *.ind - file.
  30.     This can be suppressed by inserting tildes between the words,
  31.     as in \index{foo~bar}.
  32.  
  33.       - Commas can be used to get deeper in the \item hierarchy.
  34.  
  35. Credits: The idea and some of the implementation comes from Aho, Weinberger
  36. and Kernighan: 'The Awk Programming Language'.
  37.  
  38. I place this in the public domain; do with it whatever you please.
  39.  
  40. Thomas Koenig
  41. ui0t@dkauni2.bitnet, ui0t@ibm3090.rz.uni-karlsruhe.dbp.de,
  42. ib09@rz.uni-karlsruhe.de (for now)
  43.  
  44. #---------------------------------- cut here ----------------------------------
  45. # This is a shell archive.  Remove anything before this line,
  46. # then unpack it by saving it in a file and typing "sh file".
  47. #
  48. # Wrapped by <ib09@rz30.rz.uni-karlsruhe.de> on Thu Sep 19 21:16:45 1991
  49. #
  50. # This archive contains:
  51. #    README        texindex    ix.collapse    ix.extract    
  52. #    ix.format    ix.genkey    ix.polish    ix.rotate    
  53. #
  54. # Error checking via wc(1) will be performed.
  55.  
  56. unset LANG
  57.  
  58. echo x - README
  59. cat >README <<'@EOF'
  60. This is texindex, a little utility for formatting LaTeX - generated
  61. *.idx (indexentry) - files into *.ind - files ready for inclusion
  62. as an index.
  63.  
  64. It is written as a UNIX shell script, using the utilities expand, sed, sort,
  65. uniq and awk (old style).
  66.  
  67. It has the following features:
  68.  
  69.       - parts enclosed in brackets [...] will be enclosed in \verb+...+
  70.     in the *.ind - file
  71.  
  72.       - entries consisting of several words will be rotated.  If, for
  73.         example, you have \index{foo bar} in your *.tex file,
  74.     you'll find both "\item foo bar <page>" and 
  75.     "\item bar \subitem foo <page>" in your *.ind - file.
  76.     This can be suppressed by inserting tildes between the words,
  77.     as in \index{foo~bar}.
  78.  
  79.       - Commas can be used to get deeper in the \item hierarchy.
  80.  
  81. Credits: The idea and some of the implementation comes from Aho, Weinberger
  82. and Kernighan: 'The Awk Programming Language'.
  83.  
  84. I place this in the public domain; do with it whatever you please.
  85.  
  86. --
  87. Thomas Koenig
  88. ui0t@dkauni2.bitnet, ui0t@ibm3090.rz.uni-karlsruhe.dbp.de,
  89. ib09@rz.uni-karlsruhe.de (for now)
  90. @EOF
  91. set `wc -lwc <README`
  92. if test $1$2$3 != 301671068
  93. then
  94.     echo ERROR: wc results of README are $* should be 30 167 1068
  95. fi
  96.  
  97. chmod 644 README
  98.  
  99. echo x - texindex
  100. cat >texindex <<'@EOF'
  101. expand $1.idx |
  102. sed -f ix.extract |
  103. sort -t    +0 -1 +1n -2 |
  104. uniq |
  105. awk -f ix.collapse |
  106. awk -f ix.rotate |
  107. sed -f ix.genkey |
  108. sort -f -d |
  109. awk -f ix.format |
  110. sed -f ix.polish > $1.ind
  111. @EOF
  112. set `wc -lwc <texindex`
  113. if test $1$2$3 != 1041183
  114. then
  115.     echo ERROR: wc results of texindex are $* should be 10 41 183
  116. fi
  117.  
  118. chmod 755 texindex
  119.  
  120. echo x - ix.collapse
  121. cat >ix.collapse <<'@EOF'
  122. # ix.collapse : awk - script
  123. # kollabiere Zahlenlisten fuer identische Begriffe
  124. # Eingabeformat :    
  125. # string1 \t num
  126. # string2 \t num
  127. # string2 \t num
  128. # ...
  129. # Ausgabeformat:
  130. # string1 \t num
  131. # string2 \t num, num
  132. BEGIN    {
  133.         altwort = "ASDF!@#$*&%$IU11@"
  134.         FS = OFS = "\t"
  135.     }
  136. $1 != altwort {
  137.         if (NR > 1)
  138.             printf "\n"
  139.         altwort = $1
  140.         printf "%s\t%s", $1, $2
  141.         next
  142.     }
  143.     {
  144.         printf " %s",$2
  145.     }
  146. END    {
  147.         if (NR > 1)
  148.             printf "\n"
  149.     }
  150. @EOF
  151. set `wc -lwc <ix.collapse`
  152. if test $1$2$3 != 2884434
  153. then
  154.     echo ERROR: wc results of ix.collapse are $* should be 28 84 434
  155. fi
  156.  
  157. chmod 644 ix.collapse
  158.  
  159. echo x - ix.extract
  160. cat >ix.extract <<'@EOF'
  161. # ix.extract : sed - script, um die Daten aus einem LaTeX - *.idx - File
  162. # rauszuholen.
  163. # Eingabeformat:
  164. # \indexentry{Begriff}{Seitenzahl}
  165. # Ausgabeformat:
  166. # Begriff \t Seitenzahl
  167. s/\\indexentry{\(.*\)}{\(.*\)}/\1    \2/
  168. @EOF
  169. set `wc -lwc <ix.extract`
  170. if test $1$2$3 != 730219
  171. then
  172.     echo ERROR: wc results of ix.extract are $* should be 7 30 219
  173. fi
  174.  
  175. chmod 644 ix.extract
  176.  
  177. echo x - ix.format
  178. cat >ix.format <<'@EOF'
  179. # ix.format : awk - script
  180. # entfernt Sortierschluessel, fuegt \item etc. ein
  181. BEGIN    {
  182.         FS = OFS = "\t"
  183.         printf "\\begin{theindex}"
  184.     }
  185.     {
  186.         n = split($2,feld,", ")
  187.         if (n > 3)
  188.         {
  189.             for (i=4; i <=n; i++)
  190.                 feld[3] = feld[3] ", " feld[i]
  191.             n = 3 
  192.         }
  193.         for (i = 1; feld[i]==altfeld[i] && i<=n ; i++)
  194.             ;
  195.         for (k=i; k <=n; k++)
  196.         {
  197.             printf "\n\\"
  198.             for (j=1; j<k; j++)
  199.                 printf "sub"
  200.             printf "item %s ",feld[k]
  201.         }
  202.         nzahl = split($3,zahlfeld," ")
  203.         for (j=1; j<nzahl; j++)
  204.             printf"%s, ",zahlfeld[j]
  205.         printf "%s",zahlfeld[nzahl]
  206.         for (j=1; j<=i; j++)
  207.             altfeld[i] = feld[i]
  208.     }
  209. END    {
  210.         printf "\n\\end{theindex}\n"
  211.     }
  212. @EOF
  213. set `wc -lwc <ix.format`
  214. if test $1$2$3 != 33102635
  215. then
  216.     echo ERROR: wc results of ix.format are $* should be 33 102 635
  217. fi
  218.  
  219. chmod 644 ix.format
  220.  
  221. echo x - ix.genkey
  222. cat >ix.genkey <<'@EOF'
  223. # ix.genkey : Generierung eines Sortierschluessels ohne Sonderzeichen
  224. # Eingabe: string1 string2 ... \t num num ...
  225. # Ausgabe: string1 string2 ... (ohne S.Z.) \t string1 string2 ... \t num num ..
  226. #
  227. # Ersetze global die Tilde durch Spaces
  228. s/~/ /g
  229. # kopiere die Zeile in den Zwischenpuffer
  230. h
  231. # alles hinter \t loeschen
  232. s/    .*$//
  233. # zum Sortieren loesche alle nicht - alphanumerischen Zeichen
  234. s/[^a-zA-Z0-9 ]//g
  235. # falls dabei eine leere Zeile rauskommt, setze ein Space rein
  236. s/^$/ /
  237. # kopiere die urspruengliche Zeile aus dem Puffer hinter den Speicher
  238. G
  239. # ersetze newline zwischen den Zeilen durch \t
  240. s/\n/    /
  241. # Falls ein Komma am Ende des Strings steht, loesche es
  242. s/,    /    /
  243. @EOF
  244. set `wc -lwc <ix.genkey`
  245. if test $1$2$3 != 20117669
  246. then
  247.     echo ERROR: wc results of ix.genkey are $* should be 20 117 669
  248. fi
  249.  
  250. chmod 644 ix.genkey
  251.  
  252. echo x - ix.polish
  253. cat >ix.polish <<'@EOF'
  254. # ix.polish : sed - script zum letzten Nachpolieren der Eintraege
  255. # \item etc. einruecken, eckige Klammern in \verb - Anweisungen abaendern
  256. #
  257. # Packe vor jedes \item ein \indexspace
  258. /\\item/i\
  259.   \\indexspace
  260. # ruecke \items ein
  261. /^\\item/s/^/  /
  262. # ruecke \subitems etwas mehr ein
  263. /^\\subitem/s/^/    /
  264. # ruecke \subsubitems noch etwas mehr ein
  265. /^\\subsubitem/s/^/      /
  266. # aendere [ in \verb+
  267. s/\[/\\verb+/g
  268. # aendere ] in +
  269. s/\]/+/g
  270. @EOF
  271. set `wc -lwc <ix.polish`
  272. if test $1$2$3 != 1667433
  273. then
  274.     echo ERROR: wc results of ix.polish are $* should be 16 67 433
  275. fi
  276.  
  277. chmod 644 ix.polish
  278.  
  279. echo x - ix.rotate
  280. cat >ix.rotate <<'@EOF'
  281. # ix.rotate: awk - script zur Rotation von Index - Begriffen 
  282. # Eingabe:
  283. # string1 string2 string3 ... \t num num ...
  284. # Ausgabe:
  285. # string1 string2 string3 ... \t num num ...
  286. # string2 string3 ... , string1 \t num num ...
  287. # string3 ..., string1 string2 \t num num ...
  288. #
  289. BEGIN    {
  290.         FS = OFS = "\t"
  291.     }
  292.     {
  293.         print $1, $2 # Drucke die unrotierte Form
  294.         for (i=1; (j=index(substr($1, i+1)," "))> 0;)
  295.         {
  296.             i += j # Finde jeden Blank und rotiere um ihn
  297.             printf "%s, %s\t%s\n",substr($1,i+1),substr($1,1,i-1),$2
  298.         }
  299.     }
  300. @EOF
  301. set `wc -lwc <ix.rotate`
  302. if test $1$2$3 != 1993513
  303. then
  304.     echo ERROR: wc results of ix.rotate are $* should be 19 93 513
  305. fi
  306.  
  307. chmod 644 ix.rotate
  308.  
  309. exit 0
  310.  
  311. exit 0 # Just in case...
  312. -- 
  313. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  314. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  315. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  316. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  317.