home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-bin0.lha / lib / texmf / tex / tugboat / kwic-bib.awk < prev    next >
Text File  |  1996-10-12  |  3KB  |  107 lines

  1. # /u/sy/beebe/tex/bib/kwic-bib.awk, Mon Nov 14 11:46:24 1988
  2. # Edit by Nelson H.F. Beebe (beebe at plot79.utah.edu)
  3. # /u/sy/beebe/tex/kwic-bib.awk, Thu Oct 13 11:58:32 1988
  4. # Edit by Nelson H.F. Beebe (beebe at plot79.utah.edu)
  5. # ======================================================================
  6. #
  7. # This awk program filters a BibTeX file to produce an input file for
  8. # the Unix ptx(1) program which prepares a keyword-in-context (kwic),
  9. # or permuted, index.  The output of this script is a collection of
  10. # lines, on each of which the initial token is the bibliography key.
  11. #
  12. # Because the output of ptx is permuted, we cannot easily preserve
  13. # font changes (word permutations would lose font boundaries), so we
  14. # simply strip them.  To prevent confusion with quotes (") used in the
  15. # ptx output, we drop umlauts as well.  The backslash control sequence
  16. # is changed to forward slash; otherwise the index would contain
  17. # permutations on \bs.  All remaining braces and backslashes are
  18. # stripped.
  19. #
  20. # To facilitate finding secondary authors, the author field is included
  21. # in the output as well.
  22. #
  23. # The reference tag will appear as the first non-blank field on each
  24. # output line.  The ptx -r option will move it to the 5th argument of
  25. # the .xx macro in its output.
  26. #
  27. # Usage:
  28. #    nawk -f kwic-bib.awk foo.bib | ptx -r -f >foo.nro
  29. #
  30. # The troff output of ptx is converted to lines of the form
  31. # \kwic{head}{pre-key}{key}{post-key}{tag}
  32. # by the step
  33. #
  34. #    sed -f ptx.sed <foo.nro >foo.out
  35. #
  36. # and this can then be input to LaTeX as, e.g., a supertabular
  37. # environment, with a suitable definition of the \kwic macro.
  38. #
  39. # ======================================================================
  40.  
  41. # Assume bibliography entries are keyed by an initial capital, thus
  42. # omitting the @string{} entries.
  43.  
  44. # blank trim lines
  45. /[ \t]*$/        {gsub(/[ \t]*$/,"");}
  46.  
  47. # extract tag from "@field{tag,"
  48. /^@[A-Z][a-z]*/        {
  49.     tag = substr($0,index($0,"{")+1);
  50.     tag = substr(tag,1,length(tag)-1); # strip final comma
  51.     gsub(/[{}\\ \t]/,"",tag);# strip whitespace, braces and backslashes
  52. }
  53.  
  54. # collect complete author list
  55. /^[ \t]*author[ \t]*=[ \t]*\"/    {\
  56.     author = substr($0,index($0,"\"")+1);
  57.     while (substr(author,length(author)-1) != "\",")
  58.     {
  59.         getline $0;
  60.         author = author " " $0;
  61.     }
  62.     if (substr(author,length(author)-1) == "\",")
  63.         author = substr(author,1,length(author)-2);
  64.     author = filter(author)
  65.     printf("%s\t%s\n",tag,author);
  66. }
  67.  
  68. # collect complete title list
  69. /^[ \t]*title[ \t]*=[ \t]*\"/    {\
  70.     title = substr($0,index($0,"\"")+1);
  71.     while (substr(title,length(title)-1) != "\",")
  72.     {
  73.         getline $0;
  74.         title = title " " $0;
  75.     }
  76.     if (substr(title,length(title)-1) == "\",")
  77.         title = substr(title,1,length(title)-2);
  78.     title = filter(title);
  79.     printf("%s\t%s\n",tag,title);
  80. }
  81.  
  82.  
  83. function filter(s, t)
  84. {
  85.     t = s;
  86.     gsub(/[~ \t]+/," ",t);    # collapse whitespace and ties
  87.  
  88.     gsub(/\\bs/,"/",t);        # change \bs control sequence to forward slash
  89.  
  90.     gsub(/\\[a-z][a-z] /," ",t); # remove font changes
  91.     gsub(/\\[a-z][a-z]\\/,"\\",t);
  92.  
  93.     gsub(/\\"{/,"{",t);        # drop umlauts
  94.  
  95.     gsub(/[{}\\]/,"",t);    # drop remaining braces and backslashes
  96.  
  97.     gsub(/&/," and ",t);    # change & to and
  98.  
  99.     gsub(/_/,"\\_",t);        # protect TeX special characters
  100.     gsub(/%/,"\\%",t);
  101.     gsub(/\$/,"\\$",t);
  102.  
  103.     gsub(/[ ]+/," ",t);        # collapse whitespace again
  104.  
  105.     return (t);
  106. }
  107.