forked from JelteF/PyLaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.py
135 lines (85 loc) · 2.98 KB
/
table.py
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
# -*- coding: utf-8 -*-
"""
This module implements the class that deals with tables.
.. :copyright: (c) 2014 by Jelte Fennema.
:license: MIT, see License for more details.
"""
from .utils import dumps_list
from .base_classes import Container, Command, TabularBase
from .package import Package
from warnings import warn
class MultiColumn(Container):
"""A class that represents a multicolumn inside of a table.
:param size:
:param align:
:param data:
:type size: int
:type align: str
:type data: str
TODO:
type of data can also be list
"""
def __init__(self, size, align='|c|', data=None):
self.size = size
self.align = align
super().__init__(data)
def dumps(self):
"""Represent the multicolumn as a string in LaTeX syntax.
:return:
:rtype: str
"""
multicolumn_type = self.__class__.__name__.lower()
args = [self.size, self.align, dumps_list(self.data)]
string = Command(multicolumn_type, args).dumps()
string += dumps_list(self)
super().dumps()
return string
class MultiRow(Container):
"""A class that represents a multirow in a table.
:param size:
:param width:
:param data:
:type size: int
:type width: str
:type data: str
TODO:
type of data can also be list
"""
def __init__(self, size, width='*', data=None):
self.size = size
self.width = width
packages = [Package('multirow')]
super().__init__(data, packages=packages)
def dumps(self):
"""Represent the multirow as a string in LaTeX syntax.
:return:
:rtype: str
"""
multirow_type = self.__class__.__name__.lower()
args = [self.size, self.width, dumps_list(self.data)]
string = Command(multirow_type, args).dumps()
string += dumps_list(self)
super().dumps()
return string
class Tabular(TabularBase):
"""A class that represents a tabular."""
class Table(Tabular):
"""A legacy name for the class that represents a tabular."""
container_name = 'tabular'
def __init__(self, *args, **kwargs):
warn('Table is going te be deprecated in favor of Tabular',
PendingDeprecationWarning)
super().__init__(*args, **kwargs)
class Tabu(TabularBase):
"""A class that represents a tabu (more flexible table)."""
def __init__(self, *args, **kwargs):
super().__init__(*args, packages=[Package('tabu')], **kwargs)
class LongTable(TabularBase):
"""A class that represents a longtable (multipage table)."""
def __init__(self, *args, **kwargs):
super().__init__(*args, packages=[Package('longtable')], **kwargs)
class LongTabu(Table):
"""A class that represents a longtabu (more flexible multipage table)."""
def __init__(self, *args, **kwargs):
packages = [Package('tabu'), Package('longtable')]
super().__init__(*args, packages=packages, **kwargs)