11

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[linktoc=all,frenchlinks,pdfborderstyle={/S/U/W .5},citebordercolor={1 1 1},linkbordercolor={1 1 1},urlbordercolor={1 1 1}]{hyperref}

\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[linktoc=all,frenchlinks,pdfborderstyle={/S/U/W .5},citebordercolor={1 1 1},linkbordercolor={1 1 1},urlbordercolor={1 1 1}]{hyperref}

\usepackage{xstring} % added as suggested in 1st given answer
\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}
3

1 Answer 1

12
  • 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
2
  • 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? Commented Dec 30, 2013 at 22:24
  • Heiko, there may be very few people who can add more detail on this, any help would be sincerely appreciated! Commented Jan 5, 2014 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .