-
Notifications
You must be signed in to change notification settings - Fork 1
/
draft.sty
146 lines (130 loc) · 5.63 KB
/
draft.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
%%% draft.sty -- A package for inserting draft-only comments, etc.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draft}[2016/05/08 v1.1 Draft-only comments, etc.]
\RequirePackage{xcolor}
\RequirePackage{xparse}
%% Draft mode
% A draft conditional, for detecting if we're in draft mode. Defaults to true.
\newif\ifdraft
\drafttrue
%% Defining draft-aware commands
% `\NewDefinerWrapper{\newcommandish}{\command}{BODY}' defines the command
% `\command', which has the same syntax as `\newcommand' (and friends); it's a
% wrapper around `\newcommandish' (which should have the same syntax as
% `\newcommand'), but where the body of the defined command is wrapped by
% `BODY', with `#5' becoming the original body.
%
% An example:
%
% \NewDefinerWrapper{\newcommand}{\NewParentheticalCommand}{(#5)}
%
% defines a new command `\NewParentheticalCommand' such that
%
% \NewParentheticalCommand{\pbolded}[1]{\textbf{#1}}
%
% is the same as defining
%
% \newcommand{\pbolded}[1]{(\textbf{#1})}
%
% (note the parentheses around the bolding).
\newcommand{\NewDefinerWrapper}[3]{%
\NewDocumentCommand{#2}{smO{0}o+m}{%
\IfBooleanTF{##1}
{\IfNoValueTF{##4}
{#1*{##2}[##3]{#3}}
{#1*{##2}[##3][##4]{#3}}}
{\IfNoValueTF{##4}
{#1{##2}[##3]{#3}}
{#1{##2}[##3][##4]{#3}}}%
}%
}
% `\NewStdDefinerWrappers{CommandSuffix}{BODY}' defines three commands for
% defining commands:
%
% * `\NewCommandSuffix', which wraps `\newcommand' with `BODY'.
% * `\RenewCommandSuffix', which wraps `\renewcommand' with `BODY'.
% * `\ProvideCommandSuffix', which wraps `\providecommand' with `BODY'.
\newcommand{\NewStdDefinerWrappers}[2]{%
\expandafter\NewDefinerWrapper\expandafter\newcommand
\csname New#1\endcsname{#2}%
\expandafter\NewDefinerWrapper\expandafter\renewcommand
\csname Renew#1\endcsname{#2}%
\expandafter\NewDefinerWrapper\expandafter\providecommand
\csname Provide#1\endcsname{#2}%
}
% Defines the command `\NewDraftCommand' (resp. `\RenewDraftCommand' and
% `\ProvideDraftCommand'), which acts like `\newcommand' (resp. `\renewcommand'
% and `\providecommand') except that the resulting command completely disappears
% if the document is not in draft mode.
\NewStdDefinerWrappers{DraftCommand}{%
\ifdraft
#5%
\else
\@bsphack\@esphack
\fi
}
% `\whendraft{#1}' is `#1' when the document is in draft mode and completely
% vanishes otherwise.
\NewDraftCommand{\whendraft}[1]{#1}
%% Draft-only notes, color-coded by author
% The `\noteformat{format}' command defines the `format' that notes are in; `#1'
% is replaced by the note author tag and `#2' is replaced by the text of the
% note. The default format is `[#1: #2]'; e.g. `[ASZ: I like this.]'.
% (`\@noteformat' is the internal variable that holds the format.)
\newcommand{\@noteformat}[2]{}
\newcommand{\noteformat}[1]{\long\def\@noteformat##1##2{#1}}
\noteformat{[#1: #2]}
% `\makedraftnote{color}{author}{text}' unconditionally renders a draft note by
% `author' in the given `color' with body `text'. The formatting is that
% specified by `\noteformat'. Note that this command *always* typesets text;
% see `\draftnote' for a draft-only command.
\newcommand{\makedraftnote}[3]{\textcolor{#1}{\@noteformat{#2}{#3}}}
% `\makedraftfootnote{color}{author}{text}' unconditionally renders a draft
% footnote by `author' in the given `color' with body `text'. The formatting is
% that specified by `\noteformat'. This command is like `\makedraftnote`, but
% the body of the note is placed as a footnote. Note that this command *always*
% typesets text; see `\draftfootnote' for a draft-only command.
\newcommand{\makedraftfootnote}[3]{%
\textcolor{#1}{\footnotemark}%
\begingroup
\edef\thefootnote{%
\noexpand\textcolor{#1}{\unexpanded\expandafter{\thefootnote}}}%
\footnotetext{\makedraftnote{#1}{#2}{#3}}%
\endgroup}
% `\draftnote{color}{author}{text}' renders a draft note by `author' in the
% given `color' with body `text' when in draft mode, and disappears otherwise
% (as per `\makedraftnote'). `\draftfootnote{color}{author}{text}' is the same,
% except the note is placed in a footnote.
\NewDraftCommand{\draftnote}[3]{\makedraftnote{#1}{#2}{#3}}
\NewDraftCommand{\draftfootnote}[3]{\makedraftfootnote{#1}{#2}{#3}}
% A local variable used by `\newnote'.
\newcommand*{\@note@name}{}
% A local constant used by `\newnote' to detect an empty option argument.
\newcommand*{\@note@name@empty}{\unexpanded{}}
% `\newnote[author]{cmd}{color}' defines two new commands `\cmd' and `\cmdfoot'.
% The former command is defined so that `\cmd{text}' renders a draft note by
% `author' in the given `color' with body `text' when in draft mode, and
% disappears otherwise (as per `\draftnote'); the latter command is defined so
% that `\cmdfoot{text}' does the same thing, but places it in a footnote (as per
% `\draftfootnote'). If `ABBREV' is omitted, it defaults to `CMD' (i.e., the
% uppercase form of `cmd').
\newcommand*{\newnote}[3][]{%
% Use the given name; if none was given, use the uppercase form of the command
% name.
\def\@note@name{\unexpanded{#1}}%
\ifx\@note@name\@note@name@empty
% Uppercases the *definition* of the name, so it can be used expandably
% below.
\uppercase{\def\@note@name{#2}}%
\fi
% Check that the macro names are unused, and then define the macros, expanding
% `\@note@name' but not `\draft(foot)note'.
\expandafter\newcommand\csname#2\endcsname{}%
\expandafter\long\expandafter\edef\csname#2\endcsname##1{%
\noexpand\draftnote{#3}{\@note@name}{##1}%
}%
\expandafter\newcommand\csname#2foot\endcsname{}%
\expandafter\long\expandafter\edef\csname#2foot\endcsname##1{%
\noexpand\draftfootnote{#3}{\@note@name}{##1}%
}
}