6

I have the following environment for displaying code:

Which works pretty fine but now I have the problem that -- becomes an en dash inside that environment. For example here:

I tried also {-}{-} and -{}- but inside the Verbatim {} are not translated. Any ideas how to escape this the right way?

\documentclass[11pt, twocolumn, landscape]{article}     % use "amsart" instead of "article" for AMSLaTeX format
\usepackage[a4paper]{geometry}                      % See geometry.pdf to learn the layout options. There are lots.
\usepackage[parfill]{parskip}           % Activate to begin paragraphs with an empty line rather than an indent
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage{verbatim}
\usepackage{frame}
\usepackage{fancybox,calc} 
\usepackage[svgnames]{xcolor} 
\usepackage{fullpage}
\setlength{\columnsep}{4em}

\newenvironment{code}{\VerbatimEnvironment% 
  \noindent
  %      {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt} 
  \begin{Sbox} 
  \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt}    
  \color{DarkBlue}\begin{Verbatim}
}{% 
  \end{Verbatim}  
  \end{minipage}   
  \end{Sbox} 
  \fcolorbox{DarkBlue}{Orange}{\TheSbox} 
} 

\begin{document}
\pagenumbering{gobble}

\begin{code}
git config --global user.name "Max Mustermann"
git config --global user.email "max@mustermann.de"
\end{code}

\end{document}
  • It helps tor provide a full MWE, starting with \documentclass, so that we know what packages were loaded, as well as other configuration changes or requirements. Welcome to the site. – Steven B. Segletes Oct 30 '13 at 15:44
  • fancybox and fancyvrb don't work well together. It's fancybox's fault if hyphens are not honored. – egreg Oct 30 '13 at 16:10
  • I removed fancyvrb since it is not used anyways. The problem still exists. – MeiSign Oct 30 '13 at 16:15
  • The definition of Verbatim made by fancybox is faulty. It's better to use mdframed and fancyvrb. – egreg Oct 30 '13 at 16:58
9

The problem is that both fancyvrb and fancybox define the Verbatim environment.

The one defined by fancybox has this problem, while the one defined by fancyvrb doesn't.

So, loading fancyvrb after fancybox solves the problem, that is substitute the line

\usepackage{fancyvrb,fancybox,calc}

with

\usepackage{fancybox,fancyvrb,calc}

Complete code:

\documentclass[11pt, twocolumn, landscape]{article}     % use "amsart" instead of "article" for AMSLaTeX format
\usepackage[a4paper]{geometry}                      % See geometry.pdf to learn the layout options. There are lots.
\usepackage[parfill]{parskip}           % Activate to begin paragraphs with an empty line rather than an indent
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage{verbatim}
\usepackage{frame}
\usepackage{fancybox,fancyvrb,calc}
\usepackage[svgnames]{xcolor}
\usepackage{fullpage}
\setlength{\columnsep}{4em}

\newenvironment{code}{\VerbatimEnvironment%
  \noindent
  %      {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt}
  \begin{Sbox}
  \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt}
  \color{DarkBlue}\begin{Verbatim}
}{%
  \end{Verbatim}
  \end{minipage}
  \end{Sbox}%
  \fcolorbox{DarkBlue}{Orange}{\TheSbox}
}

\begin{document}
\pagenumbering{gobble}

\begin{code}
git config --global user.name "Max Mustermann"
git config --global user.email "max@mustermann.de"
\end{code}

\end{document} 

Output:

enter image description here

P.S. I've added a % character after \end{Sbox} to avoid a spurious space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.