-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclaims.sty
129 lines (105 loc) · 3.9 KB
/
claims.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
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{claims}[2016/09/16]
\RequirePackage{color,xpatch}
\newif\if@trackinputfiles
\DeclareOption{paperdeadline}{%
\def\claim[#1]#2{#2}
\def\majorclaim[#1]#2{#2}
\def\claimref{\claimref@id}
}
\DeclareOption{checked}{%
\def\claimref{\claimref@write}
\def\claim[#1]#2{\claim@internal[minor][#1]{#2}}
\def\majorclaim[#1]#2{\claim@internal[major][#1]{#2}}
}
\DeclareOption{trackinput}{\@trackinputfilestrue}
\DeclareOption{notrackinput}{\@trackinputfilesfalse}
\ExecuteOptions{checked,trackinput}
\ProcessOptions\relax
\def\invalid@claim{1}
\def\valid@claim{2}
\if@trackinputfiles \newcount\claim@inputstack
\claim@inputstack=0
\let\old@input\input
\def\inputfile@stack@0{\jobname}
\def\input#1{\advance\claim@inputstack by1 \expandafter\def\csname inputfile@stack@\number\claim@inputstack\endcsname{#1}\old@input{#1}\advance\claim@inputstack by-1}
\def\the@input#1{\csname inputfile@stack@\number\claim@inputstack\endcsname.tex:#1}
\else
\def\the@input#1{l.#1}
\fi
\IfFileExists{\jobname.vld}{\input{\jobname.vld}}{}
\newwrite\claimoutput
\immediate\openout\claimoutput=\jobname.clm\relax
\newif\if@activeclaim
\newcount\claimrefs@counter
\claimrefs@counter=0
\newcounter{claimtext@counter}
\def\claimref@write[#1]#2{%
\advance\claimrefs@counter by1%
\global\expandafter\def\csname claimref@key@\number\claimrefs@counter\endcsname{#1}%
\global\expandafter\def\csname claimref@value@\number\claimrefs@counter\endcsname{#2}%
#2}
\def\claimref@id[#1]#2{#2}
\def\write@claimrefs@rec{%
\ifnum \number\claimrefs@counter>0%
\immediate\write\claimoutput{\csname claimref@key@\number\claimrefs@counter\endcsname}%
\immediate\write\claimoutput{\csname claimref@value@\number\claimrefs@counter\endcsname}%
\advance\claimrefs@counter by-1 %
\write@claimrefs@rec{}%
\fi}
\def\write@claimrefs{\immediate\write\claimoutput{\number\claimrefs@counter}%
\write@claimrefs@rec{}}
\def\falseclaim[#1]#2{\textcolor{red}{[Claim ``#1'']:} #2 \textcolor{red}{[is FALSE]}}
\def\unknownclaim[#1]#2{\textcolor{blue}{[Claim ``#1'']:} #2 \textcolor{blue}{[is unverified]}}
\def\validclaim[#1]#2{#2}
\def\claim@saveclaim[#1]#2{%
\stepcounter{claimtext@counter}%
\global\expandafter\def\csname claim@claimtext@\theclaimtext@counter\endcsname{#2}%
\global\expandafter\def\csname claim@claimtag@\theclaimtext@counter\endcsname{#1}%
}
% courtesy of http://tex.stackexchange.com/questions/110883/writing-to-a-file
\let\protected@iwrite\protected@write
% patch the copy to add \immediate
\xpatchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\def\claim@writeclaimtext@rec{%
\ifnum \value{claimtext@counter}>0%
\protected@iwrite\claimoutput{}{@CLAIM@\csname claim@claimtag@\theclaimtext@counter\endcsname}%
\protected@iwrite\claimoutput{\let\claimref\claimref@id}{\csname claim@claimtext@\theclaimtext@counter\endcsname}%
\addtocounter{claimtext@counter}{-1}%
\claim@writeclaimtext@rec{}%
\fi}
\def\claim@internal[#1][#2]#3{%
%% invariant checking
\if@activeclaim\PackageError{claims}{Nested claim invocation}\fi%
\ifnum \number\claimrefs@counter>0 \PackageError{claims}{Internal variant broken}\fi%
%% check for duplicated claims
\ifcsname claimed@#2\endcsname\relax%
\PackageError{claims}{Duplicate claim #2, previous definition: \csname claimed@#2\endcsname}%
\fi%
\expandafter\edef\csname claimed@#2\endcsname{\the@input{\the\inputlineno}}%
%%
%% Start claim processing
\@activeclaimtrue%
%% Write the claim to document, tagging if necessasry
\ifcsname vld@#2\endcsname\relax%
\edef\name@tmp{\csname vld@#2\endcsname}%
\ifx\name@tmp\invalid@claim\relax%
\falseclaim[#2]{#3}%
\else %
\ifx\name@tmp\valid@claim\relax%
\validclaim[#2]{#3}%
\fi%
\fi%
\else %
\unknownclaim[#2]{#3}%
\fi%
%% write metadata
\claim@saveclaim[#2]{#3}%
\immediate\write\claimoutput{#1 #2}%
\write@claimrefs{}%
%%
%% End claim processing
\@activeclaimfalse%
}
\AtEndDocument{\claim@writeclaimtext@rec{}}
\endinput