You need to group the parts that \hl
can't deal with, but unfortunately even this fails with the first use of \gls
. This can be demonstrated with the following which only works because the first use is comes before the \hl
part:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
First use: \gls{fbi}.
\added{Fox Mulder is a {\gls{fbi}} special agent educated
at Oxford~{\cite{latexcompanion}} who believes in the existence of
extraterrestrials and a government conspiracy~{\cite{einstein}}
to hide the truth regarding them~{\cite{knuthwebsite}}.
Dana Scully is an {\gls{fbi}} special agent, a medical doctor,
and scientist who is Mulder's partner. In contrast to his
credulity, Scully is a skeptic, basing her beliefs on scientific
explanations.}
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\bibitem{einstein}
Albert Einstein.
\textit{Zur Elektrodynamik bewegter K{\"o}rper}. (German)
[\textit{On the electrodynamics of moving bodies}].
Annalen der Physik, 322(10):891–921, 1905.
\bibitem{knuthwebsite}
Knuth: Computers and Typesetting,
\\\texttt{http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html}
\end{thebibliography}
\end{document}

Unfortunately even adding \mbox
fails:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
\added{Fox Mulder is a \mbox{\gls{fbi}} special agent.}
\end{document}
This results in the error:
! Package soul Error: Reconstruction failed.
Part of the problem seems to be the unsetting of the first use flag, which can be demonstrated with:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
\added{Fox Mulder is a \mbox{\glsunset{fbi}} FBI special agent.}
\end{document}
Adding \protect
removes the error message:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
\added{Fox Mulder is a \mbox{\protect\glsunset{fbi}} FBI special agent.}
\end{document}
Unfortunately, although \protect\gls
removes the error, it also removes the highlighting:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
\added{Fox Mulder is a \protect\gls{fbi} special agent.}
\end{document}

The extension package glossaries-extra
, as from version 1.30, has a way of temporarily buffering pending instances of \glsunset
. This is switched on with \GlsXtrStartUnsetBuffering
and switched off with \GlsXtrStopUnsetBuffering
(which applies \glsunset
to the saved labels):
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}% glossaries-extra.sty
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
\begin{document}
\GlsXtrStartUnsetBuffering % glossaries-extra.sty v1.30+
\added{Fox Mulder is a \mbox{\gls{fbi}} special agent.}
\GlsXtrStopUnsetBuffering % glossaries-extra.sty v1.30+
\end{document}

For convenience, this can be incorporated into the definition of \added
:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}% glossaries-extra.sty
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{%
\GlsXtrStartUnsetBuffering % glossaries-extra.sty v1.30+
{\sethlcolor{added}\hl{#1}}%
\GlsXtrStopUnsetBuffering % glossaries-extra.sty v1.30+
}
\begin{document}
\added{Fox Mulder is a \mbox{\gls{fbi}} special agent.}
\end{document}
Unfortunately \mbox
is still needed, which can cause paragraph justification problems as the content of \mbox
can't be broken across a line. The other problem is that if \gls{fbi}
is used multiple times within the same \added
argument they will all be fully expanded as the first use flag can't be unset until \GlsXtrStopUnsetBuffering
.
Another possibility with glossaries-extra
v1.30+ is to move \gls
outside of \added
and use the textformat
key to push \added
further inside the internal workings of \gls
to help \hl
work:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}% glossaries-extra.sty
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\newcommand{\added}[1]{{\sethlcolor{added}\hl{#1}}}
% command for use in `textformat` (glossaries-extra v1.30+):
\newrobustcmd{\gadded}[1]{%
{%
\def\glsxtrabbreviationfont##1{\GlsXtrExpandedFmt{\added}{##1}}%
\def\glsxtrregularfont##1{\GlsXtrExpandedFmt{\added}{##1}}%
#1%
}%
}
\begin{document}
\added{Fox Mulder is a }\gls[textformat=gadded]{fbi}\added{ special agent.}
\end{document}

With just the base glossaries
package, or with earlier versions of glossaries-extra
. the only partial solution I can think of in this case is a bit of a fudge:
\documentclass[a4paper,12pt]{report}
\usepackage[usenames, dvipsnames]{color}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{glossaries}
\newacronym{fbi}{FBI}{Federal Bureau of Investigation}
\definecolor{added}{RGB}{161,217,155}
\makeatletter
\newcommand{\added}[1]{{\let\glsunset\@gobble\sethlcolor{added}\hl{#1}}}
\makeatother
\begin{document}
\added{Fox Mulder is a \mbox{\gls{fbi}} special agent educated
at Oxford~{\cite{latexcompanion}} who believes in the existence of
extraterrestrials and a government conspiracy~{\cite{einstein}}
to hide the truth regarding them~{\cite{knuthwebsite}}.}
\glsunset{fbi}
\added{Dana Scully is an {\gls{fbi}} special agent, a medical doctor,
and scientist who is Mulder's partner. In contrast to his
credulity, Scully is a skeptic, basing her beliefs on scientific
explanations.}
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\bibitem{einstein}
Albert Einstein.
\textit{Zur Elektrodynamik bewegter K{\"o}rper}. (German)
[\textit{On the electrodynamics of moving bodies}].
Annalen der Physik, 322(10):891–921, 1905.
\bibitem{knuthwebsite}
Knuth: Computers and Typesetting,
\\\texttt{http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html}
\end{thebibliography}
\end{document}

For multiple citations it seems you need \mbox
. For example, \mbox{\cite{einstein,knuthwebsite}}
.