mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #3308: Parsed-literals don't wrap very long lines with pdf builder
This commit is contained in:
parent
c844404741
commit
8c21abeccc
@ -143,14 +143,21 @@ Here are the currently available options together with their default values.
|
||||
LaTeX requires ``true`` or ``false`` to be specified in *lowercase*.
|
||||
|
||||
``verbatimwrapslines``
|
||||
default ``true``. Tells whether long lines in :rst:dir:`code-block`\ s
|
||||
should be wrapped.
|
||||
default ``true``. Tells whether long lines in :rst:dir:`code-block`\ 's
|
||||
contents should wrap.
|
||||
|
||||
.. (comment) It is theoretically possible to customize this even
|
||||
more and decide at which characters a line-break can occur and whether
|
||||
before or after, but this is accessible currently only by re-defining some
|
||||
macros with complicated LaTeX syntax from :file:`sphinx.sty`.
|
||||
|
||||
``parsedliteralwraps``
|
||||
default ``true``. Tells whether long lines in :dudir:`parsed-literal`\ 's
|
||||
contents should wrap.
|
||||
|
||||
.. versionadded:: 1.5.2
|
||||
set this option value to ``false`` to recover former behaviour.
|
||||
|
||||
``inlineliteralwraps``
|
||||
default ``true``. Allows linebreaks inside inline literals: but extra
|
||||
potential break-points (additionally to those allowed by LaTeX at spaces
|
||||
@ -160,7 +167,7 @@ Here are the currently available options together with their default values.
|
||||
(or shrinked) in order to accomodate the linebreak.
|
||||
|
||||
.. versionadded:: 1.5
|
||||
set this option to ``false`` to recover former behaviour.
|
||||
set this option value to ``false`` to recover former behaviour.
|
||||
|
||||
``verbatimvisiblespace``
|
||||
default ``\textcolor{red}{\textvisiblespace}``. When a long code line is
|
||||
|
@ -6,7 +6,7 @@
|
||||
%
|
||||
|
||||
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
|
||||
\ProvidesPackage{sphinx}[2017/01/09 v1.5.2 LaTeX package (Sphinx markup)]
|
||||
\ProvidesPackage{sphinx}[2017/01/14 v1.5.2 LaTeX package (Sphinx markup)]
|
||||
|
||||
% we delay handling of options to after having loaded packages, because
|
||||
% of the need to use \definecolor.
|
||||
@ -91,6 +91,8 @@
|
||||
\DeclareBoolOption[true]{verbatimwithframe}
|
||||
\DeclareBoolOption[true]{verbatimwrapslines}
|
||||
\DeclareBoolOption[true]{inlineliteralwraps}
|
||||
% parsed literal
|
||||
\DeclareBoolOption[true]{parsedliteralwraps}
|
||||
% \textvisiblespace for compatibility with fontspec+XeTeX/LuaTeX
|
||||
\DeclareStringOption[\textcolor{red}{\textvisiblespace}]{verbatimvisiblespace}
|
||||
\DeclareStringOption % must use braces to hide the brackets
|
||||
@ -535,6 +537,66 @@
|
||||
\begin{sphinxVerbatim}}
|
||||
{\end{sphinxVerbatim}}
|
||||
|
||||
% Parsed literal: allow long lines to wrap like they do in code-blocks
|
||||
|
||||
% this should be kept in sync with definitions in sphinx.util.texescape
|
||||
\newcommand*\sphinxbreaksattexescapedchars{%
|
||||
\def\do##1##2% put potential break point before character
|
||||
{\def##1{\discretionary{}{\sphinxafterbreak\char`##2}{\char`##2}}}%
|
||||
\do\{\{\do\textless\<\do\#\#\do\%\%\do\$\$% {, <, #, %, $
|
||||
\def\do##1##2% put potential break point after character
|
||||
{\def##1{\discretionary{\char`##2}{\sphinxafterbreak}{\char`##2}}}%
|
||||
\do\_\_\do\}\}\do\textasciicircum\^\do\&\&% _, }, ^, &,
|
||||
\do\textgreater\>\do\textasciitilde\~% >, ~
|
||||
}
|
||||
\newcommand*\sphinxbreaksviaactiveinparsedliteral{%
|
||||
\sphinxbreaksviaactive % by default handles . , ; ? ! /
|
||||
\do\-% we need also the hyphen character
|
||||
\lccode`\~`\~ %
|
||||
% update \dospecials as it is used by \url
|
||||
% but deactivation will already have been done hence commented out
|
||||
% \expandafter\def\expandafter\dospecials\expandafter{\dospecials
|
||||
% \sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-}%
|
||||
}
|
||||
\newcommand*\sphinxbreaksatspaceinparsedliteral{%
|
||||
\lccode`~32 \lowercase{\def~}{\leavevmode
|
||||
\nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font
|
||||
\discretionary{\copy\sphinxvisiblespacebox}{\sphinxafterbreak}
|
||||
{\kern\fontdimen2\font}%
|
||||
}\lccode`\~`\~
|
||||
}
|
||||
% now the hack for \url to work (hyperref is required dependency):
|
||||
% the aim it to deactivate - . , ; ? ! / in \url's argument
|
||||
\def\spx@hack@hyper@normalise {%
|
||||
\expandafter\spx@hack@hyper@normalise@aux\hyper@normalise
|
||||
\spx@hack@hyper@normalise@aux\hyper@n@rmalise\relax\spx@undefined
|
||||
}%
|
||||
\long\def\spx@hack@hyper@normalise@aux#1\hyper@n@rmalise#2#3\spx@undefined{%
|
||||
\ifx\spx@hack@hyper@normalise@aux#2%
|
||||
\def\hyper@normalise
|
||||
{#1\let\do\@makeother
|
||||
\sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-%
|
||||
\hyper@n@rmalise}%
|
||||
\else
|
||||
\PackageWarning{sphinx}{Could not patch \string\url\space command.%
|
||||
^^J Not using active characters in alltt environment}%
|
||||
\let\do\@makeother
|
||||
\sphinxbreaksbeforeactivelist\sphinxbreaksafteractivelist\do\-%
|
||||
\fi
|
||||
}%
|
||||
% now for the modified alltt environment
|
||||
\newenvironment{sphinxalltt}
|
||||
{\begin{alltt}%
|
||||
\ifspx@opt@parsedliteralwraps
|
||||
\sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}%
|
||||
\sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}%
|
||||
\sphinxbreaksattexescapedchars
|
||||
\sphinxbreaksviaactiveinparsedliteral
|
||||
\sphinxbreaksatspaceinparsedliteral
|
||||
\spx@hack@hyper@normalise
|
||||
\fi }
|
||||
{\end{alltt}}% \end{alltt} (<-- only to fix Emacs/AUCTeX fontification issue)
|
||||
|
||||
% Topic boxes
|
||||
|
||||
% Again based on use of "framed.sty", this allows breakable framed boxes.
|
||||
|
@ -1929,7 +1929,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if node.rawsource != node.astext():
|
||||
# most probably a parsed-literal block -- don't highlight
|
||||
self.in_parsed_literal += 1
|
||||
self.body.append('\\begin{alltt}\n')
|
||||
self.body.append('\\begin{sphinxalltt}\n')
|
||||
else:
|
||||
ids = ''
|
||||
for id in self.pop_hyperlink_ids('code-block'):
|
||||
@ -1989,7 +1989,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
raise nodes.SkipNode
|
||||
|
||||
def depart_literal_block(self, node):
|
||||
self.body.append('\n\\end{alltt}\n')
|
||||
self.body.append('\n\\end{sphinxalltt}\n')
|
||||
self.in_parsed_literal -= 1
|
||||
visit_doctest_block = visit_literal_block
|
||||
depart_doctest_block = depart_literal_block
|
||||
|
Loading…
Reference in New Issue
Block a user