1

I would like to include one acronym in another using the glossary package, e.g. something like

\usepackage[acronym]{glossary}
\newacronym{a}{A}{apples}
\newacronym{ao}{AO}{apples oranges}

\begin{document}

A basket of \gls{ao} includes \gls{a}.

\end{document}

which currently results in

A basket of apples oranges (AO) includes apples (A).

but I want to have

A basket of apples oranges (AO) includes A.

How can I do this?

3
  • Do you really mean the glossary package rather than glossaries?
    – Dai Bowen
    Commented Feb 13 at 11:08
  • uhm no, I am using glossaries but solely for acronyms in the text.
    – Durd3nT
    Commented Feb 13 at 12:12
  • acro has a simple built-in mechanism through the uselist key that can handle this exact case, and depending what edge cases there are acronyms can be adapted fairly easily with \acroifused<TF>.
    – Dai Bowen
    Commented Feb 15 at 1:31

2 Answers 2

0

If what you're trying to do is get rid of the parentheses around "A," you can try the \acrshort{} command:

\documentclass{article}
\usepackage[acronym]{glossaries}

\newacronym{a}{A}{apples}
\newacronym{ao}{AO}{apples oranges}

\begin{document}

A basket of \gls{ao} includes \acrshort{a}.

\end{document}

Which produces

enter image description here

If you want glossary.sty and not glossaries.sty, you can similarly try \acrsh{}.

2
  • thanks! in that case, however, I need to manually keep track of when which of the two is used first. I want something that does that automatically.
    – Durd3nT
    Commented Feb 13 at 8:39
  • Based on your example it seems like apples (A) will always come before apples and oranges (AO) in the document. If that is the case, then by default the glossaries package will print the second instance of apples (A) without the parentheses. Are you looking for a solution that will always print the second acronym without parenthesis even if that term hasn't been used yet?
    – abc123
    Commented Feb 14 at 1:09
0

\glsunset will mark an entry as used in glossaries. I believe the equivalent macro is \unsetacronym if you genuinely are using glossary—consider switching if so.

\documentclass{article}
\usepackage[acronym]{glossaries}
\newacronym{a}{A}{apples}
\newacronym{ao}{AO}{apples oranges}

\begin{document}
A basket of \gls{ao}\glsunset{a} includes \gls{a}.
\end{document}

A basket of apples oranges (AO) includes A.

Unfortunately trying to use this as \newacronym{ao}{AO}{apples oranges\glsunset{a}} gives an error, conventionally nesting the acronym as \newacronym{ao}{AO}{\gls{a} oranges} doesn't work either. There may be a way around this, but I'm missing it.

However you can patch glossaries manually to check against a stored set of dependent keys each time an acronym is marked as used and mark those dependents as used.

\documentclass{article}
\usepackage[acronym]{glossaries}
\newacronym{a}{A}{apples}
\newacronym{ao}{AO}{apples oranges}

\ExplSyntaxOn
\seq_new:N \l_DurdnT_sub_seq
\seq_new:N \l_DurdnT_sup_seq
\NewDocumentCommand{\AddAcronymDep}{mm}{
\seq_put_right:Nn \l_DurdnT_sub_seq {#1}
\seq_put_right:Nn \l_DurdnT_sup_seq {#2}
}
\NewDocumentCommand{\CheckDependentAcronyms}{m}{
  \tl_set:Nn \l_tmpa_tl {#1}
  \seq_map_pairwise_function:NNN 
    \l_DurdnT_sup_seq
    \l_DurdnT_sub_seq
    \unsetgls_if:nn
}
\cs_new:Nn \unsetgls_if:nn {
  \tl_if_eq:NnT \l_tmpa_tl {#1} {
    \glsunset{#2}
  }
}
\ExplSyntaxOff

\makeatletter
\AtBeginDocument{%
  \renewcommand*{\glsunset}[1]{%
    \gls@ifnotmeasuring
    {%
      \glsdoifexists{#1}%
      {%
        \@glsunset{#1}%
        \CheckDependentAcronyms{#1}%
      }%
    }%
  }%
}
\makeatother

\AddAcronymDep{a}{ao}% Indicate that a should be marked used when ao is used

\begin{document}
\showoutput
A basket of \gls{ao} includes \gls{a}.
\end{document}

A basket of apples oranges (AO) includes A.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .