PDF 显示中的移动框

PDF 显示中的移动框

我尝试使用fancytooltips包,非常喜欢。我能想到的一件好事是让条目显示为可移动框,而不仅仅是工具提示。(有时工具提示会遮挡其他文本。)这有可能实现吗?我的意思是这可能需要大量工作,但如果有可能,我愿意研究一下。

示例和截图fancytooltips可以在这个帖子。引用该帖子的内容:


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。

在此处输入图片描述

答案1

这需要破解该fancytooltips软件包。

由于fancytooltips依赖于 TeXLive 中没有的包,所以我自己尝试了一些方法。

下面定义的工具提示命令支持所有常见的输出驱动程序(LaTeX 工作流程):

  • latex-> dvips-> ps2pdfdvips一定不能用选项调用-Ppdf!)
  • latex->dvipdfmx
  • xelatex,,lualatexpdflatex

命令

\tooltip[<link text colour>]{<link text>}[<tip box colour>]{<tip text>}

创建一个可以拖动的工具提示。

颜色参数是可选的,默认为blue和。可以使用yellow!20根据包的颜色模型预定义的颜色名称和颜色表达式。如果加载了 ,其内部链接的颜色设置(选项)将用作。xcolorhyperreflinkcolor<link text colour>

<link text>可以跨行结尾中断,除了latex-> dvips->ps2pdf工作流程。

多行<tip text>应该放入\parbox或中minipage

\documentclass[a6paper,12pt]{scrbook}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% tooltips with LaTeX v. 2017/11/28
%
% \tooltip[*[*[*[*]]]][<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   \tooltip     --> draggable tip, visible on mouse-over, hidden on mouse-out
%               
%   \tooltip*    --> draggable tip, toggle visiblity on mouse-over
%               
%   \tooltip**   --> NON-draggable tip, visible on mouse-over, hidden on mouse-out
%              
%   \tooltip***  --> NON-draggable tip, toggle visiblity on mouse-over
%               
%   \tooltip**** --> NON-draggable tip, toggle visiblity on mouse-click (Evince!)
%
% Default link colour can be set with
%
%   \usepackage[linkcolor=<colour>]{hyperref}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pdfbase}[2017/03/16]
\usepackage{xparse,ocgbase}
\usepackage{xcolor,calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfLink\pbs_pdflink:nn
\let\tpPdfAnnot\pbs_pdfannot:nnnn\let\tpPdfLastAnn\pbs_pdflastann:
\let\tpAppendToFields\pbs_appendtofields:n
\def\tpPdfXform{\pbs_pdfxform:nnnnn{1}{1}{}{}}
\let\tpPdfLastXform\pbs_pdflastxform:
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{%
  ssssO{\ifdefined\@linkcolor\@linkcolor\else blue\fi}mO{yellow!20}m%
}{{%
  \leavevmode%
  \IfBooleanT{#2}{%
    %for variants with two and more stars, put tip box on a PDF Layer (OCG)
    \ocgbase@new@ocg{tipOCG.\thetcnt}{%
      /Print<</PrintState/OFF>>/Export<</ExportState/OFF>>%
    }{false}%
    \xdef\tpTipOcg{\ocgbase@last@ocg}%
    %prevent simultaneous visibility of multiple non-draggable tooltips
    \ocgbase@add@ocg@to@radiobtn@grp{tool@tips}{\ocgbase@last@ocg}%
  }%
  \tpPdfLink{%
    \IfBooleanTF{#4}{%
      /Subtype/Link/Border[0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
    }{%
      /Subtype/Screen%
      /AA<<%
        \IfBooleanTF{#3}{%
          /E<</S/SetOCGState/State [/Toggle \tpTipOcg]>>%
        }{%  
          \IfBooleanTF{#2}{%
            /E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
            /X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
          }{
            \IfBooleanTF{#1}{%
              /E<</S/JavaScript/JS(%
                var fd=this.getField('tip.\thetcnt');%
                if(typeof(click\thetcnt)=='undefined'){%
                  var click\thetcnt=false;%
                  var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
                }%
                if(fd.display==display.hidden){%
                  fd.delay=true;fd.display=display.visible;fd.delay=false;%
                }else{%
                  if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
                  if(!dragging\thetcnt){click\thetcnt=false;}%
                }%
                this.dirty=false;%
              )>>%
            }{%
              /E<</S/JavaScript/JS(%
                var fd=this.getField('tip.\thetcnt');%
                if(typeof(click\thetcnt)=='undefined'){%
                  var click\thetcnt=false;%
                  var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
                }%
                if(fd.display==display.hidden){%
                  fd.delay=true;fd.display=display.visible;fd.delay=false;%
                }%
               this.dirty=false;%
              )>>%
              /X<</S/JavaScript/JS(%
                if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
                if(!dragging\thetcnt){click\thetcnt=false;}%
                this.dirty=false;%
              )>>%
            }%  
            /U<</S/JavaScript/JS(click\thetcnt=true;this.dirty=false;)>>%
            /PC<</S/JavaScript/JS (%
              var fd=this.getField('tip.\thetcnt');%
              try{fd.rect=fdor\thetcnt;}catch(e){}%
              fd.display=display.hidden;this.dirty=false;%
            )>>%
            /PO<</S/JavaScript/JS(this.dirty=false;)>>%
          }%
        }%
      >>%
    }%
  }{{\color{#5}#6}}%
  \sbox\tiptext{%
    \IfBooleanT{#2}{%
      \ocgbase@oc@bdc{\tpTipOcg}\ocgbase@open@stack@push{\tpTipOcg}}%
    \fcolorbox{black}{#7}{#8}%
    \IfBooleanT{#2}{\ocgbase@oc@emc\ocgbase@open@stack@pop\tpNull}%
  }%
  \edef\twd{\the\wd\tiptext}%
  \edef\tht{\the\ht\tiptext}%
  \edef\tdp{\the\dp\tiptext}%
  \measureremainder{\whatsleft}\tipshift=0pt%
  \ifdim\whatsleft<\twd\setlength\tipshift{\whatsleft-\twd}\fi%
  \IfBooleanF{#2}{\tpPdfXform{\tiptext}}%
  \raisebox{\heightof{#6}+\tdp}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
    \IfBooleanTF{#2}{\usebox{\tiptext}}{%
      \tpPdfAnnot{\twd}{\tht}{\tdp}{%
        /Subtype/Widget/FT/Btn/T (tip.\thetcnt)%
        /AP<</N \tpPdfLastXform>>%
        /MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
        /Ff 65536/F 3%
        /AA <<%
          /U <<%
            /S/JavaScript/JS(%
              var fd=event.target;%
              var mX=this.mouseX;var mY=this.mouseY;%
              var drag=function(){%
                var nX=this.mouseX;var nY=this.mouseY;%
                var dX=nX-mX;var dY=nY-mY;%
                var fdr=fd.rect;%
                fdr[0]+=dX;fdr[1]+=dY;fdr[2]+=dX;fdr[3]+=dY;%
                fd.rect=fdr;mX=nX;mY=nY;%
              };%
              if(!dragging\thetcnt){%
                dragging\thetcnt=true;Int=app.setInterval("drag()",1);%
              }%
              else{app.clearInterval(Int);dragging\thetcnt=false;}%
              this.dirty=false;%
            )%
          >>%
        >>%
      }%
      \tpAppendToFields{\tpPdfLastAnn}%
    }%
  }}%
  \stepcounter{tcnt}%
}}
\makeatother
\newsavebox\tiptext\newcounter{tcnt}
\newlength{\whatsleft}\newlength{\tipshift}
\newcommand{\measureremainder}[1]{%
  \begin{tikzpicture}[overlay,remember picture]
    \path let \p0 = (0,0), \p1 = (current page.east) in
      [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
  \end{tikzpicture}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\parindent=0pt
\begin{document}\Huge
Einstein's \tooltip{formula}{$E=m c^2$} is well known.
  Another famous formula is due to \tooltip{Pythagoras}{$a^2+b^2=c^2$}.
\end{document}

在此处输入图片描述

怎么运行的:

创建了两个 PDF 注释(鼠标敏感区域):(1)蓝色链接文本周围的链接,可跨行尾断开。(2)用于提示文本的交互式( /Ff 65536)按钮(/FT/Btn)小部件( )。/Subtype/Widget

提示框的可见性通过与链接的鼠标进入事件绑定的 JavaScript 操作来控制。要显示/隐藏提示,只需将鼠标指针反复悬停在链接文本上即可。

提示文字可能不是直接嵌入到页面内容中;否则无法移动。相反,它被排版到一个框 ( \sbox) 中,然后被提炼成所谓的 Form-XObject,这是一个具有图形和/或文本内容的独立 PDF 实体。此 Form-XObject 通过条目绑定到按钮小部件外观/MK

拖动操作以 JavaScript 动作的形式实现,由提示文本按钮的鼠标释放事件触发。鼠标移动由drag()使用 JavaScript 计时器 ( ) 重复执行的函数跟踪。这样确定的鼠标位置增量会不断添加到表示提示文本按钮的JavaScript 对象的app.setInterval坐标 (属性) 中。rectField

相关内容