diff --git a/CHANGES b/CHANGES index 29fd5b8128b..b7895fe6f1a 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,8 @@ Bugs fixed * #9878: mathjax: MathJax configuration is placed after loading MathJax itself * #9857: Generated RFC links use outdated base url * #9909: HTML, prevent line-wrapping in literal text. +* #9925: LaTeX: prohibit also with ``'xelatex'`` line splitting at dashes of + inline and parsed literals Testing -------- diff --git a/sphinx/texinputs/sphinxlatexliterals.sty b/sphinx/texinputs/sphinxlatexliterals.sty index d2ba89ea73f..cc768c25ba1 100644 --- a/sphinx/texinputs/sphinxlatexliterals.sty +++ b/sphinx/texinputs/sphinxlatexliterals.sty @@ -1,7 +1,7 @@ %% LITERAL BLOCKS % % change this info string if making any custom modification -\ProvidesFile{sphinxlatexliterals.sty}[2021/01/27 code-blocks and parsed literals] +\ProvidesFile{sphinxlatexliterals.sty}[2021/12/06 code-blocks and parsed literals] % Provides support for this output mark-up from Sphinx latex writer: % @@ -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,6 +715,7 @@ \ifspx@opt@parsedliteralwraps \sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}% \sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}% + \let\sphinxhyphen\sphinxhypheninparsedliteral \sphinxbreaksattexescapedchars \sphinxbreaksviaactiveinparsedliteral \sphinxbreaksatspaceinparsedliteral @@ -757,10 +762,14 @@ \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 % break at . , ; ? ! / \sphinxbreaksviaactive diff --git a/sphinx/texinputs/sphinxlatexstyletext.sty b/sphinx/texinputs/sphinxlatexstyletext.sty index ab50aed569b..539ee0de3ed 100644 --- a/sphinx/texinputs/sphinxlatexstyletext.sty +++ b/sphinx/texinputs/sphinxlatexstyletext.sty @@ -1,7 +1,7 @@ %% TEXT STYLING % % change this info string if making any custom modification -\ProvidesFile{sphinxlatexstyletext.sty}[2021/01/27 text styling] +\ProvidesFile{sphinxlatexstyletext.sty}[2021/12/06 text styling] % Basically everything here consists of macros which are part of the latex % markup produced by the Sphinx latex writer @@ -72,12 +72,20 @@ % Special characters % -% This definition prevents en-dash and em-dash TeX ligatures. +% The \kern\z@ is to prevent en-dash and em-dash TeX ligatures. +% A linebreak can occur after the dash in regular text (this is +% normal behaviour of "-" in TeX, it is not related to \kern\z@). % -% It inserts a potential breakpoint after the hyphen. This is to keep in sync -% with behavior in code-blocks, parsed and inline literals. For a breakpoint -% before the hyphen use \leavevmode\kern\z@- (within \makeatletter/\makeatother) +% Parsed-literals and inline literals also use the \sphinxhyphen +% but linebreaks there are prevented due to monospace font family. +% (xelatex needs a special addition, cf. sphinxlatexliterals.sty) +% +% 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{-}