TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the listings package to display R code. I would like a monospaced font, bold keywords, and I would like code that works when the user cuts and pastes from the pdf file into rstudio. The default listings font works correctly when pasted, but does not display bold keywords. Some fonts display bold keywords, but the caret symbol is incorrect when pasted.

Here is sample code that illustrates the problem (cut and paste the fifth line in the listing to see what happens---the caret is wrong, i.e., it displays this character: ˆ, which is not recognized by R, rather than this: ^)

%\usepackage{pxfonts} % bold but wrong caret
\usepackage{courier} % bold but wrong caret
%\usepackage{ascii} % no bold



\begin{lstlisting}[float,frame=single,caption={A first example},label=list:ex1]
r <- 0.06
g <- 0.02
tt <- 1:5
cf0 <- 100
pv <- sum(cf0*(1+g)^(tt-1)/(1+r)^tt) 
print(pv, digits = 8)
[1] 437.41649

share|improve this question
Could you be a bit more specific about what you mean by "the caret is wrong" (or "incorrect")? – Mico Jun 14 '12 at 18:06
@Mico: Thank you, I edited the question to clarify. – rmcd Jun 14 '12 at 20:29
up vote 4 down vote accepted

instead of courier use

share|improve this answer
Thank you! This is the solution. – rmcd Jun 14 '12 at 20:29

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.