texlive[41742] Master/texmf-dist: fvextra (20jul16)

commits+karl at tug.org commits+karl at tug.org
Wed Jul 20 23:36:54 CEST 2016


Revision: 41742
          http://tug.org/svn/texlive?view=revision&revision=41742
Author:   karl
Date:     2016-07-20 23:36:54 +0200 (Wed, 20 Jul 2016)
Log Message:
-----------
fvextra (20jul16)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/fvextra/fvextra.pdf
    trunk/Master/texmf-dist/source/latex/fvextra/fvextra.dtx
    trunk/Master/texmf-dist/tex/latex/fvextra/fvextra.sty

Modified: trunk/Master/texmf-dist/doc/latex/fvextra/fvextra.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/fvextra/fvextra.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/fvextra/fvextra.dtx	2016-07-20 21:36:39 UTC (rev 41741)
+++ trunk/Master/texmf-dist/source/latex/fvextra/fvextra.dtx	2016-07-20 21:36:54 UTC (rev 41742)
@@ -26,7 +26,7 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{fvextra}
 %<*package>
-    [2016/07/14 v1.1 fvextra - extensions and patches for fancyvrb]
+    [2016/07/20 v1.2 fvextra - extensions and patches for fancyvrb]
 %</package>
 %
 %<*driver>
@@ -104,9 +104,6 @@
 
 \def\PrintMacroName#1{{\strut\MacroFont\color{DarkGreen}\footnotesize\string #1\ }}
 
