Add \sphinxhyphenin{inline,parsed}literal for customizability

Whether or not to allow linebreaks is matter of debate because user of
pdf can not reflow the displayed text, and overfull lines may lead to
loss of data beyond page border.

Since Sphinx 1.5, inline literals allow linebreaks after the characters
".", ",", ";", "?", "!", "/" and "\" (cf the inlineliteralwraps key of
latex_elements['sphinxsetup']).

With pdflatex the dash "-" does not allow a linebreak when used with a
monospace font (btw the dash is escaped to \sphinxhyphen{} which expands
back to a dash).  But this failed with xelatex, so previous commits
ensured nobreak behaviour by redefining \sphinxhyphen to be
\sphinxhyphennobreak when encountered in inline and parsed literals.

This commit adds \sphinxhyphenin{inline,parsed}literal macros which
default to \sphinxhyphennobreak and thus allow to customize how the
dashes from sources will behave in such contexts in pdf output.
This commit is contained in:
jfbu 2021-12-07 08:49:06 +01:00
parent 8ad49613a8
commit ccd2c83f2f
2 changed files with 11 additions and 7 deletions

View File

@ -704,6 +704,10 @@
% the \catcode13=5\relax (deactivate end of input lines) is left to callers
\newcommand*{\sphinxunactivateextrasandspace}{\catcode32=10\relax
\sphinxunactivateextras}%
% alltt uses a monospace font and linebreaks at dashes (which are escaped
% to \sphinxhyphen{} which expands to -\kern\z@) are inhibited with pdflatex.
% Not with xelatex (cf \defaultfontfeatures in latex writer), so:
\newcommand*{\sphinxhypheninparsedliteral}{\sphinxhyphennobreak}
% now for the modified alltt environment
\newenvironment{sphinxalltt}
{% at start of next line to workaround Emacs/AUCTeX issue with this file
@ -711,9 +715,7 @@
\ifspx@opt@parsedliteralwraps
\sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}%
\sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}%
% this uses a monospace font and linebreaks at dashes will be inhibited with
% pdflatex; not so with xelatex (cf \defaultfontfeatures in latex writer) so:
\def\sphinxhyphen{\mbox{-}}%
\let\sphinxhyphen\sphinxhypheninparsedliteral
\sphinxbreaksattexescapedchars
\sphinxbreaksviaactiveinparsedliteral
\sphinxbreaksatspaceinparsedliteral
@ -760,15 +762,15 @@
\protected\def\sphinxtextbackslashbreakafter
{\discretionary{\sphinx@textbackslash}{\sphinxafterbreak}{\sphinx@textbackslash}}
\let\sphinxtextbackslash\sphinxtextbackslashbreakafter
% - is escaped to \sphinxhyphen{} and this default ensures no linebreak
% behaviour (also with a non monospace font, or with xelatex)
\newcommand*{\sphinxhyphenininlineliteral}{\sphinxhyphennobreak}
% the macro must be protected if it ends up used in moving arguments,
% in 'alltt' \@noligs is done already, and the \scantokens must be avoided.
\protected\def\sphinxupquote#1{{\def\@tempa{alltt}%
\ifx\@tempa\@currenvir\else
\let\sphinxhyphen\sphinxhyphenininlineliteral
\ifspx@opt@inlineliteralwraps
% a priori, this is typeset using a monospace font (cf \sphinxcode in
% sphinxlatexstyletext.sty) so linebreaks at dashes are inhibited;
% but, for xelatex or in case of non-monospace font, let's do this:
\def\sphinxhyphen{\mbox{-}}%
% break at . , ; ? ! /
\sphinxbreaksviaactive
% break also at \

View File

@ -83,7 +83,9 @@
% Inside code-blocks, dashes are escaped via another macro, from
% Pygments latex output (search for \PYGZhy in sphinxlatexliterals.sty),
% and are configured to allow linebreaks despite the monospace font.
% (the #1 swallows the {} from \sphinxhyphen{} mark-up)
\protected\def\sphinxhyphen#1{-\kern\z@}
\protected\def\sphinxhyphennobreak#1{\mbox{-}}
% The {} from texescape mark-up is kept, else -- gives en-dash in PDF bookmark
\def\sphinxhyphenforbookmarks{-}