5

When using the acronym package (current version 2012/10/29 v1.38) with hyperref, the upper case indefinite article command \Iac does not compile in some cases. This code

\documentclass{article}

\usepackage{acronym}
\usepackage{hyperref}

\begin{document}
\begin{acronym}
  \acro {HMM} {Hidden Markov Model}
  \acroindefinite {HMM} {an} {a}
\end{acronym}

\Iac{HMM}
\Iac{HMM}


\end{document}

results in

! Undefined control sequence.
\hyper@@link ->\let \Hy@reserved@a 
                                   \relax \@ifnextchar [{\hyper@link@ }{\hyp...
l.13 \Iac{HMM}

I contacted the package maintainer and he does not have time to fix this issue but would incorporate patches into the .sty file if submitted to him. Thus my question is if anyone can provide me with either a workaround that I can use in my .tex file or a patch for the bug in the .sty file.

I so far checked these combinations of indefinite article commands:

\Iac used once works fine
\Iac used twice for the same acronym DOES NOT WORK

\Iac* works multiple times
\Iac* then \Iac on the same acronym works
\Iac then \Iac* on the same acronym DOES NOT WORK

\iac works multiple times
\iac then \Iac on the same acronym DOES NOT WORK
\Iac then \iac on the same acronym works
Note: \iac's behaviour is inverse to that of \Iac*

\iac* and \Iac on the same acronym works in both orders

As I hardly know latex myself, any help would be greatly appreciated.

1
  • I suspect that the problem is in the usage of \@firstupper, that can't work along with hyperref. I'm afraid there's no quick fix.
    – egreg
    Commented Apr 17, 2014 at 16:12

1 Answer 1

4

As suspected by egreg the problem is caused by \@firstupper. If hyperref is loaded, the first token is \AC@hyperlink, but it should be applied to the string in the second argument of \AC@hyperlink.

The following example patches \@Iac that contains the call of \@firstupper to propagate \@firstupper to the second argument of \AC@hyperlink if it is present.

\documentclass{article}

\usepackage{acronym}
\usepackage{hyperref}

\makeatletter
\newcommand*{\FU@iaci}[1]{%
   \ifcsname fn@#1@IL\endcsname
     \ifAC@dua
        \expandafter\FU@H\csname fn@#1@IL\endcsname%
     \else
        \expandafter\ifx\csname ac@#1\endcsname\AC@used
        \expandafter\FU@H\csname fn@#1@IS\endcsname
      \else
        \expandafter\FU@H\csname fn@#1@IL\endcsname
      \fi
     \fi
   \else
   A%
   \fi
}
\newcommand*{\FU@H}[1]{%
  \expandafter\futurelet\expandafter\@let@token\expandafter\FU@@H#1\@nil
}
\def\FU@@H#1\@nil{%
  \ifx\@let@token\AC@hyperlink
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {%
    \FU@@@H#1\@nil
  }{%
    \@firstupper#1%
  }%
}
\def\FU@@@H\AC@hyperlink#1#2#3\@nil{%
  \AC@hyperlink{#1}{\@firstupper#2}%
  \ifx\\#3\\%
  \else
    \errmessage{Stuff after \string\hyperlink}%
  \fi
}
\renewcommand*{\@Iac}[1]{%
  \FU@iaci{#1} \ifAC@starred\ac*{#1}\else\ac{#1}\fi
}
\makeatother

\begin{document}
\begin{acronym}
  \acro {HMM} {Hidden Markov Model}
  \acroindefinite {HMM} {an} {a}
\end{acronym}

\Iac{HMM}

\Iac{HMM}

\end{document}

Result

Making the indefinite article a hyper link seems a little odd to me. It even simplifies the patch, if the indefinite article is left as is:

\documentclass{article}

\usepackage{acronym}
\usepackage{hyperref}

\makeatletter
\renewcommand\AC@acroindefinite[3]{
  \@bsphack
  \protected@write\@auxout{}%
    {\string\newacroindefinite{#1}{#2}{#3}}%
  \@esphack
}
\makeatother

\begin{document}
\begin{acronym}
  \acro {HMM} {Hidden Markov Model}
  \acroindefinite {HMM} {an} {a}
\end{acronym}

\Iac{HMM}

\Iac{HMM}

\end{document}

Result, article without link

3
  • Well done! Probably also \iac needs a patch so that the article doesn't become part of the hyperlink; or will the final patch work also for the lowercase situation?
    – egreg
    Commented Apr 17, 2014 at 21:09
  • @egreg: The latter patch removes the link from the article for both forms \iac and \Iac. Commented Apr 17, 2014 at 21:21
  • @HeikoOberdiek this works perfectly, thank you! Indeed, you also fixed another problem of mine. I'll link your answer there, too!
    – KlausenK
    Commented Apr 18, 2014 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .