4

The following code tells every thing

\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}

3
  • It's a bug, which won't be fixed.
    – user187802
    Commented Nov 30, 2020 at 7:51
  • Why won't? Is there any discussion about it? I found an email report this bug 10 year ago, but no related reply found yet.
    – Qiang
    Commented Nov 30, 2020 at 9:15
  • Feel free to provide a patch and it will be fixed ...
    – user187802
    Commented Nov 30, 2020 at 9:41

1 Answer 1

2

Here's a patch that works for me:

$ 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%
>     }%

result with the patch applied

If you apply it locally, for example, by copy/pasting the following into a unix shell prompt:

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

I've also emailed this to the package maintainer (Herbert Voß), maybe they could tell me how to proceed towards a proper patch/fix.

2
  • The BVerbatim numbering doesn't work even with regular verbatim (non-saved), so I didn't patch it. Commented Aug 8, 2021 at 22:24
  • 1
    Will be fixed in fancyvrb. Thanks for the patch!
    – user187802
    Commented Aug 12, 2021 at 7:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .