Powtórz instrukcje przed deklaracją
TLDR
Jak wrzucić wszystkie brudne, ale niezbędne „lematy / dowody” w załączniku i powtórzyć je w tekście głównym?
Miałem kilka prób i wydawało mi się, że moje prośby są dziwne ... więc trochę wyjaśnię, zanim zadam pytanie.
Piszę artykuł matematyczny. Postrzegam pisanie argumentów matematycznych jak pisanie kodów: stwierdzenia to „funkcje”, a dowody są ciałem. Aby uzyskać kompletność, chcę dołączyć tyle dowodów, ile chcę. Ponieważ jednak struktura argumentacji nie jest liniowa, musi to w dużej mierze zmniejszyć czytelność. Dlatego chcę ukryć brudne rzeczy w załączniku i zacytować def / thm / proof w moim głównym tekście.
Idealnie, kod pseudotekstowy powinien wyglądać następująco.
Section 1
#call{main-theorem}
% nothing input here.
#endcall
.
.
Section 10
.
.
Appendix
#theorem[callable]{main-theorem}
2-1=1.
#end-theorem
Aby to osiągnąć, @Bernard wskazał thmtools
na mnie w [1]. Aby osiągnąć to, czego naprawdę chcę, wyskoczył mi błąd, ale ponieważ nie jest to główny temat, zadaję tutaj nowe pytanie.
Minimalny przykład
Poniżej znajduje się (prawie) działający minimalny przykład.
\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}
Kompiluje się poprawnie. Mam jednak nadzieję , że najpierw zadzwonię, \firsteuclid*
zanim zostanie to stwierdzone. Próba kończy się niepowodzeniem. Możesz to powtórzyć, usuwając komentarz z komentowanej linii.
Jedynym obejściem jest oczywiście zaakceptowanie jego limitu i zadeklarowanie instrukcji tak jak w [2]. Ale mam też nadzieję, że wszystkie brudne kody można zgrupować w pliku źródłowym. Znacznie ułatwi mi to życie w przyszłości, kiedy będę chciał ich użyć w następnym artykule… znowu analogia jest taka: piszesz dobre kody i korzystasz z nich w kółko.
Pytanie
Jak wrzucić wszystkie brudne, ale potrzebne „kody” w załączniku i powtórzyć je w tekście głównym?
Odniesienie
[3] Również powiązane ... moja kolejna próba Opóźnienie prezentacji sekcji
Odpowiedzi
Oto dowód słuszności koncepcji.
\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}
