cgnieder / acro

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

boolean to check if a tag has used entries? #228

Closed ratmice closed 1 year ago

ratmice commented 3 years ago

I would like to do something like the following for a series of documents which share tags and potentially unused tags, Currently, when using an empty list, it still shows the heading, and complains:

Package acro Warning: Empty acronym list. If you have used acronyms then
(acro)                re-compile to get the list filled. Otherwise remove
(acro)                \printacronyms

I assume rather than making an entire setting for not printing the heading of an empty list, a conditional might be more flexible? Something to the effect of: \ifthenelse{\FictionalIfAcronymsEmptyTest[include=badwords]}{\printacronyms[include=badwords, display = used, name={Bad Words}]}{}

I figure that could be problematic due to the 're-compile to get the list filled', and that I would also need something which filled the acronyms without printing them.

I am new to the package, and have just been reading through the manual today, but haven't seen any documented way to do this kind of thing.

below is a moderately silly minimal example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[version=3]{acro}
\usepackage{ifthen}
\acsetup{
  make-links ,
  pages / display = first ,
  pages/fill=\acrodotfill
}

\DeclareAcronym{HS}{%
  short            = HS,
  long             = Hockey Sticks ,
  long-plural      = es ,
  tag = equipment
}

\DeclareAcronym{he2xHS}{%
  short            = he2xHS ,
  long             = Hell ,
  tag = badwords
}

\begin{document}

\printacronyms[include=equipment, display = used, name={Equipment}]
\printacronyms[include=badwords, display = used, name={Bad Words}]
%\ifthenelse{\FictionalIfAcronymsEmptyTest[include=badwords]}{\printacronyms[include=badwords, display = used, name={Bad Words}]}{}
Bring your \ac{HS}% to \ac{he2xHS}
\end{document}
cgnieder commented 2 years ago

You could redefine the template for the list (or define your own template) in a way that it just prints nothing if the list is empty:

\documentclass{article}
\usepackage{acro}

\RenewAcroTemplate[list]{description}{%
  \acronymsmapT{}{%
    \acroheading
    \acropreamble
    \begin {description}
  }%
  \acronymsmapT{
    \item[\acrowrite{short}\acroifT{alt}{/}\acrowrite{alt}]
      \acrowrite{list}%
      \acroifanyT{foreign,extra}{ (}%
      \acrowrite{foreign}%
      \acroifallT{foreign,extra}{, }%
      \acrowrite{extra}%
      \acroifanyT{foreign,extra}{)}%
      \acropagefill
      \acropages
        {\acrotranslate{page}\nobreakspace}
        {\acrotranslate{pages}\nobreakspace}%
  }
  {\end{description}}
}

\DeclareAcronym{HS}{%
  short            = HS,
  long             = Hockey Sticks ,
  long-plural      = es ,
  tag = equipment
}

\DeclareAcronym{he2xHS}{%
  short            = he2xHS ,
  long             = Hell ,
  tag = badwords
}

\begin{document}

\printacronyms[include=equipment, display = used, name={Equipment}]
\printacronyms[include=badwords, display = used, name={Bad Words}]

Bring your \ac{HS}% to \ac{he2xHS}

\end{document}
ratmice commented 2 years ago

Thanks, I'll give that a go, and leave it up to you whether you think something should be added or alternately if this should just be closed