[OS X TeX] Re: BibTeX keywords
Joachim Kock
kock at math.uqam.ca
Thu Aug 12 19:16:07 EDT 2004
>Thanks for the Alpha tip. the regex that the Tcl proc uses finds cite
>keys. I'm looking for a simple way to isolate semi-colon delimited text
>within a bibtex _keywords_ field.
Sorry, I misunderstood you because I had never used _keywords_ fields,
so I thought you were talking citekeys...
I doubt this can be done with a single regexp; some further conditionals
would be required. But in a script it isn't that complicated...
Here is a quick Tcl hack that works well under the assumption that your
_keywords_ fields are in braces and that there are no braces inside the
_keywords_ field. E.g., finds
_keywords_ = {beer; red wine},
but not
_keywords_ = {{\o}l; r{\o}dvin},
or
_keywords_ = "light beer",
proc findKeywords { bibfile } {
### read in the file:
set fd [open $bibfile]
set txt [read $fd]
close $fd
### scan the file for keyword chunks
set pat {_keywords_\s*=\s*\{([^\{\}]+)\}\s*,}
set L [regexp -nocase -inline -all -- $pat $txt]
### (every second entry in $L is a keyword chunk)
set res ""
foreach {junk keywordChunk} $L {
set thisKeywordList [split $keywordChunk \;]
foreach keyword $thisKeywordList {
lappend res [string trim $keyword]
}
}
return [lsort -unique $res]
}
To do the brace handling properly, some brace matching technique is
required --- not easy to do with static regexps. There are plenty of
such situations handled by Alpha's Bib mode machinery, for example
searching for arbitrary regexps inside specified fields (which works
well even with nested braces), but I'll have to dig them out from the
Tcl files to adapt to this specific situation...
Cheers,
Joachim.
---------------------------------------------------------------
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