-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewrevisor.sty
302 lines (287 loc) · 13.4 KB
/
newrevisor.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{newrevisor}[2023/05/12 v0.7 newrevisor]
% A LaTeX style file for providing comments and revising text
%
% Author: Manuel Lopez-Ibanez <manuel.lopez-ibanez@manchester.ac.uk>
%
% This package defines 3 commands:
%
% 1. `\newrevisor{name}{color-for-insert}[color-for-delete]` where the first
% argument is the name of the revisor, second argument is color for additions
% and third optional argument is color for deletions. If the third argument is
% missing, the second argument is used for both additions and deletions. See
% colornames in https://en.wikibooks.org/wiki/LaTeX/Colors
%
% This command creates two new commands:
%
% * Lowercase `\name{text-to-delete}{text-to-insert}` for suggesting changes.
%
% * Uppercase `\NAME{text}` for adding comments.
%
% 2. `\hiderevisor{name}` Disables the corresponding commands generated by
% `\newrevisor{name}`, that is, removes comments and suggested deletions and
% shows suggested additions without coloring them.
%
% 3. \listofrevisions
%
% See full documentation: https://github.com/MLopez-Ibanez/revision
\RequirePackage{iftex}
\RequirePackage{etoolbox} % \csuse \ifdef
\RequirePackage{xparse}
\PassOptionsToPackage{dvipsnames}{xcolor}
\RequirePackage{xcolor}
\RequirePackage{amstext} % \text
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=REVISOR,
prefix=REVISOR@
}
\DeclareBoolOption{norelsize} % norelsize disables use of relsize package for compatibility with broken documentclass
\DeclareBoolOption{todonotes} % use todonotes instead of footnotes
\DeclareBoolOption{soul} % use soul instead of ulem
\DeclareStringOption{hide}[before] % hide=before hide=after
\def\REVISOR@before{before}
\def\REVISOR@after{after}
\DeclareBoolOption{inline} % inline comments
\ProcessKeyvalOptions*
\ifREVISOR@norelsize
\let\newrevisor@smaller\footnotesize % FIXME: Find a better solution without relsize
\else
\RequirePackage{relsize}
\let\newrevisor@smaller\smaller
\fi
% https://tex.stackexchange.com/questions/110780/remove-macro-from-list-like-lof
\def\vanishprotect{\ifx\protect\@typeset@protect%
\expandafter\@firstofone\else\expandafter\@gobble\fi}
%% FIXME: To remove etoolbox
% \providecommand*{\csuse}[1]{\ifcsname #1\endcsname \csname #1\expandafter \endcsname \fi}
\newcommand{\linethrough}{\mathpalette\@thickbar}
\newcommand{\@thickbar}[2]{%
{\mkern0mu\vbox{
\sbox\z@{$#1#2\mkern-1.5mu$}%
\dimen@=\dimexpr\ht\tw@-\ht\z@+2\p@\relax % The +2 represents the vertical shift of the line.
\hrule\@height0.5\p@ % The 0.5 represent the thickness on the line.
\vskip\dimen@
\box\z@}}#1}
\newcommand{\mathsout}[1]{\ensuremath{\linethrough{#1}}}
\ifREVISOR@soul
\RequirePackage{soul}
\let\@sout\st
\else
\PassOptionsToPackage{normalem}{ulem}
\RequirePackage{ulem}
\let\@sout\sout
\fi
%% Revision commands
\ifx\REVISOR@hide\@empty
\else
\ifx\REVISOR@before\REVISOR@hide
\newcommand{\newrevisor@SuggestEdit}[4]{#2}
\else
\ifx\REVISOR@after\REVISOR@hide
\newcommand{\newrevisor@SuggestEdit}[4]{#1}
\else
\PackageError{\@currname}{Unknown value for option 'hide='. Valid values are 'before' or 'after'}{Unknown value for option 'hide='. Valid values are 'before' or 'after'}
% We set this so we can continue without throwing more errors.
\let\REVISOR@hide\@empty
\fi
\fi
\fi
% FIXME: \sout is not very good. It cannot handle commands within its argument.
\ifx\REVISOR@hide\@empty
% Multi-paragraph \sout
\NewDocumentCommand\hsout{+m}{\let\helpcmd\@sout\parhelp#1\par\relax\relax} %<-- new command
\long\def\parhelp#1\par#2\relax{%
\helpcmd{#1}\ifx\relax#2\else\par\parhelp#2\relax\fi%
}
\NewDocumentCommand{\mysout}{+m}{%
% Force inline comments when deleting text, otherwise we get weird errors.
\NewCommandCopy\origrevcomment\newrevisor@RevComment
\let\newrevisor@RevComment\newrevisor@RevInlineComment
\NewCommandCopy\origref\ref% Sometimes \ref produces Extra }, or forgotten \endgroup.
\renewcommand{\ref}[1]{\mbox{\origref{##1}}}%
\NewCommandCopy\origcite\cite%
\renewcommand{\cite}[2][]{\mbox{\origcite[##1]{##2}}}%
%\makeatletter%
\@ifundefined{citet}{}{%
\NewCommandCopy\origcitet\citet%
\renewcommand{\citet}[2][]{\mbox{\origcitet[##1]{##2}}}%
}%
\@ifundefined{citep}{}{%
\NewCommandCopy\origcitep\citep%
\renewcommand{\citep}[2][]{\mbox{\origcitep[##1]{##2}}}%
}%
% \makeatother%
% \texorpdfstring requires hyperref
\providecommand{\texorpdfstring}[2]{##1}%
\texorpdfstring{\ifmmode\text{\mathsout{#1}}\else\hsout{#1}\fi}{#1}%
}
% \hypersetup requires hyperref
\NewDocumentCommand{\newrevisor@color}{m}{\color{#1}\providecommand{\hypersetup}[1]{}\hypersetup{citecolor=#1}}
\NewDocumentCommand{\newrevisor@SuggestEdit}{+m+mmm}{{\newrevisor@color{#3}\mysout{#1}}\allowbreak{\newrevisor@color{#4}#2}}%
\fi % no hide
\ifREVISOR@todonotes
\RequirePackage{todonotes}
\RequirePackage{marginnote}
\let\marginpar\marginnote
\ifx\REVISOR@hide\@empty
\newcommand{\newrevisor@RevInlineComment}[3][red]{%
\colorlet{tmpcolor}{#1}%
% caption={} allows itemize
\ifmmode\vanishprotect{\text{\todo[size=\tiny,inline,caption={},color=tmpcolor!29,bordercolor=tmpcolor!47]{\textbf{#2}: #3}}}%
\else\vanishprotect{\todo[size=\tiny,inline,caption={},color=tmpcolor!29,bordercolor=tmpcolor!47]{\textbf{#2}: #3}}\fi}%
\newcommand{\newrevisor@RevComment}[3][red]{%
\colorlet{tmpcolor}{#1}%
\ifmmode\vanishprotect{\text{\todo[size=\tiny,color=tmpcolor!29, bordercolor=tmpcolor!47]{\textbf{#2}: #3}}}%
\else\vanishprotect{\todo[size=\tiny,color=tmpcolor!29, bordercolor=tmpcolor!47]{\textbf{#2}: #3}}\fi}
\else
\newcommand{\newrevisor@RevInlineComment}[3][red]{}
\newcommand{\newrevisor@RevComment}[3][red]{}
\fi % hide
% % some fancy todos
% % \usepackage[colorinlistoftodos, prependcaption, textwidth=2cm, textsize=tiny]{todonotes}
% \usepackage[colorinlistoftodos, prependcaption, textwidth=2cm, textsize=tiny]{todonotes}
% \setuptodonotes{color=blue!29, bordercolor=blue!47}
% \newcommandx{\ourtodo}[4][4=,usedefault]{\todo[color=#3!29, inline, bordercolor=#3!47, caption={\textbf{#4} #1}]{#2}}
% \newcommand{\nayat}[1]{\ourtodo{Nayat}{#1}{purple}}
% \newcommand{\arnaud}[1]{\ourtodo{Arnaud}{#1}{magenta}}
% \newcommand{\luis}[1]{\ourtodo{Luis}{#1}{green}}
% \newcommand{\manuel}[1]{\ourtodo{Manuel}{#1}{orange}}
% \newcommand{\leslie}[1]{\ourtodo{Leslie}{#1}{magenta}}
% \newcommand{\pedro}[1]{\ourtodo{Pedro}{#1}{red}}
% \newcommand{\suggestion}[1]{\todo[inline, nolist, bordercolor=gray!47, color=gray!29, size=\tiny]{#1}}
\else
\RequirePackage{pdfcolfoot} % For colored footnotes split across pages.
\let\svthefootnote\thefootnote
\gdef\infootnote{F}
\newcommand\colorfootnote[2][black]{%
\def\thefootnote{\color{#1}\svthefootnote}%
\footnote{\def\infootnote{T}\color{#1}#2\def\infootnote{F}}\def\thefootnote{\color{black}\svthefootnote}}
%% TODO: Make this a package option
%% A different implementation in case the above one does not work, not sure which one is better
% \makeatletter
% \let\sv@makefnmark\@makefnmark
% \newcommand\colorfootnote[2][black]{\renewcommand\@makefnmark{\color{#1}\sv@makefnmark}\footnote{\protect{\color{#1}#2}}\renewcommand\@makefnmark{\sv@makefnmark}}
% \makeatother
\ifx\REVISOR@hide\@empty
\NewDocumentCommand\newrevisor@RevInlineComment{O{red}m+m}{%
\hskip 0pt\begingroup\ifmmode\text{\color{#1}\normalfont\footnotesize\bfseries\rmfamily[{\newrevisor@smaller #2}: #3]}\else\color{#1}\normalfont\footnotesize\bfseries\rmfamily[{\newrevisor@smaller #2}: #3]\fi\endgroup}
\NewDocumentCommand\newrevisor@RevComment{O{red}m+m}{%
\if T\infootnote\newrevisor@RevInlineComment[#1]{#2}{#3}\else%
\@ifundefined{@captype}{\protect\colorfootnote[#1]{{\textbf{[{\newrevisor@smaller #2}: #3]}}}}%
{\newrevisor@RevInlineComment[#1]{#2}{#3}}\fi}
\else
\newcommand\newrevisor@RevInlineComment[3][red]{}
\newcommand{\newrevisor@RevComment}[3][red]{}
\fi % hide
\fi % todonotes
\ifREVISOR@inline
\def\newrevisor@RevComment{\newrevisor@RevInlineComment}
\fi % inline
% Creates a command for edits in lowercase (delete, add) in lowercase and a command in UPPERCASE for commenting, second argument is a color
\newcommand\newrevisor@twocolors[3]{%%
\stepcounter{newrevisor@AuthorCount}%
\@namedef{newrevisor@AuthorID\thenewrevisor@AuthorCount}{#1}
% \expandafter\let\csname newrevisor@AuthorName#1\endcsname=\newrevisor@definechangesauthor@name
% \expandafter\let\csname newrevisor@AuthorColor#1\endcsname{#2}
\@namedef{newrevisor@AuthorColor#1}{#2}
\newcounter{newrevisor@locEditCounter#1}%
\newcounter{newrevisor@locCommentCounter#1}%
%\colorlet{#1}{#2}%
\expandafter\DeclareRobustCommand\csname#1\endcsname[2]{%
\newrevisor@addEditToListOfChanges{#1}{#2}%
\newrevisor@SuggestEdit{##1}{##2}{#3}{#2}}%
\uppercase{\expandafter\NewDocumentCommand\csname#1}\endcsname{s+m}{%
\newrevisor@addCommentToListOfChanges{#1}{#2}%
\IfBooleanTF##1%
% with star: inline
{\newrevisor@RevInlineComment[#2]{\MakeUppercase{#1}}{##2}}%
% without star: footnote
{\newrevisor@RevComment[#2]{\MakeUppercase{#1}}{##2}}%
}%%
\patchcmd{\@starttoc}
{\begingroup}
{\begingroup\uppercase{\expandafter\RenewDocumentCommand\csname#1}\endcsname{s+m}{\ignorespaces}}
{}{}
}
\newcommand\hiderevisor[1]{%%
\expandafter\renewcommand\csname#1\endcsname[2]{}%%
\uppercase{\expandafter\RenewDocumentCommand\csname#1}\endcsname{s+m}{}%
}
% Implement list of changes: https://gitlab.com/ekleinod/changes/-/raw/main/texmf/tex/latex/changes/changes.sty
\newcounter{newrevisor@AuthorCount}
\setcounter{newrevisor@AuthorCount}{0}
\newcounter{newrevisor@Author}
\newcommand{\newrevisor@locextension}{lor}
\ifx\REVISOR@hide\@empty
\newcommand{\listofrevisions}[1][List of revisions]{%
\@ifundefined{chapter}{\section*{#1}}{\chapter*{#1}}
\listofsumchanges%
\@starttoc{\newrevisor@locextension}%
} % \listofrevisions
\else%
\newcommand{\listofrevisions}[1][List of revisions]{}%
\fi
\newcommand{\l@revision}{\@dottedtocline{1}{0em}{2.3em}}
% #1: Author, #2: Color
\DeclareRobustCommand{\newrevisorlocEdit}[2]{\stepcounter{newrevisor@locEditCounter#1}\fcolorbox{black}{#2}{\textcolor{#2}{o}}\ \textbf{#1}: Suggested edit}
\DeclareRobustCommand{\newrevisorlocComment}[2]{\stepcounter{newrevisor@locCommentCounter#1}\fcolorbox{black}{#2}{\textcolor{#2}{o}}\ \textbf{#1}: Comment}
\newcommand{\newrevisor@addEditToListOfChanges}[2]{%
%\phantomsection%
\addcontentsline{\newrevisor@locextension}{revision}{\newrevisorlocEdit{#1}{#2}}%
}
\newcommand{\newrevisor@addCommentToListOfChanges}[2]{%
%\phantomsection%
\addcontentsline{\newrevisor@locextension}{revision}{\newrevisorlocComment{#1}{#2}}%
}
\NewDocumentCommand{\newrevisor@locEditEmpty}{mm}{\stepcounter{newrevisor@locEditCounter#1}}
\NewDocumentCommand{\newrevisor@locCommentEmpty}{mm}{\stepcounter{newrevisor@locCommentCounter#1}}
\NewDocumentCommand{\juststepcontentsline}{mmmm}{#2}
\NewDocumentCommand{\listofsumchanges}{}{%
\IfFileExists{\jobname.\newrevisor@locextension}{%
% Loop over the file and increment the counters.
\DeclareCommandCopy{\newrevisor@oldlocEdit}{\newrevisorlocEdit}%
\DeclareCommandCopy{\newrevisor@oldlocComment}{\newrevisorlocComment}%
\DeclareCommandCopy{\oldcontentsline}{\contentsline}%
\DeclareCommandCopy{\newrevisorlocEdit}{\newrevisor@locEditEmpty}%
\DeclareCommandCopy{\newrevisorlocComment}{\newrevisor@locCommentEmpty}%
\DeclareCommandCopy{\contentsline}{\juststepcontentsline}%
\newread\newrevisor@InFileX%
\openin\newrevisor@InFileX=\jobname.\newrevisor@locextension%
\loop\unless\ifeof\newrevisor@InFileX%
\read\newrevisor@InFileX to\newrevisor@LineX%
\ifx\newrevisor@InFileX\@empty\else%
\newrevisor@LineX%
\fi%
\repeat%
\closein\newrevisor@InFileX%
\DeclareCommandCopy{\newrevisorlocEdit}{\newrevisor@oldlocEdit}
\DeclareCommandCopy{\newrevisorlocComment}{\newrevisor@oldlocComment}
\DeclareCommandCopy{\contentsline}{\oldcontentsline}
\setcounter{newrevisor@Author}{0}
\loop\unless\ifnum\thenewrevisor@Author = \value{newrevisor@AuthorCount}
\stepcounter{newrevisor@Author}%
\def\newrevisor@ID{\csuse{newrevisor@AuthorID\thenewrevisor@Author}}%
\numdef{\newrevisor@InSum}{\value{newrevisor@locEditCounter\newrevisor@ID} + \value{newrevisor@locCommentCounter\newrevisor@ID}}%
\ifnumcomp{\newrevisor@InSum}{=}{0}{}{%
\noindent\textbf{\color{\csuse{newrevisor@AuthorColor\newrevisor@ID}}\newrevisor@ID}: \the\value{newrevisor@locCommentCounter\newrevisor@ID}\ comments, \the\value{newrevisor@locEditCounter\newrevisor@ID}\ revisions\\
}%
\repeat%
}{%
\emph{List of revisions is available after the next \LaTeX\ run.}%
\PackageWarning{newrevisor}{LaTeX rerun needed for list of revisions}%
}% \file_if_exist:nTF
}% \listofchanges
%% Handle different colors for deletion and adding
\NewDocumentCommand{\newrevisor}{mmO{#2}}{\newrevisor@twocolors{#1}{#2}{#3}}
% First argument is the desired command name, second argument is color for
% additions, third optional argument is color for deletions. If the third
% argument is missing, the second argument is used for both additions and
% deletions. See colornames in https://en.wikibooks.org/wiki/LaTeX/Colors
%
% \newrevisor{yourname}{color} creates two new commands:
% 1: \yourname{TEXT-TO-DELETE}{TEXT-TO-ADD}
% 2: \YOURNAME{COMMENT TEXT} which adds comments as footnotes. Use the starred version \YOURNAME*{COMMENT TEXT} to make the comment appear within the text (or use the package option "inline" to make all comments appear inline).
% \newrevisor{manuel}{violet!75}
% \hiderevisor{manuel}
\endinput