blob: 5a898e054104595f368c7696ec2291b1daa2afa9 (
plain)
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
|
%%
%% This is file `reptheorem.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% reptheorem.dtx (with options: `package')
%%
%% Copyright (c) 2024- Jesse Straat
%%
%% This work 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
%% https://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Jesse Straat.
%%
%% This work consists of the main file reptheorem.dtx
%% and the derived files
%% reptheorem.sty, reptheorem.pdf, reptheorem.ins
%%
\ProvidesPackage{reptheorem}[2024-10-07 v1.3 Reptheorem package]
\def\reptheorem@theoremfile{\relax}
\NewDocumentCommand{\theoremfile}{ O{\jobname.thm} }{
\def\reptheorem@theoremfile{#1}
\newwrite\@thmlist
\immediate\openout\@thmlist=#1
}
\NewDocumentCommand{\loadtheorems}{ m }{
\IfFileExists{#1}{
\input{#1}
}{
\PackageWarning{reptheorem}{%
File #1 not found. I will not import any theorems.%
}
}
}
\NewDocumentEnvironment{makethm}{ m m o +b }
{%
\IfValueTF{#3}{% Check if theorem has optional arguments
\begin{#1}[#3]\label{#2}
}{
\begin{#1}\label{#2}
}
#4
\expandafter\gdef\csname thmtype@#2\endcsname{#1}%
\expandafter\long\expandafter\gdef\csname thm@#2\endcsname{#4}%
\IfValueT{#3}{% Only save theorem name if it exists
\expandafter\gdef\csname thmdesc@#2\endcsname{#3}%
}
\expandafter\long\expandafter\gdef\csname thmoutput@#2\endcsname{%
\string\expandafter\string\gdef\noexpand%
\csname thmtype@#2\string\endcsname{#1}%
^^J%
\string\expandafter\string\long\string\expandafter%
\string\gdef\noexpand\csname thm@#2\string\endcsname{#4}%
\IfValueT{#3}{
^^J%
\string\expandafter\string\gdef\noexpand%
\csname thmdesc@#2\string\endcsname{#3}%
}
}
\write\@auxout{\csname thmoutput@#2\endcsname}
\if\reptheorem@theoremfile\relax
\else
\write\@thmlist{\csname thmoutput@#2\endcsname}
\fi
\end{#1}
}{}
\newcounter{old@counter}
\NewDocumentCommand{\repthm}{ m +o }{
\begingroup
\ifcsname thmtype@#1\endcsname%
\expandafter\let\expandafter\@@thmtype\csname thmtype@#1\endcsname%
\else%
\def\@@thmtype{theorem}%
\fi%
\setcounter{old@counter}{\value{\@@thmtype}}
\setcounter{\@@thmtype}{-900}
\expandafter\def\csname the\@@thmtype\endcsname{\ref{#1}}
\let\@@theoremnotdefined\relax
\ifcsname thm@#1\endcsname% Check if theorem is even defined
\expandafter\let\expandafter\@@thm\csname thm@#1\endcsname
\ifcsname thmdesc@#1\endcsname % Check if theorem has name
\begin{\@@thmtype}[\csname thmdesc@#1\endcsname]
\@@thm
\end{\@@thmtype}
\else % No optionals
\begin{\@@thmtype}
\@@thm
\end{\@@thmtype}
\fi
\else
\IfValueTF{#2}{
\begin{\@@thmtype}
#2
\end{\@@thmtype}
}{% No theorem or alt text provided: throw warning
\begin{\@@thmtype}
\end{\@@thmtype}
\PackageWarning{reptheorem}{%
Theorem #1 not defined; rebuild your project.
If the issue persists, create the theorem using
\begin{makethm} or consider adding alt text to \repthm
using the optional parameter%
}
}
\fi
\setcounter{\@@thmtype}{\value{old@counter}}
\endgroup
}
\endinput
%%
%% End of file `reptheorem.sty'.
|