Skip to content

Commit

Permalink
Merge pull request sphinx-doc#8779 from jfbu/latex_hlist_support
Browse files Browse the repository at this point in the history
Fix sphinx-doc#8072: Directive hlist not implemented in LaTeX
  • Loading branch information
jfbu committed Jan 29, 2021
2 parents 879bf54 + 9abe2ed commit be20f17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Expand Up @@ -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
--------------------

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sphinx/directives/other.py
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions sphinx/texinputs/sphinx.sty
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions sphinx/writers/latex.py
Expand Up @@ -1177,22 +1177,29 @@ 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:
self.table.has_problematic = True

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:
Expand Down

0 comments on commit be20f17

Please sign in to comment.