
當我打開由 firefox 等產生的 pdf 時pdflatex
,將滑鼠懸停在參考上時的 URL 顯示內部 bibkey。我怎樣才能防止這種情況發生?
考慮以下 MWE:
特克斯
\documentclass{article}
\usepackage[backend=biber]{biblatex}
\addbibresource{bib.bib}
\usepackage{hyperref}
\begin{document}
Test\cite{secretbibkey}
\printbibliography
\end{document}
圍脖圍脖
@article{secretbibkey,
author = {Joe},
title = {Just a title},
number = {ABCD-E/2008/ab/1234},
institution = {University},
year = {2008}
}
現在來看看下面的截圖:
它顯示了我將滑鼠懸停在引文上時使用的 bibkey(顯然螢幕截圖不包括我的遊標,但它位於綠色“1”上方)。有沒有辦法對這些 URL 金鑰進行隨機化/匿名化?
答案1
你可以嘗試這樣的事情。我不確定是否可以\int_to_alpha
處理目標中可能出現的所有字元和輸入,以及它是否可以導致相同的目標,但它是我目前找到的最好的可擴展函數。它將打亂所有目的地,甚至是分段和標籤的目的地。僅打亂號碼布密鑰需要對代碼進行大量更改biblatex
。
\documentclass{article}
\usepackage[backend=biber]{biblatex}
\addbibresource{test.bib}
\usepackage{hyperref}
\ExplSyntaxOn
\cs_new:Npn \pix_scrample_dest:n #1 {\int_eval:n{\int_from_alph:n{#1} + 2}} %2= secret number
\def\HyperDestNameFilter#1{\exp_args:Ne\tl_map_function:nN {#1}\pix_scrample_dest:n}
\ExplSyntaxOff
\begin{document}
Test\cite{secretbibkey}
\printbibliography
\end{document}
答案2
如果您想隱藏所有內部標籤,Ulrike's回答更好,但這裡有一種僅混淆透過biblatex
MD5 哈希創建的連結的方法(我相信 MD5 哈希不再推薦用於任何安全關鍵的東西,但它可能足以滿足您的目的)。
\blx@mdfivesum
這裡使用的命令需要相對較新的biblatex
版本。如果你被舊的困住了biblatex
,請裝載\usepackage{pdftexcmds}
自己並說出來\let\blx@mdfivesum\pdf@mdfivesum
。
這個想法是將所有連結命令從使用條目密鑰更改為條目密鑰的雜湊版本。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\protected\def\blx@anchor{%
\xifinlist{\the\c@refsection @\blx@mdfivesum{\abx@field@entrykey}}{\blx@anchors}
{}
{\listxadd\blx@anchors{\the\c@refsection @\blx@mdfivesum{\abx@field@entrykey}}%
\hypertarget{cite.\the\c@refsection @\blx@mdfivesum{\abx@field@entrykey}}{}}}%
\ifundef\hyper@natanchorstart
{\long\def\blx@bibhyperref[#1]#2{%
\blx@sfsave\hyperlink{cite.\the\c@refsection @\blx@mdfivesum{#1}}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@sfsave\hyperlink{cite.\the\c@refsection:\blx@mdfivesum{#1}}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@sfsave\hypertarget{cite.\the\c@refsection:\blx@mdfivesum{#1}}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}}%
{\long\def\blx@bibhyperref[#1]#2{%
\blx@sfsave\hyper@natlinkstart{\the\c@refsection @\blx@mdfivesum{#1}}\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@sfsave\hyper@natlinkstart{\the\c@refsection:\blx@mdfivesum{#1}}\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@sfsave\hyper@natanchorstart{\the\c@refsection:\blx@mdfivesum{#1}}\blx@sfrest
#2%
\blx@sfsave\hyper@natanchorend\blx@sfrest}}}
\makeatother
\addbibresource{biblatex-examples.bib}
\begin{document}
\autocite{sigfridsson,worman,geer,nussbaum}
\printbibliography
\end{document}
如果您喜歡數字指示符(與上面的雜湊不同,它根本不是從輸入鍵派生的),請使用以下命令
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{hyperref}
\makeatletter
\newcounter{blx@refnocount}
\newcommand*{\blx@getrefnocount}[1]{%
\xifinlistcs{#1}{blx@refcounts@\the\c@refsection}
{}
{\stepcounter{blx@refnocount}%
\csnumgdef{blx@refcount@\the\c@refsection @#1}{\value{blx@refnocount}}%
\listcsxadd{blx@refcounts@\the\c@refsection}{#1}}%
\letcs\blx@thisrefcount{blx@refcount@\the\c@refsection @#1}}
\AtBeginDocument{%
\ifundef\hyper@natanchorstart
{\protected\def\blx@anchor{%
\xifinlist{\the\c@refsection @\abx@field@entrykey}{\blx@anchors}
{}
{\listxadd\blx@anchors{\the\c@refsection @\abx@field@entrykey}%
\blx@getrefnocount{\abx@field@entrykey}%
\hypertarget{cite.\the\c@refsection @blxlinkno\blx@thisrefcount}{}}}%
\long\def\blx@bibhyperref[#1]#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hyperlink{cite.\the\c@refsection @blxlinkno\blx@thisrefcount}
{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hyperlink{cite.\the\c@refsection:blxlinkno\blx@thisrefcount}
{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hypertarget{cite.\the\c@refsection:blxlinkno\blx@thisrefcount}
{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}}%
{\protected\def\blx@anchor{%
\xifinlist{\the\c@refsection @\abx@field@entrykey}{\blx@anchors}
{}
{\listxadd\blx@anchors{\the\c@refsection @\abx@field@entrykey}%
\blx@getrefnocount{\abx@field@entrykey}%
\hyper@natanchorstart{\the\c@refsection @blxlinkno\blx@thisrefcount}%
\hyper@natanchorend}}%
\long\def\blx@bibhyperref[#1]#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hyper@natlinkstart{\the\c@refsection @blxlinkno\blx@thisrefcount}%
\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hyper@natlinkstart{\the\c@refsection:blxlinkno\blx@thisrefcount}%
\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@getrefnocount{#1}%
\blx@sfsave
\hyper@natanchorstart{\the\c@refsection:blxlinkno\blx@thisrefcount}%
\blx@sfrest
#2%
\blx@sfsave\hyper@natanchorend\blx@sfrest}}}
\makeatother
\addbibresource{biblatex-examples.bib}
\begin{document}
\autocite{sigfridsson,worman,geer,nussbaum}
\printbibliography
\autocite{sigfridsson,worman,geer,nussbaum}
\end{document}
答案3
您可以使用一些命令列工具對已建立的 pdf 進行後處理,以搜尋引用鍵並在 pdf 來源中取代它們。
首先,您需要解壓縮 pdf 以允許文字搜尋和替換,例如使用pdftk
.
在未壓縮的 pdf 中,連結如下所示:
3 0 obj
<<
/Border [0 0 1]
/Subtype /Link
/H /I
/Type /Annot
/C [0 1 0]
/Rect [169.08 653.748 176.054 665.704]
/A
<<
/D (cite.0@secretbibkey)
/S /GoTo
>>
>>
endobj
以及下面的相應部分:
34 0 obj
<<
/Names [(Doc-Start) 22 0 R (cite.0@secretbibkey) 21 0 R (page.1) 14 0 R (section*.1) 18 0 R]
/Limits [(Doc-Start) (section*.1)]
>>
endobj
現在您可以獲得grep
模式的來源/D (cite.0@[some key])
並僅儲存關鍵部分。
然後,循環遍歷所有金鑰,您可以產生替換金鑰,例如校驗和md5
(可以合理地預期每個金鑰都是唯一的)。
接下來,您可以使用 替換所有出現的按鍵sed
。
在循環結束時,您重新壓縮 pdf,pdftk
然後就完成了。
完整腳本(使用 呼叫bash myscript.sh mypdf.pdf
):
pdftk $1 output "raw$1" uncompress
grep -aoP "\/D \(\Kcite.0@[^\)]+(?=\))" "raw$1" | while read -r line ; do
echo $line
citehash=`echo $line|md5sum|awk '{ print $1 }'`
sed -i "s/$line/$citehash/g" "raw$1"
done
pdftk "raw$1" output $1 compress
Firefox 中產生的連結工具提示:
額外的好處:該連結仍然有效。