Skip to content

Commit

Permalink
Simplify LaTeX mark-up for table column widths (ref sphinx-doc#3379)
Browse files Browse the repository at this point in the history
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 extra packages or macro definitions. 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.
  • Loading branch information
jfbu committed Feb 1, 2017
1 parent ecdcb4c commit c318fa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 4 additions & 1 deletion sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}
Expand Down
6 changes: 2 additions & 4 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,14 +1206,12 @@ def depart_table(self, node):
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:
Expand Down

0 comments on commit c318fa9

Please sign in to comment.