-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefstate.sty
145 lines (144 loc) · 4.17 KB
/
refstate.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
%%
%% This is file `refstate.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% refstate.dtx (with options: `package')
%%
%% File: refstate.dtx
%% Copyright (C) 2021--2024 by Maximilian Teegen
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c 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.
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{refstate}
[2024/10/10 v0.2 ]
\ProvidesPackage{refstate}
\RequirePackage{amsthm,xparse}
\RequirePackage{marginnote}
\ExplSyntaxOn
\let\rfst@newtheorem@original=\newtheorem
\RenewDocumentCommand{\newtheorem}{s m o m o}{
\tl_if_in:nnTF {#2} {phfthm@} {
\tl_set:Nx \l_tmpa_tl
{\tl_range:nnn{#2}{8}{-1}}
\cs_if_exist:NTF \cmdKV@phfmkthm@thmstyle {
\if\relax\detokenize\expandafter{\cmdKV@phfmkthm@thmstyle}\relax % ... why?
\tl_const:cx {rfst@style@\tl_use:N\l_tmpa_tl} {\the\thm@style}
\else
\tl_const:cx {rfst@style@\tl_use:N\l_tmpa_tl} {\cmdKV@phfmkthm@thmstyle}
\fi
}{
\tl_const:cx {rfst@style@\tl_use:N\l_tmpa_tl} {\the\thm@style}
}
\tl_const:cx {rfst@style@#2} {plain}
\tl_const:cx {rfst@name@\tl_use:N\l_tmpa_tl}
{#4}
}{
\tl_const:cx {rfst@style@#2} {\the\thm@style}
\tl_const:cx {rfst@name@#2} {#4}
}
\IfBooleanTF{#1}{
\IfValueTF{#3}{
\IfValueTF{#5}{
\rfst@newtheorem@original*{#2}[#3]{#4}[#5]
}{
\rfst@newtheorem@original*{#2}[#3]{#4}
}
}{
\IfValueTF{#5}{
\rfst@newtheorem@original*{#2}{#4}[#5]
}{
\rfst@newtheorem@original*{#2}{#4}
}
}
}{
\IfValueTF{#3}{
\IfValueTF{#5}{
\rfst@newtheorem@original{#2}[#3]{#4}[#5]
}{
\rfst@newtheorem@original{#2}[#3]{#4}
}
}{
\IfValueTF{#5}{
\rfst@newtheorem@original{#2}{#4}[#5]
}{
\rfst@newtheorem@original{#2}{#4}
}
}
}
}
\NewExpandableDocumentCommand{\rfst@gobble@label}{o m}{}
\NewDocumentCommand{\rfst@faketheorem}{m m m m +m O{}}{
% 1=Label 2=Style 3=Type 4=TypeName 5=Body 6=Head
\begingroup
\let\label\rfst@gobble@label
% \let\index\@gobble \let\glossary\@gobble
% Not all of these may be desirable...
\ifhmode\unskip\unskip\par\fi
\normalfont
\trivlist
\let\thmheadnl\relax
\let\thm@swap\@gobble
\thm@notefont{\fontseries\mddefault\upshape}%
\thm@headpunct{.}% add period after heading
\thm@headsep 5\p@ plus\p@ minus\p@\relax
\thm@space@setup
\csname th@#2\endcsname
\@topsep \thm@preskip % used by thm head
\@topsepadd \thm@postskip % used by \@endparenv
\@begintheorem{#4}{\ref{#1}}[#6]
\marginnote{\textit{\footnotesize$\leadsto$\,p.\,\pageref*{#1}}}
\ignorespaces
#5
\@endtheorem
\endgroup
}
\newcommand{\refstate}[1]{%
\ifcsname rfst@storedthm@#1\endcsname
\@nameuse{rfst@storedthm@#1}
\else
\ifhmode\unskip\unskip\par\fi
\thm@space@setup
\vskip\thm@preskip
\noindent
\textbf{Restate}~\texttt{\detokenize{#1}}
\par
\vskip\thm@postskip
\fi
}
\NewExpandableDocumentCommand{\rfst@thm@detok}{o m m m}{
\detokenize{{#2}{#3}{#4}}
}
\NewDocumentEnvironment{store}{ m o +b } {%
\IfValueTF{#2}{\begin{#1}[#2]}{\begin{#1}} % Begin wrapped theorem
\newtoks\rfst@labelval % Capture the first label.
\let\rfst@oldlabel\label
\newcommand{\rfst@label}[1]{\rfst@labelval{##1}\let\label\rfst@oldlabel\label{##1}}
\let\label\rfst@label
#3 % Display the actual theorem contents
\begingroup
\let\@thm=\rfst@thm@detok
\protected@write\@auxout{}{%
\string\global\string\long\string\@namedef{rfst@storedthm@\the\rfst@labelval}{%
\string\rfst@faketheorem%
{\the\rfst@labelval}%
{\tl_use:c{rfst@style@#1}}{#1}{\tl_use:c{rfst@name@#1}}
{\detokenize{#3}}%
\IfValueT{#2}{[#2]}%
}
}
\endgroup
\end{#1} % End wrapped theorem
} {}
\endinput
%%
%% End of file `refstate.sty'.