# How to properly display backticks in verbatim environment?

I am preparing a beamer presentation where I need to display some markdown code involving backticks. Specifically, I want to show backticks in the verbatim environment. However, LaTeX renders them as open quotation marks.

How can I ensure backticks in the verbatim environment display as backticks?

Here's a minimal example:

\begin{verbatim}
Example: 2 + 2
\end{verbatim}


An ideal solution would not require me to change the code itself.

-
I don't know if it is an option for you but using LuaLaTeX/XeLaTeX with fontspec generate the right characters. –  ArTourter Jul 15 '12 at 10:22

You can also use the relative new package upquote, which is explicitly created for that task – together with the change for single quote marks, compare How to make a real apostrophe or single-quote in LaTeX.

\documentclass{article}
\usepackage{upquote}
\begin{document}
\begin{verbatim}
Example: 2 + 2
\end{verbatim}
\end{document}


Without upquote:

With upquote:

-

It is possible to do this with a variation of the code found under a similar question here.

\makeatletter
\let\@sverbatim\@verbatim
\def\@verbatim{\@sverbatim \verbatimwithtick}
{\catcode=13 \gdef\verbatimwithtick{\chardef=18 }}
\makeatother


In the verbatim environment this sets the definition of  to correspond to the 18th character in the font table which is a back tick. Normally it corresponds to an opening quote.

-

With eTeX, @jpallen doesn't need auxiliary commands:

\documentclass{article}
\makeatletter
{\catcode\=13
\xdef\@verbatim{\unexpanded\expandafter{\@verbatim}\chardef\noexpand=18 }
}
\makeatother

\begin{document}
\begin{verbatim}
Example: 2 + 2
\end{verbatim}
\end{document}

-
{\catcode\=13 \g@addto@macro\@verbatim{\chardef=18 }} seems less complicated. :) –  egreg Jul 16 '12 at 6:39
Eh, complicated? I can't see the complication! –  Ahmed Musa Jul 16 '12 at 15:55