/usr/share/pyshared/plasTeX/Packages/subfig.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 | """
subfig package
TO-DO
- Options handling
- Only works with figure environment
- Lists of floats
"""
import new
from plasTeX import Command, Environment
from plasTeX.Base.LaTeX.Floats import Float
def ProcessOptions(options, document):
context = document.context
context.newcounter('subfloat', resetby='figure', format='${subfloat.alph}')
class newsubfloat(Command):
args = '[ options:dict ] name:str'
def invoke(self, tex):
Command.invoke(self, tex)
c = self.ownerDocument.context
name = str(self.attributes['name'])
options = self.attributes['options'] or {}
# Create new subfloat class
newclass = new.classobj(name, (subfloat,),
{'options':options,'counter':name})
c.addGlobal(name, newclass)
# Create new counter
c.newcounter(name, resetby='figure', format='${%s.alph}' % name)
# Create the float name macro
c.newcommand(name+'name', 0, name)
class DeclareCaptionListOfFormat(Command):
args = 'keyword code'
class subfloatname(Command):
unicode = ''
class subfloat(Command):
args = '[ toc ] [ caption ] self'
counter = 'subfloat'
options = {}
def preParse(self, tex):
"""
This is getting tricky. The ContinuedFloat tells whether or not
the counter should be incremented. We save the lastvalue of the
counter in the userdata so we can get it back here.
"""
doc = self.ownerDocument
c = doc.context
if doc.userdata.getPath('packages/subfig/continued'):
v = doc.userdata.getPath('packages/subfig/subfloats/%s/lastvalue' %
self.tagName, 1)
c.counters[self.counter].setcounter(v+1)
doc.userdata.setPath('packages/subfig/continued', False)
else:
doc.userdata.setPath('packages/subfig/subfloats/%s/lastvalue' %
self.tagName, c.counters[self.counter].value)
return Command.preParse(self, tex)
def invoke(self, tex):
Command.invoke(self, tex)
self.title = self.attributes['caption'] or self.attributes['toc']
def ref():
"""
This is a bit crazy. We have to override ref so that we can
add some new functionality. The value normally gotten by ref
is now held in subref. The ref value also contains the ref value
of the parent float node.
"""
def fset(self, value):
self.subref = value
def fget(self):
# Find the parent float of this subfloat
node = self.parentNode
while node is not None and not(isinstance(node, Float)):
node = node.parentNode
parentFloat = node
# Add the float number to the ref value
doc = self.ownerDocument
frag = doc.createDocumentFragment()
frag.append(parentFloat.caption.ref)
frag.append(self.subref)
return frag
return locals()
ref = property(**ref())
class subref(Command):
args = '* label:idref'
class ContinuedFloat(Command):
def invoke(self, tex):
Command.invoke(self, tex)
doc = self.ownerDocument
c = doc.context
c.counters['figure'].value -= 1
doc.userdata.setPath('packages/subfig/continued', True)
class listsubcaptions(Command):
pass
class captionsetup(Command):
args = '[ type:str ] options:dict'
|