mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
parent
8ad49613a8
commit
ccd2c83f2f
@ -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 \
|
||||
|
@ -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{-}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user