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.

When I use \textunderscore to print an underscore "_" character, the copy-paste functionality of Adobe Acrobat Reader does not appear to work properly. For instances, when I copy

test_case 

from Acrobat, and paste it in notepad, I get

test case

How to ensure that underscore is copied properly?

share|improve this question
7  
You have to use T1 encoded fonts (\usepackage[T1]{fontenc}), otherwise the underscore is emulated with a rule and is not a character. –  egreg Jan 30 '12 at 12:57
    
@willem: You can use \_ instead, and this will copy the underscore no problem such as: test\_case. Try this for yourself to see. –  night owl Jan 30 '12 at 13:00
1  
including \usepackage[T1]{fontenc} does the trick, both when using \textunderscore and when using \_. \_ doesn't work without using \usepackage[T1]{fontenc}. Perhaps post your fix as answer, as I didn't know that underscore gets emulated without T1? –  willem Jan 30 '12 at 13:24
add comment

1 Answer 1

up vote 6 down vote accepted

The fonts used with the "Original TeX" encoding (aka OT1) don't have an underscore character: they are only 7 bit fonts (128 characters) and some positions are hijacked to make room for more useful characters. For example in the position of the underscore there is the "dot accent", in place of < and > there are ¡ and ¿.

So with the default OT1 encoding, the command \textunderscore (or \_) is defined to produce a small rule, which is not recognized by PDF viewers as a character.

The problem doesn't show when T1 encoded fonts are used, because this encoding has all the printable ASCII characters in their slots. So the answer is

\usepackage[T1]{fontenc}

Make sure to have available the CM-Super font package, or the T1 fonts will be in bitmap form. An alternative is to use also

\usepackage{lmodern}

since the Latin Modern fonts are almost the same as the European Modern that are chosen by default with T1 and are surely available as Type1 fonts.

share|improve this answer
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.