10

I am revising a scientific publication and keeping track of the changes using the \added{}, \deleted{}, and \replaced{good}{bad} 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 is a better sentence \citep{somearticle2016}}{This sentence is lame}

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{good}{bad} command (like this: \replaced{This is a better sentence} \added{\citep{somearticle2016}}{This sentence is lame}).

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{good}{bad} 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! –  May 12 '16 at 11:27

1 Answers1

3

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...

jarauh
  • 2,762
  • 15
  • 27
  • 1
    Help! Enclosing in \mbox does not compile, nor does just enclosing in brackets per https://tex.stackexchange.com/questions/14327/trackchange-and-citations?noredirect=1&lq=1. Enclosing in \protect per https://tex.stackexchange.com/questions/559007/how-do-you-use-trackchanges-with-a-citation-in-a-journal-template?noredirect=1&lq=1 compiles but the citation is not deleted. Can't use latexdiff per https://tex.stackexchange.com/questions/98222/ulem-incompatibility-with-multiple-entries-in-cite?noredirect=1&lq=1 since am generating latex via RStudio/Rmd. Same AGU template, package = trackchanges. – InColorado Mar 21 '21 at 18:25
  • @InColorado I had the same issue with mbox. Following https://tex.stackexchange.com/questions/139463/how-to-make-hl-highlighting-to-automatically-place-incompatible-commands-in I figured that you can introduce e.g. \soulregister\citep7 or \soulregister<yourcommand>7. That fixed the issue for me! – Erik Nov 24 '23 at 12:15