cgnieder / acro

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

barriers/single can lead to use of undefined short form #210

Open bersbersbers opened 3 years ago

bersbersbers commented 3 years ago
\documentclass{article}
\usepackage{acro}
\acsetup{
    use-id-as-short,
    single,
    barriers/use,
    barriers/single,
}
\DeclareAcronym{CPU}{long=central processing unit}
\DeclareAcronym{RAM}{long=random access memory}
\begin{document}
    \ac{CPU} -- OK (single use)

    \ac{RAM}, \ac{RAM} -- OK (first and nth use)

    --- Here's a barrier! \acbarrier ---

    \ac{CPU}, \ac{CPU} -- not OK (CPU is undefined)

    \ac{RAM}, \ac{RAM} -- OK (nth use, twice)
\end{document}

Yields: image

I am not sure this is a bug, but my expectation was that after the first barrier, I would get "central processing unit (CPU), CPU": currently, "CPU" is "undefined".

Technically, after a \barrier'ed section with a singly-used acronym, I'd expect that acronym (only that one) to be reset even under barriers/reset=false. (Note that "RAM" is defined twice when using barriers/reset=true - as expected, but unwanted - so that is not really a solution.) If that is not possible, maybe barriers/single should force barriers/reset, but I don't think that is necessary.

By the way, what is my use case?

cgnieder commented 3 years ago

I get no undefined error along the lines of

./test.tex:16: Package acro Error: You've requested acronym `xx' on line 16 but you
(acro)                apparently haven't defined it, yet!
(acro)                Maybe you've misspelled `xx'?

so I guess you don't actually mean undefined.

I am not sure what the expected outcome should be. IMHO barriers/single=true does only make sense in combination with barriers/reset=true. In your example none of the two usages of CPU after the barrier is the first use in the document so technically the outcome is correct.

What you actually want is that an acronym is reset at a barrier if it is has been used only once, despite having chosen barriers/reset=false.

I can understand your setup but I have to think about a solution.

BTW: I guess this should be true if it happens multiple times as well? Like in this example:

1: \ac{aa} \par
\acbarrier
2: \ac{aa}, \ac{aa} \par
\acbarrier
3: \ac{aa} \par
\acbarrier
4: \ac{aa}, \ac{aa} \par
bersbersbers commented 3 years ago

I get no undefined error [...] so I guess you don't actually mean undefined.

Correct - I mean it in a semantic way from the point of view of the final document. I did not have any better expression - I could have said "short form used without being introduced alongside the long form".

I am not sure what the expected outcome should be. IMHO barriers/single=true does only make sense in combination with barriers/reset=true.

I agree that this is one valid way to see it. This is not my preferred one, but if it's yours, it would make sense to enforce that through a warning or something like this.

In your example none of the two usages of CPU after the barrier is the first use in the document so technically the outcome is correct.

Technically, yes ;)

What you actually want is that an acronym is reset at a barrier if it is has been used only once

Correct - after a single use which is the first use in the document.

despite having chosen barriers/reset=false.

Yes, and a bit of no. I would not say "chosen" - I have not actively set it to false: I have only omitted it. From a user standpoint, I think it should be considered valid to pick only a few options and set them to true while ignoring other options, if the package does not give a warning (or forces other values internally).

I can understand your setup but I have to think about a solution.

I have a couple of ideas:

BTW: I guess this should be true if it happens multiple times as well? Like in this example:

1: \ac{aa} \par
\acbarrier
2: \ac{aa}, \ac{aa} \par
\acbarrier
3: \ac{aa} \par
\acbarrier
4: \ac{aa}, \ac{aa} \par

I think what we currently get is

1: Long 2: short, short 3: short 4: short, short

What would I expect here? Only a single exception at 2, I believe:

1: Long 2: Long (short), short 3: short 4: short, short (Is that identical to internally using the starred version in the sections with single use? Maybe not for lists, but for everything else it should be.)

For me, since we are not using barriers/reset, the expected rule is "introduce the short form if it has not been introduced yet to obtain a consistent document". Technically, this may translate into