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 < prev    next >
Encoding:
Text File  |  1988-09-11  |  5.7 KB  |  243 lines

  1. Subject: texindex -- make an index from a LaTeX .idx file
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 106
  6. Submitted by: seismo!turtlevax!weitek!robert (Robert Plamondon)
  7.  
  8. Below is a shar file of my texindex program, which takes the (relatively
  9. useless) .idx file that LaTeX produces, and sorts it on major minor entries,
  10. reformats it, turns lists of consecutive page numbers into ranges, and 
  11. kicks out a file that LaTeX can actually make an index from.
  12.  
  13. It consists of two awk files, a shell script to tie them together, and a
  14. man page.
  15.  
  16.  
  17.     Robert Plamondon
  18.     UUCP: {turtlevax, cae780}!weitek!robert
  19.     FidoNet: 143/12 robert plamondon
  20.  
  21.  
  22. # This is a shell archive.  Remove anything before this line,
  23. # then unpack it by saving it in a file and typing "sh file".
  24. #
  25. # Wrapped by weitek!robert on Fri May  2 09:39:36 PDT 1986
  26. # Contents:  texindex.n texindex index.awk index1.awk
  27.  
  28. echo x - texindex.n
  29. sed 's/^@//' > "texindex.n" <<'@//E*O*F texindex.n//'
  30. @.TH TEXINDEX N "25 April 1986"
  31. @.SH NAME
  32. texindex \- Create an index for a LATEX document
  33. @.SH SYNOPSIS
  34. @.B
  35. texindex
  36. file
  37. @.SH DESCRIPTION
  38. @.I LATEX
  39. produces
  40. @.I .idx
  41. files that contain the information that goes into the index.
  42. @.I LATEX
  43. also has a set of macros that are used to format an index. For some reason,
  44. the
  45. @.I .idx
  46. file that
  47. @.I LATEX
  48. produces has no resemblance to the input file that it requires. In addition,
  49. the
  50. @.I .idx
  51. file isn't sorted, doesn't have multiple page numbers per entry line, and
  52. doesn't arrange subentries under the corresponding main entry.
  53. @.PP
  54. @.I Texindex
  55. takes a 
  56. @.I LATEX \|.idx
  57. file and converts it into a format that
  58. @.I LATEX
  59. will
  60. recognize as an index. It puts multiple page numbers on the same line, and
  61. handles subentries properly,
  62. @.I i.e.,
  63. @.PP
  64.     Gnus, 5-6, 25, 111
  65. @.br
  66.     \ \ \ Habits of, 5
  67. @.br
  68.     \ \ \ Smell, 25
  69. @.PP
  70. Output is directed to standard out.
  71. @.PP
  72. @.I Texindex
  73. uses two
  74. @.I awk
  75. script and calls
  76. @.I sort
  77. to sort the index.
  78. @.SH FILES
  79. /usr/new/texindex    main program (a csh script)
  80. @.br
  81. /usr/lib/tex/index.awk    first awk script
  82. @.br
  83. /usr/lib/tex/index1.awk    second awk script
  84. @.br
  85. /tmp/texindex.xx    temporary file
  86. @.SH BUGS
  87. Blank space is left between entries for each letter of the
  88. alphabet. If there are no entries for that letter, blank space
  89. is left anyway, leaving larger gaps.
  90. @.PP
  91. Should probably put large capitals before the entries for each letter, but
  92. doesn't.
  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
  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.     print("\\begin{theindex}")}
  149.  
  150. # leave spaces on comment lines
  151. $2 ~ /^%/        {print ""
  152.              print("\\indexspace")
  153.              print ""
  154.              next}
  155. # Replace ! with \
  156. #$2 ~ /^[\\]*[!]/        {while(index($2,"!") > 0)
  157. #                 {x = index($2,"!")
  158. #                 $2 = (substr($2,1,x-1) "\\" substr($2,x+1))}}
  159.  
  160.             {    $2 = substr($2,1,length($2)-1)
  161.                 newentry = $2
  162.                 newpage = substr($3,1,length($3)-1)
  163.             }
  164. # Handle subentries (entries with commas in them)
  165.         {comma = index($2,",")
  166.         if (comma > 0)
  167.          {
  168.           subentry = substr($2,comma+1)
  169.           mainentry = substr($2,1,comma-1)
  170.           {
  171.            if (mainentry != substr(oldentry,1,comma-1))
  172. # make new major entry
  173.             printf("\n\\item %s %s", mainentry, newpage)
  174.           else
  175.             if (oldentry == newentry)
  176.                 {
  177.             if (oldpage != newpage)
  178.             printf(", %s", newpage)
  179.               }
  180.             else
  181.                printf("\n    \\subitem %s %s", subentry,newpage)
  182.            } 
  183.         }
  184.         else    # no comma -- this is a major entry
  185.             {
  186.             if (oldentry == newentry)
  187.               {if (oldpage != newpage)
  188.                 printf(", %s", newpage)}
  189.             else
  190.                 printf("\n\\item, %s %s", newentry,newpage)
  191.             }
  192.     }
  193.         {oldpage = newpage}
  194.         {oldentry = newentry}
  195.  
  196. END    {print("\\end{theindex}")}
  197. @//E*O*F index.awk//
  198. chmod u=rw,g=r,o=r index.awk
  199.  
  200. echo x - index1.awk
  201. sed 's/^@//' > "index1.awk" <<'@//E*O*F index1.awk//'
  202. # index1.awk -- takes index entries in the form:
  203. # entry, number, number, number...
  204. # and turns consecutive numbers into ranges, i.e., 
  205. # gnus, 5, 6, 7, 10, 11, 15
  206. # becomes
  207. # gnus, 5-7, 10-11, 15
  208. #
  209. # Robert Plamondon, April 25, 1986
  210. #
  211. BEGIN    {FS = ","}
  212.  { if (NF > 1)
  213.    {
  214.     {toprange = 0; field = 2; botrange = $field; field1 = 1+field}
  215.     { printf("%s",$1)
  216.       while (field < NF)
  217.         { 
  218.           while ($field1 == 1+$field)
  219.             { toprange = $field1; field++; field1++}
  220.  
  221.         if (toprange != 0)
  222.             {printf(", %d-%d",botrange,toprange)
  223.              lasttop = toprange
  224.             }
  225.         else
  226.             printf(", %d",$field)
  227.  
  228.         toprange = 0
  229.         botrange = $field1
  230.         field ++; field1++
  231.         }
  232.     if (lasttop != $NF)
  233.         if ($NF != 0)
  234.             printf(", %d", $NF)
  235.     printf("\n")
  236.     }
  237.   }
  238.   else print}
  239. @//E*O*F index1.awk//
  240. chmod u=rw,g=r,o=r index1.awk
  241.  
  242. exit 0
  243.