Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

3 Answers 3

up vote 1 down vote accepted

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}
share|improve this answer
1  
{\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

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

In your case, add the following to your preamble:

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

share|improve this answer

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:
Example without "upquote"

With upquote:
Example with "upquote"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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