I have several issues with searching and/or copy-pasting text from my PDF created with XeLaTex. Consider the following MWE, the PDF search gives me no results for certain words.
\documentclass[%
headsepline,
footsepline,
twoside,
numbers=noenddot,
fontsize=11pt]{scrbook}
\usepackage[a4paper]{geometry}%
\usepackage{fontspec}
\setmainfont{Cambria}
\makeatletter\chardef\l@nohyphenation=255 \makeatother
\usepackage[ngerman=nohyphenation]{hyphsubst}
\usepackage[ngerman]{babel}
\usepackage{microtype}
\newcommand{\name}[1]{\textsc{#1}}
\begin{document}
\sloppy
\name{Albert Einstein} veröffentlichte 1905 die spezielle
und 1916 die allgemeine Relativitätstheorie.
Aus dem Relativitätsprinzip folgt unmittelbar, dass es keine Möglichkeit gibt,
eine absolute Geschwindigkeit eines Beobachters im Raum zu ermitteln
und damit ein absolut ruhendes Bezugssystem zu definieren.
Übersetzt man die Beobachtungen des ruhenden Beobachters über eine
\name{Lorentz}-Transformation in die des Bewegten, so stellt sich heraus,
dass dieser neben der elektrischen Kraft eine weitere, magnetische, Kraft wahrnimmt.
\end{document}
Words with small caps are not found, I guess, because there is no definition of a font "Cambria-smallcaps" or something like that. I get searchable and copyable small caps in the PDF, when I use another font which has small caps defined, for example, something like
\setmainfont[SmallCapsFont={Latin Modern Roman Caps}]{Cambria}
. However, I don't feel comfortable using several fonts in one document. So another method to achieve searchable and copyable small caps is to add this:\usepackage{accsupp} \newcommand*{\copyablesc}[1]{% \BeginAccSupp{% ActualText=\detokenize{#1},% method=escape, }% \textsc{\lowercase{#1}}% \EndAccSupp{}% }
With
\newcommand{\name}[1]{\copyablesc{#1}}
I now get the names in lowercase small caps. This means that the uppercase smallcaps i.e. capitalization (e.g. at beginning of the words/names) are ignored which is not what I want. Is there a way to define\copyablesc
in a way it functions/looks exactly like the usual\textsc
or another way to redefine\textsc
so that it is found in PDF search without changing the font?EDIT: I just recognized that I get the desired result by leaving
\lowercase
and just typing\textsc{#1}%
in the above code. I am sorry for the mistake.Words with ligatures (e.g. the "fi" in "definieren") are not found in the PDF and when I copy-paste them, I get a dummy symbol instead. I tried
cmap
andmmap package
and\input{glyphtounicode}
, but these don't work with XeLaTex. So the only way to make ligatures searchable/copyable obvioulsy is to switch them off completely with\setmainfont[Ligatures={NoCommon, Tex}]{Cambria}
. But I would really like to keep them because it looks nicer. Is there another way to keep ligatures and make them searchable/copyable in PDF?In contrary to ligatures, umlaute (ä, ö, ü) are somewhat treated like the behavior I would want for ligatures. This means, they behave like a melt of two signs.
When I copy-paste them from PDF into MS Word the uncapitalized umlaute (ä, ö, ü) are treated like letters with a math accent, meaning that in MS Word all words containing them are marked as spelled incorrectly and that when deleting them I have to delete the accent first and the letter second. When I search for umlaute (e.g. for "ö") in PDF, every "o" is found, which is not correct. These umlaute are single signs in German and should be treated as such. Searching for "ö" should find only "ö" and not "o".
Capitalized umlaute (Ä, Ö, Ü) are not searchable/copyable at all and copy-pasting results in "A, O, U", respectively, followed by a dummy sign.
So is there any way to tell XeLaTex to treat umlaute as one sign/ligature and turn them searchable/copyable as such?
\XeTeXgenerateactualtext=1
makes the small caps and ligatures searchable without the use of switching them off. As outlined here the selection boxes are located incorrectly. Nevertheless copy-pasting still works.