[OS X TeX] New TeXShop macro: "Insert reference"

Joachim Kock kock at math.uqam.ca
Mon Aug 23 18:43:25 EDT 2004

>Still, I guess this could be done in a better way, most probably with some sophisticated calls to awk and/or sed to extract the cite keys from *.bib files, but I that's beyond what I could do. But my hack works and that's the point, eh?

Hello Thomas and others,

Last week on this mailing list, I posted a simple Tcl script to do
exactly this.  I did this in response to Jon Crump's request for a
keywords script, but I misunderstood him.  So I find it funny if now
my script can be of any use.  Here it is again.  I don't know how to
run it from within applescript, but from the command line it is just

    getkeys bibfiles.bib

assuming that the script file is called getkeys.  The script is mostly
taken from Alpha, which does an awful lot of bib tricks.  The regexp
is very conscious about the variations in bib file syntax.


PS: watch out that the email transmission is likely to break the two
long lines, and hence break the script.  If it doesn't work you can
also take it from http://www.cirget.uqam.ca/~kock/alpha-tcl/tmp/getkeys.gz

# the next line restarts using tclsh \
exec tclsh "$0" "$@"

# Given a list of bibfiles, scan them for citekeys
# and return a list of all citekeys found.
set res [list ]
foreach bibfile $argv {
    ### 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
puts [join [lsort -dictionary $res] \n]

--------------------- 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