I came along Clemens’ solutions from 161521 for adding mouse over effects to a PDF.
It works pretty fine, except when I got nested acronyms. As a MWE [Edit: no errors/warnings in Acro 1.6b [Edit: With Acro 2.0, the code is not working anymore.]]:
\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{B}{
short = {B},
long = {byte},
short-plural = {},
long-plural = {},
class = {non-SI-unit},
}
\DeclareAcronym{g}{
short = {g},
long = {gramm},
short-plural = {},
long-plural = {},
class = {SI-unit-derived},
}
\DeclareAcronym{k}{
short = {k},
long = {kilo},
short-plural = {},
long-plural = {},
class = {SI-prefix},
}
\DeclareAcronym{kB}{
short = {\acs{k}\acs{B}},
long = {\Acl{k}\acl{B}},
short-plural = {},
long-plural = {},
class = {non-SI-unit-derived},
}
\DeclareAcronym{kg}{
short = {\acs{k}\acs{g}},
long = {\Acl{k}\acl{g}},
short-plural = {},
long-plural = {},
class = {SI-unit},
}
\DeclareAcronym{m}{
short = {m},
long = {milli},
short-plural = {},
long-plural = {},
class = {SI-prefix},
}
\DeclareAcronym{mg}{
short = {\acs{m}\acs{g}},
long = {\Acl{m}\acl{g}},
short-plural = {},
long-plural = {},
class = {SI-unit-derived},
}
\begin{document}
1~\ac{mg}
1~\ac{kg}
1~\ac{kB}
2~\acp{mg}
2~\acp{kg}
2~\acp{kB}
\end{document}
(For this example siunitx or the like might help, but that is not the point here.)
The text of the PDF looks fine, but the mouse over shows only the last part (gramm/byte). [Edit: with Adobe Reader 9.4.2 on Linux there are actually mouse overs for the prefixes in the first call, albeit lower case. Still none in the second call. [Edit: Same for Adobe Acrobat Reader DC on Windows 7. Somehow overlooked this.] Seems like Poppler is almost the only alternative on Linux. No support for tooltips as far as I guess.]
Honestly, Clemens’ code is overwhelming me, so I just use it as is.
