5

In the acronym package, the starred commands \ac* and \acp* omit the acronym from the list of acronyms with option "printonlyused". My problem is that acronyms inserted like this are still hyperref links in PDFs created with pdflatex. I would like to have link-free acronyms if they are inserted with the starred commands and thus are not in the acronym table. How would I do this?

In the example below, pdflatex creates three pages, a dummy page 1, the acronym table on page 2 and two acronyms used on page 3. The first acronym correctly links to the acronym table. However, the starred command also is a hyperref. In my trials, all starred commands produced hyperref links to page 1, which has nothing to do with acronyms at all.

\documentclass{article}

\PassOptionsToPackage{printonlyused}{acronym}
\usepackage{acronym}
\usepackage{hyperref}

\begin{document}
the initial page

\newpage
the acronym page

\begin{acronym}
  \acro{AAA}{Aaa Abb Acc}
  \acro{TMN}{This Means Nothing}
\end{acronym}

\newpage
\ac{AAA}
\ac*{TMN}

\end{document}
3

For starred versions of its commands acronym calls \AC@starredtrue. We can use this to redefine \AC@hyperlink to only produce a hyperlink if a non-starred version is used. Without hyperref \AC@hyperlink essentially is the same as \@secondoftwo and with hyperref it is \let to \hyperlink at begin document. This means the redefinition should be done with the \AtBeginDocument hook.

The following definition lets \AC@hyperlink use \@secondoftwo in starred versions and \hyperlink in the non-starred versions.

\documentclass{article}

\usepackage[printonlyused]{acronym}
\usepackage{hyperref}

\makeatletter
\AtBeginDocument{%
  \renewcommand*\AC@hyperlink{%
    \ifAC@starred
      \expandafter\@secondoftwo
    \else
      \expandafter\hyperlink
    \fi
  }%
}
\makeatother

\begin{document}
the initial page

\newpage
the acronym page

\begin{acronym}
  \acro{AAA}{Aaa Abb Acc}
  \acro{TMN}{This Means Nothing}
\end{acronym}

\newpage
\ac{AAA}
\ac*{TMN}

\end{document}

enter image description here

  • Thank you very much! This is what I wanted. In your description you say "Without hyperref \AC@hyperlink essentially is the same as \@secondoftwo". Are there any side effects associated with the 'essentially' that I need to know about to avoid them? – Klaus Kopec Mar 17 '14 at 9:04
  • 1
    @KlausKopec no I don't think so. \@secondoftwo is defined with \long and \AC@hyperlink isn't. See tex.stackexchange.com/a/1057/5049 for background on this – clemens Mar 17 '14 at 9:41
  • can this easily be made into a patch for the sty file so that I can forward it as suggestion to the package maintainer? – Klaus Kopec Apr 17 '14 at 16:06
  • If you refer to this question the package maintainer should be able to adapt it easily enough if he wants to – clemens Apr 17 '14 at 22:00
  • I realize that, but unfortunately he seems to have lost interest in the package. He literally said that he'll not do it unless a patch is submitted. Maybe the package ist best abandoned in that case in favor of glossaries or s.th. similar. Thank you for your help! – Klaus Kopec Apr 18 '14 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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