1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
# This file is part of pybliographer
#
# Copyright (C) 1998-2004 Frederic GOBRY
# Email : gobry@pybliographer.org
#
# 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.
#
#
""" This module is a formatter for LaTeX output """
from Pyblio import Formatter, Autoload
import string
class LaTeX (Formatter.Formatter):
coding = 'LaTeX'
def write (self, text, style = None):
if style == 'bold':
self.out.write ('{\bf %s}' % text)
elif style == 'italic':
self.out.write ('{\it %s}' % text)
elif style == 'emph':
self.out.write ('{\em %s}' % text)
elif style == 'slanted':
self.out.write ('{\sl %s}' % text)
elif style == 'smallcaps':
self.out.write ('{\sc %s}' % text)
else:
self.out.write (text)
def start_group (self, id, key_list = None):
if key_list:
id = ''
l = 0
for k in key_list:
# compute length
w = 0
for i in range (0, len (k)):
if k [i] == string.lower (k [i]):
w = w + .5
else:
w = w + 1
if w > l:
id = k
l = w
else:
id = 'KEY99'
self.out.write ('\\begin{thebibliography}{%s}\n' % id)
return
def separator (self):
self.out.write ('\n\\newblock ')
return
def end_group (self):
self.out.write ('\\end{thebibliography}\n')
return
def start (self, key, entry):
if key is None: key = self.next_key ()
self.out.write ('\\bibitem[%s]{%s}\n' % (key, entry.key.key))
return
Autoload.register ('output', 'LaTeX', LaTeX)
|