Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: 4teamwork/ftw.pdfgenerator
base: 1c4e852805
...
head fork: 4teamwork/ftw.pdfgenerator
compare: ffeabb5df0
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
6 docs/HISTORY.txt
@@ -4,7 +4,11 @@ Changelog
1.1.3 (unreleased)
------------------
-- Nothing changed yet.
+- Tables: calculate widths properly respecting \tabcolsep.
+ [jone]
+
+- Tables: support plone css classes (grid, listing, vertical).
+ [jone]
1.1.2 (2012-05-02)
View
32 ftw/pdfgenerator/html2latex/subconverters/table.py
@@ -118,17 +118,28 @@ def get_table_layout(self):
return NO_LAYOUT
def render(self):
- latex = '\\begin{%s}{%s}\n' % (
- self.environment, self.get_table_format())
+ latex = [
+ r'\makeatletter\@ifundefined{tablewidth}{' + \
+ r'\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-%i\tabcolsep}' % (
+ 2 * len(self.columns))]
+
+ latex.append(r'\begin{%s}{%s}' % (
+ self.environment, self.get_table_format()))
+
caption_command, insert_caption_at_top = self.render_caption()
if caption_command and insert_caption_at_top:
- latex += caption_command
+ latex.append(caption_command.strip())
+
+ latex.append(self.render_rows().strip())
- latex += self.render_rows()
if caption_command and not insert_caption_at_top:
- latex += caption_command
- latex += '\\end{%s}\n' % self.environment
- return latex
+ latex.append(caption_command.strip())
+
+ latex.append(r'\end{%s}' % self.environment)
+ latex.append('')
+ return '\n'.join(latex)
def render_rows(self):
head_rows = []
@@ -533,8 +544,7 @@ def render(self, row):
span = str(self.get_rowspan())
latex = '\\multirow{%s}{%s}{%s}' % (
span,
- str(self.get_calculated_width()).replace(r'\linewidth',
- r'\textwidth'),
+ str(self.get_calculated_width()),
self.render_content(),
)
else:
@@ -793,7 +803,7 @@ class LatexWidth(object):
"""
TYPE_ABSOLUTE = 'absolute width (px, em, ..)'
- TYPE_RELATIVE = 'relative width (% of linewidth, ..)'
+ TYPE_RELATIVE = 'relative width (% of tablewidth, ..)'
VALID_ABSOLUTE_UNITS = [
'cm',
'mm',
@@ -846,7 +856,7 @@ def get(self):
if self.type == LatexWidth.TYPE_ABSOLUTE:
return '%s%s' % (str(self.width), self.unit)
elif self.type == LatexWidth.TYPE_RELATIVE:
- return '%s\\linewidth' % str(self.width)
+ return '%s\\tablewidth' % str(self.width)
def __str__(self):
return self.get()
View
303 ftw/pdfgenerator/tests/test_html2latex_table_subconverter.py
@@ -51,6 +51,9 @@ def test_table_converted(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{\textbf{My Head}} \\',
r'\multicolumn{1}{l}{My Body} \\',
@@ -81,6 +84,9 @@ def test_headings(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
r'\begin{tabular}{ll}',
r'\multicolumn{1}{l}{\textbf{headA}} & ' + \
r'\multicolumn{1}{l}{\textbf{headB}} \\',
@@ -110,13 +116,16 @@ def test_colgroup_with_width(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.3\linewidth}p{0.7\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.3\tablewidth}p{0.7\tablewidth}}',
- r'\multicolumn{1}{p{0.3\linewidth}}{test1} & '
- r'\multicolumn{1}{p{0.7\linewidth}}{test2} \\',
+ r'\multicolumn{1}{p{0.3\tablewidth}}{test1} & '
+ r'\multicolumn{1}{p{0.7\tablewidth}}{test2} \\',
- r'\multicolumn{1}{p{0.3\linewidth}}{test3} & '
- r'\multicolumn{1}{p{0.7\linewidth}}{test4} \\',
+ r'\multicolumn{1}{p{0.3\tablewidth}}{test3} & '
+ r'\multicolumn{1}{p{0.7\tablewidth}}{test4} \\',
r'\end{tabular}',
r''))
@@ -139,9 +148,12 @@ def test_colgroup_with_invalid_width(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.3\linewidth}r}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.3\tablewidth}r}',
- r'\multicolumn{1}{p{0.3\linewidth}}{test1} & '
+ r'\multicolumn{1}{p{0.3\tablewidth}}{test1} & '
r'\multicolumn{1}{r}{test2} \\',
r'\end{tabular}',
@@ -171,14 +183,17 @@ def test_col_and_cell_have_widths(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.3\linewidth}p{0.7\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.3\tablewidth}p{0.7\tablewidth}}',
- r'\multicolumn{1}{p{0.3\linewidth}}{'
+ r'\multicolumn{1}{p{0.3\tablewidth}}{'
r'\raggedleft test1} & \multicolumn{1}{'
- r'p{0.7\linewidth}}{\raggedright test2} \\',
+ r'p{0.7\tablewidth}}{\raggedright test2} \\',
- r'\multicolumn{1}{p{0.3\linewidth}}{\center\vspace{-1.5em}'
- r'test3} & \multicolumn{1}{p{0.7\linewidth}}{test4} \\',
+ r'\multicolumn{1}{p{0.3\tablewidth}}{\center\vspace{-1.5em}'
+ r'test3} & \multicolumn{1}{p{0.7\tablewidth}}{test4} \\',
r'\end{tabular}',
r''))
@@ -195,6 +210,9 @@ def test_caption_is_used(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\caption{Testtabelle} \\',
r'\multicolumn{1}{l}{test} \\',
@@ -214,6 +232,9 @@ def test_caption_not_listed(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\caption*{NotIndexedCaption} \\',
r'\multicolumn{1}{l}{foo} \\',
@@ -233,6 +254,9 @@ def test_caption_at_bottom(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{foo} \\',
r'\caption{My Table} \\',
@@ -248,9 +272,17 @@ def test_multiple_tables(self):
r'<table><tr><td>test2</td></tr></table>'
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength' + \
+ r'\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test1} \\',
r'\end{tabular}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength' + \
+ r'\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test2} \\',
r'\end{tabular}',
@@ -264,6 +296,9 @@ def test_convert_cell_html(self):
html = r'<table><tr><td><b>Hello</b> <i>World</i></td></tr></table>'
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{{\bf Hello} {\it World}} \\',
r'\end{tabular}',
@@ -281,7 +316,10 @@ def test_convert_other_html(self):
latex = '\n'.join((
r'This {\it is} a {\bf Table}:\\',
- r' \begin{tabular}{l}',
+ r' \makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
+ r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test} \\',
r'\end{tabular}',
r' {\bf yeah}'))
@@ -299,6 +337,9 @@ def test_htmlentities(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{2>1} \\',
'\\multicolumn{1}{l}{X\xc3\xa4Y} \\\\',
@@ -328,15 +369,18 @@ def test_colspan(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.33\linewidth}p{0.33\linewidth}'
- r'p{0.34\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-6\tabcolsep}',
+ r'\begin{tabular}{p{0.33\tablewidth}p{0.33\tablewidth}'
+ r'p{0.34\tablewidth}}',
- r'\multicolumn{1}{p{0.33\linewidth}}{one} & '
- r'\multicolumn{1}{p{0.33\linewidth}}{two} & '
- r'\multicolumn{1}{p{0.34\linewidth}}{three} \\',
+ r'\multicolumn{1}{p{0.33\tablewidth}}{one} & '
+ r'\multicolumn{1}{p{0.33\tablewidth}}{two} & '
+ r'\multicolumn{1}{p{0.34\tablewidth}}{three} \\',
- r'\multicolumn{2}{p{0.66\linewidth}}{one and two} & '
- r'\multicolumn{1}{p{0.34\linewidth}}{three} \\',
+ r'\multicolumn{2}{p{0.66\tablewidth}}{one and two} & '
+ r'\multicolumn{1}{p{0.34\tablewidth}}{three} \\',
r'\end{tabular}',
r''))
@@ -361,12 +405,15 @@ def test_rowspan(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multirow{2}{0.5\textwidth}{one} & \multicolumn{1}'
- r'{p{0.5\linewidth}}{two} \\',
+ r'\multirow{2}{0.5\tablewidth}{one} & \multicolumn{1}'
+ r'{p{0.5\tablewidth}}{two} \\',
- r' & \multicolumn{1}{p{0.5\linewidth}}{three} \\',
+ r' & \multicolumn{1}{p{0.5\tablewidth}}{three} \\',
r'\end{tabular}',
r''))
@@ -400,23 +447,27 @@ def test_complex_rowspan_colspan(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.25\linewidth}p{0.25\linewidth}' + \
- r'p{0.25\linewidth}p{0.25\linewidth}l}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength' + \
+ r'\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-10\tabcolsep}',
+ r'\begin{tabular}{p{0.25\tablewidth}p{0.25\tablewidth}' + \
+ r'p{0.25\tablewidth}p{0.25\tablewidth}l}',
# row 1
- r'\multicolumn{1}{p{0.25\linewidth}}{A1} & ' + \
- r'\multirow{2}{0.25\textwidth}{B1-B2} & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{C1} & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{D1} \\',
+ r'\multicolumn{1}{p{0.25\tablewidth}}{A1} & ' + \
+ r'\multirow{2}{0.25\tablewidth}{B1-B2} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{C1} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{D1} \\',
# row 2
- r'\multicolumn{1}{p{0.25\linewidth}}{A2} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{A2} & ' + \
r' & '
- r'\multirow{2}{0.25\textwidth}{C2-C3} & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{D2} \\',
+ r'\multirow{2}{0.25\tablewidth}{C2-C3} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{D2} \\',
# row 3
- r'\multicolumn{2}{p{0.5\linewidth}}{A3-B3} & ' + \
+ r'\multicolumn{2}{p{0.5\tablewidth}}{A3-B3} & ' + \
r' & '
r'\multicolumn{2}{l}{D3-E3} \\',
@@ -445,16 +496,19 @@ def test_gridborder(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{|p{0.3\linewidth}|p{0.7\linewidth}|}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{|p{0.3\tablewidth}|p{0.7\tablewidth}|}',
r'\hline',
- r'\multicolumn{1}{|p{0.3\linewidth}}{test1} & '
- r'\multicolumn{1}{|p{0.7\linewidth}|}{test2} \\',
+ r'\multicolumn{1}{|p{0.3\tablewidth}}{test1} & '
+ r'\multicolumn{1}{|p{0.7\tablewidth}|}{test2} \\',
r'\hline',
- r'\multicolumn{1}{|p{0.3\linewidth}}{test3} & '
- r'\multicolumn{1}{|p{0.7\linewidth}|}{test4} \\',
+ r'\multicolumn{1}{|p{0.3\tablewidth}}{test3} & '
+ r'\multicolumn{1}{|p{0.7\tablewidth}|}{test4} \\',
r'\hline',
r'\end{tabular}',
@@ -477,11 +531,15 @@ def test_newlines(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength' + \
+ r'\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'hello\newline world} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'foo\newline \newline bar} \\',
r'\end{tabular}',
@@ -505,11 +563,14 @@ def test_tabular_environment_depends_on_table_size(self):
))
tabular_latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -530,6 +591,9 @@ def test_longtable_environment_depends_on_table_size(self):
))
longtable_latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{longtable}{l}',
(40 * '\\multicolumn{1}{l}{foo} \\\\\n').strip(),
r'\end{longtable}',
@@ -551,11 +615,14 @@ def test_longtable_environment_enforcable_by_cssclass(self):
))
longtable_latex = '\n'.join((
- r'\begin{longtable}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{longtable}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{longtable}',
@@ -574,6 +641,9 @@ def test_tabular_environment_enforcable_by_cssclass(self):
))
tabular_latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
(20 * '\\multicolumn{1}{l}{foo} \\\\\n').strip(),
r'\end{tabular}',
@@ -646,6 +716,9 @@ def test_simple_grid_css_class(self):
r'</table>'))
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
r'\begin{tabular}{|l|l|}',
r'\hline',
@@ -694,21 +767,24 @@ def test_complex_grid_css_class(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{|p{0.5\linewidth}|p{0.25\linewidth}|' + \
- 'p{0.25\linewidth}|}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-6\tabcolsep}',
+ r'\begin{tabular}{|p{0.5\tablewidth}|p{0.25\tablewidth}|' + \
+ r'p{0.25\tablewidth}|}',
r'\hline',
- r'\multicolumn{3}{|p{1.0\linewidth}|}{\textbf{heading}} \\',
+ r'\multicolumn{3}{|p{1.0\tablewidth}|}{\textbf{heading}} \\',
r'\hline',
- r'\multicolumn{1}{|p{0.5\linewidth}|}{content 1A} & ' + \
- r'\multirow{2}{0.25\textwidth}{content 1/2 B} & ' + \
- r'\multicolumn{1}{|p{0.25\linewidth}|}{content 1C} \\',
+ r'\multicolumn{1}{|p{0.5\tablewidth}|}{content 1A} & ' + \
+ r'\multirow{2}{0.25\tablewidth}{content 1/2 B} & ' + \
+ r'\multicolumn{1}{|p{0.25\tablewidth}|}{content 1C} \\',
r'\hline',
- r'\multicolumn{1}{|p{0.5\linewidth}|}{content 2A} & ' + \
+ r'\multicolumn{1}{|p{0.5\tablewidth}|}{content 2A} & ' + \
r' & '
- r'\multicolumn{1}{|p{0.25\linewidth}|}{content 2C} \\',
+ r'\multicolumn{1}{|p{0.25\tablewidth}|}{content 2C} \\',
r'\hline',
r'\end{tabular}',
@@ -744,21 +820,24 @@ def test_listing_css_class(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.25\linewidth}' + \
- 'p{0.25\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-6\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.25\tablewidth}' + \
+ r'p{0.25\tablewidth}}',
r'\hline',
- r'\multicolumn{3}{p{1.0\linewidth}}{\textbf{heading}} \\',
+ r'\multicolumn{3}{p{1.0\tablewidth}}{\textbf{heading}} \\',
r'\hline',
- r'\multicolumn{1}{p{0.5\linewidth}}{content 1A} & ' + \
- r'\multirow{2}{0.25\textwidth}{content 1/2 B} & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{content 1C} \\',
+ r'\multicolumn{1}{p{0.5\tablewidth}}{content 1A} & ' + \
+ r'\multirow{2}{0.25\tablewidth}{content 1/2 B} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{content 1C} \\',
r'\hline',
- r'\multicolumn{1}{p{0.5\linewidth}}{content 2A} & ' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{content 2A} & ' + \
r' & '
- r'\multicolumn{1}{p{0.25\linewidth}}{content 2C} \\',
+ r'\multicolumn{1}{p{0.25\tablewidth}}{content 2C} \\',
r'\hline',
r'\end{tabular}',
@@ -794,20 +873,23 @@ def test_vertical_css_class_makes_first_column_bold(self):
r'</table>'))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.25\linewidth}' + \
- 'p{0.25\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-6\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.25\tablewidth}' + \
+ r'p{0.25\tablewidth}}',
- r'\multicolumn{3}{p{1.0\linewidth}}{\textbf{heading}} \\',
+ r'\multicolumn{3}{p{1.0\tablewidth}}{\textbf{heading}} \\',
- r'\multicolumn{1}{p{0.5\linewidth}}' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}' + \
r'{\textbf{content 1A}} & ' + \
- r'\multirow{2}{0.25\textwidth}{content 1/2 B} & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{content 1C} \\',
+ r'\multirow{2}{0.25\tablewidth}{content 1/2 B} & ' + \
+ r'\multicolumn{1}{p{0.25\tablewidth}}{content 1C} \\',
- r'\multicolumn{1}{p{0.5\linewidth}}' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}' + \
r'{\textbf{content 2A}} & ' + \
r' & ' + \
- r'\multicolumn{1}{p{0.25\linewidth}}{content 2C} \\',
+ r'\multicolumn{1}{p{0.25\tablewidth}}{content 2C} \\',
r'\end{tabular}',
r''
@@ -835,6 +917,9 @@ def test_border_classes(self):
latex = '\n'.join((
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-6\tabcolsep}',
r'\begin{tabular}{lll}',
r'\cline{2-2}',
@@ -877,6 +962,9 @@ def test_alignment_classes(self):
latex = '\n'.join((
r'without width: '
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{left} \\',
r'\multicolumn{1}{c}{center} \\',
@@ -884,11 +972,14 @@ def test_alignment_classes(self):
r'\end{tabular}',
r' with width: '
- r'\begin{tabular}{p{1.0\linewidth}}',
- r'\multicolumn{1}{p{1.0\linewidth}}{\raggedright left} \\',
- r'\multicolumn{1}{p{1.0\linewidth}}{' + \
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-2\tabcolsep}',
+ r'\begin{tabular}{p{1.0\tablewidth}}',
+ r'\multicolumn{1}{p{1.0\tablewidth}}{\raggedright left} \\',
+ r'\multicolumn{1}{p{1.0\tablewidth}}{' + \
r'\center\vspace{-1.5em}center} \\',
- r'\multicolumn{1}{p{1.0\linewidth}}{\raggedleft right} \\',
+ r'\multicolumn{1}{p{1.0\tablewidth}}{\raggedleft right} \\',
r'\end{tabular}',
r''
))
@@ -906,11 +997,14 @@ def test_indent2_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\hangindent 0.2cm\hspace{0.2cm} foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -930,11 +1024,14 @@ def test_indent10_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\hangindent 1cm\hspace{1cm} foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -954,11 +1051,14 @@ def test_bold_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\textbf{foo}} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\hangindent 1cm\hspace{1cm} \textbf{bar}} \\',
r'\end{tabular}',
@@ -978,11 +1078,14 @@ def test_grey_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\textcolor{gray}{foo}} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -1003,11 +1106,14 @@ def test_footnotesize_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\footnotesize foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -1027,11 +1133,14 @@ def test_scriptsize_class(self):
))
latex = '\n'.join((
- r'\begin{tabular}{p{0.5\linewidth}p{0.5\linewidth}}',
+ r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
+ r'\setlength\tablewidth\linewidth',
+ r'\addtolength\tablewidth{-4\tabcolsep}',
+ r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'\scriptsize foo} & ' + \
- r'\multicolumn{1}{p{0.5\linewidth}}{' + \
+ r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
r'bar} \\',
r'\end{tabular}',
@@ -1064,13 +1173,13 @@ def test_absolute_unit_width(self):
def test_relative_width(self):
width1 = table.LatexWidth.convert('10%')
- self.assertEqual(str(width1), r'0.1\linewidth')
+ self.assertEqual(str(width1), r'0.1\tablewidth')
width2 = table.LatexWidth.convert('25%')
- self.assertEqual(str(width2), r'0.25\linewidth')
+ self.assertEqual(str(width2), r'0.25\tablewidth')
self.assertEqual(str(width1 + width2),
- r'0.35\linewidth')
+ r'0.35\tablewidth')
def test_defaults_to_em(self):
width1 = table.LatexWidth.convert('50')

No commit comments for this range

Something went wrong with that request. Please try again.