This is kind of a follow-up question to a question I asked some months ago. I use XeLaTeX
with scrbook
class and Cambria as a font. Since Cambria lacks small caps, text in small caps cannot be searched or copy/pasted in/from the PDF. To overcome this, the primitive \XeTeXgenerateactualtext=1
can be used. This works excellent but produces strange and deficient selecting boxes upon searching or marking text in the PDF. (As pointed out here, this seems to be dependent on the PDF reader used. I use Acrobat Reader DC.)
Because this behavior might be irritating to readers (it purports that the text can't be copy/pasted, although it works unproblematically despite the flawed selecting boxes), I decided to give the solution with accsupp package
another try. So I redefined \textsc
the following way:
\let\oldtextsc\textsc
\newcommand*{\copyablesc}[1]{%
\BeginAccSupp{%
method=escape,
ActualText=\detokenize{#1},%
}%
\oldtextsc{#1}%
\EndAccSupp{}%
}
\renewcommand{\textsc}[1]{\copyablesc{#1}}
This works excellent when small caps are used in normal text. But now I realized that it produces a strange output when small caps occur in the bibliography as I use it for names. This is the full MWE:
\documentclass[%
fontsize=11pt,%
ngerman,
]{scrbook}
\usepackage{fontspec}
\setmainfont[Ligatures={NoCommon}]{Cambria}
%\XeTeXgenerateactualtext=1
\usepackage{accsupp}
\usepackage[
backend=biber,
bibwarn=true,
texencoding=auto,
bibencoding=auto,
bibstyle=chem-angew,
citestyle=chem-angew,
sorting=none,
language=german,
]{biblatex}
\ExecuteBibliographyOptions{
doi=false,
eprint=false,
firstinits=true,
isbn=true,
maxnames=999,
maxcitenames=2,
pageranges=true,
url=true,
}
% small caps for authors/editors:
\renewcommand*{\mkbibnamefamily}[1]{\textsc{#1}}
\addbibresource{MWE.bib}
\usepackage{hyperref}
% copyable small caps:
\let\oldtextsc\textsc
\newcommand*{\copyablesc}[1]{%
\BeginAccSupp{%
%method=pdfstringdef,
%method=plain,
method=escape,
ActualText=\detokenize{#1},%
%ActualText={#1},%
}%
\oldtextsc{#1}%
\EndAccSupp{}%
}
\renewcommand{\textsc}[1]{\copyablesc{#1}}
% names in small caps:
\newcommand{\name}[1]{\textsc{#1}}
\begin{document}
\mainmatter
Die Geschwister \name{Mustermann} sind Koryphäen auf dem Gebiet der Beispiele.\cite{Buch}
Die Forschungen im Arbeitskreis um \name{Doe} bauen auf diese Erkenntnisse auf.\cite{Artikel}
\printbibliography
\end{document}
This is my MWE.bib:
@Book{Buch,
author = {Erika Mustermann and Max Mustermann},
title = {Das große Buch der Beispiele},
year = {1994},
editor = {Kovács János and Fulanita {de Tal}},
edition = {3., erw. und überarb. Aufl.},
publisher = {Bsp-Verlag},
location = {Hintertupfingen},
isbn = {0-08150815},
}
@Article{Artikel,
author = {{Dampf in allen Gassen}, Hans and Normal-Verbraucher, Otto and Müller, Lieschen and Doe, Jane},
title = {Beispiele trivialisieren},
journal = {Zeitschrift für belanglose Beispiele},
year = {2015},
volume = {97},
number = {4},
pages = {08--15},
issn = {1234-5678},
url = {https://www.merriam-webster.com/dictionary/example},
urldate = {2018-03-16},
}
When I copy the bibliography from the PDF generated using method=escape
for accsupp
and paste it into Word I get this:
[1] E. \namepartfamily , M. \namepartfamily , Das große Buch der Beispiele, 3., erw. und überarb. Aufl., (Hrsg.: K. \namepartfamily , F. \namepartfamily ), Bsp-Verlag, Hintertupfingen, 1994, \MakeLowercase {ISBN}: 0- 08150815.
So somehow accsupp
is detokenizing the commands biblatex
uses to generate the author and editor names. The output with method=plain
is similar. With method=pdfstringdef
I get this:
[1] E. 洀攀瀀愀爀琀昀愀洀椀氀礀 , M. 洀攀瀀愀爀琀昀愀洀椀氀礀 , Das große Buch der Beispiele, 3., erw. und überarb. Aufl., (Hrsg.: K. 洀攀瀀愀爀琀昀愀洀椀氀礀 , F. 洀攀瀀愀爀琀昀愀洀椀氀礀 ), Bsp-Verlag, Hintertupfingen, 1994, 䵡欀攀䰀漀眀攀爀挀愀猀攀 笀䤀匀䈀一紀: 0- 08150815.
Beside copy/pasting, the author names are of course not found when searching them in the PDF. So instead of ActualText=\detokenize{#1}
I tried ActualText={#1}
with the hope that this would give me the plain text instead of the biblatex
commands. But then I get a lot of error messages like ! Use of \\blx@imc@printfield doesn't match its definition.
and ! Illegal parameter number in definition of \ACCSUPP@ActualText.
However, this compiles without problems, when I exclude the bibliography. So it has to do something with biblatex
and the way it processes the names.
Does anyone have an idea how to overcome this? Am I missing an option for accsupp
? Do you have any idea how to make the small caps in the bibliography searchable and copyable?
PS: If anyone has an idea how to fix the selecting boxes for \XeTeXgenerateactualtext=1
please let me know, because this would be the easiest solution.