# /ActualText in small cap hyperlinks

I'm using the frenchlinks option for hyperref, which due to solicitous care of XeLaTeX + Linux Libertine, gives bona fide small-caps links on the page. The problem is, when I cut and paste out of the generated PDF, I get Unicode small-caps out, whereas I'd prefer ASCII.

Can anyone suggest how to modify this MWE? (Did I make a mistake in the setup?)

Note, for the updated MWE, I've tried to patch \href using the accepted answer from Patching arguments inside a macro (no dice).

Updated MWE

\documentclass[article, a4paper, 12pt, oneside]{memoir}

\usepackage{xunicode}
\usepackage[MnSymbol]{mathspec}
%\defaultfontfeatures{Mapping=tex-text}

\setmainfont[Mapping= tex-text,
SmallCapsFont={Linux Libertine O},
SmallCapsFeatures= {Color=FFFFFF, RawFeature={+smcp,+hlig,+dlig}},
BoldFont={Linux Biolinum O Bold},
%     BoldFeatures={Color = FFFFFF,SmallCapsFont={Linux Libertine Capitals O Bold},%
%       SmallCapsFeatures = { Color=FFFFFF,   RawFeature={+smcp,+hlig,+dlig}} },
ItalicFont={Linux Libertine O Italic},
ItalicFeatures={Color = FFFFFF,  %
SmallCapsFont={Linux Libertine Capitals O Italic}, %
SmallCapsFeatures = {Color=FFFFFF}},
BoldItalicFont={Linux Biolinum O},
BoldItalicFeatures={ Color = FFFFFF, %
SmallCapsFont={Linux Libertine Capitals O Bold Italic},  %
SmallCapsFeatures = { Color=FFFFFF,RawFeature={+smcp,+hlig,+dlig}}} ]{Linux Libertine O}

\usepackage{xstring}
\usepackage{accsupp}

\usepackage{etoolbox}
\catcode\#=12
\newcommand{\newhref}{%
\normalexpandarg%
\patchcmd{\href}{#2}{%
\BeginAccSupp{method=pdfstring,ActualText={#2}}%
#2%
\EndAccSupp{}%
}{}{}%
}
\catcode\#=6

\begin{document}

Sexy tex: \newhref{http://tex.stackexchange.com}{sxe}.

\end{document}


Original MWE

\documentclass[article, a4paper, 12pt, oneside]{memoir}

\usepackage{xunicode}
\usepackage[MnSymbol]{mathspec}
%\defaultfontfeatures{Mapping=tex-text}

\setmainfont[Mapping= tex-text,
SmallCapsFont={Linux Libertine O},
SmallCapsFeatures= {Color=FFFFFF, RawFeature={+smcp,+hlig,+dlig}},
BoldFont={Linux Biolinum O Bold},
%     BoldFeatures={Color = FFFFFF,SmallCapsFont={Linux Libertine Capitals O Bold},%
%       SmallCapsFeatures = { Color=FFFFFF,   RawFeature={+smcp,+hlig,+dlig}} },
ItalicFont={Linux Libertine O Italic},
ItalicFeatures={Color = FFFFFF,  %
SmallCapsFont={Linux Libertine Capitals O Italic}, %
SmallCapsFeatures = {Color=FFFFFF}},
BoldItalicFont={Linux Biolinum O},
BoldItalicFeatures={ Color = FFFFFF, %
SmallCapsFont={Linux Libertine Capitals O Bold Italic},  %
SmallCapsFeatures = { Color=FFFFFF,RawFeature={+smcp,+hlig,+dlig}}} ]{Linux Libertine O}

\usepackage{accsupp}

\let\hrefold\href
\newcommand*{\hrefnew}[2]{%
\normalexpandarg%
\BeginAccSupp{method=plain,unicode,ActualText={#2}}%
\hrefold{#1}{#2}%
\EndAccSupp{}%
}

\begin{document}

Sexy tex: \href{http://tex.stackexchange.com}{sxe}.

\end{document}

• – Joe Corneli Dec 30 '13 at 18:04
• The only PDF viewer that understands \AccSupp that I know of is Adobe Reader. Are you using it? – egreg Dec 30 '13 at 18:23
• Some people here say it works in Evince, which is what I'm using: tex.stackexchange.com/questions/149581/… (I tested the original MWE on Adobe Reader too, for good measure). – Joe Corneli Dec 30 '13 at 22:27

• The macro \hrefnew is defines with the new feature /ActualText, but the body is using the unmodified \href.

• Macro \href is using the undefined \normalexpandarg that comes from package xstring that is not loaded.

• If method plain with option unicode is used, then the argument must be a valid UTF-16BE string. In this case I would let hyperref do the right conversion by using method pdfstringdef:

\BeginAccSupp{method=pdfstringdef,ActualText={#2}}


\href is not a good candidate for redefining, because of its special treatment of the first argument that is read with changed catcodes. Therefore a better candidate is the internal \href@:

\makeatletter
\let\href@old\href@
\renewcommand*{\href@}[2]{%
\href@old{#1}{%
\BeginAccSupp{%
method=pdfstringdef,%
ActualText={#2},%
}%
#2%
\EndAccSupp{}%
}%
}
\makeatletter

• I've tried to fix the MWE, but modifying the original \href seems like a challenge, could you give me some suggestion about how to do that? – Joe Corneli Dec 30 '13 at 22:24
• Heiko, there may be very few people who can add more detail on this, any help would be sincerely appreciated! – Joe Corneli Jan 5 '14 at 19:35