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 using copy paste from the PDF generated from my Latex document, the text comes out garbled. What could be causing this?

This is an example of the original text:

At last, and taking the risk a being too abstract, I should point out that evolutionary algorithms are inspired by nature's evolutionary process. This is a good opportunity to gain some insight how deeply can that metaphor hold. Specially since life itself is less a phenomena of optimising functionality but more of getting good results with what you already have while not becoming too sensitive to internal and external variation. This last aspect must not stand in the way of obtaining phenotypes with biological interest but is relevant nonetheless.

And this is the garbled copy-paste:

❆t ❧❛st✱ ❛♥❞ t❛❦✐♥❣ t❤❡ r✐s❦ ❛ ❜❡✐♥❣ t♦♦ ❛❜str❛❝t✱ ■ s❤♦✉❧❞ ♣♦✐♥t ♦✉t t❤❛t ❡✈♦❧✉t✐♦♥❛r2 ❛❧❣♦r✐t❤♠s ❛r❡ ✐♥s♣✐r❡❞ ❜2 ♥❛t✉r❡✬s ❡✈♦❧✉t✐♦♥❛r2 ♣r♦❝❡ss✳ ❚❤✐s ✐s ❛ ❣♦♦❞ ♦♣♣♦rt✉♥✐t2 t♦ ❣❛✐♥ s♦♠❡ ✐♥s✐❣❤t ❤♦✇ ❞❡❡♣❧2 ❝❛♥ t❤❛t ♠❡t❛♣❤♦r ❤♦❧❞✳ ❙♣❡❝✐❛❧❧2 s✐♥❝❡ ❧✐❢❡ ✐ts❡❧❢ ✐s ❧❡ss ❛ ♣❤❡♥♦♠❡♥❛ ♦❢ ♦♣t✐♠✐s✐♥❣ ❢✉♥❝t✐♦♥❛❧✐t2 ❜✉t ♠♦r❡ ♦❢ ❣❡tt✐♥❣ ❣♦♦❞ r❡s✉❧ts ✇✐t❤ ✇❤❛t 2♦✉ ❛❧r❡❛❞2 ❤❛✈❡ ✇❤✐❧❡ ♥♦t ❜❡❝♦♠✐♥❣ t♦♦ s❡♥s✐t✐✈❡ t♦ ✐♥t❡r♥❛❧ ❛♥❞ ❡1t❡r♥❛❧ ✈❛r✐❛t✐♦♥✳ ❚❤✐s ❧❛st ❛s♣❡❝t ♠✉st ♥♦t st❛♥❞ ✐♥ t❤❡ ✇❛2 ♦❢ ♦❜t❛✐♥✐♥❣ ♣❤❡♥♦t2♣❡s ✇✐t❤ ❜✐♦❧♦❣✐❝❛❧ ✐♥t❡r❡st ❜✉t ✐s r❡❧❡✈❛♥t ♥♦♥❡t❤❡❧❡ss✳

The commands I run to generate the pdf are:

    pdflatex thesis.tex
    bibtex thesis
    pdflatex thesis.tex
    pdflatex thesis.tex

I am using the debian packages from debian wheezy.

This is the minimum example with the problem.

\documentclass{article}

% The Unicode character encoding UTF8 includes several special characters and characters with accents.
% The following code specifies that the encoding of the LaTeX document source file is UTF8.
% Font encoding is specified as T1, because it supports the encoding of extended character sets in fonts.
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

\title{A optimisation tool for the functional improvement\\ of Biological Models}
\begin{document}

Some garbled text with an accented à.

Some garbled text.

\end{document}
share|improve this question
1  
Are you loading the fontenc package; for example, \usepackage[T1]{fontenc}? –  Gonzalo Medina Sep 17 '12 at 13:51
    
You should post a minimal example which reproduces the error. Probably interesting are fontenc, cmap, and your used font. Also maybe your pdf reader. –  Juri Robl Sep 17 '12 at 13:52
1  
A MWE (minimal (non)Working Example) would be really useful. –  Gonzalo Medina Sep 17 '12 at 13:59
2  
No, you should really use fontenc. See here –  Juri Robl Sep 17 '12 at 14:09
1  
@AlexandreMartins Your example works fine for me. Maybe it's a problem with your pdf reader. Have you tried another one? (I included fontenc in the test). –  Juri Robl Sep 17 '12 at 14:12
show 5 more comments

1 Answer

up vote 12 down vote accepted

It depends on the fonts that you are using:

pdffonts test.pdf

Type 3 fonts

Try to avoid them, because they are bitmapped fonts that do not scale well. Also the characters do not have glyph names that make it easier for text extraction tools.

If you are using \usepackage[T1]{fontenc} with standard fonts, then you get the EC fonts. Install cm-super to get the Type 1 versions. Alternatively use the successor fonts Latin Modern (\usepackage{lmodern}).

Package cmap

It is based on LaTeX's font encodings and adds map entries from slot positions to Unicode slots.

The package should be loaded at the very beginning:

\RequirePackage{cmap}
\documentclass{...}

The package does not depend on correct glyph names in the font or the font type. On the other side, undefined encodings (for symbol fonts, …) are not well supported.

\pdfgentounicode

This primitive of pdfTeX adds the Unicode mapping based on font glyph names. It does not work for Type 3 fonts. The support is better if the fonts contain the correct glyph names and a mapping is provided.

Usage:

\pdfgentounicode=1 %
\input glyphtounicode.tex %

The file glyphtounicode.tex contains predefined mappings for many glyhp names to Unicode.

Package accsupp

The package uses the /ActualText feature of PDF that allows to say what text should be used for the displayed glyphs. This allows the support and finer control of symbols, for example.

PDF viewer/text extractor

Also it depends on the PDF viewer or tool that extracts the text, what features they support to detect the characters. Some might only work with glyph names and slot positions, others support the Unicode mappings (they should) and more advanced support the /ActualText feature.

Addition: Package cmap and the method \pdfgentounicode should not be used together, because they add the same data structures to the fonts in the PDF file. If these are the same exactly it would not be too much of a problem, but there might be differences and this violates the PDF structure causing unpredictable behavior of the PDF reader applications that are free to choose, which value they use for the same key.

share|improve this answer
    
Should you use cmap together with glyphtounicode, or only one of them? –  Juri Robl Sep 17 '12 at 14:17
1  
And installing cm-super solves the problem and makes copy-paste work well with all the pdf viewers I tried. Evince, PDF-XChange and Okular –  Alexandre Martins Sep 17 '12 at 14:54
    
@HeikoOberdiek Just one question. Is there any advantage in using lmodern instead of cm-super? –  Alexandre Martins Sep 17 '12 at 14:56
    
Thanks for the thorough listing of options and possibilities @HeikoOberdiek. And here is an answer to my own question tex.stackexchange.com/questions/1390/latin-modern-vs-cm-super . –  Alexandre Martins Sep 17 '12 at 15:32
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.