Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a lot of acronyms in my thesis and I am using the acro package. I would like to know if there is an option to make it possible for the acronyms within the thesis to display a mouse over definition, this is obviously only a function useful for the PDF output file, is there a possibility to make them display the long name if the mouse is hovered over the acronym term?

(FIXED) Edit: problem using the \tooltip macro (FIXED)

To AlexG I encountered a problem with using the \tooltip macro whereby you get the following overlapping of acronyms:

enter image description here

I can't work out why or how to fix it, but its an essential flaw of the \tooltip macro as, when I remove it it disappears: please feel free to play around with this 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}
share|improve this question
3  
fancytooltips, cooltooltips and pdfcomment can create pop-ups I think. –  Torbjørn T. Feb 20 at 12:17
3  
See e.g. tex.stackexchange.com/questions/32314/… –  doncherry Feb 20 at 12:25
1  
In addition to the packages mentioned by @TorbjørnT., the \tooltip macro for draggable tooltips which supports all known output drivers. –  AlexG Feb 20 at 12:54
1  
I'll have a look into it tomorrow. –  AlexG Feb 20 at 21:20
1  
\tooltip code has been fixed. –  AlexG Feb 21 at 9:27
show 4 more comments

2 Answers

up vote 19 down vote accepted

Here is an example using the previously defined \tooltip command. Some user macros from the Acro package needed to be redefined to insert the tooltips only after first use:

enter image description here

For Acronyms in black and non-draggable tip boxes use

\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}}}

instead of

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

in the code below.

The complete code:

\documentclass[a6paper,12pt]{scrbook}
%\documentclass[12pt]{scrbook}
\usepackage{acro}
\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} }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%re-defining \ac, \acp
\let\acorig\ac
\let\acporig\acp
\def\ac#1{\acifused{#1}{\tooltip{\acs{#1}}{\acl{#1}}}{\acorig{#1}}}
\def\acp#1{\acifused{#1}{\tooltip{\acsp{#1}}{\aclp{#1}}}{\acporig{#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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/03/25]
\usepackage{xcolor}
\usepackage{calc}
\usetikzlibrary{calc}

\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}
\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');%
        \IfBooleanF{#1}{%
          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;%
      )>>%
      \IfBooleanTF{#1}{%
        /PC<</S/JavaScript/JS(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{#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%
  \tpPdfXform{\tiptext}%
  \raisebox{\heightof{#3}}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
    \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}%
  }}%
  \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}
share|improve this answer
    
That is brilliant, thank you so much its pretty much exactly what I was hoping for!! so by using the \tooltip* I am able to make them non draggable. Just one more question, how can I make them appear black? I would like the acronyms not stand out from the text please. –  Fiztban Feb 20 at 13:59
    
Ah worked it out just need to add the \tooltip*[black]{...}{...} I get a permanent error is that normal? –  Fiztban Feb 20 at 14:02
1  
@Fiztban: No error here. Perhaps old version of media9 at your end? Get media9.sty from CTAN and place it into your current directory, or better run the package updater if you are using TeXLive-2013 or MikTeX-2.9. –  AlexG Feb 20 at 14:11
1  
@Fiztban: Some months ago I posted the method for Linux and X11 on Meta. –  AlexG Feb 20 at 14:31
1  
@Fiztban: The bug you reported has been fixed. –  AlexG Feb 21 at 9:25
show 7 more comments

The code below adds a tooltip property to acronyms that allows to specify the hover text for an acronym if it should differ from the long form. If not specified the long form is used. The code takes care that the tooltips are inserted for the short forms and the alternative forms but not on first use and not in the list of acronyms. This is done by redefining the corresponding internal commands.

The code uses the pdfcomment package and its \pdftooltip macro for generating the tooltips as an example. AlexG's \tooltip macro can just as easily be used, though, which means the integration into acro is independent from a tooltip generating package/code. Below the macro that needs to be adjusted is shown.

(I'm thinking of adding something like this to acro... but I'd like some feedback first. So far the feedback isn't overly enthusiastic...).

General usage

\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}

enter image description here

If another package/code for tooltips should be used then the definition in the code below

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

must be adjusted accordingly.

Here's the complete code

\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}
share|improve this answer
    
Hello @cgnieder I just realised you are the author of the acro package. I have been experimenting with your code which does not present the problem the \tooltip macro presents when integrated into the \ac redefinition (see my initial question's edit). It runs pretty smoothly though as feedback the first two things that I can offer for improvement are 1) the tooltip click box is smaller than the word itself, I think if it were slightly bigger it would be a feature that people would stumble across in a PDF more easily 2) the macro does not treat alternative \aca commands. I will offer more –  Fiztban Feb 20 at 21:39
    
I will keep you posted of any other feedback I can give while using the macro. Thank you for sharing it! I think it would be a lovely addition to the acro package. –  Fiztban Feb 20 at 21:42
    
@Fiztban I can't help with the tooltips themselves: they are created by the pdfcomment in my code. But the package provides lot's of options so it should be possible to customize the output. You could even use any other package to create the tooltips (or use AlexG's code) by changing the definition \cs_new_protected:Npn \acro_tooltip:nn #1#2 { \pdftooltip {#1} {#2} }. (My code above mainly provides an integration of a tooltip functionality into acro.) As for \aca: I'm aware of that. Also \acs and some others. The above is a draft of changes that could be integrated into acro –  cgnieder Feb 20 at 21:50
    
Thank you for explaining your code, I am learning a lot since last week when I started so I appreciate the time you have taken. My feedback was simply what I could offer with my beginners view of LaTeX, I will experiment with other tooltips though your code suits me perfectly for the time being. Thank you –  Fiztban Feb 20 at 23:04
    
@Fiztban I added support for \aca and \acs and friends –  cgnieder Feb 21 at 9:54
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.