# Error using \usepackage{fancyvrb, fancybox}

With TeX Live 2009, with this MWE.

\documentclass{article}
\usepackage{fancyvrb, fancybox}
\begin{document}
\begin{Verbatim}[frame=single]
auto eth0
\end{Verbatim}
\end{document}


I get the following error when compiling

Runaway argument?
auto eth0^^M    \end{Verbatim}^^M^^M\end{document} ! File ended while scanning use of \Verbatim. <inserted text>


Using

\usepackage{fancybox, fancyvrb}


makes the error go away, but it is disturbing. I assume that fancyvrb depends on fancybox, but the packages don't handle this gracefully. This took me a while to track down. For reference, I was looking at Peter Flynn's example in http://groups.google.com/group/latexusersgroup/browse_thread/thread/c8c2e5dd1e9ff5cf

The message in question starts with

I don't understand the problem. What I wrote works in any class. Just copy and paste it into a report.

and his example has those packages loaded in that order, to be precise \usepackage{fancyvrb,fancybox,calc}. So my question is, what is going wrong here precisely, and how can I effectively debug these kinds of issues in the future?

UPDATE: The choice between's Enrico's solution and Werner's solution was basically a tossup. I did like Enrico's identification of a problem with the fancybox Verbatim environment. However, I still am not clear how one can efficiently identify these problems when they crop up. If anyone has debugging tips, I'd like to hear them.

-
\end{Verbatim} must start in the first column of a line – Herbert Dec 25 '11 at 21:04
@Herbert: Not sure what you mean. – Faheem Mitha Dec 26 '11 at 0:48
spaces before \end{Verbatim} are not allowed. – Herbert Dec 26 '11 at 6:47
@Herbert: Don't follow. Not allowed according to who/what? – Faheem Mitha Dec 26 '11 at 8:11
Debugging starts with patience! :) You literally have to pull the code apart by removing things (unnecessary packages, code or commands) in order to find the root of the problem. It's very subjective, since experience plays a big part in where to look and what to look for. For example, since load order played a part here, it definitely made me suspicious that one package might redefine a command. Completely dropping one was sufficient. Then, upon further investigation, I noticed the difference in notation, and experimented with either. Widdling it down to an MWE is always best. – Werner Dec 30 '11 at 5:53

You should have noticed that in Peter Flynn's message the syntax used is

\begin{Verbatim}{frame=single}


and not

\begin{Verbatim}[frame=single]


This makes quite a big difference. Moreover, the Verbatim environment as redefined by fancybox seems not to like blank spaces in front of \end{Verbatim}: the following input

\documentclass{article}
\usepackage{fancybox}
\begin{document}
\begin{Verbatim}{frame=single}
auto eth0
\end{Verbatim}
\end{document}


raises the

Runaway argument?
{frame=single}^^M   auto eth0^^M \end{Verbatim}^^M\end{document}^^M
! File ended while scanning use of \FV@BeginScanning.


error.

Of course, both packages trying to redefine \VerbatimEnvironment is not very helpful to the user. However, if you load fancyvrb as second, you get all of its functionality, without losing fancybox's as regards to boxes and frames. The implementation of the verbatim environments in fancybox seems buggy (the requirement that \end{Verbatim} starts on column 1 is surely a bug), so I believe it's best to say

\usepackage{fancybox,fancyvrb}

-
Hi egreg. Thanks for the pointers. Firstly, Peter seems to think that he is using the fancyvrb package ("The Verbatim (capital V) environment from fancyvrb still has that restriction, but has options for a frame and a lot of other bells and whistles."), but as you point out, with the Verbatim env in fancyvrb you would have [frame=single] not {frame=single}. You imply (but do not say) that the latter usage is from fancybox. Unfortunately this is not clear from the fancybox docs. – Faheem Mitha Dec 25 '11 at 13:23
I'm not clear what you mean by "Moreover, the Verbatim environment as redefined by fancybox seems not to like blank spaces in front of \end{Verbatim}". I stuck blank spaces in various places, but it didn't seem to mind. As I mentioned in my answer to Werner, reformatting code gives an error, so there is something wrong here, but not sure what. Also, am even less clear what you mean by "the requirement that \end{Verbatim} starts on column 1 is surely a bug". Perhaps you could give an illustrative example? Thanks. – Faheem Mitha Dec 25 '11 at 13:25
Thanks for the illustrative example. I think you meant to put fancybox rather than fancyvrb in your example, at the current version doesn't really illustrate your point. With fancyvrb you get an error with and without a space in front of \end{Verbatim}. And I'm not sure about "redefined". Where is Verbatim earlier defined, such that fancybox is redefining it? – Faheem Mitha Dec 26 '11 at 0:46
@FaheemMitha Yes, it was fancybox and not fancyvrb – egreg Dec 26 '11 at 11:07

The problem here is that both packages define internal commands that are very similar, yet conflicting. For example, fancyvrb defines

\def\VerbatimEnvironment{%
\ifx\FV@EnvironName\relax\xdef\FV@EnvironName{\@currenvir}\fi}


while fancybox defines

\def\VerbatimEnvironment{%
\ifx\@VerbEnvir\relax\xdef\@VerbEnvir{\@currenvir}\fi}


Not to say that this is the root of the problem, but it is meant to illustrate the similarities between some of the definitions. As such, switching the load order of the packages could make the one package work, but not the other.

\usepackage{fancybox,fancyvrb}


work? Well, because you only used functionality provided by fancyvrb making the load/use of fancybox unnecessary. Why does Peter's suggested solution work? Well, because he didn't need to load fancyvrb in the first place, since he only used fancybox functionality.

How come you were not alerted of conflicting commands until compilation? That's because many macro definitions and environments are constructed using TeX's \def rather than LaTeX's \newcommand. The latter automatically checks to see whether a command already exists and issues an error if it does, while the former happily overwrites a previous definition.

Perhaps this could be considered a partial incompatibility between the two packages - an incompatibility none the less.

-
Thanks for the summary, Greg. Would best usage be to use \newcommand rather than \def? And do you think the errors in my example above stem from fancybox overwriting something that fancyvrb has defined? Actually, Peter's version gives errors too, but (improbably) whether there is an error seems to depend on how it is formatted. I didn't investigate carefully to make sure of this though. I see both fancybox and fancyvrb define a Verbatim environment. How can you tell Peter is not using fancyvrb functionality? – Faheem Mitha Dec 25 '11 at 8:12

The following works.

\documentclass{article}
\begin{document}
\begin{verbatim}[frame=single]
auto eth0
\end{verbatim}
\end{document}

-
That doesn't answer my question, sorry. – Faheem Mitha Dec 25 '11 at 2:07
Is there a Verbatim environment? – Sony Dec 25 '11 at 2:11
Yes, the Verbatim environment is from the fancyvrb package. – Faheem Mitha Dec 25 '11 at 2:15
OK thanks. Your code (without including fancybox package) works in TeX Live 2011. No errors. – Sony Dec 25 '11 at 2:18
Yes, I know. My question is why including fancybox creates problems. If you look at the posting I cite, you'll see this is a stripped down version of code by Peter Flynn. – Faheem Mitha Dec 25 '11 at 2:27