0

TLDR

How to throw all dirty but necessary "lemmas/proofs" in the appendix, and restate them in the main text?


I had a few attempts, and it seemed that my requests are weird.. so I would explain a bit before I ask the question.

I'm writing a mathematical paper. I view writing math arguments as writing codes: statements are "functions" and proofs are the flesh. For completeness, I want to include as much proof as I want. However, since the structure of argument is not linear, doing so must by large decreases the readability. Therefore, I want to hide the dirty things in the appendix, and quote the def/thm/proof in my main text.

Ideally, a pseudo tex code should look as follows.

Section 1

#call{main-theorem}
  % nothing input here.
#endcall

.
.

Section 10
.
.

Appendix
#theorem[callable]{main-theorem}
2-1=1.
#end-theorem

To achieve this, @Bernard has pointed to thmtools for me in [1]. To achieve what I really want, I got an error, but since it's not the main topic there, I make a new question here.

Minimal example

Below is a (almost) working minimal example.

\documentclass{article}
\usepackage{thmtools, thm-restate}
\declaretheorem{theorem}
\begin{document}
%\firsteuclid*
%%% Uncommenting the above causes an error:
%%% > ! Undefined control sequence.
%%% > l.7 \firsteuclid
\begin{restatable}[Euclid]{theorem}{firsteuclid}
\label{thm:euclid}
$$1+1 = 2.$$
\end{restatable}
\firsteuclid* % This, however, works fine.
\end{document}

It compiles correctly. However, I hope that I can first call \firsteuclid* before it has been stated. An attempt fails. You can replicate that by uncommenting the commented line.

One work-around, of course, is to accept its limit, and declare statements anyway as in [2]. But I also hope that the dirty codes can all be grouped together in the source file. It will make my life much easier in the future, when I want to use them in my next paper.. again, the analogy holds: you write good codes, and use them again and again.

Question

How to throw all dirty but necessary "codes" in the appendix, and restate them in the main text?

Reference

3
  • I'm not sure if I understand: you want just the statement of some theorems/lemmas/whatnot in the main text and have the same statement with its proof in the appendix?
    – egreg
    Commented Nov 23, 2020 at 22:39
  • I want the statement and the proof in the appendix, and call them in the main text.
    – Student
    Commented Nov 23, 2020 at 22:55
  • Should the appendix contain just statements and proofs thereof? Would a separate file for these fit the bill?
    – egreg
    Commented Nov 23, 2020 at 23:10

1 Answer 1

3

Here's a proof of concept.

\documentclass{article}
\usepackage{amsthm}

\ExplSyntaxOn

