diff options
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r-- | sphinx/highlighting.py | 35 |
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 ''' |