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.

Possible Duplicate:
How to make a real apostrophe or single-quote in LaTeX

I'm building a Python Regex cheat sheet using Latex, which has the following line:

\texttt{re.match('a\textbackslash sb', 'a b')

However, when the line is copied from the PDF document, the apostrophe (') is converted to Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019) ():

re.match(’a\sb’, ’a b’)

This text is not recognizable by the Python interpreter.

Is there a LaTex tag for code that preserves the original characters?

share|improve this question

marked as duplicate by egreg, lockstep, Marco Daniel, Thorsten, Martin Schröder Oct 22 '12 at 11:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I wouldn't have expected that, what tex engine are you using. If it's pdftex try adding \usepackage[T1]{fontenc} –  David Carlisle Oct 22 '12 at 9:29

1 Answer 1

With pdflatex use \textquotesingle or \verb together with the package upquote:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{upquote}
\begin{document}
\texttt{re.match('a\textbackslash sb', 'a b')}

\texttt{re.match(\textquotesingle a\textbackslash sb\textquotesingle, \textquotesingle a b\textquotesingle)}

\verb+re.match('a\sb', 'a b')+
\end{document}

But you should be aware that copy code lines from a pdf can be problematic: e.g. spaces and identation can easily change.

share|improve this answer
    
I don't seem to have pdflatex in texShop (Mac OSX), and it does not work with LuaLatex nor XeLaTeX. –  Adam Matan Oct 22 '12 at 10:40
    
You certainly have pdflatex. But I forgot a brace in the code (now corrected). With lualatex/xelatex + \usepackage{fontspec} I can't reproduce your problem. You should make a complete example. –  Ulrike Fischer Oct 22 '12 at 11:36

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