cgnieder / acro

acronyms for LaTeX
LaTeX Project Public License v1.3c
42 stars 9 forks source link

Feature Request: \acresetall for specific tags only #197

Closed SamThilmany closed 3 years ago

SamThilmany commented 3 years ago

I like the concept of \acresetall as it is sometimes desired to re-introduce the abbreviations, e.g., in each new chapter, especially if the reader may skip some chapters.

However, I think that there are acronyms that are well known and should thus only be introduced at their very first appearance for the sake of completeness. Thus it would be great to be able to filter the acronyms to reset using the available tags. Currently, a possibility to reset a specific list of acronyms is provided, but it would be quite cumbersome to write down every single acronym manually in this context. That's why I'm suggesting an \acresettag{<csv list of acronym tags>} command.

What do you think?

cgnieder commented 3 years ago

Would be possible to add:

\documentclass{article}
\usepackage{acro}

\DeclareAcronym{aa}{
  short = a ,
  long = the letter a ,
  tag = letter
}
\DeclareAcronym{bb}{
  short = b ,
  long = the letter b ,
  tag = letter
}
\DeclareAcronym{11}{
  short = 1 ,
  long = the number one ,
  tag = number
}
\DeclareAcronym{22}{
  short = 2 ,
  long = the number two ,
  tag = number
}

\ExplSyntaxOn
\NewDocumentCommand \acresettags {m}
  {
    \seq_map_inline:Nn \g__acro_acronyms_seq
      {
        \clist_map_inline:nn {#1}
          {
            \acro_tag_if:nnT {##1} {####1}
              {
                \acro_reset:n {##1}
                \clist_map_break:
              }
          }
      }
  }
\ExplSyntaxOff

\begin{document}

\ac{aa} \ac{bb} \ac{11} \ac{22} \par
\ac{aa} \ac{bb} \ac{11} \ac{22}

\acresettags{letter}
\ac{aa} \ac{bb} \ac{11} \ac{22}

\acresettags{letter,number}
\ac{aa} \ac{bb} \ac{11} \ac{22}

\end{document}
cgnieder commented 3 years ago

I'm hesitating a little bit to add the command itself but I'll add a few interface commands so the definition can be done without expl3 on the document level:

\documentclass{article}
\usepackage{acro}

\DeclareAcronym{aa}{
  short = a ,
  long = the letter a ,
  tag = letter
}
\DeclareAcronym{bb}{
  short = b ,
  long = the letter b ,
  tag = letter
}
\DeclareAcronym{11}{
  short = 1 ,
  long = the number one ,
  tag = number
}
\DeclareAcronym{22}{
  short = 2 ,
  long = the number two ,
  tag = number
}

\newcommand*\acresettagsaux[1]{\AcroAcronymsMap{\acroiftagT{#1}{\acreset{##1}}}}
\NewDocumentCommand\acresettags{>{\SplitList{,}}m}{%
  \ProcessList{#1}{\acresettagsaux}%
}

\begin{document}

\ac{aa} \ac{bb} \ac{11} \ac{22} \par
\ac{aa} \ac{bb} \ac{11} \ac{22}

\acresettags{letter}
\ac{aa} \ac{bb} \ac{11} \ac{22}

\acresettags{letter,number}
\ac{aa} \ac{bb} \ac{11} \ac{22}

\end{document}