/usr/share/pyshared/plasTeX/Packages/natbib.py is in python-plastex 0.9.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | """
natbib
TODO:
- compress multiple years
- \shortcites
- Indexing features
- Bibliography preamble
"""
import plasTeX, re, string
from plasTeX import Base, Node, Text
from plasTeX.Base.LaTeX.Sectioning import chapter, section
log = plasTeX.Logging.getLogger()
PackageOptions = {}
def ProcessOptions(options, document):
""" Process package options """
context = document.context
if options is None:
return
PackageOptions.update(options)
for key, value in options.items():
if key == 'numbers':
bibpunct.punctuation['style'] = 'n'
ProcessOptions({'square':True, 'comma':True}, document)
elif key == 'super':
bibpunct.punctuation['style'] = 's'
bibpunct.punctuation['open'] = ''
bibpunct.punctuation['close'] = ''
elif key == 'authoryear':
ProcessOptions({'round':True, 'colon':True}, document)
elif key == 'round':
bibpunct.punctuation['open'] = '('
bibpunct.punctuation['close'] = ')'
elif key == 'square':
bibpunct.punctuation['open'] = '['
bibpunct.punctuation['close'] = ']'
elif key == 'angle':
bibpunct.punctuation['open'] = '<'
bibpunct.punctuation['close'] = '>'
elif key == 'curly':
bibpunct.punctuation['open'] = '{'
bibpunct.punctuation['close'] = '}'
elif key == 'comma':
bibpunct.punctuation['sep'] = ','
elif key == 'colon':
bibpunct.punctuation['sep'] = ';'
elif key == 'sectionbib':
Base.bibliography.level = Base.section.level
elif key == 'sort':
pass
elif key in ['sort&compress','sortandcompress']:
pass
elif key == 'longnamesfirst':
pass
elif key == 'nonamebreak':
pass
class bibliography(Base.bibliography):
class setcounter(Base.Command):
# Added so that setcounters in the aux file don't mess counters up
args = 'name:nox num:nox'
def loadBibliographyFile(self, tex):
doc = self.ownerDocument
# Clear out any bib info from the standard package.
# We have to get our info from the aux file.
doc.userdata.setPath('bibliography/bibcites', {})
self.ownerDocument.context.push(self)
self.ownerDocument.context['setcounter'] = self.setcounter
tex.loadAuxiliaryFile()
self.ownerDocument.context.pop(self)
Base.bibliography.loadBibliographyFile(self, tex)
class bibstyle(Base.Command):
args = 'style:str'
class citestyle(Base.Command):
args = 'style:str'
styles = {
'plain' : [', ','[',']',',','n','',','],
'plainnat':[', ','[',']',',','a',',',','],
'chicago': [', ','(',')',';','a',',',','],
'chicago': [', ','(',')',';','a',',',','],
'named' : [', ','[',']',';','a',',',','],
'agu' : [', ','[',']',';','a',',',', '],
'egs' : [', ','(',')',';','a',',',','],
'agsm' : [', ','(',')',';','a','',','],
'kluwer' : [', ','(',')',';','a','',','],
'dcu' : [', ','(',')',';','a',';',','],
'aa' : [', ','(',')',';','a','',','],
'pass' : [', ','(',')',';','a',',',','],
'anngeo' : [', ','(',')',';','a',',',','],
'nlinproc':[', ','(',')',';','a',',',','],
'cospar' : [', ','/','/',',','n','',''],
'esa' : [', ','(Ref. ',')',',','n','',''],
'nature' : [', ','','',',','s','',','],
}
def invoke(self, tex):
res = Base.Command.invoke(self, tex)
try:
s = self.styles[self.attributes['style']]
except KeyError:
# log.warning('Could not find bibstyle: "%s"',
# self.attributes['style'])
return res
p = bibpunct.punctuation
for i, opt in enumerate(['post','open','close','sep','style','dates','years']):
p[opt] = s[i]
return res
class bstyleoption(Text):
""" Option that can only be overridden by package options,
citestyle, or bibpunct """
class bibliographystyle(citestyle):
def invoke(self, tex):
res = Base.Command.invoke(self, tex)
try:
s = self.styles[self.attributes['style']]
except KeyError:
# log.warning('Could not find bibstyle: "%s"',
# self.attributes['style'])
return res
p = bibpunct.punctuation
for i, opt in enumerate(['post','open','close','sep','style','dates','years']):
if isinstance(p[opt], bstyleoption):
p[opt] = s[i]
return res
class bibpunct(Base.Command):
""" Set up punctuation of citations """
args = '[ post:str ] open:str close:str sep:str ' + \
'style:str dates:str years:str'
punctuation = {'post': bstyleoption(', '),
'open': bstyleoption('('),
'close':bstyleoption(')'),
'sep': bstyleoption(';'),
'style':bstyleoption('a'),
'dates':bstyleoption(','),
'years':bstyleoption(',')}
def invoke(self, tex):
res = Base.Command.invoke(self, tex)
for key, value in self.attributes.items():
if value is None:
continue
elif type(value) == str or type(value) == unicode:
bibpunct.punctuation[key] = value
else:
bibpunct.punctuation[key] = value.textContent
return res
class bibcite(Base.Command):
""" Auxiliary file information """
args = 'key:str info'
def invoke(self, tex):
Base.Command.invoke(self, tex)
value, year, author, fullauthor = list(self.attributes['info'])
value.attributes['year'] = year
value.attributes['author'] = author
if not fullauthor.textContent.strip():
value.attributes['fullauthor'] = author
else:
value.attributes['fullauthor'] = fullauthor
doc = self.ownerDocument
bibcites = doc.userdata.getPath('bibliography/bibcites', {})
bibcites[self.attributes['key']] = value
doc.userdata.setPath('bibliography/bibcites', bibcites)
class thebibliography(Base.thebibliography):
class bibitem(Base.thebibliography.bibitem):
@property
def bibcite(self):
try:
doc = self.ownerDocument
return doc.userdata.getPath('bibliography/bibcites', {})[self.attributes['key']]
except KeyError, msg:
pass
# We don't have a citation that matches, fill the fields
# with dummy data
value = self.ownerDocument.createElement('citation')
value.parentNode = self
value.append('??')
for item in ['year','author','fullauthor']:
obj = self.ownerDocument.createDocumentFragment()
obj.parentNode = value
obj.append('??')
value.attributes[item] = obj
return value
def ref():
def fset(self, value):
pass
def fget(self):
return self.bibcite.textContent
return locals()
ref = property(**ref())
class harvarditem(thebibliography.bibitem):
args = '[ abbrlabel ] label year key:str'
class NatBibCite(Base.cite):
""" Base class for all natbib-style cite commands """
args = '* [ text ] [ text2 ] bibkeys:list:str'
class Connector(str):
pass
@property
def bibitems(self):
items = []
opts = PackageOptions
doc = self.ownerDocument
b = doc.userdata.getPath('bibliography/bibitems', {})
for key in self.attributes['bibkeys']:
if key in b:
items.append(b[key])
if bibpunct.punctuation['style'] in 'ns' and \
('sort' in opts or 'sort&compress' in opts or 'sortandcompress' in opts):
items.sort(lambda x, y: int(x.ref) - int(y.ref))
if 'sort&compress' in opts or 'sortandcompress' in opts:
items = self.compressRange(items)
return items
def compressRange(self, items):
""" Compress ranges of numbers """
idx, idxdict = [], {}
for i, value in enumerate(items):
idx.append(int(value.ref))
idxdict[int(value.ref)] = value
output = []
for i, value in enumerate(idx):
if i == 0:
output.append(' ')
output.append(value)
elif idx[i-1] == (value-1):
output.append('-')
output.append(value)
else:
output.append(' ')
output.append(value)
output.append(' ')
output = ''.join([str(x) for x in output])
output = re.sub(r'( \d+)-(\d+ )', r'\1 \2', output)
while re.search(r'-\d+-', output):
output = re.sub(r'-\d+-', r'-', output)
output = [x for x in re.split(r'([ -])', output) if x.strip()]
for i, value in enumerate(output):
if value in string.digits:
output[i] = idxdict[int(value)]
else:
output[i] = self.Connector(value)
return output
def isConnector(self, value):
return isinstance(value, self.Connector)
@property
def prenote(self):
""" Text that comes before the citation """
a = self.attributes
if a.get('text2') is not None and a.get('text') is not None:
if not a.get('text').textContent.strip():
return ''
out = self.ownerDocument.createElement('bgroup')
out.extend(a['text'])
out.append(' ')
return out
return ''
@property
def postnote(self):
""" Text that comes after the citation """
a = self.attributes
if a.get('text2') is not None and a.get('text') is not None:
if not a.get('text2').textContent.strip():
return ''
out = self.ownerDocument.createElement('bgroup')
out.append(bibpunct.punctuation['post'])
out.extend(a['text2'])
return out
elif a.get('text') is not None:
if not a.get('text').textContent.strip():
return ''
out = self.ownerDocument.createElement('bgroup')
out.append(bibpunct.punctuation['post'])
out.extend(a['text'])
return out
return ''
@property
def separator(self):
""" Separator for multiple items """
return bibpunct.punctuation['sep']
@property
def years(self):
""" Separator for multiple years """
return bibpunct.punctuation['years']
def selectAuthorField(self, key, full=False):
""" Determine if author should be a full name or shortened """
if full or self.attributes.get('*modifier*'):
return 'fullauthor'
doc = self.ownerDocument
# longnamesfirst means that only the first reference
# gets the full length name, the rest use short names.
cited = doc.userdata.getPath('bibliography/cited', [])
if 'longnamesfirst' in PackageOptions and key not in cited:
full = True
cited.append(key)
doc.userdata.setPath('bibliography/cited', cited)
if full:
return 'fullauthor'
return 'author'
def isNumeric(self):
return bibpunct.punctuation['style'] in ['n','s']
def isSuperScript(self):
return bibpunct.punctuation['style'] == 's'
def citeValue(self, item, text=None):
""" Return cite value based on current style """
b = self.ownerDocument.createElement('bibliographyref')
b.idref['bibitem'] = item
if text is not None:
b.append(text)
elif bibpunct.punctuation['style'] in ['n','s']:
b.append(item.bibcite)
else:
b.append(item.bibcite.attributes['year'])
return b
def capitalize(self, item):
""" Capitalize the first text node """
item = item.cloneNode(True)
textnodes = [x for x in item.allChildNodes
if x.nodeType == self.TEXT_NODE]
if not textnodes:
return item
node = textnodes.pop(0)
node.parentNode.replaceChild(node.cloneNode(True).capitalize() ,node)
return item
# class citep(NatBibCite):
# def numcitation(self):
# """ Numeric style citations """
# res = []
# res.append(bibpunct.punctuation['open'])
# for i, item in enumerate(self.bibitems):
# frag = self.ownerDocument.createDocumentFragment()
# frag.append(item.ref)
# frag.idref = item
# res.append(frag)
# res.append(bibpunct.punctuation['sep'])
# res.pop()
# res.append(bibpunct.punctuation['close'])
# return res
# def citation(self):
# if bibpunct.punctuation['style'] == 'n':
# return self.numcitation()
# elif bibpunct.punctuation['style'] == 's':
# return self.numcitation()
# res = []
# res.append(bibpunct.punctuation['open'] + self.prenote)
# prevauthor = None
# prevyear = None
# duplicateyears = 0
# previtem = None
# for i, item in enumerate(self.bibitems):
# currentauthor = item.citeauthor().textContent
# currentyear = item.citeyear().textContent
# # Previous author and year are the same
# if prevauthor == currentauthor and prevyear == currentyear:
# res.pop()
# # This is the first duplicate
# if duplicateyears == 0:
# # Make a reference that points to the same item as
# # the first citation in this set. This will make
# # hyperlinked output prettier since the 'a' will
# # be linked to the same place as the reference that
# # we just put out.
# res.append('')
# frag = self.ownerDocument.createDocumentFragment()
# frag.append('a')
# frag.idref = previtem
# res.append(frag)
# res.append(bibpunct.punctuation['years'])
# else:
# res.append(bibpunct.punctuation['years'])
# # Create a new fragment with b,c,d... in it
# frag = self.ownerDocument.createDocumentFragment()
# frag.append(chr(duplicateyears+ord('b')))
# frag.idref = item
# res.append(frag)
# res.append(bibpunct.punctuation['sep']+' ')
# duplicateyears += 1
# # Previous author is the same
# elif prevauthor == currentauthor:
# duplicateyears = 0
# res.pop()
# res.append(bibpunct.punctuation['years']+' ')
# res.append(item.citeyear())
# res.append(bibpunct.punctuation['sep']+' ')
# # Nothing about the previous citation is the same
# else:
# doc = self.ownerDocument
# cited = doc.userdata.getPath('bibliography/cited', [])
# duplicateyears = 0
# if 'longnamesfirst' in PackageOptions and \
# item.attributes['key'] not in cited:
# cited.append(item.attributes['key'])
# doc.userdata.setPath('bibliography/cited', cited)
# res.append(item.citealp(full=True))
# else:
# res.append(item.citealp())
# res.append(bibpunct.punctuation['sep']+' ')
# prevauthor = currentauthor
# prevyear = currentyear
# previtem = item
# res.pop()
# res.append(self.postnote + bibpunct.punctuation['close'])
# return res
class citet(NatBibCite):
def citation(self, full=False, capitalize=False, text=None):
""" Jones et al. (1990) """
if text is None and self.isNumeric():
return self.numcitation()
res = self.ownerDocument.createDocumentFragment()
i = 0
sameauthor = prevauthor = None
for i, item in enumerate(self.bibitems):
if text is None:
if not item.bibcite.attributes:
continue
fullauthor = item.bibcite.attributes['fullauthor'].textContent
sameauthor = (prevauthor == fullauthor)
prevauthor = fullauthor
# Author, only print author if it wasn't equal to the last author
if sameauthor:
# Pop punctuation from previous year
res.pop()
res.pop()
# Add year separator
res.append(self.years+' ')
else:
author = self.selectAuthorField(item.attributes['key'], full=full)
if i == 0 and capitalize:
res.extend(self.capitalize(item.bibcite.attributes[author]))
else:
res.extend(item.bibcite.attributes[author])
res.append(' ')
res.append(bibpunct.punctuation['open'])
# Prenote
res.append(self.prenote)
# Year or text
res.append(self.citeValue(item, text=text))
# Separator, postnote, and closing punctuation
if i < (len(self.bibitems)-1):
if text is None:
res.append(bibpunct.punctuation['close'])
res.append(self.separator+' ')
else:
res.append(self.postnote)
if text is None:
res.append(bibpunct.punctuation['close'])
return res
def numcitation(self, full=False, capitalize=False):
""" (1, 2) """
element = self.ownerDocument.createElement
orig = res = self.ownerDocument.createDocumentFragment()
if self.isSuperScript():
group = element('bgroup')
orig.append(group)
res = element('active::^')
group.append(res)
i = 0
res.append(self.prenote)
res.append(bibpunct.punctuation['open'])
for i, item in enumerate(self.bibitems):
if self.isConnector(item):
res.pop()
res.append('-')
continue
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
res.append(bibpunct.punctuation['close'])
res.append(self.postnote)
return orig
class citetfull(citet):
def citation(self):
""" Jones, Baker, and Williams (1990) """
return citet.citation(self, full=True)
class Citet(citet):
def citation(self):
return citet.citation(self, capitalize=True)
class citep(NatBibCite):
def citation(self, full=False, capitalize=False, text=None):
""" (Jones et al., 1990) """
if text is None and self.isNumeric():
return self.numcitation()
res = self.ownerDocument.createDocumentFragment()
res.append(bibpunct.punctuation['open'])
res.append(self.prenote)
i = 0
sameauthor = prevauthor = None
for i, item in enumerate(self.bibitems):
if text is None:
if item.bibcite.attributes is None:
continue
fullauthor = item.bibcite.attributes['fullauthor'].textContent
sameauthor = (prevauthor == fullauthor)
prevauthor = fullauthor
# Author, only print author if it wasn't equal to the last author
if sameauthor:
res.pop()
res.append(self.years+' ')
else:
author = self.selectAuthorField(item.attributes['key'], full=full)
if i == 0 and capitalize:
res.extend(self.capitalize(item.bibcite.attributes[author]))
else:
res.extend(item.bibcite.attributes[author])
res.append(self.separator+' ')
res.append(self.citeValue(item, text=text))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
res.append(bibpunct.punctuation['close'])
return res
def numcitation(self):
""" (1, 2) """
element = self.ownerDocument.createElement
orig = res = self.ownerDocument.createDocumentFragment()
if self.isSuperScript():
group = element('bgroup')
orig.append(group)
res = element('active::^')
group.append(res)
res.append(bibpunct.punctuation['open'])
res.append(self.prenote)
i = 0
for i, item in enumerate(self.bibitems):
if self.isConnector(item):
res.pop()
res.append('-')
continue
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
res.append(bibpunct.punctuation['close'])
return orig
class cite(citep, citet):
def citation(self, full=False, capitalize=False):
if self.prenote or self.postnote:
return citep.citation(self, full=full, capitalize=capitalize)
return citet.citation(self, full=full, capitalize=capitalize)
class Cite(cite):
def citation(self):
return cite.citation(self, capitalize=True)
class citepfull(citep):
def citation(self):
""" (Jones, Baker, and Williams, 1990) """
return citep.citation(self, full=True)
class Citep(citep):
def citation(self):
return citep.citation(self, capitalize=True)
class citealt(NatBibCite):
def citation(self, full=False, capitalize=False):
""" Jones et al. 1990 """
if self.isNumeric():
return self.numcitation()
res = self.ownerDocument.createDocumentFragment()
i = 0
prevauthor = sameauthor = None
for i, item in enumerate(self.bibitems):
fullauthor = item.bibcite.attributes['fullauthor'].textContent
sameauthor = (prevauthor == fullauthor)
prevauthor = fullauthor
# Author, only print author if it wasn't equal to the last author
if sameauthor:
res.pop()
res.append(self.years+' ')
else:
author = self.selectAuthorField(item.attributes['key'], full=full)
if i == 0 and capitalize:
res.extend(self.capitalize(item.bibcite.attributes[author]))
else:
res.extend(item.bibcite.attributes[author])
res.append(' ')
res.append(self.prenote)
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
return res
def numcitation(self):
""" 1, 2 """
element = self.ownerDocument.createElement
orig = res = self.ownerDocument.createDocumentFragment()
if self.isSuperScript():
group = element('bgroup')
orig.append(group)
res = element('active::^')
group.append(res)
i = 0
res.append(self.prenote)
for i, item in enumerate(self.bibitems):
if self.isConnector(item):
res.pop()
res.append('-')
continue
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
return orig
class citealtfull(citealt):
def citation(self):
""" Jones, Baker, and Williams 1990 """
return citealt.citation(self, full=True)
class Citealt(citealt):
def citation(self):
return citealt.citation(self, capitalize=True)
class citealp(NatBibCite):
def citation(self, full=False, capitalize=False):
""" Jones et al., 1990 """
if self.isNumeric():
return self.numcitation()
res = self.ownerDocument.createDocumentFragment()
res.append(self.prenote)
i = 0
prevauthor = sameauthor = None
for i, item in enumerate(self.bibitems):
fullauthor = item.bibcite.attributes['fullauthor'].textContent
sameauthor = (prevauthor == fullauthor)
prevauthor = fullauthor
# Author, only print author if it wasn't equal to the last author
if sameauthor:
res.pop()
res.append(self.years+' ')
else:
author = self.selectAuthorField(item.attributes['key'], full=full)
if i == 0 and capitalize:
res.extend(self.capitalize(item.bibcite.attributes[author]))
else:
res.extend(item.bibcite.attributes[author])
res.append(self.separator+' ')
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
return res
def numcitation(self):
""" 1, 2 """
element = self.ownerDocument.createElement
orig = res = self.ownerDocument.createDocumentFragment()
if self.isSuperScript():
group = element('bgroup')
orig.append(group)
res = element('active::^')
group.append(res)
res.append(self.prenote)
i = 0
for i, item in enumerate(self.bibitems):
if self.isConnector(item):
res.pop()
res.append('-')
continue
res.append(self.citeValue(item))
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
res.append(self.postnote)
return orig
class citealpfull(citealp):
def citation(self):
""" Jones, Baker, and Williams, 1990 """
return citealp.citation(self, full=True)
class Citealp(citealp):
def citation(self):
return citealp.citation(self, capitalize=True)
class citeauthor(NatBibCite):
def citation(self, full=False, capitalize=False):
""" Jones et al. """
if self.isNumeric():
return
res = self.ownerDocument.createDocumentFragment()
#res.append(self.prenote)
i = 0
for i, item in enumerate(self.bibitems):
author = self.selectAuthorField(item.attributes['key'], full=full)
b = self.ownerDocument.createElement('bibliographyref')
b.idref['bibitem'] = item
if i == 0 and capitalize:
b.append(self.capitalize(item.bibcite.attributes[author]))
else:
b.append(item.bibcite.attributes[author])
res.append(b)
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
return res
class citefullauthor(citeauthor):
def citation(self):
""" Jones, Baker, and Williams """
return citeauthor.citation(self, full=True)
class Citeauthor(citeauthor):
def citation(self):
return citeauthor.citation(self, capitalize=True)
class citeyear(NatBibCite):
def citation(self):
""" 1990 """
if self.isNumeric():
return
res = self.ownerDocument.createDocumentFragment()
#res.append(self.prenote)
i = 0
for i, item in enumerate(self.bibitems):
b = self.ownerDocument.createElement('bibliographyref')
b.idref['bibitem'] = item
b.append(item.bibcite.attributes['year'])
res.append(b)
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
return res
class citeyearpar(NatBibCite):
def citation(self):
""" (1990) """
if self.isNumeric():
return
res = self.ownerDocument.createDocumentFragment()
res.append(bibpunct.punctuation['open'])
res.append(self.prenote)
i = 0
for i, item in enumerate(self.bibitems):
b = self.ownerDocument.createElement('bibliographyref')
b.idref['bibitem'] = item
b.append(item.bibcite.attributes['year'])
res.append(b)
if i < (len(self.bibitems)-1):
res.append(self.separator+' ')
else:
res.append(self.postnote)
res.append(bibpunct.punctuation['close'])
return res
class citetext(Base.Command):
args = 'self'
def digest(self, tokens):
self.insert(0, bibpunct.punctuation['open'])
self.append(bibpunct.punctuation['close'])
class defcitealias(Base.Command):
args = 'key:str text'
aliases = {}
def invoke(self, tex):
res = Base.Command.invoke(self, tex)
defcitealias.aliases[self.attributes['key']] = self.attributes['text']
return res
class citetalias(citet):
args = 'bibkeys:list:str'
def citation(self):
return citet.citation(self, text=defcitealias.aliases.get(self.attributes['bibkeys'][0],''))
class citepalias(citep):
args = 'bibkeys:list:str'
def citation(self):
return citep.citation(self, text=defcitealias.aliases.get(self.attributes['bibkeys'][0],''))
class shortcites(Base.Command):
args = 'bibkeys:list:str'
class urlstyle(Base.Command):
pass
|