Merge pull request #8779 from jfbu/latex_hlist_support

Fix #8072: Directive hlist not implemented in LaTeX
This commit is contained in:
Jean-François B 2021-01-29 21:05:19 +01:00 committed by GitHub
commit be20f17892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -276,6 +276,7 @@ class HList(SphinxDirective):
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()

View File

@ -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

View File

@ -1177,9 +1177,11 @@ class LaTeXTranslator(SphinxTranslator):
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:
@ -1187,12 +1189,17 @@ class LaTeXTranslator(SphinxTranslator):
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: