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
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ezedits.sty
%% Copyright 2024 J. A. Smiga
%
% This work 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.
%
% This work has the LPPL maintenance status “maintained”.
%
% The Current Maintainer of this work is J. A. Smiga.
%
% This work consists of the file ezedits.sty
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This package was written by Joseph A. Smiga <joseph.smiga@rochester.edu>
%% Originally developed ca. 2018, this has been refined over the years.
%%
%% Some useful commands: (not up to date, see documentation)
%% Included are a set of commands to generate comments for a LaTeX file.
%%
%% This package requires the following standard packages:
%% ulem: for \sout
%% xcolor: for coloring text.
%% pdfcomment: if pdfcomment option is used
%%
%% Options are:
%% arrows: add arrows pointing to edits in margins (in captions, a pair of arrows are added, instead).
%% accept: accept all edits (arrows still appear).
%% pdfcomments: write edits as pdf annotations (arrows still appear).
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ezedits}[2024/09/12]
% \RequirePackage{xcolor}
\newif\if@accept\@acceptfalse % accept all comments (does not suppress package warnings)
\newif\if@pdfcomm\@pdfcommfalse % write pdf comments
\newif\if@showarrows\@showarrowsfalse
\newif\if@importulem\@importulemtrue
\DeclareOption{accept}{
\@accepttrue
}
\DeclareOption{pdfcomment}{ % add pdf comments
\@pdfcommtrue
\AtEndOfPackage{\RequirePackage{pdfcomment}}
}
\DeclareOption{arrows}{ % point to edits with arrows in the margin
\@showarrowstrue
\AtEndOfPackage{\RequirePackage{marginnote}}
}
\DeclareOption{nosout}{ % do not crossout deleted text
\@importulemfalse
}
\ProcessOptions\relax
\if@importulem
\RequirePackage[normalem]{ulem}% import ulem (for sout)
% update \sout to work better with \cite
\let\old@cite\cite% remember original
\def\new@cite#1{\mbox{\old@cite{#1}}}% put cite in mbox
\def\new@sout#1{\let\cite\new@cite\sout{#1}\let\cite\old@cite}% redefine sout
\else
\def\new@sout{}% do nothing
\fi
%% edit record
\newcounter{ez@editcount}
\newcounter{ez@totalcount}
\gdef\ez@editrecord{}
\newcommand{\ez@addeditpage}{%
\ifx\ez@lastpage\undefined% first edit
\xdef\ez@lastpage{\thepage}% initialize "last page" variable
% counter starts at 0, so it does not need to be updated
\else% 2nd+ edit
\if\ez@lastpage\thepage% same page as last edit
\relax% handled after if
\else% new page
% add record
\xdef\ez@editrecord{\ez@editrecord \ez@lastpage & \arabic{ez@editcount} \\}%
% reset counter/page number
\setcounter{ez@editcount}{0}%
\xdef\ez@lastpage{\thepage}%
\fi%
\fi%
% Note stepping needs to be "protected" (counters do not always like being changed, since this can mess up, e.g., TOC)
\protect\stepcounter{ez@editcount}% update counter
\protect\stepcounter{ez@totalcount}%
}
%TODO there is an issue with \thepage not always being accurate
% Possible solution: use \label{} (with generated unique labels) and \pageref{} instead of \thepage.
% -> This solution may cause out-of-order problems with floating images.
\newcommand{\makeeditreport}{%
\begin{tabular}{l|r}
%\hline\hline
Page & \# edits/notes \\
\hline
\ifx\ez@lastpage\undefined
\relax% no edits
\else%
\ez@editrecord
\ez@lastpage & \arabic{ez@editcount}% current state
\fi \\
\hline
Total & \arabic{ez@totalcount}
%\hline\hline
\end{tabular}
}
% Style of \draftnote (may be a better way to write this)
\newcommand{\@draftstyle}[1]{
{\ttfamily%
\ifx\textcolor\undefined%
#1%
\else%
\textcolor{red}{#1}%
\fi}%
}
% let user change the style
\newcommand{\setnotestyle}[1]{\let\@draftstyle#1}
%% Editing commands
\newcommand{\draftnote}[1]{%
\PackageWarning{ezedits}{Unresolved note: #1}%
\ez@addeditpage{}% update record
\if@showarrows%
\@ifundefined{@captype}%
{\marginnote{\@draftstyle{$\Longleftarrow$}}}%
{\@draftstyle{$\Longrightarrow$}}%
\fi%
\if@accept{}\relax\else%
\if@pdfcomm%
\pdfmargincomment{#1}%
\else%
\@draftstyle{[#1]}%
\fi%
\fi%
\if@showarrows% if in caption, draw end arrow
\@ifundefined{@captype}{}{\@draftstyle{$\Longleftarrow$}}%
\fi%
}
\newcommand{\defineEdit}[3]{%
% "\###Edit" for removing and adding text
\expandafter\newcommand\csname #1Edit\endcsname[2]{%
\PackageWarning{ezedits}{Unresolved modifications by #1: "##1" ---> "##2"}%
\ez@addeditpage{}% update record
\if@showarrows%
\@ifundefined{@captype}%
{\marginnote{{#3{$\Longleftarrow$}}}}%
{{#3{$\Longrightarrow$}}}%
\fi%
\if@accept% Display as if accepted
##2%
\else%
\if@pdfcomm%
\pdfmarkupcomment[author=#1,markup=StrikeOut]{##1{$_\wedge$}}{##2}%
\else%
{#2{\new@sout{##1}}}{#3{##2}}%
\fi%
\fi%
\if@showarrows% if in caption, draw end arrow
\@ifundefined{@captype}{}{{#3{$\Longleftarrow$}}}%
\fi%
}%
% "\###Ins" for adding text
\expandafter\newcommand\csname #1Ins\endcsname[1]{%
\ez@addeditpage{}% update record
\PackageWarning{ezedits}{Unresolved modifications by #1: "##1" inserted.}%
\if@showarrows%
\@ifundefined{@captype}%
{\marginnote{{#3{$\Longleftarrow$}}}}%
{{#3{$\Longrightarrow$}}}%
\fi%
\if@accept% Display as if accepted
##1%
\else%
\if@pdfcomm%
% \pdfcomment[author=#1,icon=Insert]{##1}%
\pdfmarkupcomment[author=#1,markup=Underline]{$_\wedge$}{##1}%
\else%
{#3{##1}}%
\fi%
\fi%
\if@showarrows% if in caption, draw end arrow
\@ifundefined{@captype}{}{{#3{$\Longleftarrow$}}}%
\fi%
}%
% "\###Del" for removing text
\expandafter\newcommand\csname #1Del\endcsname[1]{%
\PackageWarning{ezedits}{Unresolved modifications by #1: "##1" removed.}%
\ez@addeditpage{}% update record
\if@showarrows%
\@ifundefined{@captype}%
{\marginnote{{#3{$\Longleftarrow$}}}}%
{{#3{$\Longrightarrow$}}}%
\fi%
\if@accept% Display as if accepted
{}%
\else%
\if@pdfcomm%
\pdfmarkupcomment[author=#1,markup=StrikeOut,color=red]{##1}{}%
\else%
{#2{\new@sout{##1}}}%
\fi%
\fi%
\if@showarrows% if in caption, draw end arrow
\@ifundefined{@captype}{}{{#3{$\Longleftarrow$}}}%
\fi%
}%
}
\endinput
|