\documentclass{article}
\usepackage{amssymb, amsthm, amsmath}
\usepackage{xparse}
\usepackage{verbatim}
% Load the package (put the proof-at-the-end.sty file in the working directory)
% with default options and shortcuts for thmE/... WARNING: this requires a version above 2022/01/28.
\usepackage[createShortEnv]{proof-at-the-end}
% If you use cref, use instead:
% \usepackage[createShortEnv,commandRef=Cref]{proof-at-the-end}
% You can change the default options in the 'conf' option:
%\usepackage[createShortEnv, conf={text link section}]{proof-at-the-end}
%\usepackage[createShortEnv, conf={normal, one big link}]{proof-at-the-end}
%\usepackage[createShortEnv, conf={normal, one big link=Goto proof}]{proof-at-the-end}
%\usepackage[createShortEnv, conf={one big link translated=Aller à la preuve page}]{proof-at-the-end}
%%% If you want to use options with macros, you cannot
% use directly the package options, so just modify
% the global custom defaults like that:
% \pgfkeys{/prAtEnd/global custom defaults/.style={
% text link={\hyperref[proof:prAtEnd\pratendcountercurrent]{See proof on page~\pageref*{proof:prAtEnd\pratendcountercurrent}}}
% }
% }
%%% You can also easily modify the global/locals defaults in other parts of the code using:
% \pgfkeys{/prAtEnd/local custom defaults/.style={
% category=greattheorem
% }
% }
%%% Or create new styles to apply:
% \pgfkeys{/prAtEnd/great category/.style={
% category=greattheorem
% }
% }
%% Define your theorem/lemma/... environments the way you want:
% Theorems
\newtheorem{thm}{Theorem}[section]
\newtheorem*{thm*}{Theorem}
\providecommand*\thmautorefname{Theorem}
% Lemmata
\newtheorem{lemma}[thm]{Lemma}
\newtheorem*{lemma*}{Lemma}
\providecommand*\lemmaautorefname{Lemma}
%% If you want you can define shortcuts to create new theorem.
%% Since 2022/01/28, the option createShortEnv automatically defines
%% shortcuts for thmE, theoremE, lemmaE...
%% You can define new shortcuts using something like:
%% \newEndThm[normal]{thmE}{thm}
%% This is itself a shortcut for the rather length old way to define new theorem shorcuts, namely:
% And to define new shortcuts, in order to avoid typing:
% \NewDocumentEnvironment{thmE}{O{}O{}+b}{%
% \begin{theoremEnd}[normal,#2]{thm}[#1]%
% #3%
% \end{theoremEnd}%
% }{}
\usepackage{hyperref}
\begin{document}
\section{Demo of proof-at-the-end}
NB: This file is just a demo of proof-at-the-end. You can find the documentation, sources, and example of proof-at-the-end at \url{https://github.com/leo-colisson/proof-at-the-end}. Note that this file is getting a bit big but it should contain more or less everything that is possible in this lib as it's also used to ``test'' the library.
% And use \theoremProofEnd[]{theorem environment name}[Title]{Theorem}{Optional proof}
\begin{theoremEnd}{thm}[Yes I can have a title]
\label{thm:ilikelabels}
Simplicity is luxury, I am a default theorem.
\end{theoremEnd}
\begin{proofEnd}
Let's be simple.
\end{proofEnd}
And I can refer to my theorems using classic labels, like in \autoref{thm:ilikelabels}.
\begin{theoremEnd}[text link section]{thm}[Changing link]
It is possible to change the link.
\end{theoremEnd}
\begin{proofEnd}
Here I'm using ``text link section''.
\end{proofEnd}
\begin{theoremEnd}[category=greattheorem, end]{thm}[Different categories]
You can also create several categories, and put the proofs in different sections.
\[2\Delta = \Delta + \Delta\]
\end{theoremEnd}
\begin{proofEnd}
See, I am in another section! And I refer to \autoref{thm:ilikelabels} even in the proof.
\end{proofEnd}
\begin{theoremEnd}[restate]{thm}[I am restatable]
I am a restatable theorem, go in Appendix you will see ;-)
\end{theoremEnd}
\begin{proofEnd}
I am a proof of a restatable theorem.
\end{proofEnd}
\begin{theoremEnd}[normal]{thm}
You can easily turn it back into a normal theorem!
\end{theoremEnd}
\begin{proofEnd}
And keep the proof with you!
\end{proofEnd}
\begin{theoremEnd}[normal,restate]{thm}[I am restatable but normal]
See, if you are both normal and restatable, then no need to restate the theorem at the end!
\end{theoremEnd}
\begin{proofEnd}
I am a proof of a restatable but normal theorem.
\end{proofEnd}
You can also put comments that appear only in the appendix.
\textEnd{See, I am a simple comments with math $\delta = b^2-ac$ and references \autoref{thm:mytheoremattheend}.}
\begin{textAtEnd}
You can also use the environment syntax.
\end{textAtEnd}
\textEnd[both]{Or that appears in both and with references \autoref{thm:mytheoremattheend}!}
\begin{theoremEnd}[proof here]{thm}
And you can duplicate the proof, here AND in appendix ;)
\end{theoremEnd}
\begin{proofEnd}
I am a proof that is everywhere, practical if you want to use synctex while you write the proof ;)
\end{proofEnd}
\begin{theoremEnd}{lemma}
You can mix it with lemmas... Or any other theorem-like environment easily!
\end{theoremEnd}
\begin{proofEnd}
See, I'm the proof of a lemma!
\end{proofEnd}
And also you can put both the theorem and the proof at the end, like for \autoref{thm:mytheoremattheend}!
\begin{theoremEnd}[all end]{thm}
\label{thm:mytheoremattheend}
$\delta = b^2-4ac$
You can also put theorems only at the end.
\end{theoremEnd}
\begin{proofEnd}
See, I'm the proof of a lemma that is only at the end!
\end{proofEnd}
You can also remove the link to the theorem:
\begin{theoremEnd}[no link to theorem, restate]{thm}
I don't like links in proofs.
\end{theoremEnd}
\begin{proofEnd}
Yes, I like being lost, but not too lost, so I prefer to restate as well!
\end{proofEnd}
Or keep the link, but remove the reference (practical for stared versions):
\begin{theoremEnd}[stared]{thm*}
I don't like numbers.
\end{theoremEnd}
\begin{proofEnd}
Yes, I hate numbers, but I like links.
\end{proofEnd}
\pgfkeys{/prAtEnd/french/.style={
one big link translated={Voir preuve page},
text proof translated={Preuve du}
}
}
\begin{theoremEnd}[french]{thm}%% See how "french" is defined just above
Change the text/languages of the link: Il est même possible de changer la langue du texte du lien!
\end{theoremEnd}
\begin{proofEnd}
Si c'est pas beau ;)
\end{proofEnd}
And of course it is easy to define custom shortcuts, using in prelude:
\begin{verbatim}
\NewDocumentEnvironment{frenchthm}{O{}+b}{%
\begin{theoremEnd}[french]{thm}[#1]%
#2%
\end{theoremEnd}%
}{}
\end{verbatim}
\newsavebox{\myEndBox}
\begin{lrbox}{\myEndBox}
\begin{minipage}{1.0\linewidth}
\begin{verbatim}
\newEndThm[normal]{thmE}{thm}
\newEndProof{proofE}
\end{verbatim}
\end{minipage}
\end{lrbox}
\newsavebox{\myEndBoxB}
\begin{lrbox}{\myEndBoxB}
\begin{minipage}{1.0\linewidth}
\begin{verbatim}
\begin{thmE}[Title][optional options]
Theorem
\end{thmE}
\begin{proofE}
Your proof
\end{proofE}
\end{verbatim}
\end{minipage}
\end{lrbox}
\begin{thmE}[My own environment][normal]
You can then create a wrapper to avoid typing the full theoremEnd environment, and to add custom options by using:
\begin{center}
\usebox{\myEndBox}
\end{center}
\noindent (see that we need to use \texttt{\textbackslash textt} or \texttt{lrbox} to typeset verbatim inside theorem)
Then, you can simply use:
\end{thmE}
\begin{proofEnd}
That's quicker :D
\end{proofEnd}
\begin{thmE}[My own environment][end]
You can use options also with your custom environments.
\end{thmE}
\begin{proofEnd}
That's quicker with the proof at the end :D
\end{proofEnd}
\begin{thmE}[][end]
And you can remove the title and have options.
\end{thmE}
\begin{proofE}
Just leave empty title.
\end{proofE}
\begin{thmE}[My second own environment][all end]
My normal theorem is moved at the end!
\end{thmE}
\begin{proofE}
Custom environments are practical no ;)
\end{proofE}
\begin{theoremEnd}[]{thm}[Yes I can have no proof]
Proof is useless. You can do do it. And see, I can include other environments inside me ;)\\
\begin{tabular}{ c c }
A & B \\
C & D \\
\end{tabular}
\end{theoremEnd}
\begin{theoremEnd}[restate command=mymanualrestate]{thm}[Manual restate]
A theorem can be manually restated
\end{theoremEnd}
\begin{proofEnd}
Use restate command for that! (see \autoref{sec:manualrestate} for an example)
\end{proofEnd}
\begin{theoremEnd}[see full proof]{thm}
I can also write a sketch of proof, and put the full proof in appendix.
\end{theoremEnd}
\begin{proof}
Hint: look at the alias options.
\end{proof}
\begin{proofEnd}
You just use ``see full proof'' as an option
\end{proofEnd}
It should also deal with protected commands: $\mathtt{mathtt}$:
\begin{theoremEnd}[end]{thm}[Title $\Delta$ et $\mathtt{Gad}$]
You can use commands that should be protected $\mathtt{See}$!
\end{theoremEnd}
\begin{theoremEnd}[end]{thm}[Deal with paragraphs]
You can have a theorem
with several paragraphs.
\end{theoremEnd}
\begin{proofEnd}
And I also like to have big proofs.
With several paragraphs.
\end{proofEnd}
\section{Section with restate before theorem}\label{sec:restatebefore}
\begin{theoremEndRestateBefore}{thm}[Title]{laterrestatable}
\label{thm:laterrestatable}
This theorem has been introduced in \autoref{sec:restatebefore} before the real definition, but the real definition is in \autoref{sec:restateafter}, more precisely here: \autoref{thm:laterrestatable}.
\end{theoremEndRestateBefore}
\begin{theoremEnd}{thm}
And this is a normal theorem
\end{theoremEnd}
\begin{proofEnd}
With a normal proof
\end{proofEnd}
\section{Section with late theorems}\label{sec:restateafter}
\begin{theoremEnd}[restated before]{thm}
laterrestatable
\end{theoremEnd}
\begin{proofEnd}
To state a theorem before the initial definition, use theoremEndRestateBefore environment where you first want to state the theorem, with a unique name in the second mandatory argument, and when you want to insert the theorem for the second time, use the usual theoremProofEnd command with the same unique name as before in place of the theorem definition and the ``restated before'' option.
\end{proofEnd}
\pratendEnableDebugSynctex{}
\begin{thmE}[My own environment][end]
This proof
should go
in appendix.
But to make synctex work
we can force the environments
to behave like normal theorems or proofs
using \texttt{pratendEnableDebugSynctex} and \texttt{pratendDisableDebugSynctex} around the theorem.
You can try now (note that restate is not compatible with this mode as the restate library is not working with synctex due to a quite \href{https://tex.stackexchange.com/questions/643294/synctex-make-it-work-with-environment-accessing-its-content-e-g-environ-or-xp}{fundamental limitation of LaTeX}).
\end{thmE}
\begin{proofED}
See
how this
long proof works
with synctex now. And solve \href{https://github.com/leo-colisson/proof-at-the-end/issues/10}{Issue 10}.
\end{proofED}
\pratendDisableDebugSynctex{}
You can also use shortcuts like:
\begin{thmED}[My own environment][end]
Here
Is
An
example to test synctex.
\end{thmED}
\begin{proofEndDebug}
See
how this
long proof works
with synctex now.
\end{proofEndDebug}
\section{Section with standard proofs}
% \verbatiminput{defaultcategory}
\printProofs
\section{Section with important proofs only}
\printProofs[greattheorem]
\section{Section with manual restate}\label{sec:manualrestate}
I like to manually restate theorems:
\mymanualrestate*
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: