鼠标悬停在首字母缩略词上可以定义吗?

鼠标悬停在首字母缩略词上可以定义吗?

我的论文中有很多缩写词,我正在使用该acro软件包。我想知道是否有选项可以让论文中的缩写词在鼠标悬停定义上显示,这显然只是 PDF 输出文件的一个有用功能,是否有可能让它们在鼠标悬停在缩写词上时显示长名称?

(固定的)编辑:使用\tooltip宏的问题(固定的)

致 AlexG 我在使用宏时遇到了一个问题\tooltip,即出现以下首字母缩略词重叠的情况:

在此处输入图片描述

我不知道为什么或者如何修复它,但它是\tooltip宏的一个本质缺陷,因为当我删除它时它就消失了:请随意尝试这个 MWE:

\documentclass[a4paper,11pt]{scrreprt}

\usepackage{acro}

\usepackage{tensor}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The re-defining of the acronym entering commands \ac for the normal form, \acp for the plural form of the acronym, \acl, \aclp
\let\acorig\ac
\let\acporig\acp
\def\ac#1{\acifused{#1}{\tooltip*[black]{\acs{#1}}{\acl{#1}}}{\acorig{#1}}}
\def\acp#1{\acifused{#1}{\tooltip*[black]{\acsp{#1}}{\aclp{#1}}}{\acporig{#1}}}



%%%%%%%%%% THE LONG ASS MACRO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%        \tooltip*[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%        (starred variant is not draggable)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}[2014/02/06]
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\newlength{\whatsleft}
\newlength{\tipshift}

\ExplSyntaxOn
\let\tpPdfLink\mix_pdflink:nn
\let\tpPdfAnnot\mix_pdfannot:nnnn\def\tpPdfLastAnn{\g_mix_pdflastann_tl}
\let\tpPdfXform\mix_pdfxform:n\def\tpPdfLastXform{\g_mix_pdflastxform_tl}
\let\tpInsertAcroForm\mix_insert_acroform:
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{sO{blue}mO{yellow!20}m}{{%
  \leavevmode%
  \tpPdfLink{%
    /Subtype/Screen%
    /AA<<%
      /E<</S/JavaScript/JS(%
        var fd=this.getField('tip.\thetcnt');%
        \IfBooleanTF{#1}{fd.display=display.visible;}{%
          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(%
      \IfBooleanTF{#1}{fd.display=display.hidden;}{%
        if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
        if(!dragging\thetcnt){click\thetcnt=false;}this.dirty=false;%
      }%
      )>>%
      \IfBooleanF{#1}{%
        /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;%
        )>>%
      }%
    >>%
  }{{\color{#2}#3}}%
  \sbox\tiptext{\fcolorbox{black}{#4}{#5}}%
  \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%
  \hspace{\tipshift}\tpPdfXform{\tiptext}%
  \raisebox{\heightof{#3}}[0pt][0pt]{\makebox[0pt][l]{%
    \tpPdfAnnot{\twd}{\tht}{\tdp}{%
      /Subtype/Widget/FT/Btn/Ff 65536/T (tip.\thetcnt)/F 3%
      /MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
      \IfBooleanF{#1}{%
        /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;%
            )%
          >>%
        >>%
      }%
    }%
    \xdef\@anim@fields{\@anim@fields\space\tpPdfLastAnn}
    \tpInsertAcroForm
  }}%
  \stepcounter{tcnt}%
}}
\makeatother
\newsavebox\tiptext\newcounter{tcnt}
\newcommand{\measureremainder}[1]{%
  \begin{tikzpicture}[overlay,remember picture]
    \path let \p0 = (0,0), \p1 = (current page text area.east) in
      [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
  \end{tikzpicture}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINED ACRONYMS
\DeclareAcronym{pwr}{
    short = PWR ,
    short-plural = s ,
    long = Pressurised Water Reactor ,
    long-plural = s ,
    class = reactor ,
}

\DeclareAcronym{ebr}{
    short = EBR-I ,
    short-plural =  ,
    long = Experimental Breeder Reactor I ,
    long-plural =  ,
    class = reac.exist ,
}

\DeclareAcronym{vhtr}{
    short = VHTR ,
    short-plural = s ,
    long = Very High Temperature Reactor ,
    long-plural = s ,
    class = reactor ,
}

\DeclareAcronym{sfr}{
    short = SFR ,
    short-plural = s ,
    long = Sodium Fast Reactor ,
    long-plural = s ,
    class = reactor ,
}

\DeclareAcronym{heu}{
    short = HEU ,
    short-plural =  ,
    long = High Enriched Uranium ,
    long-plural =  ,
    class = reac.term ,
}

\DeclareAcronym{leu}{
    short = LEU ,
    short-plural =  ,
    long = Low Enriched Uranium ,
    long-plural =  ,
    class = reac.term ,
}

\DeclareAcronym{htgr}{
    short = HTGR ,
    short-plural = s ,
    long = High Temperature Gas cooled Reactor ,
    long-plural = s ,
    alt = HTR ,
    class = reactor ,
}

\begin{document}

The flexibility of fuel cycle use is one of the attractive features presented by \acp{htgr}. Initially \acp{htgr} took advantage of the efficient uranium-thorium fuel cycle which combined \ac{heu} as fissile fuel with fertile thorium that would breed fissile \nuclide[233][92]{U} during operation. With the non-proliferation treaty in force by 1970 a \ac{leu} fuel cycle was designed and adopted to avoid diversion of fissile material.

\end{document}

答案1

以下是使用先前定义的命令的示例。需要重新定义包\tooltip中的一些用户宏才能仅插入工具提示Acro首次使用:

在此处输入图片描述

对于黑色和不可拖动的提示框中的首字母缩略词,请使用

\def\ac#1{\acifused{#1}{\tooltip**[black]{\acs{#1}}{\acl{#1}}}{\acorig{#1}}\relax}
\def\acp#1{\acifused{#1}{\tooltip**[black]{\acsp{#1}}{\aclp{#1}}}{\acporig{#1}}\relax}

代替

\def\ac#1{\acifused{#1}{\tooltip{\acs{#1}}{\acl{#1}}}{\acorig{#1}}\relax}
\def\acp#1{\acifused{#1}{\tooltip{\acsp{#1}}{\aclp{#1}}}{\acporig{#1}}\relax}

在下面的代码中。

完整代码:

\documentclass[a6paper,12pt]{scrbook}
%\documentclass[12pt]{scrbook}

\usepackage{acro}
% some acronyms
\DeclareAcronym{cd}{ short={CD}, long={Compact Disc}, short-plural={s}, long-plural={s} }
\DeclareAcronym{mc}{ short={MC}, long={Musicassette}, short-plural={s}, long-plural={s} }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The re-defining of the acronym entering commands \ac for the normal form,
% \acp for the plural form of the acronym, \acl, \aclp
\let\acorig\ac
\let\acporig\acp
\def\ac#1{\acifused{#1}{\tooltip{\acs{#1}}{\acl{#1}}}{\acorig{#1}}\relax}
\def\acp#1{\acifused{#1}{\tooltip{\acsp{#1}}{\aclp{#1}}}{\acporig{#1}}\relax}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% tooltips with LaTeX v. 2018/01/15
%
% \tooltip[*[*[*[*]]]]
%            [<link colour>]{<link text>}
%            [<tip box colour>]{<tip text>}
%            [<x-offset>,<y-offset>]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   \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,linegoal}
\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:
\let\cListSet\clist_set:Nn\let\cListItem\clist_item:Nn
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{%
  ssssO{\ifdefined\@linkcolor\@linkcolor\else blue\fi}mO{yellow!20}mO{0pt,0pt}%
}{{%
  \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}%
  }%
  \cListSet\tpOffsets{#9}%
  \edef\twd{\the\wd\tiptext}%
  \edef\tht{\the\ht\tiptext}%
  \edef\tdp{\the\dp\tiptext}%
  \tipshift=0pt%
  \IfBooleanTF{#2}{%
    %OCG-based (that is, all non-draggable) boxes should not extend beyond the
    %current column as they may get overlaid by text in the neighbouring column
    \setlength\whatsleft{\linegoal}%
  }{%
    \measureremainder{\whatsleft}%
  }%
  \ifdim\whatsleft<\dimexpr\twd+\cListItem\tpOffsets{1}\relax%
    \setlength\tipshift{\whatsleft-\twd-\cListItem\tpOffsets{1}}\fi%
  \IfBooleanF{#2}{\tpPdfXform{\tiptext}}%
  \raisebox{\heightof{#6}+\tdp+\cListItem\tpOffsets{2}}[0pt][0pt]{%
    \makebox[0pt][l]{\hspace{\dimexpr\tipshift+\cListItem\tpOffsets{1}\relax}%
    \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}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\acp{mc} and \acp{cd} are media for recording music. The \ac{mc} appeared about 15 years earlier than the \ac{cd}.
\end{document}

答案2

更新2015-09-08:

从 2.1 版开始acro直接支持工具提示。它们可以通过两种方式激活:

  1. 只需设置选项\acsetup{tooltip=true}。这将加载pdfcomment包并用作\pdftooltip创建工具提示的命令。
  2. 将选项设置\acsetup{tooltip-cmd = <macro>}为您喜欢的工具提示创建宏。

作为一般规则,工具提示仅用于短的缩写形式,而长形式则从不。嵌套支持方式如下:禁用“内部”缩写的工具提示,并使用“外部”缩写的工具提示。

可以通过定义宏来直观地检查插入情况

\providecommand\tooltip[2]{[PDF:#1][tooltip:#2]}

并通过 使用它\acsetup{tooltip-cmd = \tooltip}

在此处输入图片描述

\documentclass{article}

\usepackage{acro}

\providecommand\tooltip[2]{[PDF:#1][tooltip:#2]}
\acsetup{
  tooltip-cmd = \tooltip ,
}

\DeclareAcronym{m}{
  short        = {m},
  long         = {milli},
  short-plural = {},
  long-plural  = {},
  class        = {SI-prefix},
  tooltip      = milli
}

\DeclareAcronym{g}{
  short        = {g},
  long         = {gramm},
  short-plural = {},
  long-plural  = {},
  class        = {SI-unit-derived},
  tooltip      = gramm
}

\DeclareAcronym{mg}{
  short        = {\acs{m}\acs{g}},
  long         = {\Acl{m}\acl{g}},
  short-plural = {},
  long-plural  = {},
  class        = {SI-unit-derived},
}

\begin{document}

\ac{g}\par
\ac{g}\par
\Ac{g}

\bigskip

\ac{m}\par
\acp{m}\par
\Acp{m}

\bigskip

\ac{mg}\par
\ac{mg}\par
\acf{mg}

\end{document}

原始答案-适用于1.6以下的版本:

以下代码tooltip向首字母缩略词添加了一个属性,允许指定首字母缩略词的悬停文本(如果该文本应与完整格式不同)。如果未指定,则使用完整格式。代码会注意为缩写形式和替代形式插入工具提示,但不是首次使用时不是在首字母缩略词列表中。这是通过重新定义相应的内部命令来实现的。

代码以生成工具提示的pdfcomment包及其\pdftooltip宏为例。\tooltip不过,AlexG 的宏同样易于使用,这意味着集成acro与工具提示生成包/代码无关。下面显示了需要调整的宏。

(我正在考虑添加类似的东西acro……但我首先想得到一些反馈。到目前为止,反馈并不是非常热情……)。

一般用法

\documentclass{article}
\usepackage{pdfcomment}

\usepackage{acro}
\ExplSyntaxOn
...
\ExplSyntaxOff

% long form used as tooltip text:
\DeclareAcronym{cd}{
  short = {CD},
  long  = {Compact Disc}
}
% custom tooltip text:
\DeclareAcronym{mc}{
  short   = {MC},
  long    = {Music Cassette},
  tooltip = {my mouse-over text}
}


\begin{document}

\ac{cd} \ac{mc}\par\vspace{1cm}
\ac{cd} \ac{mc}

\end{document}

在此处输入图片描述

如果应使用另一个工具提示包/代码,则以下代码中的定义

% #1: printed text
% #2: tool tip text
\cs_new_protected:Npn \acro_tooltip:nn #1#2
  { \pdftooltip {#1} {#2} }

必须进行相应调整。

以下是完整代码

\documentclass{article}
\usepackage{pdfcomment}

\usepackage{acro}
\ExplSyntaxOn
\prop_new:N \l__acro_tooltip_prop

\cs_new_protected:Npn \__acro_declare_tooltip:nn #1#2
  {
    \__acro_key_check:nn { #1 } { tooltip }
    \prop_put:Nnn \l__acro_tooltip_prop { #1 } { #2 }
  }
\cs_generate_variant:Nn \__acro_declare_tooltip:nn { V }

\keys_define:nn { acro / declare-acronym }
  {
    tooltip .code:n =
    \__acro_declare_tooltip:Vn \l__acro_current_key_tl { #1 } ,
  }

\cs_new_protected:Npn \acro_write_tooltip:nnn #1#2#3
  {
    \prop_get:NnNTF \l__acro_tooltip_prop { #1 } \l__acro_tmpc_tl
      { \acro_tooltip:nn { #2 } { \l__acro_tmpc_tl } }
      { \acro_tooltip:nn { #2 } { #3 } }
  }
\cs_generate_variant:Nn \acro_write_tooltip:nnn { nnV }

\cs_set_protected:Npn \acro_use:n #1
  {
    % get the acronym and the plural settings:
    \acro_get:n { #1 }
    \acro_is_used:nTF { #1 }
      {
        % this is not the first time
        \__acro_indefinite:nn { #1 } { short }
        \__acro_acc_supp:nn
          { #1 }
          {
            \acro_write_tooltip:nnn
              { #1 }
              { \__acro_write_short:V \l__acro_short_tl }
              { \l__acro_long_tl }
          }
        \acro_after:n { #1 }
      }
      {
        % this is the first time
        \bool_gset_true:c { g__acro_#1_first_use_bool }
        \__acro_is_single:nTF { #1 }
          {
            \__acro_indefinite:nn { #1 } { long }
            \__acro_write_long:NV \l__acro_long_format_tl \l__acro_long_tl
          }
          { 
            \UseInstance { acro-first } { \l__acro_first_instance_tl }
              { #1 }
              { \l__acro_short_tl }
              { \l__acro_long_tl }
          }
      }
  }

\cs_set_protected:Npn \acro_short:n #1
  {
    \acro_get:n { #1 }
    \acro_is_used:n { #1 }
    \__acro_indefinite:nn { #1 } { short }
    \__acro_is_single:nT { #1 }
      { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn }
    \__acro_acc_supp:nn
      { #1 }
      {
        \acro_write_tooltip:nnn
          { #1 }
          { \__acro_write_short:V \l__acro_short_tl }
          { \l__acro_long_tl }
      }
    \acro_after:n { #1 }
  }

\cs_set_protected:Npn \acro_alt:n #1
  {
    \acro_get:n { #1 }
    \acro_is_used:n { #1 }
    \__acro_indefinite:nn { #1 } { alt }
    \__acro_is_single:nT { #1 }
      { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn }
    \__acro_acc_supp:nn
      { #1 }
      {
        \acro_write_tooltip:nnn
          { #1 }
          { \__acro_write_short:V \l__acro_alt_tl }
          { \l__acro_long_tl }
      }
    \acro_after:n { #1 }
  }

% use whatever command you like here:
% #1: printed text
% #2: tool tip text
\cs_new_protected:Npn \acro_tooltip:nn #1#2
  { \pdftooltip {#1} {#2} }

\ExplSyntaxOff

\DeclareAcronym{cd}{
  short = {CD},
  long  = {Compact Disc}
}
\DeclareAcronym{mc}{
  short   = {MC},
  long    = {Music Cassette},
  tooltip = {my mouse-over text}
}


\begin{document}

\ac{cd} \ac{mc}\par\vspace{1cm}
\ac{cd} \ac{mc}

\aca{cd} \aca{mc}

\acs{cd} \acs{mc}

\end{document}

答案3

对于 的较新版本acro,以下代码(最初由 Denis Bitouzé 编写)有效:

\documentclass{article}
\usepackage{acro}
\usepackage{pdfcomment}
\usepackage{hyperref}

\DeclareAcronym{cd}{
  short = {CD},
  long  = {Compact Disc}
 }
\DeclareAcronym{mc}{
  short   = {MC},
  long    = {Music Cassette},
  pdfcomment = {my mouse-over text}
}
 
\acsetup{
  pdfcomments/use=true
}

\begin{document}

 \ac{cd} \ac{mc}\par\vspace{1cm}
 \ac{cd} \ac{mc}

 \aca{cd} \aca{mc}

 \acs{cd} \acs{mc}
\end{document}

答案4

从 2.1 版开始,代码可以简化为

\documentclass{article}

\usepackage[tooltip]{acro}

\DeclareAcronym{cd}{
  short = {CD},
  long  = {Compact Disc}
}
\DeclareAcronym{mc}{
  short   = {MC},
  long    = {Music Cassette},
  tooltip = {my mouse-over text}
}


\begin{document}

 \ac{cd} \ac{mc}\par\vspace{1cm}
 \ac{cd} \ac{mc}

 \aca{cd} \aca{mc}

 \acs{cd} \acs{mc}

\end{document}

在这八种情况下我都得到了鼠标悬停。

256627对于嵌套缩略词的情况。

相关内容