[Tex/LaTex] Acronym Nested Parentheses

acronymsnesting

This question is mainly to collect your opinion, and probably to reach a good solution. That said, let's go to the discussion topic and question.

I commonly use the acronym package in my work, mainly to write article with lots of abbreviations. Sometimes I also use glossaries for the same purpose. I know there are others.

Well, when using those, it sometime may happen that an acronym is expanded inside parentheses, e.g.,

the \ac{BS} (also known as \ac{eNB})

become

the Base Station (BS) (also known as Enhanced Node B (eNB))

As it may be seen, in the second expansion, it get nested parentheses. To avoid this, I sometimes use \acs{} instead of \ac{} while inside parentheses. However, it may happen that the acronym is first used inside the parentheses, and with this approach it is not expanded in the first use.

I was reading link 1 and link 2, and while people said it is acceptable, others recommend to rephase, or use brackets. With brackets, my simple example would become

the Base Station (BS) (also known as Enhanced Node B [eNB])

A solution for this, would be use always brackets instead of parentheses while using acronyms. But I don't know if it is acceptable of all purposes or not.

What is your opinion?

Further, is it possible to say to acronym or other package to use brackets inside parentheses?

\documentclass{article}

\usepackage{acronym}

\begin{document}

\begin{acronym}
  \acro{BS}{Base Station}
  \acro{eNB}{Enhanced Node B}
\end{acronym}

the \ac{BS} (also known as \ac{eNB})

\end{document}

Best Answer

I can't help with the acronym package as I don't use it, but if you don't mind using glossaries instead you can do the following:

\documentclass{article}

\usepackage[shortcuts]{glossaries}

\newacronym{bs}{BS}{Base Station}
\newacronym{enb}{eNB}{Enhanced Node B}

\newcommand*{\pac}[2][]{\ifglsused{#2}{\acs[#1]{#2}}{%
 \glsunset{#2}%
 \acl[#1]{#2} [\acs[#1]{#2}]}}

\begin{document}

\ac{bs} (also known as \pac{enb}).

Later: \ac{bs} (also \pac{enb})

\end{document}

Here you can just use \pac instead of \ac when you want to use the acronym in parentheses.

Result:

Image of resulting text

An alternative approach (which most may consider overkill) is to do:

\documentclass{article}

\usepackage[shortcuts]{glossaries}

\newcount\parencount
\DeclareRobustCommand{\openparen}{\global\advance\parencount by 1\relax
\ifodd\parencount(\else[\fi}
\DeclareRobustCommand{\closeparen}{\ifodd\parencount)\else]\fi
 \global\advance\parencount by -1\relax
}

\catcode`\(=\active
\catcode`\)=\active

\let(\openparen
\let)\closeparen

\renewcommand{\acrfullformat}[2]{#1\space\noexpand\openparen#2\noexpand\closeparen}

\newacronym{bs}{BS}{Base Station}
\newacronym{enb}{eNB}{Enhanced Node B}

\begin{document}

Some parenthesis: (outer level (inner level (getting silly))).

\ac{bs} (also known as \ac{enb}).

\end{document}

Result:

Image of resulting text

Edit: Caveat: it's best not to use the second approach if you use a package such as tikz where parentheses form part of the command syntax.

Edit: Here's an example that switches back and forth, which can either be done by changing the category codes of ( and ) or changing their definition:

\documentclass{article}

\let\orgopenparen(
\let\orgcloseparen)

\newcount\parencount
\DeclareRobustCommand{\openparen}{\global\advance\parencount by 1\relax 
\ifodd\parencount(\else[\fi}
\DeclareRobustCommand{\closeparen}{\ifodd\parencount)\else]\fi
 \global\advance\parencount by -1\relax
}

\catcode`\(=\active
\catcode`\)=\active

\let(\openparen
\let)\closeparen

\begin{document}

Some parenthesis: (outer level (inner level (getting silly))).

% restore original behaviour (changing definition)
\let(\orgopenparen
\let)\orgcloseparen

Some parenthesis: (outer level (inner level (getting silly))).

% switch back

\let(\openparen
\let)\closeparen

Some parenthesis: (outer level (inner level (getting silly))).

% restore original behaviour (changing category code)
\catcode`\(=12\relax
\catcode`\)=12\relax

Some parenthesis: (outer level (inner level (getting silly))).

\end{document}

Result:

Image of resulting text

Related Question