-
Notifications
You must be signed in to change notification settings - Fork 1
/
moveproofs.sty
166 lines (148 loc) · 6.31 KB
/
moveproofs.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
% moveproofs: a package for auto-moving proofs to the appendix of a document.
%
% (c) Daniel Haas, 2016
%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{moveproofs}[2016/02/22 LaTex package for auto-moving proofs to the appendix]
\RequirePackage{pgfkeys}
\RequirePackage{pgfopts}
\RequirePackage{xparse}
% Namespace our key-value store.
\pgfkeys{/moveproofs/.is family}
% Set up the 'location' option, which may be set to 'inline' (don't move proofs) or 'appendix' (move proofs to the appendix).
\newif\ifmoveproofstoappendix
\pgfkeys{moveproofs,
options/location/.is choice,
options/location/inline/.code={\moveproofstoappendixfalse},
options/location/appendix/.code={\moveproofstoappendixtrue},
}
% Set up the 'manual' option, which may be set to 'true' (the user must use \appendixproofsection and \appendixproof in
% order for proofs to appear in the appendix) or 'false' (default, proofs are automatically displayed in the appendix in a
% section called 'Proofs'.
\newif\ifmanualappendix
\pgfkeys{moveproofs, options/manual/.is if=manualappendix}
% Set up the 'appendixsectionname' option, which takes a string, and (if 'manual=false'), will be used instead of 'Proofs'
% as the name of the appendix section where proofs are displayed.
\newcommand{\MPAppendixSectionName}{Proofs}
\pgfkeys{moveproofs,
options/appendixsectionname/.code={\renewcommand{\MPAppendixSectionName}{#1}}
}
% Set up the 'prependtoappendix' option, which may be set to 'true' (proofs are added to the beginning of the appendix)
% or 'false' (default, proofs are added to the end of the appendix). Option is only used if location=appendix, manual=false,
% and the user has already created their own appendix section.
\newif\ifprependtoappendix
\pgfkeys{moveproofs, options/prependtoappendix/.is if=prependtoappendix}
% Process the passed package options
\ProcessPgfOptions{moveproofs/options}
% Define a simple proof environment if it doesn't exist.
\newcommand{\BlackBox}{\rule{1.5ex}{1.5ex}}
\newcommand*{\MPQED}{\hfill\BlackBox\\[0.1mm]}
\makeatletter
\def\provideenvironment{\@star@or@long\provide@environment}
\def\provide@environment#1{%
\@ifundefined{#1}%
{\def\reserved@a{\newenvironment{#1}}}%
{\def\reserved@a{\renewenvironment{dummy@environ}}}%
\reserved@a
}
\def\dummy@environ{}
\makeatother
\provideenvironment{proof}{ \par\noindent{\bfseries\upshape Proof\ }}{\MPQED}
% Low-level commands for manipulating the kv-store.
\newcommand{\MPProofToStore}{}
\DeclareDocumentCommand{\MPStoreProof}{s m +m m}{
% Pass the * argument through to \appendixproof
\IfBooleanTF{#1}{
\renewcommand{\MPProofToStore}[1]{\appendixproof*{##1}}
}{
\renewcommand{\MPProofToStore}[1]{\appendixproof{##1}}
}
\pgfkeys{moveproofs,
proofs/#2/content/.code={#3},
proofs/#2/title/.code={#4},
proofs/list/.append={\MPProofToStore{#2}}
}
}
\newcommand{\MPGetProof}[1]{\pgfkeys{moveproofs, proofs/#1/content}}
\newcommand{\MPGetTitle}[1]{\pgfkeys{moveproofs, proofs/#1/title}}
% The \makeproof command lets you define a proof in the document.
% Arguments are a label for the proof, and the proof body itself.
% If called with a star (e.g., \makeproof*{theorem_label}{theorem body}),
% the proof content will not be auto-wrapped in a proof environment, and you
% must manually insert your own with \begin{proof} and \end{proof}.
% Example usage: \makeproof{theorem_one}{$a = b$, so we're done.}.
\DeclareDocumentCommand{\makeproof}{s m +m m}{
\IfBooleanTF{#1}{
\MPStoreProof*{#2}{#3}{#4}%
}{
\MPStoreProof{#2}{#3}{#4}%
}
% Insert the proof directly into the document inline if required by package options.
\ifmoveproofstoappendix
\else
\IfBooleanTF{#1}{
\MPGetProof{#2}%
}{
\MPGetProof{#2}%
}
\fi
}
% The \appendixproof command lets you mark where a proof will be moved to.
% If location="appendix" was passed, it will create a subsection in the appendix with the proof in it.
% The argument is the theorem label you passed to \makeproof.
% If called with a star (e.g., \appendixproof*{theorem_label}),
% the behavior will match that of \makeproof*.
% Example usage: \appendixproof{theorem_one}
\DeclareDocumentCommand{\appendixproof}{s m}{
\ifmoveproofstoappendix
\subsection{\protect\MPGetTitle{#2}}\label{#2_proof}
\IfBooleanTF{#1}{
\MPGetProof{#2}%
}{
\MPGetProof{#2}%
}
\else
\fi
}
% The \appendixproofsection command lets you add a section to contain proofs in the appendix.
% The section will only appear if location="appendix".
\newcommand{\appendixproofsection}[1]{\ifmoveproofstoappendix\section{#1}\fi}
% The \appendixproofnotice command lets you define a notice that the proofs have been moved to the appendix
% The section will only appear if location="appendix". The optional argument is a replacement for the default language.
\newcommand{\appendixproofnotice}[1][All proofs will appear in the appendix.]{\ifmoveproofstoappendix#1\fi}
% Internal use only: track existence of appendix and auto-add proofs to the appendix.
\let\oldappendix\appendix% Store \appendix
\newif\ifnoappendix % True if the user hasn't created an appendix
\newif\ifproofsinserted % True if this package has auto-inserted proofs into the document.
\noappendixtrue
\newcommand{\appendixprelim}{\clearpage\onecolumn}
\newcommand{\MPAppendixProofs}{
\ifproofsinserted
\else
\ifmanualappendix
\else
\ifnoappendix
\oldappendix
\fi
\appendixprelim
\appendixproofsection{\MPAppendixSectionName}
\pgfkeys{moveproofs, proofs/list}
\proofsinsertedtrue
\fi
\fi
}
% Redefine the \appendix command to track whether the appendix exists and prepend content if necessary.
\renewcommand{\appendix}{% Update \appendix
\oldappendix% Default \appendix
\noappendixfalse% Mark appendix as created
% Insert proofs at the beginning of the appendix if so specified.
\ifprependtoappendix
\MPAppendixProofs
\fi
}
% Add all proofs to the end of the appendix if they weren't already prepended.
\AtEndDocument{\MPAppendixProofs}