home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume04 / texindex.2 < prev    next >
Encoding:
Text File  |  1988-09-11  |  5.8 KB  |  243 lines

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