# How to use \cite in \DeclareRobustCommand

How do I use \cite in \DeclareRobustCommand? I'm using \DeclareRobustCommand to create two ways to highlight text using package soul. For example, this is what I have in the header of the document:

\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}

\DeclareRobustCommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}
\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}


When I use these commands like this, it works:

\hlyg{This is my text here}


However, when I use these comands with \cite, it fails and throws the error below:

\hlyg{This is~\cite{someone} my text here}


And this is the error that I get when I compile the document with Miktex 2.9:

template.tex
191
Argument of \@citex has an extra }.
<inserted text>
\par
l.191 ...ct and limitations on larger scenarios. }


This is an MWE

\documentclass{article}

\usepackage{color}
\usepackage{soul}

\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}

\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}
\DeclareRobustCommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}

\begin{document}

\noindent In order to outline the changes made to the document, the revised
sentences/words are highlighted in two colours:
\begin{enumerate}
\item \hly{Yellow} colour for reviewer 1's comments.
\item \hlyg{Green} colour for reviewer 2's comments.
\end{enumerate}

\\hly{Lorem Ipsum~\cite{lipsum} is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum}

\begin{thebibliography}{9}
\bibitem{lipsum}
Lorem Ipsum
\\\texttt{https://www.lipsum.com/}
\end{thebibliography}

\end{document}

• Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. Dec 14 '17 at 18:36

You just need to brace \cite{someone}. There's no need to declare \hlyg and \hly as robust commands, unless you need them in sectional titles or captions.

\documentclass{article}
\usepackage{soul,xcolor}

\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}

\newcommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}
\newcommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}

\begin{document}

\hlyg{This is my text here}

\hlyg{This is~{\cite{someone}} my text here}

\begin{thebibliography}{1}

\bibitem{someone} A. Uthor, Title, Journal.

\end{thebibliography}

\end{document}


I found the answer in another post, but basically \cite needs to be wrapped into curly brackets:

\hlyg{This is{~\cite{someone}} my text here}