/ActualText 小寫超連結

/ActualText 小寫超連結

我正在使用frenchlinkshyperref 選項,由於 XeLaTeX + Linux Libertine 的細心照顧,它給出了善意頁面上的小型大寫字母連結。問題是,當我從生成的 PDF 中剪下並貼上時,我得到的是 Unicode 小寫字母,而我更喜歡 ASCII。

誰能建議如何修改這個 MWE? (我是不是設定錯了?)

請注意,對於更新的 MWE,我嘗試\href使用已接受的答案進行修補 修補宏內的參數 (沒有骰子)。

更新了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}

原始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}

答案1

  • 巨集\hrefnew是用新功能定義的/ActualText,但主體是使用未修改的\href

  • 巨集正在使用來自未載入的套件的\href未定義。\normalexpandargxstring

  • plain如果使用帶有選項的方法unicode,則參數必須是有效的UTF-16BE字串。在這種情況下,我將hyperref使用以下方法進行正確的轉換pdfstringdef

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

\href不是重新定義的好候選者,因為它對使用更改後的目錄程式碼讀取的第一個參數進行了特殊處理。因此,更好的候選人是內部\href@

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

相關內容