使用 SaveVerbatim 时 fancyvrb 的行号不起作用

使用 SaveVerbatim 时 fancyvrb 的行号不起作用

下面的代码说明了一切

\documentclass{article}
\usepackage{fancyvrb}

\begin{SaveVerbatim}{FOO}
    However,
    if I define an reusable Verbatim by SaveVerbatim,
    line number failed to works.
\end{SaveVerbatim}

\begin{document}

\begin{Verbatim}[numbers=left]
    This works.
    Because I use Verbatim directly.
\end{Verbatim}

\UseVerbatim[numbers=left]{FOO}
\BUseVerbatim[numbers=left]{FOO}
\end{document}

答案1

这是一个对我有用的补丁:

$ cat fancyvrb.sty.patch 
992c992,993
<   \ifx\@tempa\@tempb
---
>   \def\FV@FirstNumber{#1}%
>   \ifx\@tempa\@tempb%
1128,1129c1129,1139
<         \FV@TheVerbatim\FV@ProcessLine{##1}}}%
<     \gdef\FV@TheVerbatim{}%
---
>         \FV@TheVerbatim\advance\c@FancyVerbLine\@ne\FV@ProcessLine{##1}}}%
>     \gdef\FV@TheVerbatim{%
>       \edef\@tempa{\FV@FirstNumber}%
>       \def\@tempb{auto}%
>       \ifx\@tempa\@tempb%
>         \c@FancyVerbLine\FV@CodeLineNo%
>       \else%
>         \c@FancyVerbLine\FV@FirstNumber%
>         \advance\c@FancyVerbLine\m@ne%
>       \fi%
>     }%

应用补丁后的结果

如果您在本地应用它,例如,通过将以下内容复制/粘贴到 unix shell 提示符中:

cat > fancyvrb.sty.patch
992c992,993
<   \ifx\@tempa\@tempb
---
>   \def\FV@FirstNumber{#1}%
>   \ifx\@tempa\@tempb%
1128,1129c1129,1139
<         \FV@TheVerbatim\FV@ProcessLine{##1}}}%
<     \gdef\FV@TheVerbatim{}%
---
>         \FV@TheVerbatim\advance\c@FancyVerbLine\@ne\FV@ProcessLine{##1}}}%
>     \gdef\FV@TheVerbatim{%
>       \edef\@tempa{\FV@FirstNumber}%
>       \def\@tempb{auto}%
>       \ifx\@tempa\@tempb%
>         \c@FancyVerbLine\FV@CodeLineNo%
>       \else%
>         \c@FancyVerbLine\FV@FirstNumber%
>         \advance\c@FancyVerbLine\m@ne%
>       \fi%
>     }%
  C-c C-c
patch -o fancyvrb.sty $(kpsewhich fancyvrb.sty) fancyvrb.sty.patch

我还将这个问题通过电子邮件发送给了软件包维护者(Herbert Voß),也许他们可以告诉我如何进行正确的修补/修复。

相关内容