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
[LaTeX] Text can fall out of code-block at end of page and leave artifact on next page #8686
Comments
Thanks for reporting. Unfortunately I think this falls under the caveat from the following code comments in sphinx.sty: sphinx/sphinx/texinputs/sphinx.sty Lines 1243 to 1244 in d635d94
I guess fix for that issue can only come from a complete replacement of Sphinx usage of fancyvrb by something else... |
However perhaps I should try to dig into how to avoid the empty small height framing at top of next page. Here another old LaTeX package is at play: |
@jessetan I looked again at that issue. i checked again \documentclass[a4paper]{article}
% compile with shell-escape flag
\usepackage{geometry}
\usepackage{minted}
\begin{document}
\vspace*{17.3cm}% all on page 1
\vspace*{1mm}% all goes to page 2 if uncommented here
\begin{minted}[breaklines]{python}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus aliquet sagittis sagittis. Phasellus elementum, felis sed fringilla maximus, nibh magna vestibulum erat, ac tincidunt turpis felis vel massa. Quisque vel lacus odio. Aenean velit felis, tincidunt vitae ante id, porttitor consequat magna. Nullam in venenatis nibh, in hendrerit risus. Etiam libero justo, tempor nec quam ut, ultrices pretium erat. Mauris at ullamcorper velit.
\end{minted}
\end{document} Thinking about this, one may think that this could be moved upstream to Pygments as a feature request. Because if the line-breaking is created there, this will fix it. But on second thoughts, no this can't work. Because Pygments will have no idea what the target line-width is supposed to be. So we would have, if the feature is implemented at Pygments, to pass it that information. But this is in itself is not obvious because it will depend on how deeply nested the code-block directive was located. This seems to add great difficulties on Sphinx side as well. I am afraid only way out is either
As per the problem of an empty box on top of continuation page, this is but a small aesthetic problem compared to the tragic overflow occuring at bottom of page it a very long line in source got wrapped to multi-line in output. Besides it is probably time Sphinx drops usage of This is borderline to wont-fix :-(. I am afraid if I engage into hacking too much into fancyvrb that this will create various unexpected problems. The more reasonable would be if I rather invest time into the |
hmm. Actually looks like transitioning to tcolorbox would cost at least as much effort/time as hacking fancyvrb. Alas... |
I have been thinking about this issue. Currently Sphinx renders literal blocks using
This is legacy situation, and the additional code is for, among others:
I see currently two main issues with this:
The present issue is intrinsic to package The best solution, I believe is to drop entirely usage of And it will be possible I imagine on this occasion to add an inner hook wrapper for people who will want to do the framing via Thus this is my intention, perhaps in time for 4.0 release. |
@jfbu code:
link to rst file: examples_cli.rst |
@sebastien-riou Thanks for example. This is another issue, unrelated. I thought we had a ticket already for this, but I can't find it. Can you please open a ticket? I will comment over there. |
I have made up my mind on this issue, and the fix is that we drop fancyvrb usage in future. This will also be occasion to unify more code-blocks and parsed-literals. However I have to write up the needed latex package. |
…en wrapping This maintains existing behavior.
I have finally solved this issue with limited extra code, but I needed to take deep breath and plunge into fancyvrb.sty internals to understand them fully. At long last I am relieved of this... The difficulty in all of this is also to no break possible customized usage of fancyvrb by Sphinx users. In truth, rendering of Pygmentized code-blocks does not need "Verbatim" like approach, because Pygmentize has already escaped all special characters, and mainly all we need to do is to ensure suitable font is used and spaces are obeyed, but it is legacy situation that Pygmentize library is configured to produce its ouput in a "Verbatim" environment (allowing LaTeX macros...), by default using fancyvrb, and at this stage the effort of removing all this and start afresh would be too great if we were to also try to support options people may have used via the |
When wrapping long code lines, recover the TeX "hbox"es and trick fancyvrb into considering each as an input code line. This way, pagebreaks are allowed. No change to existing output (in particular, codeline number is printed only once) when the wrapped line had place on current page.
This does not fix entirely sphinx-doc#10610 but it does sufficiently for it not to require reverting sphinx-doc#10577 which tried to solve sphinx-doc#8686 conundrum. In extreme cases, the sphinx-doc#8686 problem meant that some contents disappearing at page bottom, so it is probably better that to maintain sphinx-doc#10577 which will avoid anysuch overflow of code beyond its frame, even though in some specific cases (a colored entity such as a long string is partly on both pages), some syntax highlighting gets lost. There are anyhow other issues with colors for wrapped code lines, even with no pagebreaks involved, such as sphinx-doc#10615. This patch does not change the situation there.
This does not fix entirely sphinx-doc#10610 but it does sufficiently for it not to require reverting sphinx-doc#10577 which tried to solve sphinx-doc#8686 conundrum. In extreme cases, the sphinx-doc#8686 problem meant that some contents disappeared at page bottom, so it is probably better to maintain sphinx-doc#10577 which will avoid any such overflow of code beyond its frame, even though in some specific cases (a colored entity such as a long string is partly on both pages), some syntax highlighting gets lost. There are anyhow other issues with colors for wrapped code lines, even with no pagebreaks involved, such as sphinx-doc#10615. This patch does not change the situation there.
Describe the bug
When a code block is at the end of a page and the contents makes the block larger than can fit on the page, it is broken into two sections. In particular when the last line was wrapped, the content spills out of the code block. The code block on the next page remains empty.
To Reproduce
make latexpdf
Expected behavior
The code block is split across two pages, and the contents of the code block directive is spread between the two pages.
Actual behavior
Environment info
The text was updated successfully, but these errors were encountered: