From e97d4e955b78dea0e5df1742dc09a90abf687158 Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 1 Feb 2017 19:50:53 +0100 Subject: [PATCH] Simplify LaTeX mark-up for table column widths (ref #3379) The ``\X`` token is used as column-specifier: this does not define or redefine ``\X`` as a LaTeX macro. Using a letter could have led to conflict with user defined column types or table packages. This column specifier takes two arguments which must be positive integers, as produced by LaTeX writer for ``:widths:`` option or for equal widths columns. As it always uses ``\linewidth`` the latter was not abstracted into a third argument. --- sphinx/texinputs/sphinx.sty | 5 ++++- sphinx/writers/latex.py | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 3eea2ffe7..3929f1e9b 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -6,7 +6,7 @@ % \NeedsTeXFormat{LaTeX2e}[1995/12/01] -\ProvidesPackage{sphinx}[2017/01/16 v1.6 LaTeX package (Sphinx markup)] +\ProvidesPackage{sphinx}[2017/02/01 v1.6 LaTeX package (Sphinx markup)] % we delay handling of options to after having loaded packages, because % of the need to use \definecolor. @@ -24,6 +24,9 @@ ******** ERROR !! PLEASE UPDATE titlesec.sty !!********^^J% ******** THIS VERSION SWALLOWS SECTION NUMBERS.********}}}}{} \RequirePackage{tabulary} +% use of \X to minimize possibility of conflict with one-character column types +\newcolumntype{\X}[2]{p{\dimexpr + (\linewidth-\arrayrulewidth)*#1/#2-\tw@\tabcolsep-\arrayrulewidth\relax}} \RequirePackage{makeidx} % For framing code-blocks and warning type notices, and shadowing topics \RequirePackage{framed} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 519e655ce..e806dad54 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1206,14 +1206,12 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append(self.table.colspec) elif self.table.colwidths: total = sum(self.table.colwidths) - colspec = ['p{\\dimexpr(\\linewidth-\\arrayrulewidth)*%d/%d' - '-2\\tabcolsep-\\arrayrulewidth\\relax}' % (width, total) + colspec = ['\\X{%d}{%d}' % (width, total) for width in self.table.colwidths] self.body.append('{|%s|}\n' % '|'.join(colspec)) else: if self.table.has_problematic: - colspec = ('*{%d}{p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d' - '-2\\tabcolsep-\\arrayrulewidth\\relax}|}' % + colspec = ('*{%d}{\\X{1}{%d}|}' % (self.table.colcount, self.table.colcount)) self.body.append('{|' + colspec + '}\n') elif self.table.longtable: