mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
latex: code blocks linebreaks easier customized
Via re-definable ``\sphinxbreaksbeforelist`` and ``\sphinxbreaksafterlist``, latex user can specify (using ``'preamble'`` key for example) if broken code lines are split before or after the said character when code blocks are wrapped. Punctuation characters use active catcodes and are configurable via further macros ``\sphinxbreaksbeforeactivelist`` and ``\sphinxbreaksafteractivelist``. The defaults in ``sphinx.sty`` can be modified by imitation in user document preamble. n.b.: ``\sphinxbreaksatpunct`` has been renamed to ``\sphinxbreaksviaactive``.
This commit is contained in:
parent
1d7c82b3bb
commit
0464c52bce
@ -274,41 +274,39 @@
|
|||||||
% {, <, #, %, $, ' and ": go to next line.
|
% {, <, #, %, $, ' and ": go to next line.
|
||||||
% _, }, ^, &, >, - and ~: stay at end of broken line.
|
% _, }, ^, &, >, - and ~: stay at end of broken line.
|
||||||
% Use of \textquotesingle for straight quote.
|
% Use of \textquotesingle for straight quote.
|
||||||
|
\newcommand*\sphinxbreaksbeforelist {%
|
||||||
|
\do\PYGZob\{\do\PYGZlt\<\do\PYGZsh\#\do\PYGZpc\%% {, <, #, %,
|
||||||
|
\do\PYGZdl\$\do\PYGZdq\"% $, "
|
||||||
|
\def\PYGZsq
|
||||||
|
{\discretionary{}{\sphinxafterbreak\textquotesingle}{\textquotesingle}}% '
|
||||||
|
}
|
||||||
|
\newcommand*\sphinxbreaksafterlist {%
|
||||||
|
\do\PYGZus\_\do\PYGZcb\}\do\PYGZca\^\do\PYGZam\&% _, }, ^, &,
|
||||||
|
\do\PYGZgt\>\do\PYGZhy\-\do\PYGZti\~% >, -, ~
|
||||||
|
}
|
||||||
\newcommand*\sphinxbreaksatspecials {%
|
\newcommand*\sphinxbreaksatspecials {%
|
||||||
\def\PYGZus{\discretionary{\char`\_}{\sphinxafterbreak}{\char`\_}}%
|
\def\do##1##2%
|
||||||
\def\PYGZob{\discretionary{}{\sphinxafterbreak\char`\{}{\char`\{}}%
|
{\def##1{\discretionary{}{\sphinxafterbreak\char`##2}{\char`##2}}}%
|
||||||
\def\PYGZcb{\discretionary{\char`\}}{\sphinxafterbreak}{\char`\}}}%
|
\sphinxbreaksbeforelist
|
||||||
\def\PYGZca{\discretionary{\char`\^}{\sphinxafterbreak}{\char`\^}}%
|
\def\do##1##2%
|
||||||
\def\PYGZam{\discretionary{\char`\&}{\sphinxafterbreak}{\char`\&}}%
|
{\def##1{\discretionary{\char`##2}{\sphinxafterbreak}{\char`##2}}}%
|
||||||
\def\PYGZlt{\discretionary{}{\sphinxafterbreak\char`\<}{\char`\<}}%
|
\sphinxbreaksafterlist
|
||||||
\def\PYGZgt{\discretionary{\char`\>}{\sphinxafterbreak}{\char`\>}}%
|
|
||||||
\def\PYGZsh{\discretionary{}{\sphinxafterbreak\char`\#}{\char`\#}}%
|
|
||||||
\def\PYGZpc{\discretionary{}{\sphinxafterbreak\char`\%}{\char`\%}}%
|
|
||||||
\def\PYGZdl{\discretionary{}{\sphinxafterbreak\char`\$}{\char`\$}}%
|
|
||||||
\def\PYGZhy{\discretionary{\char`\-}{\sphinxafterbreak}{\char`\-}}%
|
|
||||||
\def\PYGZsq{\discretionary{}{\sphinxafterbreak\textquotesingle}{\textquotesingle}}%
|
|
||||||
\def\PYGZdq{\discretionary{}{\sphinxafterbreak\char`\"}{\char`\"}}%
|
|
||||||
\def\PYGZti{\discretionary{\char`\~}{\sphinxafterbreak}{\char`\~}}%
|
|
||||||
}
|
}
|
||||||
|
|
||||||
\def\sphinx@verbatim@nolig@list {\do \`}%
|
\def\sphinx@verbatim@nolig@list {\do \`}%
|
||||||
% Some characters . , ; ? ! / are not pygmentized.
|
% Some characters . , ; ? ! / are not pygmentized.
|
||||||
% This macro makes them "active" and they will insert potential linebreaks
|
% This macro makes them "active" and they will insert potential linebreaks
|
||||||
\newcommand*\sphinxbreaksatpunct {%
|
\newcommand*\sphinxbreaksbeforeactivelist {}% none
|
||||||
\lccode`\~`\.\lowercase{\def~}{\discretionary{\char`\.}{\sphinxafterbreak}{\char`\.}}%
|
\newcommand*\sphinxbreaksafteractivelist {\do\.\do\,\do\;\do\?\do\!\do\/}
|
||||||
\lccode`\~`\,\lowercase{\def~}{\discretionary{\char`\,}{\sphinxafterbreak}{\char`\,}}%
|
\newcommand*\sphinxbreaksviaactive {%
|
||||||
\lccode`\~`\;\lowercase{\def~}{\discretionary{\char`\;}{\sphinxafterbreak}{\char`\;}}%
|
\def\do##1{\lccode`\~`##1%
|
||||||
\lccode`\~`\:\lowercase{\def~}{\discretionary{\char`\:}{\sphinxafterbreak}{\char`\:}}%
|
\lowercase{\def~}{\discretionary{}{\sphinxafterbreak\char`##1}{\char`##1}}%
|
||||||
\lccode`\~`\?\lowercase{\def~}{\discretionary{\char`\?}{\sphinxafterbreak}{\char`\?}}%
|
\catcode`##1\active}%
|
||||||
\lccode`\~`\!\lowercase{\def~}{\discretionary{\char`\!}{\sphinxafterbreak}{\char`\!}}%
|
\sphinxbreaksbeforeactivelist
|
||||||
\lccode`\~`\/\lowercase{\def~}{\discretionary{\char`\/}{\sphinxafterbreak}{\char`\/}}%
|
\def\do##1{\lccode`\~`##1%
|
||||||
\catcode`\.\active
|
\lowercase{\def~}{\discretionary{\char`##1}{\sphinxafterbreak}{\char`##1}}%
|
||||||
\catcode`\,\active
|
\catcode`##1\active}%
|
||||||
\catcode`\;\active
|
\sphinxbreaksafteractivelist
|
||||||
\catcode`\:\active
|
|
||||||
\catcode`\?\active
|
|
||||||
\catcode`\!\active
|
|
||||||
\catcode`\/\active
|
|
||||||
\lccode`\~`\~
|
\lccode`\~`\~
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +375,7 @@
|
|||||||
% 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)
|
||||||
\def\FancyVerbCodes{\sphinxbreaksatpunct}%
|
\def\FancyVerbCodes{\sphinxbreaksviaactive}%
|
||||||
\fi % end of conditional code for wrapping long code lines
|
\fi % end of conditional code for wrapping long code lines
|
||||||
% go around fancyvrb's check of \@currenvir
|
% go around fancyvrb's check of \@currenvir
|
||||||
\let\VerbatimEnvironment\sphinxVerbatimEnvironment
|
\let\VerbatimEnvironment\sphinxVerbatimEnvironment
|
||||||
|
Loading…
Reference in New Issue
Block a user