9

For quite a while I am having the problem that copying and searching from my PDFs is a bit difficult as ligatures are not properly translated. I am using XeLaTeX with Libertine/Biolinum.

I am a simple user, so I tried workarounds I found on the internet (Make ligatures in Linux Libertine copyable (and searchable) - \pdfglyphtounicode with XeTeX - Can PDF search find words with ligatures in XeLaTeX-documents?) but all of this doesn't work.

Here's my MWE

%!TEX TS-program = xelatex 
%!TEX encoding = UTF-8 Unicode 
\documentclass{scrreprt}
\usepackage{fontspec}
%\defaultfontfeatures{Ligatures=Historic}
%\setmainfont{Linux Libertine O}
\usepackage{libertine}
\begin{document}
fluffier soufflé fisticuffs fb fh ffh fj ffj fk ffk ft fft tt Qu Th ch ck ct
\end{document}

Which renders

u er sou é sticu s ch ck ct

for the above and

u er sou é icu s ch ck

when I use the historic ligatures.

Using \input{glyphtounicode} workaround I get:

Undefined control sequence. l.7 \pdfglyphtounicode{A}{0041}

Using \usepackage[t1]{fontenc} I get:

/usr/local/texlive/2014/texmf-dist/tex/latex/base/fontenc.sty:100: LaTeX Error: Encoding scheme `t1' unknown.

See the LaTeX manual or LaTeX Companion for explanation.

Type H for immediate help.

l.100 \fontencoding\encodingdefault\selectfont

Experimenting with other fonts shows very mixed results, so while it's obviously possible that the problem is in the fonts, is there something, anything, I can do to work around this and still keep ligatures?

Something like the above-mentioned

\input{glyphtounicode}

\pdfglyphtounicode{f_f}{FB00}

where I could "translate" the ligatures by hand - the above doesn't work for me, though.

13
  • 2
    If I compile your very example, select the words in my PDF previewer and paste, I get what you can see here: fluffier soufflé fisticuffs fb fh ffh fj ffj fk ffk ft fft tt Qu Th ch ck ct
    – egreg
    Commented Jan 21, 2016 at 13:29
  • It depends on where you paste the text. A while ago it happened to me with certain ligatures, and nowadays it still occurs with accents appearing as ’e but it only occurs in some editors. If you paste it somewhere else and then copy it back, it works fine.
    – ienissei
    Commented Jan 21, 2016 at 13:35
  • 1
    @egreg - In a way I am glad to hear that, what am I doing wrong then? I am using the latest Libertine fonts (well, they haven't been updated for ages, but still) and "This is XeTeX, Version 3.14159265-2.6-0.99991 (TeX Live 2014)" BTW, I am on OSX.
    – Thorsten
    Commented Jan 21, 2016 at 17:03
  • My try was with TL 2015, but if I do the same with TL 2014, I paste here like this: fluffier soufflé fisticuffs fb fh ffh fj ffj fk ffk ft fft tt Qu Th ch ck ct
    – egreg
    Commented Jan 21, 2016 at 17:07
  • 1
    @jan I can also reproduce Thorsten’s problem on a Mac using either Skim or Preview. However, in Acrobat Reader everything works as it should, and I can correctly copy and paste ligatures. Commented Feb 1, 2018 at 23:06

1 Answer 1

3

Try adding \XeTeXgenerateactualtext=1 at the start of your document.

(IIRC, I think this requires XeTeX from TeX Live 2016 or later, or an equivalent from other distributions such as MikTeX; and the result of copy/paste will also depend on the PDF reader used, as not all PDF viewers support ActualText annotations.)

1
  • This answer worked for me and solved a long standing problem that I faced when copying Devanagari letters from the XeLaTeX generated PDF into an Unicode-aware text editor. Thanks a lot @jfkthame !!
    – vrgovinda
    Commented Jul 14, 2021 at 6:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .