summaryrefslogtreecommitdiff
path: root/sphinx/highlighting.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-07-03 22:40:34 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2022-07-03 22:40:34 +0900
commit3d175d9a2423e52e549f003700abb42c7a9db21f (patch)
tree01e7b8612b93cefcd7502b0b292ee247df4b310a /sphinx/highlighting.py
parent80198e82aa9174802cb1eb30d69ce7fe98e24399 (diff)
parent2ac802fbd430513560529fda11b0dbe312787eea (diff)
downloadsphinx-git-3d175d9a2423e52e549f003700abb42c7a9db21f.tar.gz
Merge branch '5.x'
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r--sphinx/highlighting.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index b86c31f5e..62f10f7a1 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -40,12 +40,39 @@ escape_hl_chars = {ord('\\'): '\\PYGZbs{}',
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`\<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
'''