From a68a05533dfc1a40622b44ddfc6fab31cb4cb7fb Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 28 Jan 2021 21:03:17 +0100 Subject: [PATCH 1/2] Fix #8072: Directive hlist not implemented in LaTeX Adds ``multicol`` LaTeX package requirement, but it is a required part of any latex distribution. --- CHANGES | 4 ++++ doc/usage/restructuredtext/directives.rst | 2 ++ sphinx/directives/other.py | 1 + sphinx/texinputs/sphinx.sty | 2 ++ sphinx/writers/latex.py | 13 ++++++++++--- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 9a5c3ef5101..b4237ac54cb 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,9 @@ Release 3.5.0 (in development) Dependencies ------------ +* LaTeX: ``multicol`` (it is anyhow a required part of the official latex2e + base distribution) + Incompatible changes -------------------- @@ -103,6 +106,7 @@ Bugs fixed specified * #7576: LaTeX with French babel and memoir crash: "Illegal parameter number in definition of ``\FNH@prefntext``" +* #8072: LaTeX: Directive :rst:dir:`hlist` not implemented in LaTeX * #8214: LaTeX: The :rst:role:`index` role and the glossary generate duplicate entries in the LaTeX index (if both used for same term) * #8735: LaTeX: wrong internal links in pdf to captioned code-blocks when diff --git a/doc/usage/restructuredtext/directives.rst b/doc/usage/restructuredtext/directives.rst index e8b88c21b25..57b2c0c3aef 100644 --- a/doc/usage/restructuredtext/directives.rst +++ b/doc/usage/restructuredtext/directives.rst @@ -394,6 +394,8 @@ units as well as normal text. .. versionadded:: 0.6 + .. versionchanged:: 3.5.0 + support by the latex builder. .. _code-examples: diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 9325cbe4f97..2ace3738f78 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -276,6 +276,7 @@ def run(self) -> List[Node]: npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 newnode = addnodes.hlist() + newnode['ncolumns'] = str(ncolumns) for column in range(ncolumns): endindex = index + ((npercol + 1) if column < nmore else npercol) bullet_list = nodes.bullet_list() diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index f406b1089f9..cd4671e7ce8 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -239,6 +239,8 @@ \ltx@ifundefined{@removefromreset} {\RequirePackage{remreset}} {}% avoid warning +% To support hlist directive +\RequirePackage{multicol} % to make pdf with correct encoded bookmarks in Japanese % this should precede the hyperref package \ifx\kanjiskip\@undefined diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 918dda7746b..3d62f455ec6 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1175,9 +1175,11 @@ def depart_centered(self, node: Element) -> None: self.body.append('\n\\end{center}') def visit_hlist(self, node: Element) -> None: - # for now, we don't support a more compact list format - # don't add individual itemize environments, but one for all columns self.compact_list += 1 + ncolumns = node['ncolumns'] + if self.compact_list > 1: + self.body.append('\\setlength{\\multicolsep}{0pt}\n') + self.body.append('\\begin{multicols}{' + ncolumns + '}\\raggedright\n') self.body.append('\\begin{itemize}\\setlength{\\itemsep}{0pt}' '\\setlength{\\parskip}{0pt}\n') if self.table: @@ -1185,12 +1187,17 @@ def visit_hlist(self, node: Element) -> None: def depart_hlist(self, node: Element) -> None: self.compact_list -= 1 - self.body.append('\\end{itemize}\n') + self.body.append('\\end{itemize}\\raggedcolumns\\end{multicols}\n') def visit_hlistcol(self, node: Element) -> None: pass def depart_hlistcol(self, node: Element) -> None: + # \columnbreak would guarantee same columns as in html ouput. But + # some testing with long items showed that columns may be too uneven. + # And in case only of short items, the automatic column breaks should + # match the ones pre-computed by the hlist() directive. + # self.body.append('\\columnbreak\n') pass def latex_image_length(self, width_str: str, scale: int = 100) -> str: From 9abe2edf93007fcc2646680424f0ed90eeb8a44d Mon Sep 17 00:00:00 2001 From: jfbu Date: Fri, 29 Jan 2021 20:20:25 +0100 Subject: [PATCH 2/2] Remove unneeded versionchanged data in docs of hlist directive --- doc/usage/restructuredtext/directives.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/usage/restructuredtext/directives.rst b/doc/usage/restructuredtext/directives.rst index 57b2c0c3aef..e8b88c21b25 100644 --- a/doc/usage/restructuredtext/directives.rst +++ b/doc/usage/restructuredtext/directives.rst @@ -394,8 +394,6 @@ units as well as normal text. .. versionadded:: 0.6 - .. versionchanged:: 3.5.0 - support by the latex builder. .. _code-examples: