latex-packages-build/wip/mkessler-proof.sty
2022-01-08 22:43:15 +00:00

153 lines
5.9 KiB
TeX

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright © 2022 Maximilian Keßler
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the “Software”), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
%
% This package has been generated by PyTeX, available at
% https://github.com/kesslermaximilian/PyTeX
% and built from source file 'proof.pysty'.
% It is STRONGLY DISCOURAGED to edit this source file directly, since local
% changes will not be versioned by Git and overwritten by the next build. Always
% edit the source file and build the package again.
%
% Build details:
% PyTeX version: v1.0.0-18 (commit 126d420)
% Source code version: v2.4.0-beta-8 (commit c592a7f)
%
% This LaTeX package is free software and distributed under the MIT License. You
% may use it freely for your purposes. The latest version of the package can be
% obtained via GitHub under
% https://github.com/kesslermaximilian/LatexPackages
% For further information see the url above.
% Reportings of bugs, suggestions and improvements are welcome, see the README
% at the Git repository for further information.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mkessler-proof}[2022/01/08 - Automatic references to theorems in proofs. Claim counters within proofs]
\RequirePackage{xkeyval}
\RequirePackage{refcount}
\newif\ifmkessler@proof@english\mkessler@proof@englishtrue
\DeclareOptionX{german}{\mkessler@proof@englishfalse}
\DeclareOptionX{ngerman}{\mkessler@proof@englishfalse}
\DeclareOptionX{english}{\mkessler@proof@englishtrue}
\DeclareOptionX*{\PackageWarning{mkessler-proof}{Unknown '\CurrentOption'}}
\ProcessOptionsX*\relax
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{etoolbox}
\RequirePackage{xparse}
%%Give claim an own counter and let it reset at each proof
%See also at:
%https://tex.stackexchange.com/questions/283502/reset-counter-at-beginning-of-proof
\newtheorem{claim}{\ifmkessler@proof@english Claim\else Behauptung\fi}
\newtheorem*{claim*}{\ifmkessler@proof@english Claim\else Behauptung\fi}
\AtBeginDocument{\def\claimautorefname{\ifmkessler@proof@english Claim\else Behauptung\fi}}
\newif\ifmkessler@proof@hyperref\mkessler@proof@hyperreffalse
\AtBeginDocument{
\@ifpackageloaded{hyperref}{
\mkessler@proof@hyperreftrue
\let\mkessler@proof@autoref\autoref
}{
\mkessler@proof@hyperreftrue
\let\mkessler@proof@autoref\ref
}
}
\let\mkessler@proof@saved@proof\proof
\let\mkessler@proof@saved@endproof\endproof
\NewDocumentEnvironment{refproof}{s m o}
{
% Restore correct counter for claim
\ifcsdef{themkessler@proof@#2@save@claim}{
\setcounter{claim}{\value{mkessler@proof@#2@save@claim}}
\def\mkessler@proof@proofprefix{\ifmkessler@proof@english Continuation of proof\IfBooleanT{#1}{*}\space of\else Fortsetzung des Beweises\IfBooleanT{#1}{*}\space zu\fi}
}{
\newcounter{mkessler@proof@#2@save@claim}
\setcounter{claim}{0}
\def\mkessler@proof@proofprefix{\ifmkessler@proof@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
\let\mkessler@proof@theoldclaim\theclaim
\def\theclaim{\getrefnumber{#2}.\mkessler@proof@theoldclaim}
% Now, start the actual proof
\mkessler@proof@saved@proof[\mkessler@proof@proofprefix\space\mkessler@proof@autoref{#2}\IfValueT{#3}{\space(#3)}]
}
{
\mkessler@proof@saved@endproof % End proof
% Save current claim counter for later restoration
\setcounter{mkessler@proof@#2@save@claim}{\value{claim}}
}
% Proof (with asterisk)
\AtBeginDocument{
\RenewDocumentEnvironment{proof}{s o}
{
\IfNoValueTF{#2}{
\mkessler@proof@saved@proof[
\ifmkessler@proof@english
Proof\IfBooleanT{#1}{\emph{*}}
\else
Beweis\IfBooleanT{#1}{\emph{*}}
\fi
]
}{
\mkessler@proof@saved@proof[\ifmkessler@proof@english Proof\else Beweis\fi\IfBooleanT{#1}{\emph{*}}\space(#2)]
}
}
{
\mkessler@proof@saved@endproof
}
}
%%subproof environment - essentially copied proof environment from amsthm and modified its name + symbol
\DeclareRobustCommand{\blackqed}{%
\ifmmode \mathqed
\else
\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
\quad\hbox{$\blacksquare$}%
\fi
}
\newenvironment{subproof}[1][\ifmkessler@proof@english Subproof\else Unterbeweis\fi]{\par
\pushQED{\blackqed}%
\normalfont \topsep6\p@\@plus6\p@\relax
\trivlist
\item[\hskip\labelsep
\itshape
#1\@addpunct{.}]\ignorespaces
}{%
\popQED\endtrivlist\@endpefalse
}
%%%% This might be dropped, but for now is collected here
%%Solution (for exercises)
\newenvironment{solution}[1][]{\begin{proof}[\ifmkessler@proof@english{}Solution\else{}Lösung\fi{}#1]}{\end{proof}}