2

I use the acro package for acronyms. In the following example, I define the acronym "i.i.d.", which ends with a period. If I use it at the end of a sentence, I get two periods.

How can I avoid this automatically?

MWE

\documentclass{article}
\usepackage{acro}
\DeclareAcronym{iid}{short=i.i.d.,long=independent and identically distributed}

\begin{document} The random variables A and B are \ac{iid}. Likewise, the random variables C and D are \ac{iid}. \end{document}

Output

The random variables A and B are independent and identically distributed (i.i.d.).
Likewise, the random variables C and D are i.i.d..

The first sentence is fine. The problem is the two periods at the very end of the second sentence.

2 Answers2

2

This is exactly what \acdot is intended to manage

\documentclass{article}
\usepackage{acro}
\DeclareAcronym{iid}{short=i.i.d\acdot,long=independent and identically distributed}

\begin{document} The random variables A and B are \ac{iid}. Likewise, the random variables C and D are \ac{iid}. \end{document}

However, there is some likely unexpected behaviour in the first instance of \ac{iid} as the command is followed by a dot, but the \acdot in the full form appears within brackets, rather than directly before the full stop. This is intentional, and the acro documentation gives an example with \acspace where suppressing characters within an acronym on the basis of a trailing token may be desirable.

In this case though, a bracket replacing a full stop is less desirable. There is no user interface to deactivate trailing characters in specific contexts only, but we can modify the long-short template (or whatever non-default template is being used) to avoid this and use \acro_trailing_action_deactivate:n to deactivate checks for the dot character when printing the first-style so that \acdot reliably expands to . in those instances.

\ExplSyntaxOn
\RenewAcroTemplate{long-short}{%
\acroiffirstTF{%
  \acro_trailing_action_deactivate:n {dot}
  \acrowrite{long}%
  \acspace(%
    \acroifT{foreign}{\acrowrite{foreign}, }%
    \acrowrite{short}%
    \acroifT{alt}{ \acrotranslate{or} \acrowrite{alt}}%
    \acrogroupcite
  )%
  }%
  {\acrowrite{short}}%
}
\ExplSyntaxOff

The effect of \acro_trailing_action_deactivate:n is local so \acs{iid}. continues to absorb the extra stop, while first use of \ac{iid} and any further uses of \acf{iid} will never suppress the stop in the bracketed short form.

Dai Bowen
  • 6,117
1

Try replacing the final period with \acdot, per section 19 of the acro manual. It looks like this also supports a few other pieces of punctuation as well. For your example, it should look like this:

\documentclass{article}
\usepackage{acro}
\DeclareAcronym{iid}{short=i.i.d\acdot,long=independent and identically distributed}

\begin{document} The random variables A and B are \ac{iid}. Likewise, the random variables C and D are \ac{iid}. \end{document}

  • Using short=i.i.d\acdot the period disappears in the first sentence. – Andrey L. Jun 22 '22 at 14:51
  • Nice, thank you. I didn't know about \acdot. However, as @AndreyL. mentions, also the first sentence is affected... –  Jun 22 '22 at 14:59