This is a follow-up question to Is it possible to provide alternative text to use when copying text from the PDF?.
I am essentially trying to redefine textsc/scshape in order to use accsupp automatically, i.e. that the copied text is in uppercase automatically. I've been playing around with the textcase package, but without success:
\documentclass{article}
\usepackage{accsupp}
\RequirePackage{textcase}
\begin{document}
\newcommand{\newsc}[1]{
{\scshape{%
\BeginAccSupp{method=escape,ActualText=#1}%
\MakeTextLowercase{#1}%
\EndAccSupp{}}%
}}
\newsc{This could be} the beginning of a chapter
But there is a \newsc{mysterious} whitespace
\end{document}
What I would want is to wrap ActualText=#1 into something like ActualText=\MakeTextUppercase{#1}, but that does not work as I get a Generic error: undefined control sequence.
There are a few more issues:
there is a whitespace before text wrapped in the
\newsccommandI am unsure how to redefine the small caps commands to incorporate the new feature (hence I created a new command in the MWE)
In the quoted answer Ulrike mentions something like
\expandafter\PDFreplace\expandafter{\USA}to make the text selectable for each character. How would that work with my example?
Edit: I just realised that this approach breaks completely when trying to use accsupp in headings in conjunction with hyperref. The error is:
! Extra \else.
\KV@split ...errx {\@tempa \space undefined}\else
\ifx \@empty #3\@empty \KV...
l.27 ...This could be} the beginning of a chapter}

\def\USA{usa}you have to use\expandafter\textsc\expandafter{\USA}– Mar 29 '12 at 12:50