# Unable to copy _ from pdf

\documentclass{article}
\usepackage[T1,OT4]{fontenc}
\begin{document}
Text with \_.
\end{document}


In PDF there is a correct output: Text with _.
But when I select and copy it I get: Text with .

How can it be fixed?

-
WHy do you need the two encodings (OT4 and T1)? –  Gonzalo Medina Aug 27 '12 at 12:19
I really don't know :P. I have always had T1 and OT4 in my docs... –  Ichibann Aug 27 '12 at 12:23
I've added a remark to my answer. –  Gonzalo Medina Aug 27 '12 at 12:25
@Ichibann The T1 encoding has complete coverage for Polish diacritics. There is no need for OT4 for typesetting Polish. –  egreg Aug 27 '12 at 14:08
It's 2012. Go Unicode and use XeLaTeX or LuaLaTeX and forget about encodings. –  Martin Schröder Aug 27 '12 at 21:01

Change to

\usepackage[OT4,T1]{fontenc}


As far as I can see it, you don't really need the OT4 encoding; according to this remark from the fontenc documentation referring to OT4:

While Knuth included the means of typesetting the ‘lost L’ (Ł) in his OT1 encoding, he omitted the ogonek, a diacritic mark that is also needed in Polish text; hence the appearance, well before the T1 encoding, of fonts using this encoding.

So you can simply say

\usepackage[T1]{fontenc}

-
I have \usepackage[T1,OT4]{fontenc} in my real document. I think I need OT4. –  Ichibann Aug 27 '12 at 12:12
@Ichibann use \usepackage[OT4,T1]{fontenc}; by the way, you should have mentioned this in the question. –  Gonzalo Medina Aug 27 '12 at 12:14
Gonzalo, I didn't know it was causing the problem. I tried to make a real MWE. So I removed everything that didn't change the output. This included \usepackage[T1,OT4]{fontenc}. –  Ichibann Aug 27 '12 at 12:16

"Old" fontencodings like OT1 or OT4 don't have a glyph for \_ (\textunderscore), they use the default defined in the kernel which is a small rule. But you can change this default so that the glyph from the T1-encoding is used instead:

\documentclass{article}
\usepackage[T1,OT4]{fontenc}
\DeclareTextSymbolDefault{\textunderscore}{T1}
\begin{document}
Text with \_.
\end{document}

-