\NewDocumentCommand{\theoremstatement}{m m}
 {% #1 = label, #2 = theorem type
  \use:e
   {
    \exp_not:N \begin{#2}
    \prop_item:Nn \g_student_theorems_statements_prop { #1 }
    \exp_not:N \end{#2}
   }
  \prop_gput:Nnx \g_student_theorems_numbers_prop { #1 } { \thethm }
 }

\NewDocumentEnvironment{delayedtheorem}{m m +b}
 % #1 = label, #2 = theorem type, #3 = theorem statement
 {
  \cs_set:Npx \thethm { \prop_item:Nn \g_student_theorems_numbers_prop { #1 } }
  \begin{#2}#3\end{#2}
  \iow_now:Nn \g_student_theorems_statements_iow
   {
    \studentpropgput { g_student_theorems_statements_prop } { #1 } { #3 }
   }
 }{}

\cs_new_eq:NN \studentpropgput \prop_gput:cnn

\iow_new:N \g_student_theorems_statements_iow
\prop_new:N \g_student_theorems_statements_prop
\prop_new:N \g_student_theorems_numbers_prop

\AtBeginDocument
 {
  \file_if_exist_input:n { \c_sys_jobname_str.thm }
  \iow_open:Nn \g_student_theorems_statements_iow { \c_sys_jobname_str.thm }
 }

\ExplSyntaxOff

\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}

\begin{document}

\section{First}

\begin{thm}
This is a normal theorem.
\end{thm}

\begin{proof}
Which has a proof.
\end{proof}

\theoremstatement{A}{thm}

\section{Second}

\theoremstatement{B}{lem}


\appendix

\section{Statements and proofs}

\begin{delayedtheorem}{A}{thm}
This is a theorem whose proof is in the appendix.
\end{delayedtheorem}

\begin{proof}
And its proof.
\end{proof}

\begin{delayedtheorem}{B}{lem}[With name]
A boring lemma.
\end{delayedtheorem}

\begin{proof}
Even more boring proof.
\end{proof}

\end{document}

enter image description here

thmtools

The above code doesn't work properly with thmtools, but it can be adjusted.

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\ExplSyntaxOn

\NewDocumentCommand{\theoremstatement}{m m}
 {% #1 = label, #2 = theorem type
  \use:e
   {
    \exp_not:N \begin{#2}
    \prop_item:Nn \g_student_theorems_statements_prop { #1 }
    \exp_not:N \end{#2}
   }
  \prop_gput:Nnx \g_student_theorems_numbers_prop { #1 } { \use:c {the#2} }
 }

\NewDocumentEnvironment{delayedtheorem}{m m +b}
 % #1 = label, #2 = theorem type, #3 = theorem statement
 {
  \cs_set:cpx {the#2} { \prop_item:Nn \g_student_theorems_numbers_prop { #1 } }
  \begin{#2}#3\end{#2}
  \iow_now:Nn \g_student_theorems_statements_iow
   {
    \studentpropgput { g_student_theorems_statements_prop } { #1 } { #3 }
   }
 }{}

\cs_new_eq:NN \studentpropgput \prop_gput:cnn

\iow_new:N \g_student_theorems_statements_iow
\prop_new:N \g_student_theorems_statements_prop
\prop_new:N \g_student_theorems_numbers_prop

\AtBeginDocument
 {
  \file_if_exist_input:n { \c_sys_jobname_str.thm }
  \iow_open:Nn \g_student_theorems_statements_iow { \c_sys_jobname_str.thm }
 }

\ExplSyntaxOff

\declaretheorem[within=section]{theorem}
\declaretheorem[sibling=theorem]{lemma}

\begin{document}

\section{First}

\begin{theorem}
This is a normal theorem.
\end{theorem}

\begin{proof}
Which has a proof.
\end{proof}

\theoremstatement{A}{theorem}

\section{Second}

\theoremstatement{B}{lemma}


\appendix

\section{Statements and proofs}

\begin{delayedtheorem}{A}{theorem}
This is a theorem whose proof is in the appendix.
\end{delayedtheorem}

\begin{proof}
And its proof.
\end{proof}

\begin{delayedtheorem}{B}{lemma}[With name]
A boring lemma.
\end{delayedtheorem}

\begin{proof}
Even more boring proof.
\end{proof}

\end{document}
7
  • Oh wow! Thank you for taking time writing this! I will test it tomorrow. (PS what kind of tex-fu is this? I have never seen it.. it seems deeper than the usual commands).
    – Student
    Commented Nov 24, 2020 at 1:27
  • Thanks for your beautiful answer! I am using the "thmtools" package via declaretheorem. It seems that the counter "\thethm" needs to be adjusted to the environment used, i.e. \thethm, \thelem, \thecor etc. I tried to replace it by \expandafter\csname let#2\csname and some other approaches but with no luck.
    – wueb
    Commented Dec 14, 2020 at 18:07
  • @wueb I start from the assumption that there is a single counter for theorems and friends. Separately numbering theorems, propositions, lemmas and so on is unfriendly to the reader who can't know whether Lemma 2 comes before or after Theorem 3.
    – egreg
    Commented Dec 14, 2020 at 18:09
  • @egreg I totally agree. I define the same counter to be used (starting from the theorem declaration) via \declaretheorem[sibling=theorem,style=italicshape]{lemma}; but the common counter \thetheorem does not work. If I split into single counters \thetheorem, \thelemma etc. the numbering fits in a minimal working example.
    – wueb
    Commented Dec 14, 2020 at 19:12
  • 1
    @wueb I added a version for thmtools. Unfortunately it doesn't work both ways.
    – egreg
    Commented Dec 14, 2020 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .