rework proof package: refproof and proof environments functional

This commit is contained in:
Maximilian Keßler 2022-01-08 23:42:40 +01:00
parent 14c4939841
commit c592a7f8ac
2 changed files with 55 additions and 30 deletions

View file

@ -1,6 +1,7 @@
__HEADER__(Automatic references to theorems in proofs. Claim counters within proofs) __HEADER__(Automatic references to theorems in proofs. Claim counters within proofs)
\RequirePackage{xkeyval} \RequirePackage{xkeyval}
\RequirePackage{refcount}
__LANGUAGE_OPTIONS_X__ __LANGUAGE_OPTIONS_X__
@ -22,52 +23,59 @@ __NEW_IF__(hyperref,false)
\AtBeginDocument{ \AtBeginDocument{
\@ifpackageloaded{hyperref}{ \@ifpackageloaded{hyperref}{
__SET_IF__(hyperref,true) __SET_IF__(hyperref,true)
\def\grab#1{\expandafter\@firstoffive#1}
\def__PACKAGE_MACRO__(blankref)#1{\expandafter\grab\csname r@#1\endcsname}
\let__PACKAGE_MACRO__(autoref)\autoref \let__PACKAGE_MACRO__(autoref)\autoref
}{ }{
__SET_IF__(hyperref,true) __SET_IF__(hyperref,true)
\let__PACKAGE_MACRO__(blankref)\ref
\let__PACKAGE_MACRO__(autoref)\ref \let__PACKAGE_MACRO__(autoref)\ref
} }
} }
\NewDocumentEnvironment{rproof}{m O{}}{\def__PACKAGE_MACRO__(aster){\relax}\begin{__PACKAGE_PREFIX__rproof@impl}{#1}[#2]}{\end{__PACKAGE_PREFIX__rproof@impl}} \let__PACKAGE_MACRO__(saved@proof)\proof
\NewDocumentEnvironment{rproof*}{m O{}}{\def__PACKAGE_MACRO__(aster){*}\begin{__PACKAGE_PREFIX__rproof@impl}{#1}[#2]}{\end{__PACKAGE_PREFIX__rproof@impl}} \let__PACKAGE_MACRO__(saved@endproof)\endproof
\NewDocumentEnvironment{__PACKAGE_PREFIX__rproof@impl}{m O{}} \NewDocumentEnvironment{refproof}{s m o}
{ {
% Restore correct counter for claim % Restore correct counter for claim
\ifcsdef{the__PACKAGE_PREFIX__#1@save@claim}{ \ifcsdef{the__PACKAGE_PREFIX__#2@save@claim}{
\setcounter{claim}{\value{__PACKAGE_PREFIX__#1@save@claim}} \setcounter{claim}{\value{__PACKAGE_PREFIX__#2@save@claim}}
\def__PACKAGE_MACRO__(proofprefix){__IF__(english) Continuation of proof__PACKAGE_MACRO__(aster)\space of\else Fortsetzung des Beweises__PACKAGE_MACRO__(aster)\space zu\fi} \def__PACKAGE_MACRO__(proofprefix){__IF__(english) Continuation of proof\IfBooleanT{#1}{*}\space of\else Fortsetzung des Beweises\IfBooleanT{#1}{*}\space zu\fi}
\edef\haha{\value{__PACKAGE_PREFIX__#1@part}}
}{ }{
\newcounter{__PACKAGE_PREFIX__#1@save@claim} \newcounter{__PACKAGE_PREFIX__#2@save@claim}
\setcounter{claim}{0} \setcounter{claim}{0}
\def__PACKAGE_MACRO__(proofprefix){__IF__(english) Proof__PACKAGE_MACRO__(aster)\space of\else Beweis__PACKAGE_MACRO__(aster)\space von\fi} \def__PACKAGE_MACRO__(proofprefix){__IF__(english) Proof\ifBooleanT{#1}{*}\space of\else Beweis\IfBooleanT{#1}{*}\space von\fi}
} }
% Set up counter number printing as subindexed by numbering of the reference % Set up counter number printing as subindexed by numbering of the reference
\let__PACKAGE_MACRO__(theoldclaim)\theclaim \let__PACKAGE_MACRO__(theoldclaim)\theclaim
\def\theclaim{__PACKAGE_MACRO__(blankref){#1}.__PACKAGE_MACRO__(theoldclaim)} \def\theclaim{\getrefnumber{#2}.__PACKAGE_MACRO__(theoldclaim)}
% Now, start the actual proof % Now, start the actual proof
\begin{proof}[__PACKAGE_MACRO__(proofprefix)\space__PACKAGE_MACRO__(autoref){#1}\if\relax\detokenize{#2}\relax\else\space(#2)\fi] __PACKAGE_MACRO__(saved@proof)[__PACKAGE_MACRO__(proofprefix)\space__PACKAGE_MACRO__(autoref){#2}\IfValueT{#3}{\space(#3)}]
} }
{ {
\end{proof} % End proof __PACKAGE_MACRO__(saved@endproof) % End proof
% Save current claim counter for later restoration % Save current claim counter for later restoration
\setcounter{__PACKAGE_PREFIX__#1@save@claim}{\value{claim}} \setcounter{__PACKAGE_PREFIX__#2@save@claim}{\value{claim}}
} }
% Proof (with asterisk) % Proof (with asterisk)
\NewDocumentEnvironment{proof*}{O{}} \AtBeginDocument{
\RenewDocumentEnvironment{proof}{s o}
{ {
\if\relax\detokenize{#1}\relax\begin{proof}[__IF__(english) Proof\emph{*}\else Beweis\emph{*}\fi]\else\begin{proof}[#1\emph{*}]\fi \IfNoValueTF{#2}{
__PACKAGE_MACRO__(saved@proof)[
__IF__(english)
Proof\IfBooleanT{#1}{\emph{*}}
\else
Beweis\IfBooleanT{#1}{\emph{*}}
\fi
]
}{
__PACKAGE_MACRO__(saved@proof)[__IF__(english) Proof\else Beweis\fi\IfBooleanT{#1}{\emph{*}}\space(#2)]
}
} }
{ {
\end{proof} __PACKAGE_MACRO__(saved@endproof)
}
} }
%%subproof environment - essentially copied proof environment from amsthm and modified its name + symbol %%subproof environment - essentially copied proof environment from amsthm and modified its name + symbol
\DeclareRobustCommand{\blackqed}{% \DeclareRobustCommand{\blackqed}{%

View file

@ -12,18 +12,18 @@
Man sollte nach Würzburg fahren. Man sollte nach Würzburg fahren.
\end{theorem} \end{theorem}
\begin{rproof}{thm:krass} \begin{refproof}*{thm:krass}[hi]
\begin{claim}\label{cl:qed} \begin{claim}\label{cl:qed}
Der QED ist toll. Der QED ist toll.
\end{claim} \end{claim}
Um \autoref{cl:qed} zu beweisen, brauchen wir zunächst ein Lemma. Um \autoref{cl:qed} zu beweisen, brauchen wir zunächst ein Lemma.
\end{rproof} \end{refproof}
\begin{lemma}\label{lm:krass} \begin{lemma}\label{lm:krass}
Mathevereine sind krass. Mathevereine sind krass.
\end{lemma} \end{lemma}
\begin{rproof}{lm:krass} \begin{refproof}{lm:krass}[quasi ein Fakt]
\begin{claim} \begin{claim}
Mathe ist cool. Mathe ist cool.
\end{claim} \end{claim}
@ -31,11 +31,11 @@
trivial. trivial.
\end{subproof} \end{subproof}
Damit folgt nun das Lemma. Damit folgt nun das Lemma.
\end{rproof} \end{refproof}
Nun kommen wir wieder zurück zum eigentlichen Beweis: Nun kommen wir wieder zurück zum eigentlichen Beweis:
\begin{rproof}{thm:krass} \begin{refproof}{thm:krass}[hi]
\begin{claim}\label{cl:würzburg} \begin{claim}\label{cl:würzburg}
Der QED macht ein Seminar in Würzburg Der QED macht ein Seminar in Würzburg
\end{claim} \end{claim}
@ -43,6 +43,23 @@ Nun kommen wir wieder zurück zum eigentlichen Beweis:
Zu prüfen in der DB. Fakt! Zu prüfen in der DB. Fakt!
\end{subproof} \end{subproof}
Aus \autoref{cl:qed} und \autoref{cl:würzburg} folgt nun die Aussage. Aus \autoref{cl:qed} und \autoref{cl:würzburg} folgt nun die Aussage.
\end{rproof} \end{refproof}
test
a
\begin{proof}
first
\end{proof}
a
\begin{proof}[anm]
second
\end{proof}
a
\begin{proof}*
third
\end{proof}
a
\begin{proof}*[anm]
fourth
\end{proof}
\end{document} \end{document}