I'm trying to insert Octave code in a pdf containing the character ^. However when I copy the code from the generated pdf, the code doesn't run: The I already posted similar question and could solve the problem. However the problem reappeared. I suspect one of the loaded package is responsible.

Here is an example of code with the loaded packages

\documentclass[a4paper, 12pt]{book}


\author{John Smith}



  • Code produced by a listing is not necessarily meant to run and one shouldn't expect it to after just copy&pasting it. – Skillmon Dec 2 '18 at 21:55
  • indeed when copying pasting from PDF I get the MODIFIER LETTER CIRCUMFLEX ACCENT U+02C6 (letter ˆ) and not the usual ascii caret. Culprit is lmodern package. But add \usepackage[T1]{fontenc} and it should fix the issue. – user4686 Dec 3 '18 at 21:58
  • MWE: simply load lmodern and consider \texttt{x\string^2}. – user4686 Dec 3 '18 at 22:03
  • @UlrikeFischer you may be interested into this why does \OT1/lmtt/m/n/10 ^ give a ˆ in PDF (or at least when copying back from PDF, tested with Skim on mac os x) – user4686 Dec 3 '18 at 22:04

I am providing this as a provisory answer to give a workaround awaiting the fonts expert (... or experts).



Uncomment the fontenc line to fix the issue. Then copy-pasting from PDF gives a normal ascii caret, not a MODIFIER LETTER CIRCUMFLEX ACCENT U+02C6 (letter ˆ)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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