home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / texindex2 (.txt) < prev    next >
LaTeX Document  |  1986-11-30  |  6KB  |  192 lines

  1. Subject: AAAAARRRRGGGGGHHHH!!!! Bugs in texindex!!!
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4. Mod.sources:  Volume 4, Issue 116
  5. Submitted by: seismo!turtlevax!weitek!robert (Robert Plamondon)
  6. The previous version of texindex I sent out has bugs. How they got there is
  7. beyond me, since I made a special effort to test it before I sent it. Either
  8. my test file (which WAS very short) didn't exercise it, or I didn't look
  9. at the output carefully, or I stupidly made a change after I send it.
  10. In any event, THIS version has been tested on the largest .idx file I have
  11. and seems to be okay. I've also cleaned up some miscellaneous stuff.
  12. With great embarrassment,
  13.     Robert Plamondon
  14. New shar file follows:
  15. # This is a shell archive.  Remove anything before this line,
  16. # then unpack it by saving it in a file and typing "sh file".
  17. # Wrapped by weitek!robert on Fri May  9 09:34:01 PDT 1986
  18. # Contents:  texindex.n texindex index.awk index1.awk
  19. echo x - texindex.n
  20. sed 's/^@//' > "texindex.n" <<'@//E*O*F texindex.n//'
  21. @.TH TEXINDEX N "9 May 1986"
  22. @.SH NAME
  23. texindex \- Create an index for a LATEX document
  24. @.SH SYNOPSIS
  25. texindex
  26. @.SH DESCRIPTION
  27. @.I LATEX
  28. produces
  29. @.I .idx
  30. files that contain the information that goes into the index.
  31. @.I LATEX
  32. also has a set of macros that are used to format an index. For some reason,
  33. @.I .idx
  34. file that
  35. @.I LATEX
  36. produces has no resemblance to the input file that it requires. In addition,
  37. @.I .idx
  38. file isn't sorted, doesn't have multiple page numbers per entry line, and
  39. doesn't arrange subentries under the corresponding main entry.
  40. @.I Texindex
  41. takes a 
  42. @.I LATEX \|.idx
  43. file and converts it into a format that
  44. @.I LATEX
  45. recognize as an index. It puts multiple page numbers on the same line, and
  46. handles subentries properly,
  47. @.I i.e.,
  48.     Gnus, 5-6, 25, 111
  49.     \ \ \ Habits of, 5
  50.     \ \ \ Smell, 25
  51. Output is directed to standard out.
  52. @.I Texindex
  53. uses two
  54. @.I awk
  55. script and calls
  56. @.I sort
  57. to sort the index.
  58. @.SH FILES
  59. /usr/new/texindex    main program (a csh script)
  60. /usr/lib/tex/index.awk    first awk script
  61. /usr/lib/tex/index1.awk    second awk script
  62. /tmp/texindex.xx    temporary file
  63. @.SH BUGS
  64. Handles subentries, but not sub-subentries.
  65. Should probably put large capitals before the entries for each letter, but
  66. doesn't.
  67. @.SH HISTORY
  68. This is the second release. The first one, dated April 25, 1986, had
  69. some bugs that didn't show up in my (too short) test index.
  70. @//E*O*F texindex.n//
  71. chmod u=rw,g=r,o=r texindex.n
  72. echo x - texindex
  73. sed 's/^@//' > "texindex" <<'@//E*O*F texindex//'
  74. #!/bin/csh -f
  75. # texindex -- create an index from a LaTeX .idx file
  76. # uses the file index.awk
  77. set INDEXAWK = /usr/lib/tex/index.awk
  78. set INDEXAWK1 = /usr/lib/tex/index1.awk
  79. set TEMP = /tmp/texindex.$$
  80. cat $1 > $TEMP
  81. cat >> $TEMP <<xxx
  82. %\indexentry{%AZZZZZZ}{}
  83. %\indexentry{%BZZZZZZ}{}
  84. %\indexentry{%CZZZZZZ}{}
  85. %\indexentry{%DZZZZZZ}{}
  86. %\indexentry{%EZZZZZZ}{}
  87. %\indexentry{%FZZZZZZ}{}
  88. %\indexentry{%GZZZZZZ}{}
  89. %\indexentry{%HZZZZZZ}{}
  90. %\indexentry{%IZZZZZZ}{}
  91. %\indexentry{%JZZZZZZ}{}
  92. %\indexentry{%KZZZZZZ}{}
  93. %\indexentry{%LZZZZZZ}{}
  94. %\indexentry{%MZZZZZZ}{}
  95. %\indexentry{%NZZZZZZ}{}
  96. %\indexentry{%OZZZZZZ}{}
  97. %\indexentry{%PZZZZZZ}{}
  98. %\indexentry{%QZZZZZZ}{}
  99. %\indexentry{%RZZZZZZ}{}
  100. %\indexentry{%SZZZZZZ}{}
  101. %\indexentry{%TZZZZZZ}{}
  102. %\indexentry{%UZZZZZZ}{}
  103. %\indexentry{%VZZZZZZ}{}
  104. %\indexentry{%WZZZZZZ}{}
  105. %\indexentry{%XZZZZZZ}{}
  106. %\indexentry{%YZZZZZZ}{}
  107. %\indexentry{%ZZZZZZZ}{}
  108. sort -o $TEMP -bdfu -t\{ +1 -2 +2n $TEMP
  109. awk -f $INDEXAWK $TEMP | awk -f $INDEXAWK1 | uniq
  110. rm -f $TEMP
  111. @//E*O*F texindex//
  112. chmod u=rwx,g=rx,o=rx texindex
  113. echo x - index.awk
  114. sed 's/^@//' > "index.awk" <<'@//E*O*F index.awk//'
  115. # index.awk -- take a sorted LaTeX index, and produce \item and
  116. # \subitem entries for it
  117. # Robert Plamondon, March 1986
  118. BEGIN    {FS = "{"
  119.     oldentry= GaRgLeBlAsTeR
  120.     print("\\begin{theindex}")}
  121. # leave spaces on comment lines
  122. $2 ~ /^%/        {printf("\n\\indexspace")
  123.              next}
  124. # Replace ! with \
  125. #$2 ~ /^[\\]*[!]/        {while(index($2,"!") > 0)
  126. #                 {x = index($2,"!")
  127. #                 $2 = (substr($2,1,x-1) "\\" substr($2,x+1))}}
  128.             {    $2 = substr($2,1,length($2)-1)
  129.                 newentry = $2
  130.                 newpage = substr($3,1,length($3)-1)
  131. # Handle subentries (entries with commas in them)
  132.         {comma = index($2,",")
  133.         if (comma > 0)
  134.           subentry = substr($2,comma+1)
  135.           mainentry = substr($2,1,comma-1)
  136.           {
  137.            if (mainentry != substr(oldentry,1,comma-1))
  138. # make new major entry
  139.             printf("\n\\item %s, %s", mainentry, newpage)
  140. #          else
  141.             if (oldentry == newentry)
  142.                 {
  143.             if (oldpage != newpage)
  144.             printf(", %s", newpage)
  145.               }
  146.             else
  147.                printf("\n    \\subitem %s, %s", subentry,newpage)
  148.            } 
  149.         else    # no comma -- this is a major entry
  150.             if (oldentry == newentry)
  151.               {if (oldpage != newpage)
  152.                 printf(", %s", newpage)}
  153.             else
  154.                 printf("\n\\item %s, %s", newentry,newpage)
  155.         {oldpage = newpage}
  156.         {oldentry = newentry}
  157. END    {printf("\n\\end{theindex}")}
  158. @//E*O*F index.awk//
  159. chmod u=rw,g=r,o=r index.awk
  160. echo x - index1.awk
  161. sed 's/^@//' > "index1.awk" <<'@//E*O*F index1.awk//'
  162. # index1.awk -- takes index entries in the form:
  163. # entry, number, number, number...
  164. # and turns consecutive numbers into ranges, i.e., 
  165. # gnus, 5, 6, 7, 10, 11, 15
  166. # becomes
  167. # gnus, 5-7, 10-11, 15
  168. # Robert Plamondon, April 25, 1986
  169. BEGIN    {FS = ","}
  170.  { if (NF > 1)
  171.     {toprange = 0; field = 2; botrange = $field; field1 = 1+field}
  172.     { printf("%s",$1)
  173.       while (field < NF)
  174.           while ($field1 == 1+$field)
  175.             { toprange = $field1; field++; field1++}
  176.         if (toprange != 0)
  177.             {printf(", %d-%d",botrange,toprange)
  178.              lasttop = toprange
  179.         else
  180.             printf(", %d",$field)
  181.         toprange = 0
  182.         botrange = $field1
  183.         field ++; field1++
  184.     if (lasttop != $NF)
  185.         if ($NF != 0)
  186.             printf(", %d", $NF)
  187.     printf("\n")
  188.   else print}
  189. @//E*O*F index1.awk//
  190. chmod u=rw,g=r,o=r index1.awk
  191. exit 0
  192.