-\DeclareRobustCommand\cs[1]{\texttt{\symbol{`\\}#1}}
-
-
 \def\PrintDescribeMacro#1{\strut\MacroFont\textcolor{DarkGreen}{\string #1\ }}
 \let\PrintDescribeEnv\PrintDescribeMacro
 %\let\PrintMacroName\PrintDescribeMacro
@@ -216,7 +213,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{2566}
+% \CheckSum{2843}
 %
 % \CharacterTable
 %  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -235,6 +232,12 @@
 %   Right brace   \}     Tilde         \~}
 %
 %
+% \begin{changelog}{v1.2}{2016/07/20}
+% \item Added support for line breaking when working with Pygments for syntax highlighting.
+% \item The default \texttt{highlightcolor} is now defined with \texttt{rgb} for compatibility with the \texttt{color} package.  Fixed a bug in the conditional color definition when \texttt{color} and \texttt{xcolor} are not loaded before \texttt{fvextra}.
+% \end{changelog}
+%
+%
 % \begin{changelog}{v1.1}{2016/07/14}
 % \item The options \texttt{rulecolor} and \texttt{fillcolor} now accept color names directly; using \texttt{\string\color\{<color\_name>\}} is no longer necessary, though it still works.
 % \item Added \texttt{tabcolor} and \texttt{spacecolor} options for use with \texttt{showtabs} and \texttt{showspaces}.
@@ -305,7 +308,7 @@
 % \section{General options}
 % \label{sec:general-options}
 %
-% \fvextra\ adds several general options to \fancyvrb.  All options related to automatic line breaking are described separately in \cref{sec:breaklines}.
+% \fvextra\ adds several general options to \fancyvrb.  All options related to automatic line breaking are described separately in \cref{sec:breaklines}.  All options related to syntax highlighting using Pygments are described in \cref{sec:pygments}.
 %
 % \begin{optionlist}
 %
@@ -835,6 +838,46 @@
 %
 %
 %
+% \section{Pygments support}
+% \label{sec:pygments}
+%
+%
+% \subsection{Options for users}
+% \label{sec:pygments:users}
+%
+% \fvextra\ defines additional options for working code that has been highlighted with \href{pygments.org}{Pygments}.  These options work with the \pkg{minted} and \pkg{pythontex} packages, and may be enabled for other packages that work with Pygments output (\cref{sec:pygments:package-authors}).
+%
+%
+% \begin{optionlist}
+% \item[breakbytoken (boolean) (false)]
+% When |breaklines=true|, do not allow breaks within \href{http://pygments.org/docs/tokens/}{Pygments tokens}.  This would prevent, for example, line breaking within strings.
+%
+% \item[breakbytokenanywhere (boolean) (false)]
+% When |breaklines=true|, do not allow breaks within Pygments tokens, but always allow breaks between tokens even when they are immediately adjacent (not separated by spaces).  \textbf{This option should be used with care.}  Due to the details of how each Pygments lexer works, and due to the tokens defined in each lexer, this may result in breaks in locations that might not be anticipated.  Also keep in mind that this will not allow breaks between tokens if those tokens are actually ``subtokens'' within another token.
+% \end{optionlist}
+%
+% \DescribeMacro{\FancyVerbBreakByTokenAnywhereBreak}
+%
+% This defines the break inserted when |breakbytokenanywhere=true|.  By default, it is |\allowbreak|.
+%
+%
+% \subsection{For package authors}
+% \label{sec:pygments:package-authors}
+%
+% By default, line breaking will only partially work with Pygments output; |breakbefore| and |breakafter| will not work with any characters that do not appear literally in Pygments output but rather are replaced with a character macro.  Also, |breakbytoken| and |breakbytokenanywhere| will not function at all.
+%
+% \DescribeMacro{\VerbatimPygments\marg{literal\_macro}\marg{actual\_macro}}
+%
+% To enable full Pygments support, use this macro before \verb|\begin{Verbatim}|, etc.  This macro must be used within |\begingroup...\endgroup| to prevent settings from escaping into the rest of the document.  It may be used safely at the beginning of a |\newenvironment| definition.  When used with |\newcommand|, though, the |\begingroup...\endgroup| will need to be inserted explicitly.
+%
+% \meta{literal\_macro} is the Pygments macro that literally appears in Pygments output; it corresponds to the Pygments |commandprefix|.  For \pkg{minted} and \pkg{pythontex}, this is |\PYG|.  \meta{actual\_macro} is the Pygments macro that should actually be used.  For \pkg{minted} and \pkg{pythontex}, this is |\PYG|\meta{style}.  In the \pkg{minted} and \pkg{pythontex} approach, code is only highlighted once (|\PYG|), and then the style is changed by redefining the macro that literally appears (|\PYG|) to use the appropriate style macro (|\PYG|\meta{style}).
+%
+% |\VerbatimPygments| takes the two Pygments macros and redefines \meta{literal\_macro} so that it will invoke \meta{actual\_macro} while fully supporting line breaks, |breakbytoken|, and |breakbytokenanywhere|.  No further modification of either \meta{literal\_macro} or \meta{actual\_macro} is possible after |\VerbatimPygments| is used.
+%
+% In packages that do not make a distinction between \meta{literal\_macro} and \meta{actual\_macro}, simply use |\VerbatimPygments| with two identical arguments; |\VerbatimPygments| is defined to handle this case.
+%
+%
+%
 % \section{Patches}
 % \label{sec:patch}
 %
@@ -1076,6 +1119,15 @@
 % \end{macro}
 %
 %
+% \begin{macro}{\FV at PygmentsHook}
+% This is a hook for turning on Pygments-related features for packages like \pkg{minted} and \pkg{pythontex} (\cref{sec:impl:pygments}).  It needs to be the first thing in |\FV at FormattingPrepHook|, since it will potentially affect some of the later things in the hook.  It is activated by |\VerbatimPygments|.
+%    \begin{macrocode}
+\let\FV at PygmentsHook\relax
+\g at addto@macro\FV at FormattingPrepHook{\FV at PygmentsHook}
+%    \end{macrocode}
+% \end{macro}
+%
+%
 % \subsection{Escaped characters}
 % \begin{macro}{\FV at EscChars}
 % Define versions of common escaped characters that reduce to raw characters.  This is useful, for example, when working with text that is almost verbatim, but was captured in such a way that some escapes were unavoidable.
@@ -1851,7 +1903,7 @@
 \ifcsname definecolor\endcsname
 \ifx\definecolor\relax
 \else
-  \definecolor{FancyVerbHighlightColor}{HTML}{E0FFFF}
+  \definecolor{FancyVerbHighlightColor}{rgb}{0.878, 1, 1}
   \fvset{highlightcolor=FancyVerbHighlightColor}
 \fi\fi
 \AtBeginDocument{%
@@ -1859,7 +1911,7 @@
     \ifcsname definecolor\endcsname
     \ifx\definecolor\relax
     \else
-    \definecolor{FancyVerbHighlightColor}{rgb}{0,1,1}
+    \definecolor{FancyVerbHighlightColor}{rgb}{0.878, 1, 1}
     \fvset{highlightcolor=FancyVerbHighlightColor}
     \fi\fi
   \fi}
@@ -2198,6 +2250,8 @@
 %
 % The procedure here is a bit roundabout.  We need to use |\FV at EscChars| to handle character escapes, but the character redefinitions need to be kept local, requiring that we work within a |\begingroup...\endgroup|.  So we loop through the breaking tokens and assemble a macro that will itself define character macros.  Only this defining macro is declared global, and it contains \emph{expanded} characters so that there is no longer any dependence on |\FV at EscChars|.
 %
+% |\FV at BreakBeforePrep@PygmentsHook| allows additional break preparation for Pygments-based packages such as \pkg{minted} and \pkg{pythontex}.  When Pygments highlights code, it converts some characters into macros; they do not appear literally.  As a result, for breaking to occur correctly, breaking macros need to be created for these character macros and not only for the literal characters themselves.
+%
 % A pdfTeX-compatible version for working with UTF-8 is defined later, and |\FV at BreakBeforePrep| is |\let| to it under pdfTeX as necessary.
 %    \begin{macrocode}
 \def\FV at BreakBeforePrep{%
@@ -2220,8 +2274,10 @@
     \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
     \endgroup
     \FV at BreakBefore@Def
+    \FV at BreakBeforePrep@PygmentsHook
   \fi
 }
+\let\FV at BreakBeforePrep@PygmentsHook\relax
 %    \end{macrocode}
 % \end{macro}
 %
@@ -2291,8 +2347,10 @@
     \expandafter\FV at BreakAfter@Process\FV at BreakAfter\FV at Undefined
     \endgroup
     \FV at BreakAfter@Def
+    \FV at BreakAfterPrep@PygmentsHook
   \fi
 }
+\let\FV at BreakAfterPrep@PygmentsHook\relax
 %    \end{macrocode}
 % \end{macro}
 %
@@ -2802,6 +2860,7 @@
     \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
     \endgroup
     \FV at BreakBefore@Def
+    \FV at BreakBeforePrep@PygmentsHook
   \fi
 }
 %    \end{macrocode}
@@ -2852,6 +2911,7 @@
     \expandafter\FV at BreakAfter@Process\FV at BreakAfter\FV at Undefined
     \endgroup
     \FV at BreakAfter@Def
+    \FV at BreakAfterPrep@PygmentsHook
   \fi
 }
 %    \end{macrocode}
@@ -3025,7 +3085,7 @@
 % \begin{macro}{\FV at SaveLineBox}
 % This is the macro that does most of the work.  It was inspired by Marco Daniel's code at \url{http://tex.stackexchange.com/a/112573/10742}.
 %
-% This macro is invoked when a line is too long.  We modify the |\linewidth| to take into account |breakindent| and |breakautoindent|, and insert |\hbox|es to fill the empty space.  We also account for |breaksymbolindentleft| and |breaksymbolindentright|, but \emph{only} when there are actually break symbols.  The code is placed in a |\parbox|.  Break symbols are inserted via \pkg{lineno}'s |internallinenumbers*|, which does internal line numbers without continuity between environments (the |linenumber| counter is automatically reset).  The beginning of the line has negative |\hspace| inserted to pull it out to the correct starting position.  |\strut|s are used to maintain correct line heights.  The |\parbox| is followed by an empty |\hbox| that takes up the space needed for a right-hand break symbol (if any).
+% This macro is invoked when a line is too long.  We modify the |\linewidth| to take into account |breakindent| and |breakautoindent|, and insert |\hbox|es to fill the empty space.  We also account for |breaksymbolindentleft| and |breaksymbolindentright|, but \emph{only} when there are actually break symbols.  The code is placed in a |\parbox|.  Break symbols are inserted via \pkg{lineno}'s |internallinenumbers*|, which does internal line numbers without continuity between environments (the |linenumber| counter is automatically reset).  The beginning of the line has negative |\hspace| inserted to pull it out to the correct starting position.  |\strut|s are used to maintain correct line heights.  The |\parbox| is followed by an empty |\hbox| that takes up the space needed for a right-hand break symbol (if any).  |\FV at BreakByTokenAnywhereHook| is a hook for using  |breakbytokenanywhere| when working with Pygments.  Since it is within |internallinenumbers*|, its effects do not escape.
 %    \begin{macrocode}
 \def\FV at SaveLineBox#1{%
   \savebox{\FV at LineBox}{%
@@ -3055,6 +3115,7 @@
       \ifthenelse{\boolean{FV at BreakAutoIndent}}%
        {\hspace*{-\wd\FV at LineIndentBox}}%
        {}%
+      \FV at BreakByTokenAnywhereHook
       \strut\FancyVerbFormatText{%
         \FancyVerbBreakStart #1\FancyVerbBreakStop}\nobreak\strut
       \end{internallinenumbers*}
@@ -3063,6 +3124,7 @@
      {\hbox to \FV at BreakSymbolIndentRight{\hfill}}%
   }%
 }
+\let\FV at BreakByTokenAnywhereHook\relax
 %    \end{macrocode}
 % \end{macro}
 %
@@ -3131,6 +3193,216 @@
 %
 %
 %
+%
+% \subsection{Pygments compatibility}
+% \label{sec:impl:pygments}
+%
+% This section makes line breaking compatible with \href{http://pygments.org/}{Pygments}, which is used by several packages including \pkg{minted} and \pkg{pythontex} for syntax highlighting.  A few additional line breaking options are also defined for working with Pygments.
+%
+% \begin{macro}{\FV at BreakBeforePrep@Pygments}
+% Pygments converts some characters into macros to ensure that they appear literally.  As a result, |breakbefore| and |breakafter| would fail for these characters.  This macro checks for the existence of breaking macros for these characters, and creates breaking macros for the corresponding Pygments character macros as necessary.
+%
+% The argument that the macro receives is the detokenized name of the main Pygments macro, with the trailing space that detokenization produces stripped.  All macro names must end with a space, because the breaking algorithm uses detokenization on each token when checking for breaking macros, and this will produce a trailing space.
+%    \begin{macrocode}
+\def\FV at BreakBeforePrep@Pygments#1{%
+  \ifcsname FV at BreakBefore@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zbs }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zus }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charlb\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zob }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charrb\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zcb }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zca }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zam }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zlt }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zgt }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zsh }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@percentchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zpc }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zdl }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zhy }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zsq }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zdq }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zti }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zat }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zlb }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zrb }{}%
+  \fi
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FV at BreakAfterPrep@Pygments}
+%    \begin{macrocode}
+\def\FV at BreakAfterPrep@Pygments#1{%
+  \ifcsname FV at BreakAfter@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zbs }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zus }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@charlb\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zob }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@charrb\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zcb }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zca }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zam }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zlt }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zgt }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zsh }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@percentchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zpc }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zdl }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zhy }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zsq }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zdq }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zti }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zat }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zlb }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zrb }{}%
+  \fi
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{breakbytoken}
+% When Pygments is used, do not allow breaks within \href{http://pygments.org/docs/tokens/}{Pygments tokens}.  So, for example, breaks would not be allowed within a string, but could occur before or after it.  This has no affect when Pygments is not in use, and is only intended for \pkg{minted}, \pkg{pythontex}, and similar packages.
+%    \begin{macrocode}
+\newbool{FV at breakbytoken}
+\define at booleankey{FV}{breakbytoken}%
+ {\booltrue{FV at breakbytoken}}%
+ {\boolfalse{FV at breakbytoken}\boolfalse{FV at breakbytokenanywhere}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{breakbytokenanywhere}
+% |breakbytoken| prevents breaks \emph{within} tokens.  Breaks outside of tokens may still occur at spaces.  This option also enables breaks between immediately adjacent tokens that are not separated by spaces.  Its definition is tied in with |breakbytoken| so that |breakbytoken| may be used as a check for whether either option is in use; essentially, |breakbytokenanywhere| is treated as a special case of |breakbytoken|.
+%    \begin{macrocode}
+\newbool{FV at breakbytokenanywhere}
+\define at booleankey{FV}{breakbytokenanywhere}%
+ {\booltrue{FV at breakbytokenanywhere}\booltrue{FV at breakbytoken}}%
+ {\boolfalse{FV at breakbytokenanywhere}\boolfalse{FV at breakbytoken}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\FancyVerbBreakByTokenAnywhereBreak}
+% This is the break introduced when |breakbytokenanywhere=true|.  Alternatives would be |\discretionary{}{}{}| or |\linebreak[0]|.
+%    \begin{macrocode}
+\def\FancyVerbBreakByTokenAnywhereBreak{\allowbreak{}}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\VerbatimPygments}
+% This is the command that activates Pygments features.  It must be invoked before \verb|\begin{Verbatim}|, etc., but inside a |\begingroup...\endgroup| so that its effects do not escape into the rest of the document (for example, within the beginning of an environment.  It takes two arguments:  The Pygments macro that literally appears (|\PYG| for \pkg{minted} and \pkg{pythontex}), and the Pygments macro that should actually be used (|\PYG|\meta{style\_name} for \pkg{minted} and \pkg{pythontex}).  The two are distinguished because it can be convenient to highlight everything using the same literal macro name, and then |\let| it to appropriate values to change styles, rather than redoing all highlighting to change styles.  It modifies |\FV at PygmentsHook|, which is at the beginning of |\FV at FormattingPrepHook|, to make the actual changes at the appropriate time.
+%    \begin{macrocode}
+\def\VerbatimPygments#1#2{%
+  \def\FV at PygmentsHook{\FV at VerbatimPygments{#1}{#2}}}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\FV at VerbatimPygments}
+% This does all the actual work.  Again, |#1| is the Pygments macro that literally appears, and |#2| is the macro that is actually to be used.
+%
+% The |breakbefore| and |breakafter| hooks are redefined.  This requires some trickery to get the detokenized name of the main Pygments macro without the trailing space that detokenization of a macro name produces.
+%
+% In the non-|breakbytoken| case, |#1| is redefined to use |#2| internally, bringing in |\FancyVerbBreakStart| and |\FancyVerbBreakStop| to allow line breaks.
+%
+% In the |breakbytoken| cases, an |\hbox| is used to prevent breaks within the macro (breaks could occur at spaces even without |\FancyVerbBreakStart|).  The |breakbytokenanywhere| case is similar but a little tricky.  |\FV at BreakByTokenAnywhereHook|, which is inside |\FV at SaveLineBox| where line breaking occurs, is used to define |\FV at BreakByTokenAnywhereBreak| so that it will ``do nothing'' the first time it is used and on subsequent invocations become |\FancyVerbBreakByTokenAnywhereBreak|.  Because the hook is within the |internallinenumbers*| environment, the redefinition doesn't escape, and the default global definition of |\FV at BreakByTokenAnywhereBreak| as |\relax| is not affected.  We don't want the actual break to appear before the first Pygments macro in case it might cause a spurious break after leading whitespace.  But we must have breaks \emph{before} Pygments macros because otherwise lookahead would be necessary.
+%
+% An intermediate variable |\FV at PYG| is defined to avoid problems in case |#1|$=$|#2|.  There is also a check for a non-existant |#2| (|\PYG|\meta{style\_name} may not be created until a later compile in the \pkg{pythontex} case); if |#2| does not exist, fall back to |#1|.  For the existance check, |\ifx...\relax| must be used instead of |\ifcsname|, because |#2| will be a macro, and will typically be created with |\csname...\endcsname| which will |\let| the macro to |\relax| if it doesn't already exist.
+%    \begin{macrocode}
+\def\FV at VerbatimPygments#1#2{%
+  \edef\FV at PYG@Literal{\expandafter\FV at DetokMacro@StripSpace\detokenize{#1}}%
+  \def\FV at BreakBeforePrep@PygmentsHook{%
+    \expandafter\FV at BreakBeforePrep@Pygments\expandafter{\FV at PYG@Literal}}
+  \def\FV at BreakAfterPrep@PygmentsHook{%
+    \expandafter\FV at BreakAfterPrep@Pygments\expandafter{\FV at PYG@Literal}}
+  \ifx#2\relax
+    \let\FV at PYG#1
+  \else
+    \let\FV at PYG#2
+  \fi
+  \ifbool{FV at breakbytoken}%
+   {\ifbool{FV at breakbytokenanywhere}%
+     {\def\FV at BreakByTokenAnywhereHook{%
+        \def\FV at BreakByTokenAnywhereBreak{%
+          \let\FV at BreakByTokenAnywhereBreak\FancyVerbBreakByTokenAnywhereBreak}}%
+      \def#1##1##2{%
+        \FV at BreakByTokenAnywhereBreak
+        \leavevmode\hbox{\FV at PYG{##1}{##2}}}}%
+     {\def#1##1##2{%
+        \leavevmode\hbox{\FV at PYG{##1}{##2}}}}}%
+   {\def#1##1##2{%
+     \FV at PYG{##1}{\FancyVerbBreakStart##2\FancyVerbBreakStop}}}%
+}
+\let\FV at BreakByTokenAnywhereBreak\relax
+\def\FV at DetokMacro@StripSpace#1 {#1}
+%    \end{macrocode}
+% \end{macro}
+%
+%
 % \iffalse
 %</package>
 % \fi

Modified: trunk/Master/texmf-dist/tex/latex/fvextra/fvextra.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/fvextra/fvextra.sty	2016-07-20 21:36:39 UTC (rev 41741)
+++ trunk/Master/texmf-dist/tex/latex/fvextra/fvextra.sty	2016-07-20 21:36:54 UTC (rev 41742)
@@ -20,7 +20,7 @@
 %% 
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{fvextra}
-    [2016/07/14 v1.1 fvextra - extensions and patches for fancyvrb]
+    [2016/07/20 v1.2 fvextra - extensions and patches for fancyvrb]
 \RequirePackage{ifthen}
 \RequirePackage{etoolbox}
 \RequirePackage{fancyvrb}
@@ -40,6 +40,8 @@
 \let\FV at FormattingPrepHook\@empty
 \expandafter\def\expandafter\FV at FormattingPrep\expandafter{%
   \expandafter\FV at FormattingPrepHook\FV at FormattingPrep}
+\let\FV at PygmentsHook\relax
+\g at addto@macro\FV at FormattingPrepHook{\FV at PygmentsHook}
 \edef\FV at hashchar{\string#}
 \edef\FV at dollarchar{\string$}
 \edef\FV at ampchar{\string&}
@@ -450,7 +452,7 @@
 \ifcsname definecolor\endcsname
 \ifx\definecolor\relax
 \else
-  \definecolor{FancyVerbHighlightColor}{HTML}{E0FFFF}
+  \definecolor{FancyVerbHighlightColor}{rgb}{0.878, 1, 1}
   \fvset{highlightcolor=FancyVerbHighlightColor}
 \fi\fi
 \AtBeginDocument{%
@@ -458,7 +460,7 @@
     \ifcsname definecolor\endcsname
     \ifx\definecolor\relax
     \else
-    \definecolor{FancyVerbHighlightColor}{rgb}{0,1,1}
+    \definecolor{FancyVerbHighlightColor}{rgb}{0.878, 1, 1}
     \fvset{highlightcolor=FancyVerbHighlightColor}
     \fi\fi
   \fi}
@@ -619,8 +621,10 @@
     \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
     \endgroup
     \FV at BreakBefore@Def
+    \FV at BreakBeforePrep@PygmentsHook
   \fi
 }
+\let\FV at BreakBeforePrep@PygmentsHook\relax
 \define at key{FV}{breakafter}{%
   \ifstrempty{#1}%
    {\let\FV at BreakAfter\@empty
@@ -670,8 +674,10 @@
     \expandafter\FV at BreakAfter@Process\FV at BreakAfter\FV at Undefined
     \endgroup
     \FV at BreakAfter@Def
+    \FV at BreakAfterPrep@PygmentsHook
   \fi
 }
+\let\FV at BreakAfterPrep@PygmentsHook\relax
 \g at addto@macro\FV at FormattingPrepHook{%
   \ifcsname pdfmatch\endcsname
   \ifx\pdfmatch\relax
@@ -964,6 +970,7 @@
     \expandafter\FV at BreakBefore@Process\FV at BreakBefore\FV at Undefined
     \endgroup
     \FV at BreakBefore@Def
+    \FV at BreakBeforePrep@PygmentsHook
   \fi
 }
 \def\FV at BreakAfterPrep@UTF{%
@@ -1008,6 +1015,7 @@
     \expandafter\FV at BreakAfter@Process\FV at BreakAfter\FV at Undefined
     \endgroup
     \FV at BreakAfter@Def
+    \FV at BreakAfterPrep@PygmentsHook
   \fi
 }
 \def\FV at Break@AnyToken at UTF#1{%
@@ -1172,6 +1180,7 @@
       \ifthenelse{\boolean{FV at BreakAutoIndent}}%
        {\hspace*{-\wd\FV at LineIndentBox}}%
        {}%
+      \FV at BreakByTokenAnywhereHook
       \strut\FancyVerbFormatText{%
         \FancyVerbBreakStart #1\FancyVerbBreakStop}\nobreak\strut
       \end{internallinenumbers*}
@@ -1180,6 +1189,7 @@
      {\hbox to \FV at BreakSymbolIndentRight{\hfill}}%
   }%
 }
+\let\FV at BreakByTokenAnywhereHook\relax
 \def\FV at ListProcessLine@Break#1{%
   \hbox to \hsize{%
   \kern\leftmargin
@@ -1234,6 +1244,155 @@
     \FV at RightListNumber
   \fi}%
   \hss}\baselineskip\z@\lineskip\z@}
+\def\FV at BreakBeforePrep@Pygments#1{%
+  \ifcsname FV at BreakBefore@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zbs }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zus }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charlb\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zob }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@charrb\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zcb }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zca }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zam }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zlt }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zgt }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zsh }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\@percentchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zpc }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zdl }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zhy }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zsq }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zdq }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zti }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zat }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zlb }{}%
+  \fi
+  \ifcsname FV at BreakBefore@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakBefore@Token#1Zrb }{}%
+  \fi
+}
+\def\FV at BreakAfterPrep@Pygments#1{%
+  \ifcsname FV at BreakAfter@Token\@backslashchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zbs }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at underscorechar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zus }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@charlb\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zob }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@charrb\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zcb }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{^}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zca }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at ampchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zam }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{<}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zlt }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{>}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zgt }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at hashchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zsh }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\@percentchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zpc }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at dollarchar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zdl }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{-}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zhy }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{'}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zsq }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{"}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zdq }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\FV at tildechar\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zti }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{@}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zat }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{[}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zlb }{}%
+  \fi
+  \ifcsname FV at BreakAfter@Token\detokenize{]}\endcsname
+    \@namedef{FV at BreakAfter@Token#1Zrb }{}%
+  \fi
+}
+\newbool{FV at breakbytoken}
+\define at booleankey{FV}{breakbytoken}%
+ {\booltrue{FV at breakbytoken}}%
+ {\boolfalse{FV at breakbytoken}\boolfalse{FV at breakbytokenanywhere}}
+\newbool{FV at breakbytokenanywhere}
+\define at booleankey{FV}{breakbytokenanywhere}%
+ {\booltrue{FV at breakbytokenanywhere}\booltrue{FV at breakbytoken}}%
+ {\boolfalse{FV at breakbytokenanywhere}\boolfalse{FV at breakbytoken}}
+\def\FancyVerbBreakByTokenAnywhereBreak{\allowbreak{}}
+\def\VerbatimPygments#1#2{%
+  \def\FV at PygmentsHook{\FV at VerbatimPygments{#1}{#2}}}
+\def\FV at VerbatimPygments#1#2{%
+  \edef\FV at PYG@Literal{\expandafter\FV at DetokMacro@StripSpace\detokenize{#1}}%
+  \def\FV at BreakBeforePrep@PygmentsHook{%
+    \expandafter\FV at BreakBeforePrep@Pygments\expandafter{\FV at PYG@Literal}}
+  \def\FV at BreakAfterPrep@PygmentsHook{%
+    \expandafter\FV at BreakAfterPrep@Pygments\expandafter{\FV at PYG@Literal}}
+  \ifx#2\relax
+    \let\FV at PYG#1
+  \else
+    \let\FV at PYG#2
+  \fi
+  \ifbool{FV at breakbytoken}%
+   {\ifbool{FV at breakbytokenanywhere}%
+     {\def\FV at BreakByTokenAnywhereHook{%
+        \def\FV at BreakByTokenAnywhereBreak{%
+          \let\FV at BreakByTokenAnywhereBreak\FancyVerbBreakByTokenAnywhereBreak}}%
+      \def#1##1##2{%
+        \FV at BreakByTokenAnywhereBreak
+        \leavevmode\hbox{\FV at PYG{##1}{##2}}}}%
+     {\def#1##1##2{%
+        \leavevmode\hbox{\FV at PYG{##1}{##2}}}}}%
+   {\def#1##1##2{%
+     \FV at PYG{##1}{\FancyVerbBreakStart##2\FancyVerbBreakStop}}}%
+}
+\let\FV at BreakByTokenAnywhereBreak\relax
+\def\FV at DetokMacro@StripSpace#1 {#1}
 %% \Finale
 \endinput
 %%



More information about the tex-live-commits mailing list