# How to use citation inside a newcommand? [duplicate]

I am editing an article and I want to create a method to track changes. I have defined a command using newcommand to highlight everything written inside (I use it instead of newenvironment because I don't want newenvironment creating spaces between the text).

The code is the following:

``````\newcommand{\edited}[1]{%
\definecolor{hlcolor}{RGB}{255,255,0}\sethlcolor{hlcolor}%
\hl{#1}%
}
``````

And I use it this way:

``````text text text text \edited{highlighted text highlighted text
highlighted text highlighted text highlighted text highlighted
text highlighted text highlighted text} text text text...
``````

My problem is that when I try to citate something inside the macro...

``````text text text text \edited{highlighted text highlighted text
highlighted text \cite{Ref1} highlighted text highlighted
text highlighted text highlighted text} text text text...
``````

I get the error:

``````! Argument of \@citex has an extra }.
<inserted text>
\par
l.225 ...ncy, reliability, and power consumption.}

?
``````

How can I solve this problem? I was using newcommand because I want some kind of macro that can have a behaviour change when needed (for example, delete the highlight when the document is finished).

• You could likely bypass the need for writing any such a macro if you learn to use `latexdiff`, which can be integrated with git to show how versions have changed over time. It would certainly make the source code much cleaner. – oliversm Mar 4 at 15:13
• I have just learned to use latexdiff and I end up having the same problem... Latexdiff works using its own macro "\DIFadd" and I get the same problem: if there is a citation inside a macro (in this case \DIFadd macro), I get the error shown in the original question... – Dgrm Mar 5 at 8:58
• I've used latexdiff with references and citations (using natbib) in the past with no problems (as far as I recall). Perhaps if you could replicate the error using it then it might prompt some more solutions. – oliversm Mar 5 at 11:08