[Tex/LaTex] Using \input in a fancyvrb verbatim environment – problem with hyphens

inputverbatim

I've set up a custom environment with DefineVerbatimEnvironment. Within that environment I'd like to \input{} files, which works all fine and well until one of them includes a hyphen. Here's an example that demonstrates the problem:

\documentclass{article}

\usepackage{fancyvrb}

\DefineVerbatimEnvironment{terminal}{Verbatim}{commandchars=\\\{\}}

\begin{document}

\begin{terminal}
  \input{some-file}
\end{terminal}

\end{document}

If I try to \input{file} the contents of the file show up in the verbatim environment just as I'd expect. But if I try and \input{some-file} I get the following error:

! LaTeX Error: File `more\unhbox \voidb@x \kern \z@ \char `\discretionary {-}{}{}input.tex' not found.

Obviously, my hyphen is being translated into \unhbox ... {-}{}{} – how can I stop this happening?

Best Answer

You just need to move the - somewhere safe, for example:

\documentclass{article}

\usepackage{fancyvrb}

\DefineVerbatimEnvironment{terminal}{Verbatim}{commandchars=\\\{\}}
\newcommand\somefile{\input{some-file}}
\begin{document}

\begin{terminal}
  \somefile
\end{terminal}

\end{document}