diff --git a/CHANGES b/CHANGES index d52b5e70b5f..9123a0f7667 100644 --- a/CHANGES +++ b/CHANGES @@ -19,8 +19,8 @@ Bugs fixed * #10594: HTML Theme: field term colons are doubled if using Docutils 0.18+ * #10596: Build failure if Docutils version is 0.18 (not 0.18.1) due to missing ``Node.findall()`` -* #10506: LaTeX: build error when using ``:cpp:stuff`` syntax highlighting in - figure caption +* #10506: LaTeX: build error if highlighting inline code role in figure caption + (refs: #10251) Testing -------- diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index b86c31f5e48..62f10f7a148 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -40,12 +40,39 @@ ord('}'): '\\PYGZcb{}'} # used if Pygments is available +# MEMO: no use of \protected here to avoid having to do hyperref extras, +# (if in future code highlighting in sectioning titles is activated): +# the definitions here use only robust, protected or chardef tokens, +# which are all known to the hyperref re-encoding for bookmarks. +# The " is troublesome because we would like to use \text\textquotedbl +# but \textquotedbl is *defined to raise an error* (!) if the font +# encoding is OT1. This however could happen from 'fontenc' key. +# MEMO: the Pygments escapes with \char`\ syntax, if the document +# uses old OT1 font encoding, work correctly only in monospace font. +# MEMO: the Pygmentize output mark-up is always with a {} after. _LATEX_ADD_STYLES = r''' -% Sphinx additions -% use textcomp quote to get a true single quote -\renewcommand\PYGZsq{\textquotesingle} +% Sphinx redefinitions +% Originally to obtain a straight single quote via package textcomp, then +% to fix problems for the 5.0.0 inline code highlighting (captions!). +% The \text is from amstext, a dependency of sphinx.sty. It is here only +% to avoid build errors if for some reason expansion is in math mode. +\def\PYGZbs{\text\textbackslash} +\def\PYGZus{\_} +\def\PYGZob{\{} +\def\PYGZcb{\}} +\def\PYGZca{\text\textasciicircum} +\def\PYGZam{\&} +\def\PYGZlt{\text\textless} +\def\PYGZgt{\text\textgreater} +\def\PYGZsh{\#} +\def\PYGZpc{\%} +\def\PYGZdl{\$} +\def\PYGZhy{\sphinxhyphen}% defined in sphinxlatexstyletext.sty +\def\PYGZsq{\text\textquotesingle} +\def\PYGZdq{"} +\def\PYGZti{\text\textasciitilde} \makeatletter -% use \protected to allow \PYG in \caption +% use \protected to allow syntax highlighting in captions \protected\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+{\PYG@do{#2}}} \makeatother ''' diff --git a/sphinx/texinputs/sphinxlatexstyletext.sty b/sphinx/texinputs/sphinxlatexstyletext.sty index 539ee0de3ed..31378b76f73 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/12/06 text styling] +\ProvidesFile{sphinxlatexstyletext.sty}[2022/07/02 text styling] % Basically everything here consists of macros which are part of the latex % markup produced by the Sphinx latex writer @@ -68,6 +68,7 @@ \let\sphinxcrossref \@firstofone \let\sphinxtermref \@firstofone \let\sphinxhyphen\sphinxhyphenforbookmarks + \def\PYG#1#2{#2}% (can not yet appear in section titles, but perhaps in future) }} % Special characters