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.

So I had already posted a similar question concerning the minus sign (-), but now I have an issue with the apostrophe (') that the previous solutions do not seem to solve. This seems to be a problem unrelated to listings since I cannot even get \verb!'! to create a PDF that when copied I get ASCII code 39. All I manage to get is an extended character (e2 80 99 according to hexdump).

Here's a MWE:


So the question is:

How can I create a PDF that shows a single quote that when copied has the ASCII value of a single quote?

share|improve this question
With pdflatex I get a quote. What engine are you using? –  Stephan Lehmke Apr 24 '12 at 21:42
I'm using pdflatex. Are you sure? It looks like a quote...but did you copy and paste it? –  Yossi Farjoun Apr 24 '12 at 21:43
After copying, emacs says character: ' (39, #o47, #x27) which is name: APOSTROPHE. –  Stephan Lehmke Apr 24 '12 at 21:51
@StephanLehmke Here, after copying, emacs said ’ (8217, #o20031, #x2019) which is name: RIGHT SINGLE QUOTATION MARK –  Paul Gaborit Jul 3 '13 at 9:48

2 Answers 2

In the absence of a ToUnicode CMap pdf viewers will do some heuristics to try to map the glyphs to unicode code points, but beyond ASCII this can be flakey and work only some of the time in some viewers. (See for example this patent). Hence Stephan Lehmke seeing different results to Yossi Farjoun. You can add a tounicode table easily enough, but the character in question is a quoteright which usually maps to U+2019. You could make the mapping for quoteright to U+0027 (the code point for the quotesingle glyph) which will solve your immediate problem but then single-right quotes elsewhere in the document (outside listings) would be affected. I found there is an undocumented "namespace" feature of \pdfglyphtounicode that allows to restrict the remapping to typewriter fonts only:

\input glyphtounicode.tex
\input glyphtounicode-cmr.tex
\verb!'! `hello'

Actually, it turns out that cmtt10 does in fact contain a quotesingle glyph which you may prefer to use anyway (in which case the \pdfglyphtounicode line above is not needed). To access this glyph use \usepackage{textcomp} and then \texttt{\textquotesingle} should do it. For the listings environment I believe you can do \lstset{upquote=true} to make it use this glyph when it sees an ASCII apostrophe.

share|improve this answer
Great answer! A lot of useful information in there! :-) –  Stephan Lehmke Apr 25 '12 at 6:40

With listings, you can use the upquote=true option combined with \usepackage{textcomp}:


share|improve this answer

Your Answer


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.