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 trying to incorporate programming examples in a LaTeX document.

The document renders nicely with pdflatex; however, the single quotes get transformed into U+2019, a right-single-quotation mark. And, a backtick renders as U+2018, a left-single-quotation-mark.

What I need is a U+0027 real apostrophe so that the code can be successfully cut-and-pasted from the PDF into actual source code.

\documentclass{article}
\usepackage{alltt}
\usepackage{color}
\usepackage{fullpage}

\begin{document}
\center{\LARGE{hello.py}}
\begin{alltt}

{\color{red}print} 'hello world'

\end{alltt}
\end{document}

The same issue exists also with straight typewriter fonts: \tt{don't worry, be happy}. I'm unclear how to control the exact unicode character that is produced.

share|improve this question

migrated from stackoverflow.com Jul 14 '12 at 23:07

This question came from our site for professional and enthusiast programmers.

    
I remember being bugged for this problem time ago, but forgot the result of my investigations. I kind of remember that it was an issue of font enconding, not TeX, and perhaps that changing tt font to courier solved the problem. But I can be misremembering. –  JLDiaz Jul 14 '12 at 23:19
    
Could you add a picture of the problematic output? –  doncherry Jul 15 '12 at 10:57
    
Not quite related to the q., but searching for the problem led me here: Outside of verbatim, you can use \char18 and \char13 to get ` and ' characters. –  Mohan Nov 20 '12 at 11:13
    
Reading "real apostrophe" confused me. Wikipedia had this to say about apostrophes: 'There are several types of apostrophe character in Unicode: ( ' ) Vertical typewriter apostrophe (Unicode name apostrophe or apostrophe-quote), U+0027, inherited from ASCII. ( ’ ) Punctuation apostrophe (or typographic apostrophe; right single quotation mark; single comma quotation mark), U+2019. Serves as both an apostrophe and closing single quotation mark. This is the preferred character to use for apostrophe according to the Unicode standard.' So, talk about programming only. B'marked the question though. –  Christian Feb 24 '13 at 22:59
add comment

2 Answers 2

up vote 17 down vote accepted

Use the upquote package; even if the package documentation doesn't mention alltt, it works also with it:

\documentclass{article}
\usepackage{alltt}
\usepackage{upquote}
\usepackage{color}
\usepackage{fullpage}

\begin{document}

\begin{center}
\LARGE hello.py
\end{center}

\begin{alltt}
{\color{red}print} 'hello world'
\end{alltt}

\end{document}

Notice some modifications to the input.

enter image description here

share|improve this answer
    
Thank you. The upquote package is exactly what I was looking for. –  Raymond Hettinger Jul 15 '12 at 0:04
add comment

You want to do your own layout? Why not http://en.wikibooks.org/wiki/LaTeX/Packages/Listings?

Listings even allows you to set up colors and the such.

share|improve this answer
    
I would like to know how to render apostrophes in the alltt environment for a number of reasons, not just code listings. –  Raymond Hettinger Jul 14 '12 at 1:10
add comment

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.