将鼠标悬停在引文键上时,在弹出窗口中显示书目条目

将鼠标悬停在引文键上时,在弹出窗口中显示书目条目

我认为将书目条目显示为工具提示会很有用,这样读者就不会因为点击超链接或尝试查找书目而受到干扰,因此我创建了以下命令:

\newcommand\annocite[1]{\pdfmarkupcomment[markup=Underline,subject=Citation]
   {\parencite{#1}}{\fullcite{#1}}}

不幸的是,这不起作用。它没有在弹出窗口中显示书目条目,而只是显示引用键;也就是说,该\fullcite命令似乎没有效果。我相信问题与参数扩展有关。这是一个 MWE:

\documentclass{article}
\usepackage{biblatex,pdfcomment,filecontents}
\bibliography{\jobname}

\newcommand\annocite[1]{\pdfmarkupcomment[markup=Underline,subject=Citation]
    {\parencite{#1}}{\fullcite{#1}}}

\begin{filecontents}{\jobname.bib}
@article{Bli74,
  author = {Blinder, Alan S.},
  year = {1974},
  title = {The economics of brushing teeth},
  journaltitle = {Journal of Political Economy},
  volume = {82},
  number = {4},
  pages = {887--891},
}
\end{filecontents}

\begin{document}
Hover over this citation: \annocite{Bli74}

The tooltip should contain the following text: \fullcite{Bli74}

\end{document}

有人能想到一个解决方案,或者更好的方法来重新定义 biblatex 的引用命令(例如,\parencite\cite以自动执行此操作吗?

答案1

这个想法是利用精美工具提示包。我将以示意图的形式展示这个过程:为了使我的例子可供所有人编译,我将使用以下书目数据库(称为biblio.bib):

@book{goossens93,
    author = "Michel Goossens and Frank Mittlebach and Alexander Samarin",
    title = "The Latex Companion A",
    year = "1993",
    publisher = "Addison-Wesley",
    address = "Reading, Massachusetts"

}

@book{knuth79,
    author = "Donald E. Knuth",
    title = "Tex and Metafont, New Directions in Typesetting",
    year = {1979{(}1950{)}},
    publisher = "American Mathematical Society and Digital Press",
    address = "Stanford"
}

首先,您需要创建一个 .pdf 文件,其中包含\keytips 命令和包将使用的工具提示文本fancytooltips。要创建此.pdf文档,您可以使用 LaTeX:在此示例中,我使用了一个文件(名为bibtips.tex),其内容如下:

\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\usepackage[createtips]{fancytooltips}

\newcommand\MyTip[1]{%
  \keytip{#1}
  \fcolorbox{green!50!black}{yellow!20}{\parbox{\textwidth}{\fullcite{#1}}}\newpage%
}

\bibliography{biblio}

\begin{document}

\MyTip{goossens93}
\MyTip{knuth79}

\end{document}

您需要\MyTip对最终文档中每个包含工具提示的书目条目使用该命令。

以标准方式编译此文件: pdflatex+bibtex+pdflatex+pdflatex生成参考文献,每页一个,框架精美,并使用相应的 \keytip命令。生成的.pdf文件必须位于包含主.tex文件的同一目录中。

现在,您的主文档必须类似于以下内容(请注意,键的值filename正是.pdf上一步中获得的文件的名称):

\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\usepackage[filename=bibtips,mouseover]{fancytooltips}

\bibliography{biblio}

\begin{document}

\tooltip{\cite{goossens93}}{goossens93}

\tooltip{\cite{knuth79}}{knuth79}

\end{document}

以标准方式编译此文件: pdflatex+bibtex+pdflatex+pdflatex您将看到带有蓝色气球的引用;如果将鼠标指针移动到活动区域,将打开一个工具提示,显示与引用相对应的完整书目信息。

一些评论:

  1. 当然,您可以通过改变文件中引用的方式获得更漂亮的工具提示 bibtips.pdf

  2. 这种方法并不适用于所有 PDF 查看器,因为它需要与 JavaScript 配合;您必须使用 Adob​​e Reader 或 Adob​​e Acrobat 才能查看工具提示。

答案2

Gonzalo Medina 和 Audrey 都发布了一个绝佳的解决方案。不过现在事情变得简单多了。请参阅fancy-preview网页 - 基于fancytooltips(2012 年 5 月)的新版本preview.sty和一些 bash 脚本,您可以自动获得书目条目、定理、定义、显示方程式等的工具提示。

编辑:附有小示例和屏幕截图。

\documentclass{article}
\usepackage{amsmath,amsthm}
\newtheorem{lemma}{Lemma}
\usepackage{hyperref} % Important!
\begin{document}

\begin{lemma}[Lemma from \cite{M}]\label{lemma}
  If $k<0$, then
  \begin{equation}
    \label{eq:1}
    x^2+k<x^2
  \end{equation}
  for every real number $x$.
\end{lemma}

Inequality \eqref{eq:1} in Lema \ref{lemma} can be proved easily. Is
more general than \cite[Theorem 3.4]{K}.

\begin{thebibliography}{9}
\bibitem[M]{M} Me: My book related to the problem (2006), 145 p.
  % The new line is important!

\bibitem{K} Karl: Karl's paper published in some minor proceedings, 
    a local conferrence organized by his university (2005), 23--25.
  % The new line is important!


\end{thebibliography}
\end{document}

Adobe Reader 中的文件

在此处输入图片描述

参考文献

在此处输入图片描述

参考文献 1

在此处输入图片描述

等式(1)

在此处输入图片描述

引理 1。

在此处输入图片描述

答案3

在尝试了 Gonzalo 的精彩回答后,我做了一些调整。以下是摘要。

  • \nocite{*}工具提示创建。可以使用 etoolbox 中的、\AtDataInput和 列表处理命令轻松为给定 bib 文件中的每个条目创建工具提示。

  • 工具提示位置。默认情况下,无论活动区域位于何处,工具提示都会出现在演示文档的页面顶部。我们可以通过调整工具提示文档中的页面大小并使用选项movetips设置将每个工具提示移近其活动区域。

  • 引文命令。无需\tooltip直接发出命令,工具提示可以通过格式合并到现有引文命令中bibhyperref。带星号的变体\tooltip允许我们将引文链接和工具提示的活动区域分开。

下面是如何实现所有这些想法的一个例子。

% --- tooltips document
\begin{filecontents*}{bibtooltips.tex}
\documentclass{article}
\usepackage{xcolor}
\usepackage[createtips]{fancytooltips}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[maxnames=2]{biblatex}
\usepackage{geometry}

% Size page a little larger than the longest tooltip
\geometry{noheadfoot,nomarginpar,margin=0in,paperwidth=4in,paperheight=1in}
\pagestyle{empty}
\parindent=0pt

\DeclareCiteCommand{\keytipcite}
  {}
  {\null\vfill% Move tooltip to bottom of page
   \begin{center}
   \keytip{\thefield{entrykey}}%
   \fcolorbox{brown!50}{yellow!10}
     {\footnotesize\parbox{0.95\textwidth}
        {\usedriver
           {\clearfield{extrayear}% Omit extraneous fields here
            \clearfield{addendum}%
            \clearfield{subtitle}%
            \clearfield{titleaddon}%
            \clearfield{booksubtitle}%
            \clearfield{booktitleaddon}%
            \clearfield{mainsubtitle}%
            \clearfield{maintitleaddon}%
            \clearfield{issuesubtitle}%
            \clearfield{journalsubtitle}}
           {\thefield{entrytype}}}}%
   \end{center}
   \medskip% Leave space below tooltip to avoid obscuring text
   \newpage}
  {}
  {}

\def\allkeys{}
\AtDataInput{\listxadd{\allkeys}{\thefield{entrykey},}}

\addbibresource{biblatex-examples.bib}
\begin{document}
%\nocite{*}
\nocite{companion,cicero,baez/article,bertram,kant:kpv,kant:ku}
\nocite{aristotle:poetics,aristotle:rhetoric,aristotle:anima}
\forlistloop{\keytipcite}{\allkeys}
\end{document}
\end{filecontents*}
% --- end of tooltips document

% --- presentation document
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[filename=bibtooltips,mouseover,movetips]{fancytooltips}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=numeric-comp]{biblatex}
\usepackage{hyperref}
\hypersetup{colorlinks,citecolor=Blue}
\definecolor{tooltipcolor}{named}{Green}

% Display nothing in "extratext" area following the tooltip (by default this
% area displays a speech bubble/balloon)
\let\TooltipExtratext\relax

% Apply tooltip to "extratext" area just after inline citation links
\DeclareFieldFormat{bibhyperref}{%
  \tooltip*{\bibhyperref{#1}}{\thefield{entrykey}}}

% Define new citation commands that replace citation links with tooltips
\DeclareFieldFormat{bibtooltip}{\tooltip{#1}{\thefield{entrykey}}}
\newrobustcmd*{\tooltiphook}{%
  \AtNextCite{\DeclareFieldAlias{bibhyperref}{bibtooltip}}}
\newrobustcmd*{\tooltipcite}{\tooltiphook\cite}
\newrobustcmd*{\tooltipcites}{\tooltiphook\cites}

% Apply tooltip to instance where numeric-comp uses \bibhyperref instead
% of bibhyperref format
\makeatletter
\newbibmacro*{cite:dump:tooltip}{%
  \ifnumgreater{\value{cbx@tempcnta}}{0}
    {\ifnumgreater{\value{cbx@tempcnta}}{1}
       {\bibrangedash}
       {\multicitedelim}%
     \tooltip*
       {\bibhyperref[\cbx@lastkey]{%
          \ifdef\cbx@lastprefix
            {\printtext[prefixnumber]{\cbx@lastprefix}}
            {}%
          \printtext[labelnumber]{\cbx@lastnumber}}}
       {\cbx@lastkey}}
    {}%
  \setcounter{cbx@tempcnta}{0}%
  \global\undef\cbx@lastprefix}
\ifcsundef{abx@macro@\detokenize{cite:dump}}
  {}{\renewbibmacro*{cite:dump}{\usebibmacro{cite:dump:tooltip}}}
\makeatother

\addbibresource{biblatex-examples.bib}
\begin{document}
\null\vfill
\subsection*{Inline citations}
\textcite[10--15]{companion} showed that...
\textcites[10]{companion}[1-10]{cicero}{}{kant:kpv,kant:ku}.
Filler text \parencites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text.\supercite{bertram}
\subsection*{Footnote citations}
Filler text.\footcites{cicero}{companion}
Filler text.\footnote{See \smartcite{cicero}.}
\subsection*{More inline citations}
\textcites[10--15]{companion}[10]{cicero} show that...
Filler text \parencites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text \tooltipcites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text \parencite[e.g.][]{baez/article,bertram,cicero,kant:ku,companion}.
Filler text
\cite{cicero,companion,aristotle:poetics,aristotle:rhetoric,aristotle:anima,bertram}.
\printbibliography
\end{document}

在此处输入图片描述

请注意以下几点:

  • 我习惯于filecontents将所有代码放在一起。

  • 上述格式可以将工具提示应用于任何标准引用标签,但每当使用 / 代替格式时,都需要直接应用\tooltip*/ 。样式的宏就是一个例子。\tooltip\bibhyperrefnumeric-compcite:dump

  • fancytooltips 和 biblatex 包的加载顺序是故意的。如果 biblatex 在演示文档中首先加载,它将生成持久的“重新运行 LaTeX”消息。

  • 文档最好以全宽显示。否则,您应考虑将工具提示设为\textwidth演示文档的一半。

答案4

不幸的是,JavaScript 或基于 OCG 的解决方案仅在某些 PDF 查看器中有效。我发现目前最跨查看器的解决方案是使用 PDF Underline 注释,它不仅适用于 Adob​​e 软件,甚至适用于大多数主流浏览器(至少在现代 Firefox、Chrome、Edge 和其他基于 Chromium 的浏览器中)。如果您要在线发布文档(例如在 arXiv 上),这将非常有用。

我对 TeX 不是很了解,因此我写了这段有很多错误但相对简单的代码:

\begin{filecontents}{popupcite.sty}
\usepackage{pdfcomment}
\hypersetup{unicode}
% suppress annoying hyperref warnings
\let\HyPsd@RemoveSpaceWarning\@gobble

%Fixes a bug in soulpos package (used by pdfcomment). Without this fix, pdfmarkupcomments don't play well with \clearpage. Copypasted from StackExchange.
\AtEndDocument{\clearpage\immediate\write\@auxout{\string\ulp@afterend}} 

%read bbl file and parse it to grab full citations
\providecommand{\grabfullcitations}[1]{%
\begingroup
    %we don't need to typeset the reference section
    \def\thebibliography{\begingroup\@gobble}%
    \def\endthebibliography{\endgroup}%
    %The bibliography environment contains a list of bibitems delimited by empty lines. Let's redefine \bibitem to store the bibliographic entry in \fullcitation@<key>
    \def\bibitem[##1]##2 ##3\par{%
        \expandafter\gdef\csname fullcitation@##2\endcsname{##3}%
    }%
    %Now we can read the bbl file, and LaTeX will put the bibliographic entries in \fullcitation@<key>
    \input{#1}%
    %Syntactic sugar to access \fullcitation@<key> by typing \fullcitation{<key>}
    \gdef\fullcitation##1{\csname fullcitation@##1\endcsname}%
\endgroup%
}

%We need to attach a popup to each citation label. \cite function takes citation keys and outputs all the labels altogether, so we have to interfere somewhere in its internals. Since hyperref already works with each label separately, let's patch its \hyper@natlinkstart function. The most cross-viewer kind of popups are PDF Underline annotations, which are provided by the pdfcomment package. So we wrap each label in a \pdfmarkupcomment before creating a hyperlink. \pdfmarkupcomment parameters are chosen so as to make the underlining and annotation author/date/etc. invisible.
\let\hyper@natlinkstart@old\hyper@natlinkstart
\def\hyper@natlinkstart#1#2{%
  \hyper@natlinkstart@old{#1}%
  \pdfmarkupcomment[markup=Underline,color={1 1 1},opacity=0,subject={},author={},date={{ }}]{{#2}}{\fullcitation{#1}}%
}%
\end{filecontents}

%generated by BibTeX using plainnat style
\begin{filecontents}{main.bbl}
\begin{thebibliography}{3}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\expandafter\ifx\csname urlstyle\endcsname\relax
  \providecommand{\doi}[1]{doi: #1}\else
  \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi

\bibitem[Fardin(2014)]{three}
MA~Fardin.
\newblock On the rheology of cats.
\newblock \emph{Rheology Bulletin}, 83\penalty0 (2):\penalty0 16--17, 2014.

\bibitem[Lisi(2007)]{two}
A~Garrett Lisi.
\newblock An exceptionally simple theory of everything.
\newblock arXiv preprint arXiv:0711.0770, 2007.

\bibitem[Nikoli{\'c}(2008)]{one}
Hrvoje Nikoli{\'c}.
\newblock {Would Bohr be born if Bohm were born before Born?}
\newblock \emph{American Journal of Physics}, 76\penalty0 (2):\penalty0
  143--146, 2008.

\end{thebibliography}
\end{filecontents}

\documentclass{article}
\usepackage[super,comma,sort&compress]{natbib}
\usepackage{popupcite}

\grabfullcitations{main.bbl}

\begin{document}
Pop-up~\cite{one,two,three} citations! O\textunderscore o
\input{main.bbl}
\end{document}

输出:


  • 火狐

Firefox 中显示的输出


  • 铬合金

Chrome 中显示的输出


  • 爱看阅读器

Acrobat Reader 中显示的输出

不可否认的是,Chrome 的行为并不是特别好,但至少注释是显示的。也许有人可以将下划线注释的想法与 Audrey 的代码结合起来,以实现强大的跨查看器弹出式引用。

相关内容