% \iffalse meta-comment
%
% Copyright (C) 2020-2026 by David Kempe
% ---------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<package> \ProvidesPackage{color-edits}[2026/07/05 v2.0 Class for annotating authors' edits in color]
% 
%<package> \RequirePackage{color}
%<package> \RequirePackage{etoolbox}
%<package> \RequirePackage{pdfcolfoot}
%
%<package> \newbool{coloredits@GlobalSuppress}
%<package> \newbool{coloredits@CurrentSuppress}
%<package> \newbool{coloredits@GlobalRevert}
%<package> \newbool{coloredits@CurrentRevert}
%<package> \newbool{coloredits@ShowDeletions}
%<package> \newbool{coloredits@InlineDeletions}
%
%<package> \DeclareOption{suppress}{
%<package> \booltrue{coloredits@GlobalSuppress}
%<package> \ifbool{coloredits@GlobalRevert}{%
%<package> \PackageWarningNoLine{color-edits}{Options revert and suppress both specified. Ignoring revert}}{}
%<package> }
%
%<package> \DeclareOption{revert}{
%<package> \booltrue{coloredits@GlobalRevert}
%<package> \ifbool{coloredits@GlobalSuppress}{%
%<package> \PackageWarningNoLine{color-edits}{Options revert and suppress both specified. Ignoring revert}}{}
%<package> }
%
%<package> \DeclareOption{showdeletions}{
%<package> \booltrue{coloredits@ShowDeletions}}
%
%<package> \DeclareOption{inlinedeletions}{
%<package> \booltrue{coloredits@InlineDeletions}}
%
%<package>\ProcessOptions\relax
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{color-edits}
%\usepackage{fullpage}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{color-edits.dtx}
\end{document}
%</driver>
% \fi
%
% \iffalse \OnlyDescription \fi
%
% \CheckSum{185}
% 
    % \CharacterTable
    %  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
    %   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
    %   Digits        \0\1\2\3\4\5\6\7\8\9
    %   Exclamation   \!     Double quote  \"     Hash (number) \#
    %   Dollar        \$     Percent       \%     Ampersand     \&
    %   Acute accent  \'     Left paren    \(     Right paren   \)
    %   Asterisk      \*     Plus          \+     Comma         \,
    %   Minus         \-     Point         \.     Solidus       \/
    %   Colon         \:     Semicolon     \;     Less than     \<
    %   Equals        \=     Greater than  \>     Question mark \?
    %   Commercial at \@     Left bracket  \[     Backslash     \\
    %   Right bracket \]     Circumflex    \^     Underscore    \_
    %   Grave accent  \`     Left brace    \{     Vertical bar  \|
    %   Right brace   \}     Tilde         \~}
%
% \changes{v0.1}{2014/08/17}{First version of .sty file}
% \changes{v0.2}{2016/06/16}{Improved definition for robustness, including making commands long, i.e., accepting multi-paragraph arguments}
% \changes{v0.3}{2020/02/26}{Added replace and deletecomment commands}
% \changes{v1.0}{2020/03/03}{First fully packaged version}
% \changes{v1.1}{2020/09/18}{Added ability to suppress individual authors}
% \changes{v2.0}{2026/07/05}{Refactored code using etoolbox, fixed spacing bug with suppressed content, fixed color spill bug with page-spanning footnotes, fixed spacing bug when interacting with wrapfig and such, added revert package option and name, added inlinedelete and inlinedeletecomment commands, added inlinedeletions package option}
% 
% \GetFileInfo{color-edits.sty}
%
% \DoNotIndex{\booltrue,\boolfalse,\ifbool,\ifboolexpr,\ifstrequal,\ifblank}
% \DoNotIndex{\long,\def,\csdef,\cslet,\csletcs}
% \DoNotIndex{\leavevmode,\color,\marginpar,\scriptsize}
%
%
% \title{The \textsf{color-edits} package\thanks{This document corresponds to \textsf{color-edits}~\fileversion, dated \filedate.}}
% \author{David Kempe \\ \texttt{David.M.Kempe@gmail.com}}
%
% \maketitle
%
% \begin{abstract}
%   The color-edits style file packages and streamlines/improves a functionality that I and many co-authors used to copy-paste and redo by hand: marking/annotating edits by different authors in a jointly edited document. It provides one command that generates a suite of eight commands for each author, assigning each author a color. These eight automatically generated commands allow each author to distinguish by color text which the author suggests (1) adding, (2) substituting for other text, (3) deleting, (4) deleting while giving a reason for the deletion. In addition, it provides commands to add comments in the text or margin.
%
%   The package has four options. One option |suppress| allows to suppress all colors, replacements, comments, and marked deletions --- it basically results in the document being displayed as you probably want it to when all suggested changes have been resolved. The option |revert| reverts all changes by all authors, i.e., restores deleted text, deletes added text, and reverts replaced text to the original version. The option |showdeletions| shows all suggested deletions in the text in gray, rather than just indicating that \emph{something} was deleted. The option |inlinedeletions| puts comments accompanying deletions in the text instead of in the margins, avoiding large amounts of text in the margins.
% \end{abstract}
%
% \section{Introduction}
%
% The package |color-edits| implements a suite of functionalities that is often needed when multiple authors jointly edit a document. When doing so, authors will frequently want to mark up their (suggested or implemented) changes to the document in a way that is directly visible to co-authors, and also sometimes provide explanations for their changes, or raise issues/questions for their co-authors to consider or address. Many author teams address this by defining a macro for each author that displays the author's edits in an author-specific color. While this works well for additions, it does not make it as easy to mark deletions, and requires manual changes when comments have not been addressed and a deadline looms.
%
% For example, if one has just one colorful macro for an author, and the author uses it both for marking recent edits/additions and providing comments to co-authors, there is no simple way to delete the comments while keeping the added text (but changing its color to the ``normal'' one.) The present package tries to address these issues with a fairly simple implementation that provides eight macros whose behavior can be altered in the (hopefully) ``straightforward'' way with package options.
%
% \section{Usage}
%
% \subsection{Package Options} \label{sec:package-options}
%
% The package |color-edits| has four options: |suppress|, |revert|, |showdeletions| and |inlinedeletions|. Here, we discuss their purpose at a high level --- the precise effects are discussed in Section~\ref{sec:generated-macros}.
%
% The option \DescribeMacro{suppress} |suppress| suppresses all authors (see Section~\ref{sec:suppressed-author}): it changes the definitions of the commands in such a way that the file that is produced looks as much as possible as one would expect if all editing issues had been addressed/accepted by the authors.
%
% The option \DescribeMacro{revert} |revert| reverts all edits by all authors (see Section~\ref{sec:reverted-author}): it changes the definitions of the commands in such a way that the file that is produced looks as much as possible as one would expect if no authors had performed any of the edits.
%
% If both |suppress| and |revert| are given as package options, |revert| will be ignored, and the package will display a compilation warning. Either package option will override individual author settings (see Sections~\ref{sec:exported-macro}, \ref{sec:suppressed-author}, \ref{sec:reverted-author}), i.e., if the package option |revert| is given and an individual author has name |suppress|, the author's edits will still be reverted, and vice versa.
%
% The option \DescribeMacro{showdeletions} |showdeletions| is useful when one wants to see in the compiled file not only \emph{that} something was replaced/deleted, but also \emph{what} the old text was. Specifically, for the replacement and deletion macros, instead of just marking that something was replaced/deleted, it displays the replaced/deleted text in gray. Author suppression or revert overrides |showdeletions|, i.e., |showdeletions| has no effect when an author is suppressed or reverted.
%
% The option \DescribeMacro{inlinedeletions} |inlinedeletions| changes the behavior of the macros for deletion (with and without comments) to be identical to those for inline deletion (with and without comments). Specifically, instead of leaving a small marker in the text and a longer note about the deletion in the margin, it changes the behavior to leave the note directly in the text. Author suppression or revert overrides |inlinedeletions|, i.e., |inlinedeletions| has no effect when an author is suppressed or reverted.
% 
% \subsection{The exported macro \texttt{\textbackslash{}addauthor}}
% \label{sec:exported-macro}
% The package only exports one macro: |\addauthor| \oarg{auth-name} \marg{auth} \marg{auth-color}. Calling this macro in the preamble of your document automatically generates the following eight macros, described in more detail below.
% \begin{enumerate}
% \item |\<auth>edit| \marg{text}
% \item |\<auth>replace| \marg{old-text} \marg{new-text}
% \item |\<auth>comment| \marg{comment}
% \item |\<auth>margincomment| \marg{comment}
% \item |\<auth>delete| \marg{deleted-text}
% \item |\<auth>inlinedelete| \marg{deleted-text}
% \item |\<auth>deletecomment| \marg{comment} \marg{deleted-text}
% \item |\<auth>inlinedeletecomment| \marg{comment} \marg{deleted-text}
% \end{enumerate}
%
% When the optional argument \meta{auth-name} is not provided, the argument \meta{auth} will be used as the author's name. The intended use is that \meta{auth} is short enough that authors will not mind using it as part of a command name, but \meta{auth-name} might be more descriptive, to display with comments or notes about deletions. For example, if Ada Lovelace and Charles Babbage were working on a paper together, they might write the following:
%
% \begin{verbatim}
% \usepackage{color-edits}
% \addauthor{al}{blue}
% \addauthor[Charles]{cb}{green}
% \end{verbatim}
%
% All edits by Ada will be marked in blue, and those by Charles in green. Whenever there is an attributed comment/deletion, for Ada, it would be prefaced by |al|, whereas for Charles, it would be prefaced by |Charles|.
%
% There are two additional specific uses of the optional name. If an author's optional name \meta{auth-name} is set to |suppress|, then this author's edits/comments/deletions are suppressed; see Section~\ref{sec:suppressed-author}. Similarly, if an author's optional name \meta{autho-name} is set to |revert|, then this author's edits/comments/deletions are reverted; see Section~\ref{sec:reverted-author}. Notice that this gives more fine-grained control --- for instance, it can let you focus on the most recent round of edits/comments, if a new ``author'' has been added for it, observe the status before the latest round of edits by one author, etc.\footnote{I would like to thank Krishnamurthy Iyer for this suggestion and a suggested implementation.}
% If a package option of |suppress| or |revert| has been specified, this overrides individual author names of |suppress| or |revert|.
% 
% \subsection{Suppressed Authors} \label{sec:suppressed-author}
% One sometimes wants to suppress the colorful edits and make the file look as much as possible as what is expected after all comments have been addressed and all suggested edits/deletions have been approved.
% We call this \emph{suppressing} an author\footnote{We still highly recommend explicitly addressing all issues, then removing the macros to let your co-author(s) know that you saw their edits and approve of them, and that all comments have been addressed. The use of suppression is intended primarily for a quick check of, e.g., how long your document will be once all comments are removed, or to focus on the most recent round of suggested edits. Of course, every now and then, it is 3 minutes before the submission deadline, and you have no choice.}.
% Specifically, suppressing an author does the following (described in more detail in the context of the specific macros):
% \begin{itemize}
% \item Remove all color.
% \item Remove all comments (both in the text and margins).
% \item For all text that has been (suggested as) deleted or replaced, nothing is displayed.
% \end{itemize}
%
% There are two ways to suppress authors: one can suppress individual authors by changing their optional names to |suppress| (see Section~\ref{sec:exported-macro}). Alternatively, by using the package option |suppress| (see Section~\ref{sec:package-options}), all authors are suppressed. If the package option |revert| is given, then even an author with optional name |suppress| will be \emph{reverted}, not \emph{suppressed}.
%
% \subsection{Reverted Authors} \label{sec:reverted-author}
% Another goal is to undo all (suggested) edits by one or all authors, i.e., make the file look as much as possible as what it would look like if the author(s) had never made any changes in the first place.\footnote{I would like to thank Shaddin Dughmi for this suggestion.}
% We call this \emph{reverting} an author.
% Specifically, reverting an author does the following (described in more detail in the context of the specific macros):
% \begin{itemize}
% \item Remove all edits.
% \item Restore the original text for replacements.
% \item For all text that has been (suggested as) deleted or replaced, the original text is displayed.
% \end{itemize}
%
% As with suppression, there are two ways to revert authors: one can revert individual authors by changing their optional names to |revert| (see Section~\ref{sec:exported-macro}). Alternatively, by using the package option |revert| (see Section~\ref{sec:package-options}), all authors are reverted. If the package option |suppress| is given, then even an author with optional name |revert| will be \emph{suppressed}, not \emph{reverted}.
%
% \subsection{Generated Macros} \label{sec:generated-macros}
% 
% In this section, we describe in detail the functionality of the macros generated by |\addauthor|. We will refer to them with the generic name. Throughout, keeping the earlier example of Ada and Charles in mind, the reader is encouraged to substitute in their mind |al| or |cb| for |<auth>|. We will frequently reference suppressed and reverted authors --- see Sections~\ref{sec:suppressed-author} and \ref{sec:reverted-author} for a discussion.
%
% The macros are internally defined using |\long\def|, so all arguments below that are given as \meta{text} or \meta{new-text} or \meta{comment} (and similar ones) are allowed to contain multiple paragraphs.
% 
% The macro \DescribeMacro{\<auth>edit} |\<auth>edit| \marg{text} in its default behavior simply displays \meta{text} in the color assigned to the author |<auth>|. If the author has been suppressed, it displays \meta{text} in the standard style/color. If the author has been reverted, it displays nothing. The macro is not affected by the |showdeletions| or |inlinedeletions| package options. The main purpose of this macro is to mark text as changed/added by the given author. If the text was changed, the implicit assumption is that the co-author will not care much about what the text was prior to the change --- otherwise, the macro |\<auth>replace| would be preferable.
%
% The macro \DescribeMacro{\<auth>replace} |\<auth>replace| \marg{old-text} \marg{new-text} in its default behavior simply displays \meta{new-text} in the color assigned to the author |<auth>|. The macro should be used instead of |\<auth>edit| if the co-authors might want to see what was in the file before the change or even revert the change. While the old text is not displayed in the output per default, it is of course still in the \LaTeX\ source, so co-authors can easily see it. If the author is suppressed, then |\<auth>replace| simply displays \meta{new-text} in the standard style/color. If the author is reverted, then |\<auth>replace| instead displays \meta{old-text}. If the package option |showdeletions| is used (and the author is not suppressed or reverted), then |\<auth>replace| displays \meta{old-text} in gray, followed by \meta{new-text} in the color assigned to the author |<auth>|. The macro is not affected by the |inlinedeletions| package option.
%
% The macro \DescribeMacro{\<auth>comment} |\<auth>comment| \marg{text} is used for leaving comments for one's co-authors, as opposed to text that should become part of the document itself. Its default behavior is to show |[<auth-name>: <text>]| in the color assigned to the author |<auth>|. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed or reverted, then nothing is displayed. Notice that this is the main difference to the |\<auth>edit| macro, which still displays its text when an author is suppressed. This is in line with the idea that a change to the document/text should be included in a version that is --- say --- submitted to a conference, while internal comments to co-authors should not be included. The macro is not affected by the |showdeletions| or |inlinedeletions| package options.
%
% The macro \DescribeMacro{\<auth>margincomment} |\<auth>margincomment| \marg{text} is used for leaving comments for one's co-authors in the margins as opposed to in the main text. Thus, its purpose is basically the same as that of |\<auth>comment|, but different authors may prefer comments to be displayed in different places, e.g., for reasons of flow. Its default behavior is to show a marker in the main text in the color assigned to the author |<auth>|, and to show |[<auth-name>: <text>]| in the margin, also in the color assigned to the author |<auth>|. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed or reverted, then nothing is displayed. The macro is not affected by the |showdeletions| or |inlinedeletions| package option. Because the macro is implemented using the |\marginpar| macro, it cannot be used in environments where |\marginpar| does not work, such as in footnotes, section headings, or captions.
%
% The macro \DescribeMacro{\<auth>delete} |\<auth>delete| \marg{text} is used for letting co-authors know that one deleted \meta{text} (or suggests doing so). Its default behavior is to display a marker in the color assigned to the author |<auth>| in the spot where the command occurs, and to leave a mark |[<auth-name> deleted here]| in the margin. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed, then nothing is displayed. If the author is reverted, then the text \meta{text} is displayed in its original place and the original color. The main purpose of having the argument \meta{text} is to allow co-authors to see not only \emph{that} text was deleted, but \emph{what} text was deleted, and possibly revert the edit. Accordingly, if the package option |showdeletions| is used (and the author is not suppressed), then in addition to placing a marker and a comment in the margin, the text \meta{text} is displayed, but in gray. This allows co-authors to see the deleted text not only in the source file, but also in the compiled output. If the package option |inlinedeletions| is used, then the macro instead behaves exactly like the (next) macro |<auth>inlinedelete|.
% Because the macro is implemented using the |\marginpar| macro, unless the package option |inlinedeletions| is used, the macro cannot be used in environments where |\marginpar| does not work, such as in footnotes, section headings, or captions.
%
% The macro \DescribeMacro{\<auth>inlinedelete} |\<auth>inlinedelete| \marg{text} serves the same purpose as |\<auth>delete|, but avoids any text in the margin, instead leaving the note of the deletion in the main text. It too is used for letting co-authors know that one deleted \meta{text} (or suggests doing so). Its default behavior is to leave a note |[<auth-name> deleted here]| in the spot where the command occurs. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed, then nothing is displayed. If the author is reverted, then the text \meta{text} is displayed in its original place and the original color. Again, the main purpose of having the argument \meta{text} is to allow co-authors to see not only \emph{that} text was deleted, but \emph{what} text was deleted, and possibly revert the edit. Accordingly, if the package option |showdeletions| is used (and the author is not suppressed), then in addition to the note, the text \meta{text} is displayed, but in gray. This allows co-authors to see the deleted text not only in the source file, but also in the compiled output. The macro is not affected by the package option |inlinedeletions|.
%Because the macro does not use |\marginpar|, it can also be used in environments where |\marginpar| does not work.
%
% The macro \DescribeMacro{\<auth>deletecomment} |\<auth>deletecomment| \marg{comment} \marg{text} is used for letting co-authors know that one deleted \meta{text} (or suggests doing so), and to also provide a \meta{comment} explaining the deletion. Its default behavior is to display a marker in the color assigned to the author |<auth>| in the spot where the command occurs, and to leave a mark |[<auth-name> deleted here: <comment>]| in the margin. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed, then nothing is displayed. If the author is reverted, then the text \meta{text} is displayed in its original place and the original color. As with the |\<auth>delete| command, the main purpose of having the argument \meta{text} is to allow co-authors to see what text was deleted and possibly revert the deletion. If the package option |showdeletions| is used (and the author is not suppressed), then in addition to placing a marker, the text \meta{text} is displayed, but in gray. This allows co-authors to see the deleted text not only in the source file, but also in the compiled output. In addition, |[<auth-name>: <comment>]| is still displayed in the margin in the color assigned to the author. If the package option |inlinedeletions| is used, then the macro instead behaves exactly like the (next) macro |<auth>inlinedeletecomment|.
% Because the macro is implemented using the |\marginpar| macro, it cannot be used in environments where |\marginpar| does not work, such as in footnotes, section headings, or captions.
%
% The macro \DescribeMacro{\<auth>inlinedeletecomment} |\<auth>inelinedeletecomment| \marg{comment} \marg{text} serves the same purpose as |\<auth>deletecomment|, but avoids any text in the margin, instead leaving the note and reason for deletion in the main text. It too is used for letting co-authors know that one deleted \meta{text} (or suggests doing so), and to also provide a \meta{comment} explaining the deletion. Its default behavior is to to leave a note |[<auth-name> deleted here: <comment>]| in the color assigned to the author |<auth>| in the spot where the command occurs. Here, \meta{auth-name} is the name assigned to the author --- either the optional long name if given, or otherwise \meta{auth} (see Section~\ref{sec:exported-macro}). If the author is suppressed, then nothing is displayed. If the author is reverted, then the text \meta{text} is displayed in its original place and the original color. As with the other deletion commands, the main purpose of having the argument \meta{text} is to allow co-authors to see what text was deleted and possibly revert the deletion. If the package option |showdeletions| is used (and the author is not suppressed), then in addition to placing a marker with the reason for deletion, the text \meta{text} is displayed, but in gray. This allows co-authors to see the deleted text not only in the source file, but also in the compiled output. The macro is not affected by the package option |inlinedeletions|.
%Because the macro does not use |\marginpar|, it can also be used in environments where |\marginpar| does not work.
%
%
%
% \StopEventually{\PrintChanges}
%
% \section{The Package Implementation}
%
%\subsection{The Initial Stuff}
%We define a color gray to use for showing deleted text. For all other colors, it is the user's responsibility to define them if they are not defined standard.
%    \begin{macrocode}
\definecolor{coloredits@gray}{rgb}{0.5,0.5,0.5}
%    \end{macrocode}

%\subsection{The Logic of Suppressed/Reverted Authors}
% \begin{macro}{\coloredits@setdefinitionmode}
% The macro |\coloredits@setdefinitionmode| \marg{auth} is a helper macro.
% It sets boolean flags to determine whether the author currently being processed (with the name given by the argument \meta{auth}) should be suppressed, reverted, or neither.
% It implements the following logic:
% \begin{enumerate}
%  \item If the package option |suppress| is selected, then the author is suppressed and not reverted.
%  \item Otherwise, if the package option |revert| is selected, then the author is reverted and not suppressed.
%  \item Otherwise, if the author's name is |suppress|, then the author is suppressed and not reverted.
%  \item Otherwise, if the author's name is |revert|, then the author is reverted and not suppressed.
%  \item Otherwise, the author is neither suppressed nor reverted.
% \end{enumerate}
%    \begin{macrocode}
\newcommand{\coloredits@setdefinitionmode}[1]{%
\ifbool{coloredits@GlobalSuppress}{% edits suppressed globally
\booltrue{coloredits@CurrentSuppress}%
\boolfalse{coloredits@CurrentRevert}%
}{\ifbool{coloredits@GlobalRevert}{% edits reverted globally
\boolfalse{coloredits@CurrentSuppress}%
\booltrue{coloredits@CurrentRevert}%
}{\ifstrequal{#1}{suppress}{% edits suppressed locally
\booltrue{coloredits@CurrentSuppress}
\boolfalse{coloredits@CurrentRevert}%
}{\ifstrequal{#1}{revert}{% edits reverted locally
\boolfalse{coloredits@CurrentSuppress}%
\booltrue{coloredits@CurrentRevert}%
}{% no suppression or revert
\boolfalse{coloredits@CurrentSuppress}%
\boolfalse{coloredits@CurrentRevert}%
}}}}}
%    \end{macrocode}
% \end{macro}

% \subsection{Macros not Displaying Anything}
% In many cases, due to suppressing or reverting an author, a macro should not output anything. Defining a macro with arguments as empty |{}| unfortunately lets space before and after the macro accumulate; this becomes even more noticeable when multiple (suppressed) comments or deletions succeed each other. To avoid this behavior, we instead use the following standard trick. The two versions of the macro are used for one and two arguments, respectively. The use of these macros addresses the aforementioned space problems which arose with the use of |suppress| in earlier versions of this package.
%    \begin{macrocode}
\newcommand{\coloredits@emptyone}[1]{\@bsphack\@esphack}
\newcommand{\coloredits@emptytwo}[2]{\@bsphack\@esphack}
%    \end{macrocode}

%\subsection{Helper Macros for Defining the Exported Functions}
% In the following definitions, there are many instances of the use of |\leavevmode|. This is needed to avoid spacing issues, in particular in conjunction with packages (such as |wrapfig|) which temporarily change the length of a line.\footnote{I would like to thank Qilin Ye for discovering this bug and suggesting the fix.}
%\begin{macro}{\coloredits@addauthoredit}
%   |\coloredits@addauthoredit| \marg{auth} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>edit| \marg{text}.
%   How |\<auth>edit| \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|.
%   If the author is suppressed, then |\<auth>edit| \marg{text} simply displays \meta{text}.
%   If the author is reverted, then |\<auth>edit| \marg{text} displays nothing.
%   Otherwise, it displays \meta{text} in the given color \meta{auth-color}.
%    \begin{macrocode}
\newcommand{\coloredits@addauthoredit}[2]{%
\ifbool{coloredits@CurrentSuppress}{% suppressed
\long\csdef{#1edit}##1{##1}%
}{\ifbool{coloredits@CurrentRevert}{% reverted
\cslet{#1edit}{\coloredits@emptyone}%
}{%neither suppressed nor reverted
\long\csdef{#1edit}##1{\leavevmode {\color{#2}##1}}%
}}}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\coloredits@addauthorreplace}
%   |\coloredits@addauthorreplace| \marg{auth} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>replace| \marg{old-text} \marg{new-text}.
%   How |\<auth>replace| \marg{old-text} \marg{old-text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|, as well as the package option |showdeletions|.
%   If the author is suppressed, then |\<auth>replace| \marg{old-text} \marg{new-text} simply displays \meta{new-text}.
%   If the author is reverted, then |\<auth>replace| \marg{old-text} \marg{new-text} simply displays \meta{old-text}.
%   If the author is neither suppressed nor reverted and |showdeletions| was not specified as a package option, it displays \meta{new-text} in the given color \meta{auth-color}.
%   If the author is not suppressed or reverted and |showdeletions| was specified as a package option, it displays \meta{old-text} in gray, followed by \meta{new-text} in the given color \meta{auth-color}.
%    \begin{macrocode}
\newcommand{\coloredits@addauthorreplace}[2]{%
\ifbool{coloredits@CurrentSuppress}{% suppressed
\long\csdef{#1replace}##1##2{##2}%
}{\ifbool{coloredits@CurrentRevert}{% reverted
\long\csdef{#1replace}##1##2{##1}%
}{% not suppressed or reverted
\ifbool{coloredits@ShowDeletions}{% Showing deletions
\long\csdef{#1replace}##1##2{\leavevmode {\color{coloredits@gray}##1}{\color{#2}##2}}%
}{% Not showing deletions
\long\csdef{#1replace}##1##2{\leavevmode {\color{#2}##2}}}%
}}}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\coloredits@addauthorcomment}
%   |\coloredits@addauthorcomment| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>comment| \marg{text}.
%   How |\<auth>comment| \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|.
%   If the author is suppressed or reverted, then |\<auth>comment| \marg{text} does nothing.
%   If the author is neither suppressed nor reverted, it displays, in square brackets, \meta{text} in the given color \meta{auth-color}, prefixed by \meta{auth-name}.
%    \begin{macrocode}
\newcommand{\coloredits@addauthorcomment}[3]{%
\ifboolexpr{   bool {coloredits@CurrentSuppress}
            or bool {coloredits@CurrentRevert}}{% suppressed or reverted
\cslet{#1comment}{\coloredits@emptyone}%
}{% not suppressed or reverted
\long\csdef{#1comment}##1{\leavevmode {\color{#3}[#2: ##1]}}%
}}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\coloredits@addauthormargincomment}
%   |\coloredits@addauthormargincomment| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>margincomment| \marg{text}.
%   How |\<auth>margincomment| \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|.
%   If the author is suppressed or reverted, then |\<auth>margincomment| \marg{text} does nothing.
%   If the author is neither suppressed nor reverted, it displays, in the margin and in square brackets, \meta{text} in the given color \meta{auth-color}, prefixed by \meta{auth-name}. It also places a bullet in square brackets of color \meta{auth-color} in the text at the place where the command was used.
%    \begin{macrocode}
\newcommand{\coloredits@addauthormargincomment}[3]{%
\ifboolexpr{   bool {coloredits@CurrentSuppress}
            or bool {coloredits@CurrentRevert}}{% suppressed or reverted
\cslet{#1margincomment}{\coloredits@emptyone}%
}{% not suppressed or reverted
\long\csdef{#1margincomment}##1{%
\leavevmode {\color{#3}$[\bullet]$}\marginpar{\scriptsize\color{#3}[#2: ##1]}}%
}}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\coloredits@addauthorinlinedelete}
%   |\coloredits@addauthorinlinedelete| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>inlinedelete| \marg{text}.
%   How |\<auth>inlinedelete| \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|, as well as the package option |showdeletions|.
%   If the author is suppressed, then |\<auth>inlinedelete| \marg{text} does nothing.
%   If the author is reverted, then |\<auth>inlinedelete| \marg{text} displays \meta{text}.
%   If the author is neither suppressed nor reverted and |showdeletions| was not used, it places the note |[<auth-name> deleted here]| at the location of the command in the color \meta{auth-color}.
%   If the author is neither suppressed nor reverted and |showdeletions| was used, it places the note |[<auth-name> deleted here]| at the location of the command in the color \meta{auth-color}, followed by \meta{text} in gray.
%    \begin{macrocode}
\newcommand{\coloredits@addauthorinlinedelete}[3]{%
\ifbool{coloredits@CurrentSuppress}{% suppressed
\cslet{#1inlinedelete}{\coloredits@emptyone}%
}{% not suppressed
\ifbool{coloredits@CurrentRevert}{% reverted
\long\csdef{#1inlinedelete}##1{##1}%
}{% not suppressed or reverted
\ifbool{coloredits@ShowDeletions}{% Showing deletions
\long\csdef{#1inlinedelete}##1{%
\leavevmode {\color{#3}[#2 deleted here]}{\color{coloredits@gray}##1}}%
}{% Not showing deletions
\long\csdef{#1inlinedelete}##1{%
\leavevmode {\color{#3}[#2 deleted here]}}}%
}}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\coloredits@addauthordelete}
%   |\coloredits@addauthordelete| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>delete| \marg{text}.
%   How |\<auth>delete| \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|, as well as the package options |inlinedeletions| and |showdeletions|.
%   If the package option |inlinedeletions| was given, then the definition is identical to the macro |\<auth>inlinedelete|; see that macro's documentation.
%   If the author is suppressed, then |\<auth>delete| \marg{text} does nothing.
%   If the author is reverted, then |\<auth>delete| \marg{text} displays \meta{text}.
%   If the author is neither suppressed nor reverted and |showdeletions| was not used, it places a bullet in brackets in the color \meta{auth-color} at the place of the command, and places the note |[<auth-name> deleted here]| in the margin in the color \meta{auth-color}.
%   If the author is neither suppressed nor reverted and |showdeletions| was used, it places a bullet in brackets in the color \meta{auth-color} at the place of the command, followed by \meta{text} in gray; it also places the note |[<auth-name> deleted here]| in the margin in the color \meta{auth-color}.
%    \begin{macrocode}
\newcommand{\coloredits@addauthordelete}[3]{%
\ifbool{coloredits@InlineDeletions}{% deletions are globally inline
\csletcs{#1delete}{#1inlinedelete}%
}{% deletions are not globally inline
\ifbool{coloredits@CurrentSuppress}{% suppressed
\cslet{#1delete}{\coloredits@emptyone}%
}{% not suppressed
\ifbool{coloredits@CurrentRevert}{% reverted
\long\csdef{#1delete}##1{##1}%
}{% not suppressed or reverted
\ifbool{coloredits@ShowDeletions}{% Showing deletions
\long\csdef{#1delete}##1{%
\leavevmode {\color{#3}$[\bullet]$}\marginpar{\scriptsize\color{#3}#2 deleted here}%
{\color{coloredits@gray}##1}}%
}{% Not showing deletions
\long\csdef{#1delete}##1{%
\leavevmode {\color{#3}$[\bullet]$}\marginpar{\scriptsize\color{#3}#2 deleted here}}}%
}}}}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\coloredits@addauthorinlinedeletecomment}
%   |\coloredits@addauthorinlinedeletecomment| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>inlinedeletecomment| \marg{comment} \marg{text}.
%   How |\<auth>inlinedeletecomment| \marg{comment} \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|, as well as the package option |showdeletions|.
%   If the author is suppressed, then |\<auth>inlinedeletecomment| \marg{comment} \marg{text} does nothing.
%   If the author is reverted, then |\<auth>inlinedeletecomment| \marg{comment} \marg{text} displays \meta{text}.
%   If the author is neither suppressed nor reverted and |showdeletions| is not used, it places the note |[<auth-name> deleted here: <comment>]| in the color \meta{auth-color} at the place of the command.
%   If the author is neither suppressed nor reverted and |showdeletions| was used, it places the note |[<auth-name> deleted here: <comment>]| at the command's location in the color \meta{auth-color}, followed by \meta{text} in gray, 
%    \begin{macrocode}
\newcommand{\coloredits@addauthorinlinedeletecomment}[3]{%
\ifbool{coloredits@CurrentSuppress}{% suppressed
\cslet{#1inlinedeletecomment}{\coloredits@emptytwo}%
}{% not suppressed
\ifbool{coloredits@CurrentRevert}{% reverted
\long\csdef{#1inlinedeletecomment}##1##2{##2}%
}{% not suppressed or reverted
\ifbool{coloredits@ShowDeletions}{% Showing deletions
\long\csdef{#1inlinedeletecomment}##1##2{%
\leavevmode {\color{#3}[#2 deleted here: ##1]}{\color{coloredits@gray}##2}}%
}{% Not showing deletions
\long\csdef{#1inlinedeletecomment}##1##2{%
\leavevmode {\color{#3}[#2 deleted here: ##1]}}}%
}}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\coloredits@addauthordeletecomment}
%   |\coloredits@addauthordeletecomment| \marg{auth} \marg{auth-name} \marg{auth-color} is a helper macro.
%   It defines the command |\<auth>deletecomment| \marg{comment} \marg{text}.
%   How |\<auth>deletecomment| \marg{comment} \marg{text} is defined depends on whether the author is suppressed/reverted, as captured by the boolean flags |coloredits@CurrentSuppress|, |coloredits@CurrentRevert|, as well as the package options |inlinedeletions| and |showdeletions|.
%   If the package option |inlinedeletions| was given, then the definition is identical to the macro |\<auth>inlinedeletecomment|; see that macro's documentation.
%   If the author is suppressed, then |\<auth>deletecomment| \marg{comment} \marg{text} does nothing.
%   If the author is reverted, then |\<auth>deletecomment| \marg{comment} \marg{text} displays \meta{text}.
%   If the author is not suppressed and |showdeletions| is not used, it places a bullet in brackets in the color \meta{auth-color} at the place of the command, and places the note |[<auth-name> deleted here: <comment>]| in the margin in the color \meta{auth-color}.
%   If the author is not suppressed and |showdeletions| was used, it additionally displays \meta{text} in gray after the colored bullet.
%    \begin{macrocode}
\newcommand{\coloredits@addauthordeletecomment}[3]{%
\ifbool{coloredits@InlineDeletions}{% deletions are globally inline
\csletcs{#1deletecomment}{#1inlinedeletecomment}%
}{% deletions are not globally inline
\ifbool{coloredits@CurrentSuppress}{% suppressed
\cslet{#1deletecomment}{\coloredits@emptytwo}%
}{% not suppressed
\ifbool{coloredits@CurrentRevert}{% reverted
\long\csdef{#1deletecomment}##1##2{##2}%
}{% not suppressed or reverted
\ifbool{coloredits@ShowDeletions}{% Showing deletions
\long\csdef{#1deletecomment}##1##2{%
\leavevmode {\color{#3}$[\bullet]$}%
\marginpar{\scriptsize\color{#3}#2 deleted here: ##1}%
{\color{coloredits@gray}##2}}%
}{% Not showing deletions
\long\csdef{#1deletecomment}##1##2{%
\leavevmode {\color{#3}$[\bullet]$}%
\marginpar{\scriptsize\color{#3}#2 deleted here: ##1}}}%
}}}}
%    \end{macrocode}
% \end{macro}

% \subsection{The Exported Macro \texttt{\textbackslash{}addauthor} and its Helper}
% \begin{macro}{\coloredits@addauthor}
%   |\coloredits@addauthor| \marg{auth-name} \marg{auth} \marg{auth-color} is a helper macro that simply calls all the macros for defining the individual macros for an author.
%   As a first step, it calls the helper macro |\addauthor@setdefinitionmode| to correctly encode in boolean flags whether the author is suppressed or reverted.
% Notice that the macros |\<auth>edit| and |\<auth>replace| do not need the author's name, so it is not passed in.
%    \begin{macrocode}
\newcommand{\coloredits@addauthor}[3]{%
\coloredits@setdefinitionmode{#1}
\coloredits@addauthoredit{#2}{#3}
\coloredits@addauthorreplace{#2}{#3}
\coloredits@addauthorcomment{#2}{#1}{#3}
\coloredits@addauthormargincomment{#2}{#1}{#3}
\coloredits@addauthorinlinedelete{#2}{#1}{#3}
\coloredits@addauthordelete{#2}{#1}{#3}
\coloredits@addauthorinlinedeletecomment{#2}{#1}{#3}
\coloredits@addauthordeletecomment{#2}{#1}{#3}
}
%    \end{macrocode}
% \end{macro}  
%
%
% \begin{macro}{\addauthor}
% |\addauthor| \oarg{auth-name} \marg{auth} \marg{auth-color} is the only exported macro of the package.
% All work defining the usable macros is done by the helper function |\coloredits@addauthor|. This is done so that there is no code duplication between the two cases whether the optional author name \meta{auth-name} is provided or not. In the former case (name provided), this name is passed into the helper function; otherwise, the author initial \meta{auth} is used in place of the name.
%    \begin{macrocode}
\newcommand{\addauthor}[3][]{%
\ifblank{#1}{%optional author name was not provided, use initials instead
\coloredits@addauthor{#2}{#2}{#3}}{%
\coloredits@addauthor{#1}{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
% \Finale
% 
% \section{Disclaimer and Known Problems}
% \label{sec:bugs}
% The biggest disclaimer is that I am not a very expert \TeX programmer, so this package may not be particularly well written. I am sharing it because several co-authors seem to enjoy using it and have encouraged me to share it publicly. If you see ways to improve the implementation or functionality (while keeping it still light-weight), I would love to hear from you. You are obviously using this package at your own risk.
%
% A minor known bug\footnote{Thank you to Qilin Ye for discovering it!} is that using the colorful macros inside |ulem|'s |\sout| (for struck-out text) deactivates automatic line breaking. Hopefully, this is a sufficiently niche application that it will not matter to (m)any people.
%
% As discussed above, because the macros for deletion and the one for comments in the margin are based on the |\marginpar| command in \LaTeX, their use is restricted to settings in which |\marginpar| works. In particular, this excludes using them in footnotes, captions, and section/subsection titles. An alternative might be to use the |marginnote| package and its command |\marginnote|, but that package seems to have other known problems, and at the moment, I am not ready to try to decide which issues are larger. If you see a clean way to resolve this, feel free to let me know.
%
% A second problem with these commands is that when too many notes appear in the margins (due to comments or deletions), they not only end up further from their actual location, but can cause odd downstream effects, resulting in \LaTeX losing floats and throwing resulting errors.
%
% The new macros |\<auth>inlinedelete| and |\<auth>inlinedeletecomment| are intended to address all of these issues; you can use them in footnotes, section titles, captions, etc., and they do not result in lost floats. Personally, I now believe that notes in the margins for deletions were a bad design decision in the earlier versions, and I intend to use the |inlinedeletions| package option as a default. But you can make your own choices.
%
% Earlier versions had some spacing issues when using the |suppress| package option. Specifically, when there was a space before and after --- say --- an |\<auth>comment| command, then \LaTeX would still keep both spaces, resulting in slightly more space than there should be between the preceding and following items on the line. The current version is intended (and seems) to have fixed this.
%
\endinput
