Repository navigation
Expand file tree
/
Copy pathnewrevisor.sty
More file actions
412 lines (392 loc) · 16.2 KB
/
Copy pathnewrevisor.sty
File metadata and controls
412 lines (392 loc) · 16.2 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
\NeedsTeXFormat{LaTeX2e}
% Date MUST follow YYYY/MM/DD using leading zeroes if needed!
\ProvidesPackage{newrevisor}[2026/10/11 v0.15 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 \ifstrempty
\RequirePackage{xparse}
\PassOptionsToPackage{dvipsnames}{xcolor}
\RequirePackage{xcolor}
\RequirePackage{amstext} % \text
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=REVISOR,
prefix=REVISOR@
}
\DeclareBoolOption{pretty} % Use pretty comments
\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
\ifREVISOR@todonotes%
\ifREVISOR@pretty%
\PackageError{\@currname}{'todonotes' and 'pretty' do not make sense together}
\fi
\fi
% Set defaults here so the user cannot override them.
\NewDocumentCommand{\newrevisor@colorbox}{mm}{%
\begingroup
\setlength{\fboxsep}{3pt}%
\setlength{\fboxrule}{0.4pt}%
\colorbox{#1}{#2}%
\endgroup
}
% 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: 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%
}
\gdef\inmysout{F}
\NewDocumentCommand{\mysout}{+m}{%
\ifstrempty{#1}{}{%
\if T\inmysout#1% Double mysout: Just return the deleted text.
\else%
\def\inmysout{T}%
% 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}%
\def\inmysout{F}%
\fi%
}%
}
% \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
\newif\ifnewrevisor@infootnote
\newrevisor@infootnotefalse
\IfFormatAtLeastTF{2025-06-01}
{
\AddToHook{fntext/begin}{\newrevisor@infootnotetrue}
\AddToHook{fntext/end}{\newrevisor@infootnotefalse}
}{
% Fallback for older LaTeX
\let\newrevisor@orig@footnotetext\@footnotetext
\def\@footnotetext#1{%
\newrevisor@infootnotetrue
\newrevisor@orig@footnotetext{#1}%
\newrevisor@infootnotefalse
}
}
\ifREVISOR@todonotes
\NewDocumentCommand\newrevisor@TextComment{O{red}m+m}{\textbf{\MakeUppercase{#2}}: #3}
\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]{\newrevisor@TextComment{#2}{#3}}}}%
\else\vanishprotect{\todo[size=\tiny,inline,caption={},color=tmpcolor!29,bordercolor=tmpcolor!47]{\newrevisor@TextComment{#2}{#3}}}\fi}%
\newcommand{\newrevisor@RevComment}[3][red]{%
\colorlet{tmpcolor}{#1}%
\ifmmode\vanishprotect{\text{\todo[size=\tiny,color=tmpcolor!29, bordercolor=tmpcolor!47]{\newrevisor@TextComment{#2}{#3}}}}%
\else\vanishprotect{\todo[size=\tiny,color=tmpcolor!29, bordercolor=tmpcolor!47]{\newrevisor@TextComment{#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 % NOT todonotes
\ifREVISOR@pretty%
\NewDocumentCommand\newrevisor@TextComment{O{red}m+m}{%
\newrevisor@colorbox{#1}{\normalfont\bfseries\sffamily\scriptsize\textcolor{white}{\MakeUppercase #2}}{\color{#1}\normalfont\sffamily\ensuremath{[}\nobreak{\itshape #3}\nobreak\ensuremath{]}}}
\else%
\NewDocumentCommand\newrevisor@TextComment{O{red}m+m}{[{\newrevisor@smaller\MakeUppercase{#2}}: #3]}
\fi
\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%
% All comments inside an inline comment also become inline.
\let\newrevisor@RevComment\newrevisor@RevInlineComment%
\ifmmode\text{\color{#1}\normalfont\footnotesize\bfseries\rmfamily\newrevisor@TextComment[#1]{#2}{#3}}%
\else\color{#1}\normalfont\footnotesize\bfseries\rmfamily\newrevisor@TextComment[#1]{#2}{#3}\fi\endgroup}
\NewDocumentCommand\newrevisor@RevComment{O{red}m+m}{%
\ifnewrevisor@infootnote
\newrevisor@RevInlineComment[#1]{#2}{#3}%
\else\if T\infootnote
\newrevisor@RevInlineComment[#1]{#2}{#3}%
\else\@ifundefined{@captype}
{\protect\colorfootnote[#1]{{\textbf{\newrevisor@TextComment[#1]{#2}{#3}}}}}%
{\newrevisor@RevInlineComment[#1]{#2}{#3}}%
\fi\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
\newif\ifnewrevisor@readinglist
\newrevisor@readinglistfalse
% 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}
\@namedef{newrevisor@AuthorColor#1}{#2}%
\newcounter{newrevisor@locEditCounter#1}%
\newcounter{newrevisor@locCommentCounter#1}%
% ----------------------------------------------------------
% Lowercase command:
% \name{deleted}{inserted}
%
% +m+m makes both arguments long, so \par is allowed.
%
% When an auxiliary file is being read, do not record a new
% revision; retain only the inserted text.
% ----------------------------------------------------------
\expandafter\NewDocumentCommand\csname#1\endcsname{+m+m}{%
\ifnewrevisor@readinglist
##2%
\else
\newrevisor@addEditToListOfChanges{#1}{#2}%
\newrevisor@SuggestEdit{##1}{##2}{#3}{#2}%
\fi
}%
% ----------------------------------------------------------
% Uppercase command:
% \NAME{comment}
% \NAME*{comment}
%
% xparse handles the optional star safely, including inside
% captions and other moving arguments.
%
% When an auxiliary file is being read, consume the command
% without creating another .lor entry.
% ----------------------------------------------------------
\uppercase{\expandafter\NewDocumentCommand\csname#1}\endcsname{s+m}{%
\ifnewrevisor@readinglist
\ignorespaces
\else
\newrevisor@addCommentToListOfChanges{#1}{#2}%
\IfBooleanTF##1{%
\newrevisor@RevInlineComment[#2]{#1}{##2}%
}{%
\newrevisor@RevComment[#2]{#1}{##2}%
}%
\fi
}%
}%
\newcommand\hiderevisor[1]{%%
\expandafter\renewcommand\csname#1\endcsname[2]{##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
\AddToHook{cmd/@starttoc/before}{%
\newrevisor@readinglisttrue
}
\AddToHook{cmd/@starttoc/after}{%
\newrevisor@readinglistfalse
}
\newcommand{\listofrevisions}[1][List of revisions]{%
\@ifclassloaded{acmart}{%
\@starttoc{\newrevisor@locextension}{#1}%
\listofsumchanges
}{%
\@ifundefined{chapter}{\section*{#1}}{\chapter*{#1}}
\listofsumchanges%
\@starttoc{\newrevisor@locextension}%
}%
}
\else
\newcommand{\listofrevisions}[1][List of revisions]{}
\fi
\newcommand{\l@revision}{\@dottedtocline{1}{0em}{2.3em}}
% #1: Author, #2: Color
\DeclareRobustCommand{\newrevisorlocEdit}[2]{\fcolorbox{black}{#2}{\textcolor{#2}{o}}\ \textbf{#1}: Suggested edit}
\DeclareRobustCommand{\newrevisorlocComment}[2]{\fcolorbox{black}{#2}{\textcolor{#2}{o}}\ \textbf{#1}: Comment}
\NewDocumentCommand{\newrevisor@addEditToListOfChanges}{mm}{%
% \phantomsection%
\addcontentsline{\newrevisor@locextension}{revision}{\newrevisorlocEdit{#1}{#2}}%
}
\NewDocumentCommand{\newrevisor@addCommentToListOfChanges}{mm}{%
% \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{\newrevisor@juststepcontentsline}{mmmm}{#2}
\NewDocumentCommand{\listofsumchanges}{}{%
\IfFileExists{\jobname.\newrevisor@locextension}{%
% Start from zero: the counts are reconstructed from .lor.
\setcounter{newrevisor@Author}{0}%
\loop
\unless\ifnum
\thenewrevisor@Author=\value{newrevisor@AuthorCount}
\stepcounter{newrevisor@Author}%
\edef\newrevisor@ID{%
\csuse{newrevisor@AuthorID\thenewrevisor@Author}%
}%
\setcounter{newrevisor@locEditCounter\newrevisor@ID}{0}%
\setcounter{newrevisor@locCommentCounter\newrevisor@ID}{0}%
\repeat
% Reconstruct the counts from the .lor file.
\begingroup
\let\newrevisorlocEdit\newrevisor@locEditEmpty
\let\newrevisorlocComment\newrevisor@locCommentEmpty
\let\contentsline\newrevisor@juststepcontentsline
\input{\jobname.\newrevisor@locextension}%
\endgroup
% Print the summary.
\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}%
}%
}% \listofsumchanges
%% 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