cgnieder / acro

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

acroifstarred should not expand twice. #198

Closed AlexanderWillner closed 3 years ago

AlexanderWillner commented 3 years ago

In #162 you introduced acroifstarred. However, I think using \ac*{xxx} a second time should not expand the acronym, should it? Further, in the mwe below, if \ac{normal} is used instead of a second \ac*{normal} the cited reference will be shown.


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[paperheight=20\baselineskip]{geometry}

\usepackage{url}
\usepackage{acro}

\ExplSyntaxOn
\ProvideExpandableDocumentCommand \acroifstarredF {} { \bool_if:NF \l__acro_star_bool }
\ExplSyntaxOff

\DeclareAcronym{normal}{
  short     = {normal} ,
  long      = {normal acronym},
  long-post = {\acroiffirstT{\acroifstarredF{\footnote{\url{http://normal.org}}}}},
  cite      = {Smar1992} ,
}

\begin{document}

\begin{abstract}
  Some text with \ac*{normal} and other text. And \ac*{normal} again. % <- this should not expand
\end{abstract}

Some text with \ac{normal} and other text.

\end{document}
cgnieder commented 3 years ago

What do you mean by “expand”? Expansion is TeX's process of replacing a macro by its replacement text (you know, all the stuff you can influence with \expandafter, \expanded, \unexpanded, \edef, …).

I'm guessing that you are wondering why the second \ac*{normal} looks exactly like the first one. This is expected and has nothing to do with \acifstarred. This shorter example shows the same:

\documentclass{article}
\usepackage{acro}

\DeclareAcronym{aa}{
  short = a ,
  long = the letter a
}

\begin{document}

\ac*{aa} \par
\ac*{aa} \par
\ac{aa}

\end{document}

image

Remember: a starred version of any of the \ac commands does count as usage. The .acr file of my example has \ACRO{usage}{aa=={1}} which stems of the one non-starred \ac{aa}. This means as far as the second \ac*{aa} is concerned the aa acronym has not been used before which is why the first template is used again.

AlexanderWillner commented 3 years ago

Thanks, yes, I used the wrong terminology here, as I was not referring to TeX's expansion process.

I was under the assumption that the starred version of the command would help with the use case described in #162 (using acronyms in the abstract without footnotes and bibliography). However, this was a misunderstanding as I can't properly use an acronym twice using the starred version for this specific case. Now that #164 is fixed, I'll just use the self-defined \AcroNormal and \AcroAbstract commands as described in #162. This fits my needs.

cgnieder commented 3 years ago

In my opinion it does solve #162. Given that an abstract usually is not longer than one or two paragraphs the author can easily know how often he uses an acronym or abbreviation and can decide to use \acs* where neede, just as one would do in a section title. That means personally I would use

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[paperheight=20\baselineskip]{geometry}

\usepackage{url}
\usepackage{acro}

\ExplSyntaxOn
\ProvideExpandableDocumentCommand \acroifstarredF {} { \bool_if:NF \l__acro_star_bool }
\ExplSyntaxOff

\DeclareAcronym{xx}{
  short     = {short} ,
  long      = {long form},
  long-post = {\acroiffirstT{\acroifstarredF{\footnote{\url{http://normal.org}}}}},
  cite      = {Smar1992} ,
}

\begin{document}

\begin{abstract}
  Some text with \ac*{xx} and other text.  Now we talk about \acs*{xx}
  again.
\end{abstract}

Some text with \ac{xx} and other text.

\end{document}

But if you have another solution that suits you better then go ahead :)

AlexanderWillner commented 3 years ago

True, two solutions - fit's everyone. Personally, I don't want to care about the position of an acronym, that's imho one of the most important points of the package (e.g. the position might change while refactoring / restructuring text). But this is minor in the abstract and your mileage may vary ;)