New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directive hlist not implemented in LaTeX #8072
Comments
I'm still not familiar with LaTeX. So all contributions are welcome :-) |
I could make a PR for this. Could you tell me how I can easily inject some header code into the LaTeX template? The |
Please modify |
Yeah, but when you write an extension, you don't want to hack the When writing extensions that need to add some LaTeX packages, you need to add the |
I found a better way of implementing the And with LaTex: Here a full extension that could be implemented in Sphinx-doc import re
from sphinx.writers.latex import LaTeXTranslator
from sphinx.writers.html5 import HTML5Translator
from sphinx import addnodes
from docutils import nodes
from sphinx.util.docutils import SphinxDirective
from docutils.parsers.rst import Directive, directives
latex_preamble = r"""
\newcounter{multicolminlines}
\setcounter{multicolminlines}{1}
\makeatletter
\xpatchcmd\balance@columns
{\ifnum\dimen@<\topskip
\mult@info\@ne
{Start value
\the\dimen@ \space ->
\the\topskip \space (corrected)}%
\dimen@\topskip
\fi}
{\skip@\c@multicolminlines\baselineskip
\advance\skip@-\baselineskip
\advance\skip@\topskip
\ifnum\dimen@<\skip@
\mult@info\@ne
{Start value
\the\dimen@ \space ->
\the\skip@ \space (corrected)}%
\dimen@\skip@
\fi
}
{\typeout{Success!}}{\patchFAILED}
\define@key{hlist@keys}{columns}{\def\hlist@columns{#1}}%
\define@key{hlist@keys}{minlines}{\def\hlist@minlines{#1}}%
\newcommand{\fixspacing}{\vspace{0pt plus 1filll}\mbox{}}
\newenvironment{hlist}[1][]{%
\setkeys{hlist@keys}{columns=4,minlines=4,#1}
\setcounter{multicolminlines}{\hlist@minlines}
\begin{multicols}{\hlist@columns}
}{
\fixspacing
\end{multicols}
}
\makeatother
"""
def visit_latex_hlist(self, node):
options = [
f'columns={node["columns"]}' if node['columns'] else '',
f'min-lines={mnode["min-lines"]}' if node['min-lines'] else ''
]
self.body.append('\\begin{hlist}%s\n' % ','.join(options))
if self.table:
self.table.has_problematic = True
def depart_latex_hlist(self, node):
self.body.append('\\end{hlist}\n')
def visit_html_hlist(self, node):
cols = node['columns']
self.body.append((
f'<div style="-webkit-column-count: {cols};'
f'-moz-column-count: {cols}; column-count: {cols};">'
))
def depart_html_hlist(self, node):
self.body.append('</div>\n')
class HList(SphinxDirective):
"""
Directive for a list that gets compacted horizontally.
"""
has_content = True
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {
'columns': int,
'max-height': int,
}
def run(self):
hlist = addnodes.hlist()
hlist['columns'] = self.options.get('columns', None)
hlist['min-lines'] = self.options.get('min-lines', None)
hlist.document = self.state.document
self.state.nested_parse(self.content, self.content_offset, hlist)
if len(hlist.children) != 1 or not isinstance(hlist.children[0],
(nodes.bullet_list, nodes.enumerated_list)):
reporter = self.state.document.reporter
return [reporter.warning('.. hlist content is not a list', line=self.lineno)]
return [hlist]
def add_latex_environment(app):
if hasattr(app.builder, 'context'):
context = app.builder.context
context['preamble'] += latex_preamble
def setup(app):
LaTeXTranslator.visit_hlist = visit_latex_hlist
LaTeXTranslator.depart_hlist = depart_latex_hlist
HTML5Translator.visit_hlist = visit_html_hlist
HTML5Translator.depart_hlist = depart_html_hlist
app.connect('builder-inited', add_latex_environment)
app.add_directive('hlist', HList, override=True)
app.add_latex_package('multicol', 'balancingshow')
app.add_latex_package('regexpatch')
app.add_latex_package('keyval')
return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
} |
Please use
docutils determined to co-exist with the paragraph nodes after HTML5 writer. So please don't remove them. We should add CSS to control them. |
I do use |
Ok for the |
How about adding your own .sty file (for example, hlist.sty)? Then you can use it via |
@tk0miya I modified my previous answer with a kind-of working extension. I am sure I need more testing, but do you want me to propose a PR for this feature? On which branch? |
I think adding implementation is better than nothing even if young. So +1 for merging it to the core. And 3.x branch is good to me. But I understand you'd like to test it as an extension. In any case, the next stable release will be at October. We're not in a hurry. |
The patch to multicol is not motivated, not documented, not sourced, and not maintainable. Certainly we can never merge this to Sphinx core. I get undecipherable error message with uptodate TeXLive 2020, from inserting it into a latex document preamble:
using We will never patch
Here is with
and
then we get this output |
Better with
in the test, sorry. This is needed else multicols will spread out the last column, in my test we had coincidentally a number of items equal to a multiple of number of columns 5. Notice that multicols will always proceed from top to bottom, filling first column, then second column, etc... If we want to first fill first line, then second line, etc..., multicols is not good package for that. @tk0miya I can start from work on this but I need to know if the output must have the items organized horizontally or vertically. For the former, maybe there is a LaTeX package or we can create the needed macros, for the latter we can basically use multicols as above. I also need to know if the number of columns will be a mandatory argument with possibly a default value (say 3) if absent, or if the code should try to determine it automatically. |
The tasks package might be useful to us here. However it has limitation for us that it can not contain code-blocks. Also, it is relatively recent package and we have to check if all features we will use are available at TL2015 for example. Anyway this looks like good possibility if, as I expect, hlist output should look like
|
Well, the hlist example renders in HTML like this
(with last column flushed up in Then we only need @tk0miya do you have an opinion? |
On further thoughts the As we control all the output mark-up, there is no difficulty of realizing horizontal lists with minipages. Here is output from Basically we obtain a table-like output but without all the vagaries of LaTeX table. I think this is the way to go. Pros:
Cons:
|
LaTeX2e also has a not widely known |
Fix #8072: Directive hlist not implemented in LaTeX
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:Improvement?
I think it could be implemented using a
multicol
environment with this preamble: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.The text was updated successfully, but these errors were encountered: