/usr/share/pyshared/plasTeX/Packages/longtable.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 | import sys
from plasTeX.Base.LaTeX.Arrays import tabular
from plasTeX import Command, DimenCommand, CountCommand, GlueCommand
from plasTeX import dimen, glue, count, TeXFragment
class LTleft(GlueCommand): value = glue('1fil')
class LTright(GlueCommand): value = glue('1fil')
class LTpre(GlueCommand): value = glue('1fil')
class LTpost(GlueCommand): value = glue('1fil')
class LTchunksize(DimenCommand): value = dimen('4in')
class LTchunksize(CountCommand): value = count(20)
class setlongtables(Command): pass
class longtable(tabular):
args = '[ position:str ] colspec:nox'
class caption(tabular.caption):
def digest(self, tokens):
tabular.caption.digest(self, tokens)
node = self.parentNode
# Mark caption row to be moved later
while not isinstance(node, tabular.ArrayRow):
node = node.parentNode
if node is not None:
node.isCaptionRow = True
# Attach caption to longtable node in case it is needed
while not isinstance(node, longtable):
node = node.parentNode
if node is not None and getattr(node, 'title', None) is None:
node.title = self
class nocountcaption(caption):
""" Caption that doesn't increment the counter """
counter = None
class tabularnewline(Command): pass
class LongTableEndRow(tabular.EndRow):
args = None
macroName = None
digested = False
def digest(self, tokens):
if self.digested:
return
tabular.EndRow.digest(self, tokens)
# Push the instance into the stream a second time.
# This will be used in longtable.digest() to split out
# the header and footer chunks.
tokens.push(self)
self.digested = True
class endhead(LongTableEndRow):
""" End of head section """
class endfirsthead(LongTableEndRow):
""" End of first head section """
def invoke(self, tex):
# Store the current table counter value. If more than one
# caption exists, we need to set this counter back to this value.
self._tabularcount = self.ownerDocument.context.counters[longtable.caption.counter].value
return longtable.LongTableEndRow.invoke(self, tex)
class endfoot(LongTableEndRow):
""" End of footer section """
class endlastfoot(LongTableEndRow):
""" End of last footer section """
class kill(LongTableEndRow):
""" Throw-away row used for measurement """
def digest(self, tokens):
longtable.LongTableEndRow.digest(self, tokens)
node = self.parentNode
while node is not None and not isinstance(node, longtable):
node = node.parentNode
if node is not None:
node[-1].isKillRow = True
def processRows(self):
# Strip header and footer chunks from the table
delims = [x for x in self if isinstance(x, type(self).EndRow)]
delims = [x for x in delims if not isinstance(x, type(self).kill)]
header = footer = None
for current in delims:
cache = []
while 1:
node = self.pop(0)
if current is node:
if isinstance(current, type(self).endhead):
if header is None:
header = cache
elif isinstance(current, type(self).endfirsthead):
header = cache
# Set counter back to correct value in case there
# were multiple captions.
self.ownerDocument.context.counters[longtable.caption.counter].setcounter(node._tabularcount)
elif isinstance(current, type(self).endfoot):
if footer is None:
footer = cache
elif isinstance(current, type(self).endlastfoot):
footer = cache
break
else:
cache.append(node)
# Re-insert only the first header and last footer
if header is not None:
header.reverse()
for item in header:
for cell in item:
cell.isHeader = True
self.insert(0, item)
if footer is not None:
for item in footer:
for cell in item:
cell.isHeader = True
self.append(item)
# Move caption before the longtable, and delete killed rows
removeRows = []
for i, row in enumerate(self):
if getattr(row, 'isCaptionRow', None):
#while row.childNodes:
# cell = row.pop(0)
# while cell.childNodes:
# para = cell.pop(0)
# while para.childNodes:
# self.parentNode.append(para.pop(0))
removeRows.insert(0,i)
elif getattr(row, 'isKillRow', None):
removeRows.insert(0,i)
for i in removeRows:
self.pop(i)
class LongTableStar(longtable):
macroName = 'longtable*'
|