TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the acronym package to expand acronyms and I'm also using the cleveref package. I would like to have acronyms expanded once per chapter. For instance in the following code, both acronyms should produce the expansion:

\documentclass{report}
\usepackage{acronym}
\usepackage{cleveref}

\acrodef{ac}{Acronym}

\begin{document}
\chapter{one}

\ac{ac} 

\acresetall
\chapter{two}

\ac{ac}
\end{document}

According to the acronym manual I found that calling \acresetall before each chapter produces the desired result but I get warning about duplicate labels (somehow a conflict with cleveref). Is there another way to get the desired result or avoid the warning?

share|improve this question
    
Make a complete example that can be used for testing. – Ulrike Fischer Sep 13 '12 at 11:51
    
I edited the post with a MWE. – nunolopes Sep 13 '12 at 11:55
    
I don't get warnings about duplicate labels if I add \acresetall before or after \chapter{two} – Ulrike Fischer Sep 13 '12 at 12:00
    
Right, it seems to be some strange interaction with the cleveref package. I still found no other answer so I updated the question title and text. – nunolopes Sep 13 '12 at 12:12
up vote 6 down vote accepted

You can try this:

\documentclass{report}
\usepackage{acronym}
\usepackage{cleveref}
\makeatletter
\renewcommand*\@verridelabel[1]{%
  \@bsphack
  \protected@write\@auxout{}{\string\undonewlabel{#1}}%
  \protected@write\@auxout{}{\string\undonewlabel{#1@cref}}%Added for cleverref
  \label{#1}%
  \@overriddenmessage rs{#1}%
  \@esphack
}%
\makeatother
\acrodef{ac}{Acronym}

\begin{document}
\chapter{one}

\ac{ac}

\acresetall
\chapter{two}

\ac{ac}
\end{document}
share|improve this answer

Package cleveref extends \label{<name>} to add \label{<name>@cref}. And package acronym sets a label \label{acro:ac} twice, in the first and second chapter. However it undoes the first label before setting the second, from the .aux file:

\AC@undonewlabel{acro:ac}
\newlabel{acro:ac}{{1}{1}}

Versions of acronym before 2015/03/21 v1.41 are using \undonewlabel instead of \AC@undonuewlabel (see gtownescapee's answer).

The patch below makes the same for the added label by cleveref:

\documentclass{report}
\usepackage{acronym}
\usepackage{cleveref}

\makeatletter
\newcommand*{\org@overidelabel}{}
\let\org@overridelabel\@verridelabel
\@ifpackagelater{acronym}{2015/03/21}{% v1.41
  \renewcommand*{\@verridelabel}[1]{%
    \@bsphack
    \protected@write\@auxout{}{\string\AC@undonewlabel{#1@cref}}%
    \org@overridelabel{#1}%
    \@esphack
  }%
}{% older versions
  \renewcommand*{\@verridelabel}[1]{%
    \@bsphack
    \protected@write\@auxout{}{\string\undonewlabel{#1@cref}}%
    \org@overridelabel{#1}%
    \@esphack
  }%
}
\makeatother

\acrodef{ac}{Acronym}

\begin{document}
\chapter{one}

\ac{ac} 

\acresetall
\chapter{two}

\ac{ac}
\end{document}

The .aux file:

relax 
\reset@newl@bel
\newacro{ac}[ac]{Acronym}
\@writefile{toc}{\contentsline {chapter}{\numberline {1}one}{1}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\AC@undonewlabel{acro:ac@cref}
\AC@undonewlabel{acro:ac}
\newlabel{acro:ac}{{1}{1}}
\newlabel{acro:ac@cref}{{[chapter][1][]1}{1}}
\acronymused{ac}
\@writefile{toc}{\contentsline {chapter}{\numberline {2}two}{2}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\AC@undonewlabel{acro:ac@cref}
\AC@undonewlabel{acro:ac}
\newlabel{acro:ac}{{2}{2}}
\newlabel{acro:ac@cref}{{[chapter][2][]2}{2}}
\acronymused{ac}
share|improve this answer

Both the accepted answer and @Heiko's answer solved this problem for me, until the acronym package was updated to version 1.41 on 2015-03-21. In this version the implementation changed such that the \undonewlabel command was replaced with the \AC@undonewlabel command. To be compatible with v1.41, I recommend @Heiko's answer but replace instances of \undonewlabel with \AC@undonewlabel.

I would have replied as a comment, but I don't have enough rep yet.

share|improve this answer
    
Thanks, I have updated my answer. – Heiko Oberdiek Sep 25 '15 at 18:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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