%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
%                                                                          %
% This is file 'reviewtools.sty', version 0.0.1, December 2011             %
%                                                                          %
% This package and accompanying files may be distributed and/or            %
% modified under the conditions of the LaTeX Project Public License,       %
% either version 1.3 of this license or 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.                                             %
%                                                                          %
% The LPPL maintenance status of this software is 'author-maintained'.     %
%                                                                          %
% This software is provided 'as it is', without warranty of any kind,      %
% either expressed or implied, including, but not limited to, the          %
% implied warranties of merchantability and fitness for a particular       %
% purpose.                                                                 %
%                                                                          %
% Copyright (c) 2011 Ahmed Musa (a.musa@rocketmail.com).                   %
%                                                                          %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

\@ifpackageloaded{catoptions}{%
  \@ifpackagelater{catoptions}{2011/12/12}{}{%
    \@latex@error{Loaded version of catoptions package is
      not current}\@ehc
  }%
}{%
  \RequirePackage{catoptions}[2011/12/12]%
}
\UseNormalCatcodes
\StyleFilePurpose{Multipurpose document review tools (AM)}
\StyleFileRCSInfo
$Id: reviewtools.sty,v 0.0.1 2011/12/12 09:00:00 Ahmed Musa Exp $
\ProvidesClass{reviewtools}[\StyleFileInfo]
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\SetStyleFileMessages[rvt@]{info}{warn}{err}
\cptloadpackages{%
  ltxkeys||2011/09/10;
  graphicx||1999/02/16;
  bigfoot||2006/07/15;
  xcolor|table,dvipsnames,hyperref|2007/01/21;
  marginfix||2010/08/18;
  amsmath;
  amssymb||2002/01/22;
  ltxtools-environ||2010/05/20;
}
\DeclareNewFootnote[plain]{default}
\DeclareNewFootnote[plain]{B}[alph]
% Footnote type 1:
\MakeSortedPerPage[1]{footnoteB}
\setlength{\skip\footinsB}{2\p@ minus 1\p@}
\newcounter{rvt@altfoota}
\renewcommand*\thervt@altfoota{\Alph{rvt@altfoota}}
\MakeSortedPerPage[1]{rvt@altfoota}
% Footnote type 2:
\WithSuffix\def\footnotedefault'{%
  \refstepcounter{rvt@altfoota}%
  \Footnotedefault{\thervt@altfoota}%
}
\newcounter{rvt@altfootb}
\renewcommand*\thervt@altfootb{\roman{rvt@altfootb}}
% Footnote type 3:
\MakeSortedPerPage[1]{rvt@altfootb}
\WithSuffix\def\footnotedefault*{%
  \refstepcounter{rvt@altfootb}%
  \Footnotedefault{\thervt@altfootb}%
}
\newletcs\footnotewithsymbol\Footnote
\everyeoenv{\ignorespacesafterend}
\new@def*\PrintNotes{\global\rvt@printnotestrue}
\new@def*\NoPrintNotes{\global\rvt@printnotesfalse}
\newletcs\rvt@nil\relax
\new@def*\rvt@nnil{\rvt@nil}
\newcommand\rvt@startfile[2][\jobname]{%
  \begingroup
  \makeatletter
  \if@filesw
    \expandafter\newwrite\csname rvtf@#2\endcsname
    \immediate\openout\csname rvtf@#2\endcsname=#1.#2\relax
  \else
    \rvt@warn{\string\nofiles: can't start file #1.#2}%
  \fi
  \@nobreakfalse
  \endgroup
  \AtEndDocument{%
    \if@filesw\closeout\csname rvtf@#2\endcsname\fi
  }%
}
\newcommand\rvt@writefile[3][\jobname]{%
  \if@filesw
    \ifcsndefTF{rvtf@#2}{%
      \rvt@writetofile{\usename{rvtf@#2}}{}{#3}%
    }{%
      \rvt@err{File #1.#2 not open}\@ehc
    }%
  \else
    \rvt@warn{\string\nofiles: can't write to file #1.#2}%
  \fi
}
\new@def*\rvt@verbfileheader#1{%
  \edef\reserved@c{\noexpandcsn{rvtf@#1}}%
  \immediate\write\reserved@c{%
    \@percentchar\@percentchar\space
      Notes file `\jobname.\rvt@verbfile'^^J%
    \@percentchar\@percentchar\space generated by the
      `rvtwriteverb' environment^^J%
    \@percentchar\@percentchar\space from source `\jobname' on
      \number\year/\two@digits\month/\two@digits\day.^^J%
    \@percentchar\@percentchar
  }%
}
\edef\@percentchar{\expandafter\@gobble\string\%}
% Package options:
\ltxkeys@definekeys*[RVT]{revtools}[rvt@]{%
  showreviewer/true;
  shownotetype/true;
  printnotes/true;
  final/true;
  draft/true/\ifboolTF{rvt@draft}{\setaliaskey{final}[false]}{};
  writenotes/true;
  notecolor/ForestGreen;
  deletecolor/BurntOrange;
  deletedcolor/pink;
  addcolor/red;
  wipcolor/purple;
  \needvalue{reviewer}/Rev?;
  verbfileext/vbm/
    \cptstripallouterbraces{#1}\rvt@verbfileext
    \edef\rvt@verbfileext{\s@expandarg\cpttrimspaces\rvt@verbfileext};
  openverbfile/true/
    \ifrvt@openverbfile
      \rvt@startfile\rvt@verbfileext
      \rvt@verbfileheader\rvt@verbfileext
    \fi;
}
\ltxkeys@optionkeys[RVT]{revtools}{openverbfile,verbfileext}
\ltxkeys@declareoption*{\rvt@warn{Unknown option '\CurrentOption' ignored}}
\ltxkeys@executeoptions[RVT]<revtools>{shownotetype,printnotes,final}
\ltxkeys@processoptions*[RVT]<revtools>\relax
\robust@def*\rvtoptions#1{\ltxkeys@setkeys[RVT]{revtools}{#1}}
\ltxkeys@reservekeyprefix*{RVT}
\ltxkeys@reservemacroprefix*{rvt@}
\ltxkeys@reservekeyfamily*{revtools}

\new@def*\rvt@optprinthook{}
\robust@def*\rvtoptprint#1{%
  \ltsfiltermergecsv\rvt@optprinthook{#1}\nofilter
}

% Optional print 'opt2' and 'opt3' only:
% \rvtoptprint{opt2,opt3}

% 'opt1' will be ignored, while 'opt2' and 'opt3' will
% be printed even as they appear inside ignored command
% or environment ('opt1'):

% Nested optional print command:
% \rvtoptcmd{opt1}{...\rvtoptcmd{opt2}{...\rvtoptcmd{opt3}{...}}}

% Nested optional print environment:
% \rvtbegin{rvtopt}{opt1}
%   ...
%   \rvtbegin{rvtopt}{opt2}%
%     ...
%     \rvtbegin{rvtopt}{opt3}%
%     ...
%     \rvtend{rvtopt}{opt3}%
%     ...
%   \rvtend{rvtopt}{opt2}%
%   ...
% \rvtend{rvtopt}{opt1}

\newcommand\rvtoptcmd[2]{%
  \oifinset@sp@TF,{#1}\rvt@optprinthook{%
    #2\relax
  }{%
    \long\def\reserved@a##1\rvtoptcmd##2##3##4\rvt@nil{%
      \edef\reserved@a{\unexpanded{##3}}%
      \ifcseqTF\reserved@a\rvt@nnil{}{%
        \rvtoptcmd{##2}{##3}%
      }%
    }%
    \reserved@a#2\rvtoptcmd{\rvt@nil}{\rvt@nil}\rvt@nil
  }%
}
\def\rvtnewenvironment{\cpt@starorlong\rvt@newenvironment}
\def\rvt@newenvironment#1{\cpt@testopt{\rvt@newenva#1}0}
\def\rvt@newenva#1[#2]{%
  \cpt@ifbrack{\rvt@newenvb{#1}{#2}}{\rvt@newenv{#1}{[#2]}}%
}
\def\rvt@newenvb#1#2[#3]{\rvt@newenv{#1}{[#2][{#3}]}}
\def\rvtrenewenvironment{\@star@or@long\rvt@renewenvironment}
\def\rvt@renewenvironment#1{%
  \@ifundefined{#1}{%
    \@latex@error{Environment #1 undefined}\@ehc
  }{}%
  \expandafter\let\csname#1\endcsname\relax
  \expandafter\let\csname rvtend#1\endcsname\relax
  \rvt@newenvironment{#1}%
}
\long\def\rvt@newenv#1#2#3#4{%
  \@ifundefined{#1}{\letcsntocsn{#1}{rvtend#1}}{}%
  \aftercsname\new@command{#1}#2{#3}%
  \l@ngrel@x\csn@def{rvtend#1}{#4}%
}
\newletcs\rvtbegin\begin
\new@def*\rvtend#1{%
  \csname rvtend#1\endcsname\@checkend{#1}%
  \expandafter\endgroup\if@endpe\@doendpe\fi
  \rvt@gobbletoend
}
\new@def\rvt@gobbletoend#1#{\@gobble}
\rvtnewenvironment{rvtopt}[1]{%
  \oifinset@sp@TF,{#1}\rvt@optprinthook{}{%
    \begingroup
    \toks@{}%
    \long\def\rvt@processbody##1\rvtend##2##3{%
      \def\reserved@a{##2}%
      \ifcseqTF\reserved@a\@currenvir{%
        \ifstrcmpTF{##3}{#1}{%
          \edef\rvt@tempa{\the\toks@}%
          \postgroupdef\rvt@tempa\endgroup
          \ifcseqTF\rvt@tempa\@empty{%
            \expandafter\endgroup\if@endpe\@doendpe\fi
          }{%
            \long\def\reserved@a####1\rvtbegin{\rvtbegin}%
            \expandafter\reserved@a\rvt@tempa
            \expandafter\endgroup\if@endpe\@doendpe\fi
          }%
        }{%
          \toks@\expandafter{\the\toks@##1\rvtend{##2}{##3}}%
          \rvt@processbody
        }%
      }{%
        \toks@\expandafter{\the\toks@##1\rvtend{##2}{##3}}%
        \rvt@processbody
      }%
    }%
    \rvt@processbody
  }%
}{}

\robust@def*\rvtdefinecolor{%
  \let\reserved@e\definecolor
  \cpt@testopt\rvt@definecolor{}%
}
\robust@def*\rvtcolorlet{%
  \let\reserved@e\colorlet
  \cpt@testopt\rvt@definecolor{}%
}
\robust@def*\rvt@definecolor[#1]#2{%
  \@ifundefinedcolor{#2}{%
    \reserved@e[#1]{#2}%
  }{%
    \rvt@err{Color name '#2' already defined}\@ehc
  }%
}
% Eg,
% \rvtdefinecolorset[x](0){green,0,0.50,0;blue,0,0.50,0.25}
% To use colors defined via \rvtdefinecolorset:
% eg, \color{<head>green<tail>}, where, eg, <head> is 'x' and <tail> '0'.
% When xwatermark package is loaded, this becomes redundant, but why
% load xwatermark just for this?
\robust@def*\rvtdefinecolorset{\cpt@testopt\rvt@definecolorset{x}}
\robust@def*\rvt@definecolorset[#1]{%
  \cpt@testpnopt{\rvt@d@finecolorset{#1}}{1}%
}
\robust@def*\rvt@d@finecolorset#1(#2)#3{%
  \ifcsndefTF{ver@xcolor.sty}{%
    \begingroup
    \cptemptifycsset{\rvt@tempb,\rvt@tempc,\rvt@tempd,\rvt@tempe}%
    \def\rvt@tempa##1,##2,##3,##4,##5\@nil{%
      \ifx\noboundary##4\noboundary
        \rvt@err{Incomplete color format in
          \string\rvtdefinecolorset}\@ehc
      \else
        \def\reserved@a{##1}%
      \fi
    }%
    \def\csv@do##1{%
      \rvt@tempa##1,,,,\@nil
      \xifinsetTF{,\reserved@a,}{,\rvt@tempd,}{%
        \edef\rvt@tempe{\csliststack,\rvt@tempe\reserved@a}%
      }{%
        \edef\rvt@tempd{\csliststack,\rvt@tempd\reserved@a}%
        \@ifundefinedcolor{#1\reserved@a#2}{%
          \edef\rvt@tempb{\csliststack;\rvt@tempb##1}%
        }{%
          \edef\rvt@tempc{\csliststack;\rvt@tempc#1\reserved@a#2}%
        }%
      }%
    }%
    \csv@@parse[;]{#3}%
    \ifcsemptyTF\rvt@tempe{}{%
      \rvt@err{Color names '\expandcsonce\rvt@tempe' multiply
        \MsgBrk submitted to \string\rvtdefinecolorset}\@ehc
    }%
    \ifcsemptyTF\rvt@tempc{}{%
      \rvt@err{Color names '\rvt@tempc' already in use}\@ehc
    }%
    \ifcsemptyTF\rvt@tempb{}{%
      \cptexpandarg{\xglobal\definecolorset{rgb}{#1}{#2}}
        {\expandcsonce\rvt@tempb}%
    }%
    \endgroup
  }{%
    \rvt@err{'xcolor' package not loaded}\@ehc
  }%
}
\rvtdefinecolorset[rvt](0){%
  green1,0,0.50,0;green2,0,0.50,0.25;green3,0.65,1,0.65;
  blue1,0,0,1;blue2,0,0,0.63;blue3,0,0.50,1;blue4,0,0.50,0.75;
  orange1,1,0.50,0;orange2,1,0.50,0.25;orange3,1,0.55,0.33
}

% Write verbatim to file '\jobname.verbfileext':
% \begin{rvtverbfilewrite} ... \end{rvtverbfilewrite}
\begingroup
\endlinechar-1
\begingroup
\catcode`\^^M=13
\catcode`\^^L=13\let^^L\relax
\catcode`\^^I=13
\new@gdef*\rvtverbfilewrite{
  \ifrvt@openverbfile\else
    \rvt@err{Writing to nonexistent/unopened file?}
      {Can't write to unopened verbatim file.}%
  \fi
  \edef\reserved@c{\noexpandcsn{rvtf@\rvt@verbfileext}}
  \let\do\@makeother\dospecials
  \edef\E{\@backslashchar end\string{\@currenvir\string}}
  \edef\reserved@b{
    \def\noexpand\reserved@b####1\E####2\E####3\relax
  }
  \reserved@b{
    \ifx\relax##3\relax
      \immediate\write\reserved@c{##1}
    \else
      \edef^^M{\noexpand\end{\@currenvir}}
      \ifx\relax##1\relax
      \else
        \immediate\write\reserved@c{##1}
      \fi
      \ifx\relax##2\relax
      \else
        \@latex@warning{Ignoring text `##2' %
          after \string\end{\@currenvir}}
      \fi
    \fi
    ^^M
  }
  \catcode`\^^L=13
  \let\L\rvt@undefined
  \def^^L{\@ifundefined L^^J^^J^^J}
  \catcode`\^^I=13
  \let\I\rvt@undefined
  \def^^I{\@ifundefined I\@space\@space}
  \catcode`\^^M=13
  \edef^^M##1^^M{\noexpand\reserved@b##1\E\E\relax}
}
\endgroup
\begingroup
\new@gdef*\endrvtwriteverb{
  \def\T##1##2##3{
    \ifx##1\rvt@undefined\else
      \rvt@warn{##2 has been converted to blank ##3}
    \fi
  }
  \T\L{Form Feed}{line}
  \T\I{Tab}{space}
  \immediate\write\@unused{}
}
\endgroup
\endgroup

\newcommand\rvt@writetofile[3]{%
  \begingroup
  \let\thepage\relax
  \let\label\@gobble
  #2%
  \let\protect\@unexpandable@protect
  \protected@edef\rvt@tempa{\immediate\write#1{#3}}%
  \rvt@tempa
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi
}
\newcommand\rvtfootnote[2][black]{\unskip
  \long\def\@makefntext##1{\rule\z@\footnotesep\parindent1em\noindent
    \hb@xt@2em{\hss\@textsuperscript
      {\normalfont\textcolor{#1}{\@thefnmark}}}%
    \hspace{2\p@}\ignorespaces\textcolor{#1}{##1}%
  }%
  \def\@makefnmark{%
    \hbox{\@textsuperscript{\normalfont\textcolor{#1}{\@thefnmark}}}%
  }%
  \footnote{#2}%
}
\AtBeginDocument{%
  \ifrvt@writenotes
    \rvt@startfile{rvt}%
    \rvt@writefile{rvt}{%
      \string\begin{center}^^J\string\bfseries\space
      Review notes in file\space\jobname.tex
      ^^J\string\end{center}^^J\string\par\string\medskip^^J%
    }%
  \fi
}
\newcommand\rvt@notefile[3]{%
  \ifboolTF{rvt@writenotes}{%
    \rvt@writefile{rvt}{%
      \string\noindent
      {\string\bfseries\@space#1\string~\the\c@section.\arabic{#3}}%
      \string\enskip\unexpanded{#2} (page\string~\the\c@page).
      \string\par\string\medskip^^J%
    }%
  }{}%
}
\new@def*\rvt@r@viewer{%
  \ifboolTF{rvt@showreviewer}{\textit{\rvt@reviewer}}{}%
}
\newcommand*\rvt@notefootnote[1][\rvt@notecolor]{%
  \long\def\@makefntext##1{%
    \rule\z@\footnotesep\parindent1em\noindent
    \hb@xt@0em{\hss\@textsuperscript{\normalfont\color{#1}\@thefnmark}}%
    \hspace{2\p@}\color{#1}\ignorespaces##1%
  }%
  \def\@makefnmark{\hbox{\@textsuperscript
    {\normalfont\color{#1}\@thefnmark}}}%
}
\robust@def*\rvt@refstepcounter#1#2#3{%
  \stepcounter{#1}%
  \protected@edef\@currentlabel{\thesection.\usename{the#1}}%
  \def\@currentlabelname{#2}%
  \def\@currentHref{#3.\@currentlabel}%
}
\newcounter{rvt@notecnt}[section]
\robust@def*\rvtshortnote{\cpt@ifstar\rvt@shortnote\rvt@sh@rtnote}
\newcommand*\rvt@shortnote[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next
        {\rvt@err{Can't write 'shortnote*' if 'final'}\@ehc}%
    \else
      \def\next{\rvt@shortnotebody{#1}{#2}}%
    \fi
  \fi
  \next
}
\newcommand*\rvt@sh@rtnote[2][]{%
  \ifboolFT{rvt@printnotes}{}{\rvt@shortnotebody{#1}{#2}}%
}
\newcommand*\rvt@shortnotebody[2]{%
  \begingroup
  \rvt@refstepcounter{rvt@notecnt}{note}{note}%
  \rvt@notefootnote[\rvt@notecolor]%
  \color{\rvt@notecolor}%
  \noindent
  \finalhyphendemerits\z@pt
  \rvt@notebmark
  \textbf{Note~\thesection.\thervt@notecnt}\enskip
  \ignorespaces#2~\rvt@r@viewer\relax
  \rvt@noteemark
  \ifblankTF{#1}{}{\footnote'{#1}}%
  \rvt@notefile{Note}{\string\ignorespaces#2}{rvt@notecnt}%
  \endgroup
}
\robust@def*\rvt@notebmark{%
  \marginpar{%
    \edef\rvt@tempa{\ifrvt@shownotetype Notes\fi}%
    \begin{picture}(0,0)%
      \sffamily\color{\rvt@notecolor}%
      \put(0,0){\rotatebox{-90}{\small$\blacktriangleright$\rvt@tempa}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@noteemark{%
  \marginpar{%
    \begin{picture}(0,0)%
      \sffamily\color{\rvt@notecolor}%
      \put(12,0){\rotatebox{90}{\small$\blacktriangleright$}}%
    \end{picture}%
  }%
}

\newenviron{rvtlongnote}[1][]{%
  \ifboolFT{rvt@printnotes}{}{\rvt@longnotebody{#1}}%
}{}
\newenviron{rvtlongnote*}[1][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print longnote* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@longnotebody{#1}}%
    \fi
  \fi
  \next
}{}
\newcommand*\rvt@longnotebody[1]{%
  \begingroup
  \rvt@refstepcounter{rvt@notecnt}{note}{note}%
  \rvt@notefootnote[\rvt@notecolor]%
  \color{\rvt@notecolor}%
  \medskip\noindent
  \rvt@longnotebmark
  \textbf{Note~\thesection.\thervt@notecnt}%
  \endgraf\noindent\finalhyphendemerits\z@pt
  \ignorespaces\envbody~\rvt@r@viewer\relax
  \rvt@longnoteemark
  \ifblankTF{#1}{}{\footnote'{#1}}%
  \rvt@notefile{Note}{\string\ignorespaces\envbody}{rvt@notecnt}%
  \endgroup
}
\robust@def*\rvt@longnotebmark{%
  \marginpar{%
    \sffamily\color{\rvt@notecolor}%
    \edef\rvt@tempa{\ifrvt@shownotetype Notes start\fi}%
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small$\blacktriangleright$\rvt@tempa}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@longnoteemark{%
  \marginpar{%
    \sffamily\color{\rvt@notecolor}%
    \edef\rvt@tempa{\ifrvt@shownotetype Notes end\fi}%
    \begin{picture}(0,0)%
      \put(10,0){\rotatebox{90}{\small$\blacktriangleright$\rvt@tempa}}%
    \end{picture}%
  }%
}

\newcounter{rvt@marginnotecnt}
\MakeSortedPerPage{rvt@marginnotecnt}
\robust@def*\rvtshortmarginnote{%
  \cpt@ifstar\rvt@shortmarginnote\rvt@sh@rtmarginnote
}
\robust@def*\rvt@shortmarginnote#1{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print shortmarginnote* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@marginnotebody{#1}}%
    \fi
  \fi
  \next
  \rvt@notefile{Note}{#1}{rvt@marginnotecnt}%
}
\robust@def*\rvt@sh@rtmarginnote#1{%
  \ifrvt@printnotes\rvt@marginnotebody{#1}\fi
  \rvt@notefile{Note}{#1}{rvt@marginnotecnt}%
}
\newenviron{rvtmarginnote*}{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print marginnote* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@marginnotebody{\envbody}}%
    \fi
  \fi
  \next
  \rvt@notefile{Note}{\envbody}{rvt@marginnotecnt}%
}{}
\newenviron{rvtmarginnote}{%
  \ifrvt@printnotes
    \def\next{\rvt@marginnotebody{\envbody}}%
  \else
    \let\next\relax
  \fi
  \next
  \rvt@notefile{Note}{\envbody}{rvt@marginnotecnt}%
}{}
\newenviron{rvtMarginNote}{%
  \ifrvt@printnotes
    \rvt@marginnotebody\envbody
  \fi
  \rvt@notefile{Note}{\envbody}{rvt@marginnotecnt}%
}{}
\robust@def*\rvt@marginnotebody#1{%
  \begingroup
  \rvt@refstepcounter{rvt@marginnotecnt}{margin note}{margin note}%
  \fboxsep=1\p@\fboxrule=0.4\p@\relax
  \marginpar[\sffamily\color{\rvt@notecolor}\small\raggedleft
    \fbox{\thervt@marginnotecnt}~#1]{\sffamily\color{\rvt@notecolor}%
      \small\raggedright\fbox{\thervt@marginnotecnt}~#1}%
  \endgroup
}
\newcounter{rvt@deletecnt}[section]
\robust@def*\rvtshortdelete{%
  \cpt@ifstar\rvt@shortdelete\rvt@sh@rtdelete
}
\newcommand\rvt@shortdelete[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't write shortdelete* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@deletebody{#1}{#2}}%
    \fi
  \else
    \def\next{}%
  \fi
  \next
}
\newcommand\rvt@sh@rtdelete[2][]{%
  \ifrvt@printnotes
    \rvt@deletebody{#1}{#2}%
  \fi
}
\newenviron{rvtdelete*}[1][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print delete* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@deletebody{#1}{\envbody}}%
    \fi
  \fi
  \next
  \rvt@notefile{Delete}{\envbody}{rvt@deletecnt}%
}{}
\newenviron{rvtdelete}[1][]{%
  \ifrvt@printnotes
    \rvt@deletebody{#1}{\envbody}%
  \fi
  \rvt@notefile{Delete}{\envbody}{rvt@deletecnt}%
}{}
\robust@def*\rvt@deletebody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@deletecnt}{delete}{delete}%
  \rvt@notefootnote[\rvt@deletecolor]%
  \rvt@deletebmark
  \sffamily\rvt@deletecolor\ignorespaces
  #2\xifblankTF{#1}{}{\footnote'{#1}}%
  \rvt@deleteemark
  \endgroup
}
\robust@def*\rvt@deletebmark{%
  \marginpar{%
    \sffamily\rvt@deletecolor
    \ifrvt@shownotetype\def\rvt@note{Delete}\else\def\rvt@note{}\fi
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small$\blacktriangleright$\rvt@note}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@deleteemark{\marginpar{\sffamily\rvt@deletecolor
  \begin{picture}(0,0)%
    \put(4,0){\rotatebox{90}{\small$\blacktriangleright$\rvt@r@viewer}}%
  \end{picture}}%
}
\newcounter{rvt@deletedcnt}[section]
\robust@def*\rvtshortdeleted{%
  \cpt@ifstar\rvt@shortdeleted\rvt@sh@rtdeleted
}
\newcommand\rvt@shortdeleted[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't write shortdeleted* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@deletedbody{#1}{#2}}%
    \fi
  \fi
  \next
}
\newcommand\rvt@sh@rtdeleted[2][]{%
  \ifrvt@printnotes
    \rvt@deletedbody{#1}{#2}%
  \fi
}
\newenviron{rvtdeleted*}[1][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print deleted* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@deletedbody{#1}{\envbody}}%
    \fi
  \fi
  \next
  \rvt@notefile{Deleted}{\envbody}{rvt@deletedcnt}%
}{}
\newenviron{rvtdeleted}[1][]{%
  \ifrvt@printnotes
    \rvt@deletedbody{#1}{\envbody}%
  \fi
  \rvt@notefile{Deleted}{\envbody}{rvt@deletedcnt}%
}{}
\robust@def*\rvt@deletedbody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@deletedcnt}{deleted}{deleted}%
  \rvt@notefootnote[\rvt@deletedcolor]%
  \rvt@deletedbmark
  \sffamily\rvt@deletedcolor\ignorespaces
  #2\xifblankTF{#1}{}{\footnote'{#1}}%
  \rvt@deletedemark
  \endgroup
}
\robust@def*\rvt@deletedbmark{%
  \marginpar{%
    \sffamily\rvt@deletedcolor
    \ifrvt@shownotetype\def\rvt@note{Deleted}\else\def\rvt@note{}\fi
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small$\blacktriangleright$\rvt@note}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@deletedemark{%
  \marginpar{%
    \sffamily\rvt@deletedcolor
    \begin{picture}(0,0)%
      \put(4,0){\rotatebox{90}{\small$\blacktriangleright$%
        \rvt@r@viewer}}%
    \end{picture}%
  }%
}
\newcounter{rvt@addcnt}[section]
\robust@def*\rvtshortadd{%
  \cpt@ifstar\rvt@shortadd\rvt@sh@rtadd
}
\newcommand\rvt@shortadd[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print shortadd* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@addbody{#1}{#2}}%
    \fi
  \else
    \def\next{}%
  \fi
  \next
  \rvt@notefile{Add}{#2}{rvt@addcnt}%
}
\newcommand\rvt@sh@rtadd[2][]{%
  \ifrvt@printnotes
    \rvt@addbody{#1}{#2}%
  \fi
  \rvt@notefile{Add}{#2}{rvt@addcnt}%
}
\newenviron{rvtadd*}[1][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print add* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@addbody{#1}{\envbody}}%
    \fi
  \else
    \def\next{}%
  \fi
  \next
  \rvt@notefile{Add}{\envbody}{rvt@addcnt}%
}{}
\newenviron{rvtadd}[1][]{%
  \ifrvt@printnotes\rvt@addbody{#1}{\envbody}\fi
  \rvt@notefile{Add}{\envbody}{rvt@addcnt}%
}{}
\robust@def*\rvt@addbody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@addcnt}{add}{add}%
  \rvt@notefootnote[\rvt@addcolor]%
  \rvt@addbmark
  \sffamily\rvt@addcolor\ignorespaces
  #2\xifblankTF{#1}{}{\footnote'{#1}}%
  \rvt@addemark
  \endgroup
}
\robust@def*\rvt@addbmark{%
  \marginpar{%
    \sffamily\rvt@addcolor
    \ifrvt@shownotetype\def\rvt@note{Add}\else\def\rvt@note{}\fi
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small$\blacktriangleright$\rvt@note}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@addemark{%
  \marginpar{%
    \sffamily\rvt@addcolor
    \begin{picture}(0,0)%
      \put(4,0){\rotatebox{90}{\small$\blacktriangleright$
        \rvt@r@viewer}}%
    \end{picture}%
  }%
}
\newcounter{rvt@finalizedcnt}[section]
\robust@def*\rvtfinalizedfrom{%
  \cpt@ifstar\rvt@finalizedfrom\rvt@fin@lizedfrom
}
\newcommand\rvt@finalizedfrom[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print finalizedfrom* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@finalizedfrombody{#1}{#2}}%
    \fi
  \fi
  \next
  \rvt@notefile{Finalized From}{#2}{rvt@finalizedcnt}%
}
\newcommand\rvt@fin@lizedfrom[2][]{%
  \ifrvt@printnotes
    \rvt@finalizedfrombody{#1}{#2}%
  \fi
  \rvt@notefile{Finalized From}{#2}{rvt@finalizedcnt}%
}
\robust@def\rvt@finalizedfrombody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@finalizedcnt}{finalized from}{finalized from}%
  \rvt@notefootnote[\rvt@wipcolor]%
  \rvt@finfrombmark\rvt@finfromemark
  \sffamily\rvt@wipcolor\ignorespaces
  \ignorespaces#2\xifblankTF{#1}{}{\footnote'{#1}}%
  \endgroup
}
\newcommand*\rvt@finfrombmark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(5,0){\rotatebox{-90}{\small$\blacktriangleright$%
        Finalized from here}}%
    \end{picture}%
  }%
}
\newcommand*\rvt@finfromemark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small(\rvt@r@viewer)}}%
    \end{picture}%
  }%
}
\robust@def*\rvtfinalizedto{%
  \cpt@ifstar\rvt@finalizedto\rvt@fin@lizedto
}
\newcommand\rvt@finalizedto[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print finalizedto* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@finalizedtobody{#1}{#2}}%
    \fi
  \fi
  \next
  \rvt@notefile{Finalized To}{#2}{rvt@finalizedcnt}%
}
\newcommand\rvt@fin@lizedto[2][]{%
  \ifrvt@printnotes
    \rvt@finalizedtobody{#1}{#2}%
  \fi
  \rvt@notefile{Finalized To}{#2}{rvt@finalizedcnt}%
}
\robust@def\rvt@finalizedtobody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@finalizedcnt}{finalized to}{finalized to}%
  \rvt@notefootnote[\rvt@wipcolor]%
  \rvt@finalizedtobmark\rvt@finalizedtoemark
  \sffamily\rvt@wipcolor\ignorespaces
  \ignorespaces#2\xifblankTF{#1}{}{\footnote'{#1}}%
  \endgroup
}
\newcommand*\rvt@finalizedtobmark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{90}{\small$\blacktriangleright$%
        Finalized to here}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@finalizedtoemark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(4,0){\rotatebox{90}{\small\p@blacktrig(\rvt@r@viewer)}}%
    \end{picture}%
  }%
}
% wip = work in progress
\newcounter{rvt@wipcnt}[section]
\robust@def*\rvtwipfrom{\cpt@ifstar\rvt@wipfrom\rvt@wipfr@m}
\newcommand\rvt@wipfrom[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print wipfrom* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@wipfrombody{#1}{#2}}%
    \fi
  \fi
  \next
  \rvt@notefile{WIP From}{#2}{rvt@wipcnt}%
}
\newcommand\rvt@wipfr@m[2][]{%
  \ifrvt@printnotes
    \rvt@wipfrombody{#1}{#2}%
  \fi
  \rvt@notefile{WIP From}{#2}{rvt@wipcnt}%
}
\robust@def*\rvt@wipfrombody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@wipcnt}{wip from}{wip from}%
  \rvt@notefootnote[\rvt@wipcolor]%
  \rvt@wipfrombmark\rvt@wipfromemark%
  \sffamily\rvt@wipcolor\ignorespaces
  \ignorespaces#2\xifblankTF{#1}{}{\footnote'{#1}}%
  \endgroup
}
\newcommand*\rvt@wipfrombmark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(5,0){\rotatebox{-90}{\small$\blacktriangleright$%
        WIP start}}%
    \end{picture}%
  }%
}
\newcommand*\rvt@wipfromemark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{-90}{\small(\rvt@r@viewer)}}%
    \end{picture}%
  }%
}
\robust@def*\rvtwipto{\cpt@ifstar\rvt@wipto@a\rvt@wipto@b}
\newcommand*\rvt@wipto@a[2][]{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print wipto* if 'final'}\@ehc}%
    \else
      \def\next{\rvt@wiptobody{#1}{#2}}%
    \fi
  \fi
  \next
  \rvt@notefile{WIP To}{#2}{rvt@wipcnt}%
}
\newcommand\rvt@wipto@b[2][]{%
  \ifrvt@printnotes
    \rvt@wiptobody{#1}{#2}%
  \fi
  \rvt@notefile{WIP To}{#2}{rvt@wipcnt}%
}
\robust@def*\rvt@wiptobody#1#2{%
  \begingroup
  \rvt@refstepcounter{rvt@wipcnt}{wip to}{wip to}%
  \rvt@notefootnote[\rvt@wipcolor]%
  \rvt@wiptobmark\rvt@wiptoemark
  \sffamily\rvt@wipcolor\ignorespaces
  \ignorespaces#2\xifblankTF{#1}{}{\footnote'{#1}}%
  \endgroup
}
\robust@def*\rvt@wiptobmark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(0,0){\rotatebox{90}{\small$\blacktriangleright$WIP end}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@wiptoemark{%
  \marginpar{%
    \sffamily\rvt@wipcolor
    \begin{picture}(0,0)%
      \put(5,0){\rotatebox{90}{\small\p@blacktrig(\rvt@r@viewer)}}%
    \end{picture}%
  }%
}
\robust@def*\rvt@edittext{%
  \ifboolTF{cpt@st}\rvt@edittext@a\rvt@edittext@b
}
\robust@def*\rvt@edittext@a#1{%
  \let\next\relax
  \ifrvt@printnotes
    \ifrvt@final
      \def\next{\rvt@err{Can't print edit-mark* if 'final'}\@ehc}%
    \else
      \def\next{%
        \begingroup
        \small\fboxrule.4\p@\fboxsep1.5\p@
        \textcolor{rvtgreen10}{\fbox{#1}}%
        \endgroup
      }%
    \fi
  \else
    \ifhmode
      \def\next{\unskip\unkern}%
    \fi
  \fi
  \next
}
\robust@def*\rvt@edittext@b#1{%
  \ifrvt@printnotes
    \small\textcolor{rvtgreen10}{\fboxrule.4\p@\fboxsep1.5\p@\fbox{#1}}%
  \else
    \ifhmode\unskip\unkern\fi
  \fi
}
\robust@def*\rvtpheromone{\cpt@testst{\rvt@edittext{$\clubsuit$}}}
\robust@def*\rvtedit{\cpt@testst{\rvt@edittext{Edit}}}
\robust@def*\rvtedited{\cpt@testst{\rvt@edittext{Edited}}}
\robust@def*\rvtpauseedit{\cpt@testst{\rvt@edittext{Paused editing here}}}
\robust@def*\rvtdiscuss{\cpt@testst{\rvt@edittext{Discuss}}}
\robust@def*\rvttodiscuss{\cpt@testst{\rvt@edittext{To be discussed}}}
\robust@def*\rvtaddtext{\cpt@testst{\rvt@edittext{Add text here}}}
\robust@def*\rvtaddtextbyauthor#1{%
  \cpt@testst{\rvt@edittext{Add text here:~\textcolor{blue}{#1}}}%
}
\robust@def*\rvtadddescription{%
  \cpt@testst{\rvt@edittext{Add description here}}%
}
\robust@def*\rvtadddescriptionbyauthor#1{%
  \cpt@testst{\rvt@edittext{Add description
    here:~\textcolor{blue}{#1}}}%
}
\newletcs\rvtaddbyauthor\rvtadddescriptionbyauthor
\robust@def*\rvttoaddtext{%
  \cpt@testst{\rvt@edittext{Text to be added here}}%
}
\robust@def*\rvteditbyauthor#1{%
  \cpt@testst{\rvt@edittext{Edit:~\textcolor{blue}{#1}}}%
}
\robust@def*\rvtflag#1{%
  \ifrvt@printnotes
    \endgraf
    \makebox[\z@][l]{%
      \kern-\marginparwidth\small\color{purple}%
      \fboxrule.4pt\fboxsep1pt\relax
      \fbox{$\clubsuit$}\enskip#1%
    }%
  \fi
}

\endinput
