BibEntry
# BibEntry.py
# Copyright (C) 2004 Jamie Lawrence
# http://jamie.ideasasylum.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
'''
Extract a keyed reference from a bibtex file and insert it into a page
'''
__author__ = '''Jamie Lawrence (http://jamie.ideasasylum.com)'''
__version__ = '''0.0.1'''
import string, sys, bibfile, bibgrammar
#from bibstyle import BibStyle
# Edit this line to point to your BibTeX file
file = '/usr/home/tom/references/refs.bib'
def execute(macro, arg):
# open the bib file
try :
src = open(file).read()
except :
return 'No BibTeX file: %s' % bibfile
bfile = bibfile.BibFile()
bibgrammar.Parse(src, bfile)
if arg == None:
arg = macro.formatter.page.page_name
try :
entry = bfile.get_entry_by_citekey(arg)
if entry :
#style = BibStyle() # just use default style
#return style.formatRef(entry)
return '<pre>%s</pre>' % entry.__repr__()
except KeyError :
return 'Invalid BibTex Key: %s' % arg
return ''