5

I am planning to use changes package for marking up changes in the latex document. I like to denote new additions in green, modifications in blue and deletions in red. However, changes package uses the same color for every change. Is it possible to use different colors for the above three commands?

Currently, since I am the only author editing the tex file, I've defined three authors as below

\definechangesauthor[name=new additions, color=teal]{new}
\definechangesauthor[name=in place modifications, color=blue]{modified
\definechangesauthor[name=deletions, color=red]{deleted}

and when adding, modifying, or deleting text, I use corresponding id. However, this cannot be used when there are multiple authors. Further, there are redundancies here. I have to use the command \added and still specify id=new. And in the rendered pdf document, along with the green color, there will be a superscipt saying it is new. How can I do this more efficiently and cleanly?

Edit 1: I have been able to get rid of the superscript by setting \usepackage[authormarkup=none]{changes} as suggested in the first comment to this question. However, it still requires me to use \added[id=new]{new text}

1
  • 1
    The possibility to use different colors for added, deleted and replaced is not provided for the package changes according to the documentation. Possibly, because the colors are already used to differentiate different authors.
    – dexteritas
    Aug 22, 2023 at 7:50

2 Answers 2

1

Nuisance with writing \added[id=new]{new text} can be avoided by defining

\newcommand\noidadded{\added[id=new]}

and then wring simply \noidadded{new text}.


@Ulrike Fischer's approach is very interesting, but has two drawbacks: First, it requires a recent version of latex kernel. The second is that using his hooked \added has effect also for all following commands of the package (unless they are also hooked, to get their own colour). The following reduces the impact (but has some side-effects, too).

\makeatletter
\AddToHook{cmd/added/before}{\bgroup\def\Changes@AuthorColor{red}}
\AddToHook{cmd/added/after}{\egroup}
\makeatother

1
  • Thank you. May be @Ulrike Fischer's answer is better than this, but I don't know. I am accepting this mainly because I understand this easily, requires minimal changes to my existing solution, I ca be confident that this does not affect anything else and that this supports older Latex version also. Aug 23, 2023 at 0:36
3

For one author you can do something like this:

\documentclass{article}
\usepackage{changes}
\makeatletter
\AddToHook{cmd/added/before}{\def\Changes@AuthorColor{red}}
\AddToHook{cmd/deleted/before}{\def\Changes@AuthorColor{green}}
\AddToHook{cmd/replaced/before}{\def\Changes@AuthorColor{blue}}
\makeatother
\begin{document}
{\added{added} \deleted{deleted} \replaced{new}{old}}

\added{added} \deleted{deleted} \replaced{new}{old}
\end{document}

enter image description here

For more authors you will have to be more specific about what should happen. And you should also provide an example that can be used for a test.

8
  • Can you please explain to me how this works? Especially, how the AddToHook helps. Aug 22, 2023 at 9:40
  • 1
    \AddToHook is a fairly recent addition to the LaTeX kernel. It was added in the October 2020 release of LaTeX (LaTeX 2020-10-01). (source: moewe at tex.stackexchange.com/questions/602066 ). So it is latex kernel thing, and it will not work in older versions of tex. Working can be understood from page 28-29 of ctan.math.illinois.edu/macros/latex/base/lthooks-doc.pdf .
    – minorChaos
    Aug 22, 2023 at 12:25
  • It seems that under simple circumstances, the first of them is equivalent to changing the definition \added to <HOOKTEXT><OLD\added>. You could simply define \newcommand\myadd{\def\Changes@AuthorColor{green}\added} and use \myadd with the same effect. Note that (with \AddToHook or without it) the change of \Changes@AuthorColor has effect to all following commands of the package (unless us localize by { ... }).
    – minorChaos
    Aug 22, 2023 at 12:42
  • @minorChaos did you try your \myadd? Aug 22, 2023 at 12:47
  • your changed your command after I made the remark, now it should work. But the main point of using a hook is to avoid to have define lots of new commands. Aug 22, 2023 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .