-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Milestone
Description
Describe the bug
According to the documentation hlist must contain a bullet list. It will transform it into a more compact list by either distributing more than one item horizontally, or reducing spacing between items, depending on the builder.
It works so-so in html, but it is not implemented in LaTeX:
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 columnsImprovement?
I think it could be implemented using a multicol environment with this preamble:
\usepackage{multicol}
\newcommand{\fixspacing}{\vspace{0pt plus 1filll}\mbox{}}I wrote a small example. However I did not find how to inject some headers in the LaTeX document. Modifying app.builder.env.config doesn't seem to work.
import re
from sphinx.writers.latex import LaTeXTranslator
def visit_hlist(self, node):
self.compact_list += 1
columns = len(node.children)
self.body.append('\\begin{multicols*}{%d}' % columns)
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):
self.compact_list -= 1
self.body.append('\\end{itemize}\n')
self.body.append('\\fixspacing\n\\end{multicols*}\n')
def inject_packages(app):
"""TODO: Not Working..."""
config = app.builder.env.config
to_add = '%% For hlist directive\n'
if not re.findall(r'\\usepackage(\[.*?\])?\{multicol\}',
config.latex_elements['preamble']):
to_add += '\n\\usepackage{multicol}\n'
to_add += r'\newcommand{\fixspacing}{\vspace{0pt plus 1filll}\mbox{}}'
to_add += '\n'
config.latex_elements['preamble'] += to_add
def setup(app):
LaTeXTranslator.visit_hlist = visit_hlist
LaTeXTranslator.depart_hlist = depart_hlist
app.connect('builder-inited', inject_packages)
return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
}