Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 213c29b

Browse files
committed
Fix sphinx-doc#10506 (again): replacements to Pygments escapes
Relates: pygments/pygments#2172
1 parent a7ef63a commit 213c29b

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

CHANGES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Bugs fixed
1919
* #10594: HTML Theme: field term colons are doubled if using Docutils 0.18+
2020
* #10596: Build failure if Docutils version is 0.18 (not 0.18.1) due
2121
to missing ``Node.findall()``
22-
* #10506: LaTeX: build error when using ``:cpp:stuff`` syntax highlighting in
23-
figure caption
22+
* #10506: LaTeX: build error if highlighting inline code role in figure caption
23+
(refs: #10251)
2424

2525
Testing
2626
--------

sphinx/highlighting.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,39 @@
4040
ord('}'): '\\PYGZcb{}'}
4141

4242
# used if Pygments is available
43+
# MEMO: no use of \protected here to avoid having to do hyperref extras,
44+
# (if in future code highlighting in sectioning titles is activated):
45+
# the definitions here use only robust, protected or chardef tokens,
46+
# which are all known to the hyperref re-encoding for bookmarks.
47+
# The " is troublesome because we would like to use \text\textquotedbl
48+
# but \textquotedbl is *defined to raise an error* (!) if the font
49+
# encoding is OT1. This however could happen from 'fontenc' key.
50+
# MEMO: the Pygments escapes with \char`\<char> syntax, if the document
51+
# uses old OT1 font encoding, work correctly only in monospace font.
52+
# MEMO: the Pygmentize output mark-up is always with a {} after.
4353
_LATEX_ADD_STYLES = r'''
44-
% Sphinx additions
45-
% use textcomp quote to get a true single quote
46-
\renewcommand\PYGZsq{\textquotesingle}
54+
% Sphinx redefinitions
55+
% Originally to obtain a straight single quote via package textcomp, then
56+
% to fix problems for the 5.0.0 inline code highlighting (captions!).
57+
% The \text is from amstext, a dependency of sphinx.sty. It is here only
58+
% to avoid build errors if for some reason expansion is in math mode.
59+
\def\PYGZbs{\text\textbackslash}
60+
\def\PYGZus{\_}
61+
\def\PYGZob{\{}
62+
\def\PYGZcb{\}}
63+
\def\PYGZca{\text\textasciicircum}
64+
\def\PYGZam{\&}
65+
\def\PYGZlt{\text\textless}
66+
\def\PYGZgt{\text\textgreater}
67+
\def\PYGZsh{\#}
68+
\def\PYGZpc{\%}
69+
\def\PYGZdl{\$}
70+
\def\PYGZhy{\sphinxhyphen}% defined in sphinxlatexstyletext.sty
71+
\def\PYGZsq{\text\textquotesingle}
72+
\def\PYGZdq{"}
73+
\def\PYGZti{\text\textasciitilde}
4774
\makeatletter
48-
% use \protected to allow \PYG in \caption
75+
% use \protected to allow syntax highlighting in captions
4976
\protected\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+{\PYG@do{#2}}}
5077
\makeatother
5178
'''

sphinx/texinputs/sphinxlatexstyletext.sty

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% TEXT STYLING
22
%
33
% change this info string if making any custom modification
4-
\ProvidesFile{sphinxlatexstyletext.sty}[2021/12/06 text styling]
4+
\ProvidesFile{sphinxlatexstyletext.sty}[2022/07/02 text styling]
55

66
% Basically everything here consists of macros which are part of the latex
77
% markup produced by the Sphinx latex writer
@@ -68,6 +68,7 @@
6868
\let\sphinxcrossref \@firstofone
6969
\let\sphinxtermref \@firstofone
7070
\let\sphinxhyphen\sphinxhyphenforbookmarks
71+
\def\PYG#1#2{#2}% (can not yet appear in section titles, but perhaps in future)
7172
}}
7273

7374
% Special characters

0 commit comments

Comments
 (0)