[OS X TeX] Re: BibTeX keywords

Joachim Kock kock at math.uqam.ca
Thu Aug 12 16:06:12 EDT 2004


> Does anybody know of an existing utility for extracting a list of 
> unique keywords from the keywords field of a BibTeX file?

Hello Jon,

Alpha's Bib mode maintains such a list for internal reasons (supporting
various bibtex mode features), but you can easily look into it: it is a
plain text file called bibDatabase stored in your AlphaPrefs folder.
(Typically your AlphaPrefs folder will be ~/Library/Preferences/Alpha-v8).
If you have never used Alpha's bibtex mode before, then it doesn't know
about any of your bib files.  You can explicitly tell it to include your 
bibfile by opening it and select "Databases -> Add Win To Database" from 
the Bib menu.  (In usual operation, Alpha will find your bibfiles 
automatically using kpsewhich, but this happens only when you are using 
the features for which the database is maintained, e.g. \cite completion 
in TeX mode.)

If I misunderstood your question, please write back.  It should be easy to
tweak Alpha to obtain whatever else you might want to extract from a bib
file --- there is already support for many of such operations in Alpha's
Bib mode, including exporting bibfiles to refer, html, or delimited.

If you don't want to use Alpha, here is a Tcl proc that extracts all keys.
I took the regexp from the Alpha proc [::Bib::makeDatabaseOf], and it is
very conscious about the variations in bib file syntax.  (And if you don't
want to use Tcl either, then I am sure the regexp will work also in a perl
script...)

Cheers, Joachim.

PS: beware that the mail transmission might insert line breaks which
break the code!


proc getKeys { bibfile } {
    ### read in the file:
    set fd [open $bibfile]
    set txt [read $fd]
    close $fd
    ### scan the file for this pattern:
    ###                  ____type_____   ___brace__   _______key_______   __delim_
    set pat {(?:^|\s)@\s*(?:[a-zA-Z]+)\s*(?:[\{\(])\s*([^\s\{\}\(\),]+)\s*(?:,|\})}
    set L [regexp -inline -all -- $pat $txt]
    ### every second entry in $L is a key:
    set res ""
    foreach {junk key} $L {
        lappend res $key
    }
    return $res
}



---------------------------------------------------------------
Joachim Kock <kock at math.uqam.ca>
Département de mathématiques -- Université du Québec à Montréal
Case postale 8888, succursale centre-ville
Montréal (Québec), H3C 3P8 -- Canada
---------------------------------------------------------------
--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the MacOSX-TeX mailing list