# cannot compile when using acronym package \Iac command multiple times

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.
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.

• 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 Apr 17 '14 at 16:12

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{%
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{%
\FU@@@H#1\@nil
}{%
\@firstupper#1%
}%
}
\ifx\\#3\\%
\else
\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}


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}


• 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 Apr 17 '14 at 21:09
• @egreg: The latter patch removes the link from the article for both forms \iac and \Iac. – Heiko Oberdiek Apr 17 '14 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 Apr 18 '14 at 21:36
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8517387509346008, "perplexity": 5046.94729436443}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-10/segments/1614178363217.42/warc/CC-MAIN-20210302034236-20210302064236-00220.warc.gz"}