[Tex/LaTex] Removing hyperref for acronym starred commands

acronymshyperreflinksstarred-version

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}

Best Answer

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