mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Move some LaTeX macros for easier customizability if needed
This commit is contained in:
parent
314f5291d4
commit
2bbb699b01
@ -840,6 +840,32 @@
|
|||||||
|
|
||||||
% needed to create wrapper environments of fancyvrb's Verbatim
|
% needed to create wrapper environments of fancyvrb's Verbatim
|
||||||
\newcommand*{\sphinxVerbatimEnvironment}{\gdef\FV@EnvironName{sphinxVerbatim}}
|
\newcommand*{\sphinxVerbatimEnvironment}{\gdef\FV@EnvironName{sphinxVerbatim}}
|
||||||
|
% serves to implement line highlighting and line wrapping
|
||||||
|
\newcommand\sphinxFancyVerbFormatLine[1]{%
|
||||||
|
\expandafter\sphinx@verbatim@checkifhl
|
||||||
|
\expandafter{\the\numexpr\value{FancyVerbLine}-\spx@verbatim@linedelta}%
|
||||||
|
\ifin@
|
||||||
|
\edef\sphinx@restorefboxsep{\fboxsep\the\fboxsep\relax}%
|
||||||
|
\fboxsep\z@
|
||||||
|
\colorbox{VerbatimHighlightColor}%
|
||||||
|
{\sphinx@restorefboxsep\sphinx@FancyVerbFormatLine{#1}}%
|
||||||
|
\else
|
||||||
|
\sphinx@FancyVerbFormatLine{#1}%
|
||||||
|
\fi
|
||||||
|
}%
|
||||||
|
\def\sphinx@FancyVerbFormatLine@wrap #1%
|
||||||
|
{\hsize\linewidth
|
||||||
|
\vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@
|
||||||
|
\doublehyphendemerits\z@\finalhyphendemerits\z@
|
||||||
|
\strut #1\strut}%
|
||||||
|
}%
|
||||||
|
\def\sphinx@FancyVerbFormatLine@nowrap #1{\hb@xt@\linewidth{\strut #1\hss}}%
|
||||||
|
\def\sphinx@FancyVerbCodesHook
|
||||||
|
{\FV@SetLineNo\edef\spx@verbatim@linedelta{\the\value{FancyVerbLine}}}%
|
||||||
|
\g@addto@macro\FV@SetupFont{%
|
||||||
|
\sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}%
|
||||||
|
\sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}%
|
||||||
|
}%
|
||||||
% Sphinx <1.5 optional argument was in fact mandatory. It is now really
|
% Sphinx <1.5 optional argument was in fact mandatory. It is now really
|
||||||
% optional and handled by original Verbatim.
|
% optional and handled by original Verbatim.
|
||||||
\newenvironment{sphinxVerbatim}{%
|
\newenvironment{sphinxVerbatim}{%
|
||||||
@ -886,41 +912,20 @@
|
|||||||
% to achieve this without extensive rewrite of fancyvrb.
|
% to achieve this without extensive rewrite of fancyvrb.
|
||||||
% - The (not used in sphinx) obeytabs option to Verbatim is
|
% - The (not used in sphinx) obeytabs option to Verbatim is
|
||||||
% broken by this change (showtabs and tabspace work).
|
% broken by this change (showtabs and tabspace work).
|
||||||
\expandafter\def\expandafter\FV@SetupFont\expandafter
|
\let\sphinx@FancyVerbFormatLine\sphinx@FancyVerbFormatLine@wrap
|
||||||
{\FV@SetupFont\sbox\sphinxcontinuationbox {\spx@opt@verbatimcontinued}%
|
|
||||||
\sbox\sphinxvisiblespacebox {\spx@opt@verbatimvisiblespace}}%
|
|
||||||
\def\sphinx@FancyVerbFormatLine ##1{\hsize\linewidth
|
|
||||||
\vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@
|
|
||||||
\doublehyphendemerits\z@\finalhyphendemerits\z@
|
|
||||||
\strut ##1\strut}%
|
|
||||||
}%
|
|
||||||
\let\FV@Space\spx@verbatim@space
|
\let\FV@Space\spx@verbatim@space
|
||||||
% Allow breaks at special characters using \PYG... macros.
|
% Allow breaks at special characters using \PYG... macros.
|
||||||
\sphinxbreaksatspecials
|
\sphinxbreaksatspecials
|
||||||
% Breaks at punctuation characters . , ; ? ! and / (needs catcode activation)
|
% Breaks at punctuation characters . , ; ? ! and / (needs catcode activation)
|
||||||
% Hacker note: mark-up should not use codes=... option of Verbatim, but
|
\expandafter\def\expandafter\sphinx@FancyVerbCodesHook\expandafter
|
||||||
% codes*=..., and \fvset{codes=...} if added by raw latex will be overwritten
|
{\sphinx@FancyVerbCodesHook\sphinxbreaksviaactive}%
|
||||||
\def\FancyVerbCodes{\sphinxbreaksviaactive}%
|
|
||||||
\else % end of conditional code for wrapping long code lines
|
\else % end of conditional code for wrapping long code lines
|
||||||
\def\sphinx@FancyVerbFormatLine ##1{\hb@xt@\linewidth{\strut ##1\hss}}%
|
\let\sphinx@FancyVerbFormatLine\sphinx@FancyVerbFormatLine@nowrap
|
||||||
\let\FancyVerbCodes\@empty % only for clarity
|
|
||||||
\fi
|
\fi
|
||||||
\renewcommand\FancyVerbFormatLine[1]{%
|
\let\FancyVerbFormatLine\sphinxFancyVerbFormatLine
|
||||||
\expandafter\sphinx@verbatim@checkifhl
|
% hook into \FancyVerbCodes to recover at first code line the numbering offset
|
||||||
\expandafter{\the\numexpr\value{FancyVerbLine}-\spx@verbatim@linedelta}%
|
\expandafter\def\expandafter\FancyVerbCodes\expandafter
|
||||||
\ifin@
|
{\FancyVerbCodes\sphinx@FancyVerbCodesHook}%
|
||||||
\edef\sphinx@restorefboxsep{\fboxsep\the\fboxsep\relax}%
|
|
||||||
\fboxsep\z@
|
|
||||||
\colorbox{VerbatimHighlightColor}%
|
|
||||||
{\sphinx@restorefboxsep\sphinx@FancyVerbFormatLine{##1}}%
|
|
||||||
\else
|
|
||||||
\sphinx@FancyVerbFormatLine{##1}%
|
|
||||||
\fi
|
|
||||||
}%
|
|
||||||
% hook into this macro to recover the line numbering offset (default zero)
|
|
||||||
\expandafter\def\expandafter\FancyVerbCodes\expandafter{\FancyVerbCodes
|
|
||||||
\FV@SetLineNo
|
|
||||||
\edef\spx@verbatim@linedelta{\the\value{FancyVerbLine}}}%
|
|
||||||
% go around fancyvrb's check of \@currenvir
|
% go around fancyvrb's check of \@currenvir
|
||||||
\let\VerbatimEnvironment\sphinxVerbatimEnvironment
|
\let\VerbatimEnvironment\sphinxVerbatimEnvironment
|
||||||
% go around fancyvrb's check of current list depth
|
% go around fancyvrb's check of current list depth
|
||||||
|
Loading…
Reference in New Issue
Block a user