# Create alternative uppercase text automatically with accsupp

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 \newsc command

• I 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}

-

There is a trailing space right after your definition. Use it this way:

\documentclass{article}
\usepackage{accsupp}
\usepackage{textcase}
\newcommand\newsc[1]{%
{\scshape%
\BeginAccSupp{method=escape,ActualText=#1}%
\MakeTextLowercase{#1}%
\EndAccSupp{}}}
\let\textsc\newsc

\begin{document}
\newsc{This could be} the beginning of a chapter

But there is a \textsc{Mysterious} whitespace

\end{document}


-
Thanks. One problem solved, only three more to go :-) –  Jörg Mar 29 '12 at 12:09
@Jörg: two solved ;-) –  Herbert Mar 29 '12 at 12:12
I do not undestand your \USA problem. –  Herbert Mar 29 '12 at 12:23
Thats the smallest issue. When you use accsupp like in your MWE you can only select the full word, and not each character. @josefec apparently solved that with a hint from Ulrike, but I don't understand the solution from the comments. –  Jörg Mar 29 '12 at 12:28
I just realised that this approach breaks completely when trying to use accsupp in headings in conjunction with hyperref... –  Jörg Mar 29 '12 at 13:56