diff --git a/CHANGES b/CHANGES index afdd8d436..68b6b1b19 100644 --- a/CHANGES +++ b/CHANGES @@ -52,6 +52,8 @@ Bugs fixed * #6712: Allow not to install sphinx.testing as runtime (mainly for ALT Linux) * #6741: html: search result was broken with empty :confval:`html_file_suffix` * #6001: LaTeX does not wrap long code lines at backslash character +* #6804: LaTeX: PDF build breaks if admonition of danger type contains + code-block long enough not to fit on one page Testing -------- diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 6023e6d22..2ae4f5e1c 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -1111,6 +1111,9 @@ \newcommand*\sphinxVerbatimTitle {} % This box to typeset the caption before framed.sty multiple passes for framing. \newbox\sphinxVerbatim@TitleBox +% This box to measure contents if nested as inner \MakeFramed requires then +% minipage encapsulation but too long contents then break outer \MakeFramed +\newbox\sphinxVerbatim@ContentsBox % This is a workaround to a "feature" of French lists, when literal block % follows immediately; usable generally (does only \par then), a priori... \newcommand*\sphinxvspacefixafterfrenchlists{% @@ -1257,17 +1260,23 @@ \itemsep \z@skip \topsep \z@skip \partopsep \z@skip - % trivlist will set \parsep to \parskip = zero + % trivlist will set \parsep to \parskip (which itself is set to zero above) % \leftmargin will be set to zero by trivlist \rightmargin\z@ \parindent \z@% becomes \itemindent. Default zero, but perhaps overwritten. \trivlist\item\relax - \ifsphinxverbatimwithminipage\spx@inframedtrue\fi - % use a minipage if we are already inside a framed environment - \ifspx@inframed\noindent\begin{minipage}{\linewidth}\fi - \MakeFramed {% adapted over from framed.sty's snugshade environment + \ifspx@inframed\setbox\sphinxVerbatim@ContentsBox\vbox\bgroup + \@setminipage\hsize\linewidth + % use bulk of minipage paragraph shape restores (this is needed + % in indented contexts, at least for some) + \textwidth\hsize \columnwidth\hsize \@totalleftmargin\z@ + \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip + \else + \ifsphinxverbatimwithminipage\noindent\begin{minipage}{\linewidth}\fi + \MakeFramed {% adapted over from framed.sty's snugshade environment \advance\hsize-\width\@totalleftmargin\z@\linewidth\hsize\@setminipage }% + \fi % For grid placement from \strut's in \FancyVerbFormatLine \lineskip\z@skip % active comma should not be overwritten by \@noligs @@ -1279,8 +1288,35 @@ } {% \endOriginalVerbatim - \par\unskip\@minipagefalse\endMakeFramed % from framed.sty snugshade - \ifspx@inframed\end{minipage}\fi + \ifspx@inframed + \egroup % finish \sphinxVerbatim@ContentsBox vbox + \ifdim\dimexpr\ht\sphinxVerbatim@ContentsBox+ + \dp\sphinxVerbatim@ContentsBox+ + \ht\sphinxVerbatim@TitleBox+ + \dp\sphinxVerbatim@TitleBox>.9\textheight + % long contents: do not \MakeFramed. Do make a caption (either before or + % after) if title exists. Continuation hints across pagebreaks dropped. + \spx@opt@verbatimwithframefalse + \def\sphinxVerbatim@Title{\noindent\box\sphinxVerbatim@TitleBox\par}% + \sphinxVerbatim@Before + \noindent\unvbox\sphinxVerbatim@ContentsBox\par + \sphinxVerbatim@After + \else + % short enough contents: use \MakeFramed. As it is nested, this requires + % minipage encapsulation. May move to next page as it is non-breakable. + \noindent\begin{minipage}{\linewidth}% + \MakeFramed {% Use it now with the fetched contents + \advance\hsize-\width\@totalleftmargin\z@\linewidth\hsize\@setminipage + }% + \unvbox\sphinxVerbatim@ContentsBox + % some of this may be superfluous: + \par\unskip\@minipagefalse\endMakeFramed + \end{minipage}% + \fi + \else % non-nested \MakeFramed + \par\unskip\@minipagefalse\endMakeFramed % from framed.sty snugshade + \ifsphinxverbatimwithminipage\end{minipage}\fi + \fi \endtrivlist } \newenvironment {sphinxVerbatimNoFrame}