# (fancyvrb) Error when finishing environment followed by text

I'm trying to compare he different packages that support verbatim content and I noticed that there is a small, but, big difference in behavior when closing the environment followed by text (not a new line). With this example file:

\documentclass{article}%
%\usepackage{verbatim}\newenvironment{myverbatim}{\verbatim}{\endverbatim}
\usepackage{newvbtm}\newverbatim{mynewvbtm}{}{}{}{}
\usepackage{listings}\lstnewenvironment{mylistings}{\lstset{basicstyle=\ttfamily}}{}
\usepackage{fancyvrb}\DefineVerbatimEnvironment{myfancyvrb}{Verbatim}{}
\begin{document}
\noindent\hrulefill

This text is found just before opening the verbatim (default, no package) environment
\begin{verbatim}
default verbatim environment
\end{verbatim}This text is found just after closing verbatim environment

\noindent\hrulefill

This text is found just before opening the verbatim (with listings package) environment
\begin{mylistings}
verbatim with listings package
\end{mylistings}This text is found just after closing verbatim environment

\noindent\hrulefill

This text is found just before opening the verbatim environment
\begin{mynewvbtm}
verbatim with newvbtm package
\end{mynewvbtm}This text is found just after closing verbatim environment

\noindent\hrulefill

%This text is found just before opening the verbatim (with verbatim package) environment
%\begin{myverbatim}
% LaTeX Warning: Characters dropped after \end{verbatim}' on input line
%\end{myverbatim}This text is found just after closing verbatim environment
%\noindent\hrulefill

%This text is found just before opening the verbatim (with myfancyvrb package) environment
%\begin{myfancyvrb}
%! FancyVerb Error:
%  Extraneous input This text is found just after closing verbatim environment\
%end{}' between \end{myfancyvrb} and line end
%.
%\FV@Error ... {FancyVerb Error:
%\space \space #1
%}
%\end{myfancyvrb}This text is found just after closing verbatim environment
\end{document}

The text after \end{verbatim} is placed on the following line. If we use the {verbatim} package we get the message:

LaTeX Warning: Characters dropped after \end{verbatim}' on input line

The text "This text is found..." is not displayed on the output, which is correct and appears in the package documentation, but with fancyvrb you only get one error:

! FancyVerb Error:
Extraneous input This text is found just after closing verbatim environment\
end{}' between \end{myfancyvrb} and line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}

Is there any way to skip this error?, without having to place the text on the following line, either by placing the text on a new line or by sending a warning message (I don't know which one is the most indicated).

I don't know if it's an error in the package or if it's due to the implementation of this one. I've written an email to Herbert (I think he also belongs to this community), but, he hasn't given me an answer.

Greetings

• An error seems to be the correct thing here, it is a syntax error in the file (which is quite hard to recover from) – David Carlisle Sep 11 '19 at 18:47
• @DavidCarlisle: If I understand it, the truth is that I don't need to put text as such, rather a comment \end{myfancyvrb} %...but the error spoils everything...and you don't do the same with the other packages... – Pablo González L Sep 11 '19 at 18:58
• but the % isn't a comment character in that context and by the time the \end{myfancyvrb} is detected it is too late to make it so. The whole line has already been read with verbatim settings – David Carlisle Sep 11 '19 at 18:59
• Ok, I understand that I can't detect it, but I could ignore the rest of the line if it starts with a comment ... and not show the error message. I think that placing a %comment at the end of an environment is valid. – Pablo González L Sep 11 '19 at 19:03
• No placing a %comment after a verbatim environment (from this package or the verbatim package) is explicitly not valid it is a syntax error in the document. – David Carlisle Sep 11 '19 at 19:14

The error comes from

\expandafter\@temptokena\expandafter{\@tempb}%
\FV@Error
{Extraneous input \the\@temptokena' between
\string\end{\FV@EnvironName} and line end}%
{This input will be discarded. Type <return> to continue.}}

so you could make that a warning by putting

\makeatletter
\@warning
{Extraneous input  between
\string\end{\FV@EnvironName} and line end}%
\let\next\FV@EndScanning}
%

in the preamble, but an error seems more reasonable than a warning here, as it is a syntax error in the document.

Note that I had to change the example as you can not have the string \end{myfancyverb} within a myfancyverb environment.

\documentclass{article}%
%\usepackage{verbatim}\newenvironment{myverbatim}{\verbatim}{\endverbatim}
\usepackage{newvbtm}\newverbatim{mynewvbtm}{}{}{}{}
\usepackage{listings}\lstnewenvironment{mylistings}{\lstset{basicstyle=\ttfamily}}{}
\usepackage{fancyvrb}
\makeatletter
\@warning
{Extraneous input  between
\string\end{\FV@EnvironName} and line end}%
\let\next\FV@EndScanning}
%\makeatother

\DefineVerbatimEnvironment{myfancyvrb}{Verbatim}{}
\begin{document}

\noindent\hrulefill

This text is found just before opening the verbatim (default, no package) environment
\begin{verbatim}
default verbatim environment
\end{verbatim}This text is found just after closing verbatim environment

\noindent\hrulefill

This text is found just before opening the verbatim (with listings package) environment
\begin{mylistings}
verbatim with listings package
\end{mylistings}This text is found just after closing verbatim environment

\noindent\hrulefill

This text is found just before opening the verbatim environment
\begin{mynewvbtm}
verbatim with newvbtm package
\end{mynewvbtm}This text is found just after closing verbatim environment

\noindent\hrulefill

%This text is found just before opening the verbatim (with verbatim package) environment
%\begin{myverbatim}
% LaTeX Warning: Characters dropped after \end{verbatim}' on input line
%\end{myverbatim}This text is found just after closing verbatim environment
%\noindent\hrulefill

This text is found just before opening the verbatim (with myfancyvrb package) environment
\begin{myfancyvrb}
! FancyVerb Error:
Extraneous input `This text is found just after closing verbatim environment\
end{}' between \end{myfanc--yvrb} and line end
.
p\FV@Error ... {FancyVerb Error:
\space \space #1
}
\end{myfancyvrb}This text is found just after closing verbatim environment
\end{document}
• actually I decided I do not understand your question, I get no error from the test file you provided??? @PabloGonzálezL – David Carlisle Sep 11 '19 at 18:37
• I'll undelete in a bit – David Carlisle Sep 11 '19 at 18:41
• @PabloGonzálezL added working example and undeleted the post – David Carlisle Sep 11 '19 at 19:13
• Thank you very much Master David, those are the precise lines I was looking for... Still...I still think it's "almost a bug" in the fancyvrb package. – Pablo González L Sep 11 '19 at 19:23
• @PabloGonzálezL I would say it is definitely a bug in the document, if I was maintaining the package I would certainly make it issue an error here, – David Carlisle Sep 11 '19 at 19:24