(fancyvrb)完成环境后跟文本时出错

(fancyvrb)完成环境后跟文本时出错

我正在尝试比较支持verbatim内容的不同软件包,我注意到在关闭环境后跟文本(不是新行)时,行为存在细微但很大的差异。使用此示例文件:

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

后面的文本\end{verbatim}放在下一行。如果我们使用 {verbatim} 包,我们会得到以下消息:

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

文本 ”发现此文本...“没有显示在输出中,这是正确的并出现在包文档中,但fancyvrb你只会收到一个错误:

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

有什么办法跳过这个错误?而不必将文本放在下一行,要么将文本放在新行上,要么发送警告消息(我不知道哪一个是最明显的)。

我不知道这是否是软件包中的错误,还是由于这个软件包的实现。我给 Herbert 写了一封电子邮件(我认为他也属于这个社区),但他还没有给我答复。

问候

答案1

错误来自

\def\FV@BadEndError{%
  \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.}}

所以你可以把它作为一个警告

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

在序言中,但这里的错误似乎比警告更合理,因为它是文档中的语法错误。

请注意,我必须更改示例,因为您不能\end{myfancyverb}myfancyverb环境中拥有字符串。

\documentclass{article}%
%\usepackage{verbatim}\newenvironment{myverbatim}{\verbatim}{\endverbatim}
\usepackage{newvbtm}\newverbatim{mynewvbtm}{}{}{}{}
\usepackage{listings}\lstnewenvironment{mylistings}{\lstset{basicstyle=\ttfamily}}{}
\usepackage{fancyvrb}
\makeatletter
\def\FV@BadEndError{%
  \@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}

相关内容