PDF 内の内部 bibkey を非表示にする

PDF 内の内部 bibkey を非表示にする

たとえば Firefoxで生成された PDF を開くとpdflatex、参照の上にマウスを置いたときの URL に内部 bibkey が表示されます。これを防ぐにはどうすればよいですか?

次の MWE を検討してください。

mwe.tex

\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を確認できるスクリーンショット 引用の上にマウスを置いたときに使用した bibkey が表示されます (スクリーンショットにはカーソルが含まれていませんが、緑色の「1」の上にありました)。これらの URL キーをランダム化/匿名化する方法はありますか?

答え1

このようなものを試すことができます。宛先に表示される可能性のあるすべての文字と入力を処理するかどうか、および同一の宛先につながるかどうかはわかりませんが\int_to_alpha、現時点ではこれが最も拡張可能な関数です。すべての宛先をスクランブルし、セクションとラベルへの宛先もスクランブルします。bib-key のみをスクランブルするには、コードにいくつかの変更を加える必要があります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の答えははるかに優れていますが、ここでは MD5 ハッシュを使用して作成されたリンクのみを難読化する方法を紹介しますbiblatex(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}

難読化されたリンクを含む PDF のスクリーンショット。


数値指定子(上記のハッシュとは異なり、エントリキーからはまったく派生しません)を使用する場合は、次のようにします。

\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 での結果リンクのツールチップ:

ここに画像の説明を入力してください

追加ボーナス: リンクはまだ機能します。

関連情報