5

I am revising a scientific publication and keeping track of the changes using the \added{}, \deleted{}, and \replaced{bad}{good} commands.

The compilation fails when trying to replace/add/delete text that contains citations made with the \citet{} or \citep{} commands, e.g.,:

\replaced{This sentence is lame}{This is a better sentence \citep{somearticle2016}}

does not work. I have tried to use \protect in front of the citation as suggested here, also tried to add curly brackets around the citation as suggested here, unsuccessfully. I would rather avoid putting the citation outside of the \replaced{bad}{good} command (like this: \replaced{This sentence is lame}{This is a better sentence} \added{\citep{somearticle2016}}).

Has anyone encountered this issue, and how did you work around it? Note that I cannot add macros of my own, and would like to avoid adding packages.

\replaced{bad}{good} is defined as follows (but cannot be modified):

\def\replaced{\@ifnextchar[{\xreplaced}{\yreplaced}}

\long\def\xreplaced[#1]#2#3{%
\ifdraft
\global\advance\refchangenumber by 1
\ifnumlines\xdef\doit{\noexpand\linelabel{\the\refchangenumber}}\doit\else%
\xdef\doit{\noexpand\label{\the\refchangenumber}}\doit\fi%
{\color{trackcolor}(Replaced: \sout{#2}}
{\color{black}replaced with:} {\color{trackcolor} #3)}%
\expandafter\gdef\csname
changenum\the\refchangenumber\endcsname{Replaced: [#1]
{\color{trackcolor}\sout{#2}} {\color{black} replaced with:}
{\color{trackcolor}#3}, }\else#3\fi}

\long\def\yreplaced#1#2{%
\ifdraft
\global\advance\refchangenumber by 1
\ifnumlines\xdef\doit{\noexpand\linelabel{\the\refchangenumber}}\doit\else%
\xdef\doit{\noexpand\label{\the\refchangenumber}}\doit\fi%
{\color{trackcolor}(Replaced: \sout{#1}}
{\color{black}replaced with:} {\color{trackcolor} #2)}%
\expandafter\gdef\csname changenum\the\refchangenumber\endcsname{Replaced:
{\color{trackcolor}\sout{#1}} {\color{black} replaced with:}
{\color{trackcolor}#2}, }\else#2\fi}
  • Welcome to TeX.SX! Rather than posting a screenshot can you please cut and paste the actual code into your question (and then press the {} symbol in the gui to highlight it). This way people can easily copy your code and work with it. The screenshot is close to being useless as the only way to use it is to retype it! – Andrew May 12 '16 at 11:27
2

For me, it worked to put the citation into an \mbox; like so:

\replaced{This sentence is lame}{This is a better sentence \mbox{\citep{somearticle2016}}}

That, of course, kills the line breaking. But with change highlighting active, nice line breaks are not the top priority anyways...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.