pyltk/pyltk/figure.py

47 lines
1.2 KiB
Python

# -*- encoding: utf-8 -*-
from .element import element
class figure(element):
""" Class representing a latex figure. """
templates = {
'caption': '\\caption{{{content}}}',
'content': """\\begin{{figure}}[{options}]
{centered}
{inner}
{caption}{label}
\\end{{figure}}"""
}
autolabel = False
def __init__(self, childrens=None, parent=None,
caption=None, options='!h',
centered=True, label=None):
""" Create a figure with given options.
Parameters:
- options Options for the figure.
- centered Set to true to add a centering command.
"""
super().__init__(parent, childrens, label=label)
self.options = options
self.caption = caption
self.centered = ''
if centered:
self.centered = '\\centering'
def content(self):
caption = ''
if self.caption:
caption = self.fmt().format('caption', {'content': self.caption})
return self.fmt().format('content', {
'options': self.options,
'centered': self.centered,
'caption': caption,
'label': self.format_label(self.label),
'inner': super().content()
})