General ⇒ Add appendix of Theroems
Add appendix of Theroems
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Add appendix of Theroems
Code: Select all
\documentclass[a4paper]{book}
\usepackage{amsthm}
\usepackage{tocloft}
\usepackage{lipsum}
\newcommand{\listofresultsname}{List of Results}
\newlistof[chapter]{results}{res}{\listofresultsname}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[theorem]{Corollary}
\newenvironment{mytheorem}%
{\begin{theorem}%
\addcontentsline{res}{results}{Theorem \protect\numberline{\thetheorem}}}%
{\end{theorem}}
\newenvironment{mycorollary}%
{\begin{corollary}%
\addcontentsline{res}{results}{Corollary \protect\numberline{\thetheorem}}}%
{\end{corollary}}
\begin{document}
\listofresults
\chapter{First chapter}
\begin{mytheorem}
\lipsum[1]
\end{mytheorem}
\begin{mytheorem}
\lipsum[2]
\end{mytheorem}
\begin{mycorollary}
\lipsum[3]
\end{mycorollary}
\begin{mytheorem}
\lipsum[4]
\end{mytheorem}
\chapter{Second chapter}
\begin{mytheorem}
\lipsum[1]
\end{mytheorem}
\begin{mytheorem}
\lipsum[2]
\end{mytheorem}
\begin{mycorollary}
\lipsum[3]
\end{mycorollary}
\begin{mytheorem}
\lipsum[4]
\end{mytheorem}
\end{document}
Add appendix of Theroems
Code: Select all
% LaTeX Book Template - using defaults
\documentclass[openright]{book}
\usepackage{latexsym}
\usepackage{enumerate}
\usepackage{amsmath,amssymb}
\usepackage[amsmath,amsthm]{ntheorem}
\usepackage{graphics}
\usepackage{makeidx}
\theoremstyle{remark} \newtheorem{ex}{\textsuperscript{ex}}
\theoremstyle{remark} \newtheorem{note}{\textsuperscript{note}}
\newtheorem{thm}{Theorem}
\newtheorem{lem}{Lemma}
\newtheorem{col}{Corollary}
\theoremstyle{definition}\newtheorem{defn}{Definition}[chapter]
\renewcommand{\contentsname}{Table of Contents}
\makeindex
Code: Select all
\begin{thm} \end{thm}
Code: Select all
\begin{defn} \end{defn}
Add appendix of Theroems
Code: Select all
\documentclass[a4paper]{report}
\usepackage{amsthm,amsfonts}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[chapter]
% --------------------------------------------
% --------------------------------------------
% Select the appropriate switch depending on your operating system
\newif\ifOSisUnix
\OSisUnixtrue % Unix, Linux, Mac OS X...
% \OSisUnixfalse % Windows
% Load fancyvrb
\usepackage{fancyvrb}
% Name of the scratch file: \ScratchFile is <jobname>.tmp
\newcommand{\ScratchFile}{\jobname.tmp}
% Command \SetTempFile to set names of auxiliary files where to store code.
% \SetTempFile{foo} defines \fooTempFile as <jobname>-foo.tmp and writes in this file
% the line \let\label\@gobble (this avoids warnings about multiply defined labels).
% Any existing file \fooTempFile is overwritten.
\newwrite\outputstream
\makeatletter
\newcommand{\SetTempFile}[1]{%
\@namedef{#1TempFile}{\jobname-#1.tmp}%
\immediate\openout\outputstream=\@nameuse{#1TempFile}%
\immediate\write\outputstream{\string\makeatletter}%
\immediate\write\outputstream{\string\let\string\label\string\@gobble}%
\immediate\write\outputstream{\string\makeatother}%
\immediate\closeout\outputstream}
\makeatother
% Command \AppendScratchFile.
% \AppendScratchFile{foo} appends the contents of \ScratchFile to those of
% the auxiliary file \fooTempFile
\makeatletter
\newcommand{\AppendScratchFile}[1]{%
\ifOSisUnix%
\immediate\write18{cat \ScratchFile >> \@nameuse{#1TempFile}}%
\else%
\immediate\write18{type \ScratchFile >> \@nameuse{#1TempFile}}%
\fi}
\makeatother
% Environment StoreCode. Usage:
% \begin{StoreCode}{foo}
% code
% \end{StoreCode}
% It typesets all the code that lies inside and saves it to the auxiliary file \fooTempFile.
% The definition is a bit tricky. It is not done through \newenvironment
\makeatletter
\newcommand{\StoreCode}[1]%
{\gdef\TempFileSuffix{#1}%
\VerbatimEnvironment
\begin{VerbatimOut}{\ScratchFile}}
\def\endStoreCode{%
\end{VerbatimOut}
\input{\ScratchFile}%
\AppendScratchFile{\TempFileSuffix}}
\makeatother
% Command \StoreCounterValue.
% \StoreCounterValue{count}{foo} writes in the file \fooTempFile the line
% \setcounter{count}{counter_value}. It is useful to control numbering the second
% time the code is processed.
\newcommand{\StoreCounterValue}[2]{%
\immediate\openout\outputstream=\ScratchFile%
\immediate\write\outputstream{\string\setcounter{#1}{\arabic{#1}}}%
\immediate\closeout\outputstream%
\AppendScratchFile{#2}}
% Command \InputTempFile.
% \InputTempFile{foo} inputs the file \fooTempFile
\makeatletter
\newcommand{\InputTempFile}[1]{\input{\@nameuse{#1TempFile}}}
\makeatother
% --------------------------------------------
% --------------------------------------------
% Auxiliary macro for writing maths
\newcommand{\Rset}{\mathbb{R}}
% We set the auxiliary files for storing code: thm for theorems and def for definitions.
\SetTempFile{thm}
\SetTempFile{def}
\begin{document}
\chapter{First chapter}
\StoreCounterValue{chapter}{thm}
\StoreCounterValue{theorem}{thm}
\StoreCounterValue{chapter}{def}
\begin{StoreCode}{def}
\begin{definition}\label{def:1}
A function $f:\Rset\to\Rset$ is \emph{continuous} in a point
$x_0$ if \[\lim_{x\to x_0}f(x)=f(x_0).\]
\end{definition}
\end{StoreCode}
\begin{StoreCode}{def}
\begin{definition}\label{def:2}
A funci\'on $f:\Rset\to\Rset$ is \emph{derivable} in
a point $x_0$ if \[\lim_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}\]
exists and is finite. In such a case, this limit is called the
\emph{derivative} of $f$ in $x_0$ and is denoted by $f'(x_0)$.
\end{definition}
\end{StoreCode}
The following result states the fundamental relation existing between the notions introduced in
Definitions \ref{def:1} and \ref{def:2}.
\begin{StoreCode}{thm}
\begin{theorem}
If $f:\Rset\to\Rset$ is derivable in $x_0$, then $f$ is continuous in $x_0$.
\end{theorem}
\end{StoreCode}
\chapter{Second chapter}
\StoreCounterValue{chapter}{thm}
\StoreCounterValue{theorem}{thm}
\begin{StoreCode}{thm}
\begin{theorem}[Rolle's Theorem]
Let $f:[a,b]\to\Rset$ be a function continuous on $[a,b]$, derivable on
$(a,b)$, and such that $f(a)=f(b)$. Then, there exists $c\in(a,b)$ such that
$f'(c)=0$.
\end{theorem}
\end{StoreCode}
\begin{StoreCode}{thm}
\begin{theorem}[Mean Value Theorem]
Let $f:[a,b]\to\Rset$ be a function continuous on $[a,b]$ and derivable on
$(a,b)$. Then, there exists $c\in(a,b)$ such that $f(b)-f(a)=f'(c)(b-a)$.
\end{theorem}
\end{StoreCode}
\begin{corollary}
Let $f:[a,b]\to\Rset$ be a function continuous on $[a,b]$ and derivable on
$(a,b)$. If, for all $x\in(a,b)$, $f'(x)\geq0$, then $f$ is increasing in $[a,b]$.
\end{corollary}
\StoreCounterValue{theorem}{thm}
\begin{StoreCode}{thm}
\begin{theorem}[Cauchy's Mean Value Theorem]
Let $f, g:[a,b]\to\Rset$ be two functions continuous on $[a,b]$ and derivable on
$(a,b)$. Then, there exists $c\in(a,b)$ such that $g'(b)(f(b)-f(a))=f'(c)(g(b)-g(a))$.
\end{theorem}
\end{StoreCode}
\chapter*{Main definitions}
\InputTempFile{def}
\chapter*{Main results}
\InputTempFile{thm}
\end{document}
I've tested it on Mac OS X (Tex Live 2008) and Windows (MikTeX 2.7) and works perfectly in both cases. I attach the corresponding pdf file. Select the correct value for the switch \ifOSisUnix and be sure that the \write18 feature is enabled (that's the case, by default, on a Mac). A forum search of "write18" will bring you more information on that feature.
- Attachments
-
- pru.pdf
- (53.06 KiB) Downloaded 213 times
Add appendix of Theroems
Code: Select all
\appendix
\chapter{Definitions}
\InputTempFile{def}
\chapter{Theorems}
\InputTempFile{thm}
\chapter{Important Graphs}
Appendix A: Definitions
Appendix B: Theorems
Appendix B: Important Graphs
for some reason it is not counting Theorems as an appendix and lettering two different appendices as "B"
The second problem is that all the definations come out labeled as A.1, A.2. i think this has something to do with my placemnt of the code
Code: Select all
\StoreCounterValue{chapter}{thm}
\StoreCounterValue{theorem}{thm}
\StoreCounterValue{chapter}{defn}
Add appendix of Theroems
Code: Select all
% Command \InputTempFile.
% \InputTempFile{foo} inputs the file \fooTempFile. It is assumed that this is done in an appendix
% chapter (so the \appendix command has already been issued). We initially need to save the actual
% value of the chapter counter and change its format to arabic (used in the main chapters). Then
% the contents of \fooTempFile are processed. Finally, the value and format of the chapter counter
% is restored.
\newcounter{TempChapter}
\makeatletter
\newcommand{\InputTempFile}[1]{%
\setcounter{TempChapter}{\value{chapter}}%
\renewcommand{\thechapter}{\arabic{chapter}}%
\input{\@nameuse{#1TempFile}}%
\setcounter{chapter}{\value{TempChapter}}%
\renewcommand{\thechapter}{\Alph{chapter}}}
\makeatother
A command like \StoreCounterValue{chapter}{thm} just saves the actual value of the chapter counter (through a \setcounter command) in the temp file with suffix thm. Look the contents of the temp files. I'll try to explain the sense of such a command. Suppose that you write a long book with many chapters. Suppose that, say, L'Hôpital's Rule is stated as Theorem 7.5 (that is, the fifth result using counter theorem in Chapter 7). When LaTeX processes the appendix, before rewritting theorems in Chapter 7, it needs to know that they belong to that chapter, that is, that the value of the chapter counter is 7. A simple way to tell to LaTeX this information is to put \setcounter{chapter}{7} in the temp file before the code of any theorem in Chapter 7. This is precisely the role of \StoreCounterValue{chapter}{thm}.
Likewise, before typesetting L'Hôpital's Rule, LaTeX needs to know that the theorem counter is 4. Thus, when processing
\begin{theorem}[L'H\^opital's Rule], LaTeX increments the theorem counter and correctly writes "Theorem 7.5". If you have stored the code of the four previous results (asuming that the numbering of the first one is correct), nothing is needed, since each \begin{theorem} increments the theorem counter. However, if you skip one result, you need to explicitly tell the correct value of that counter, so you need a \StoreCounterValue command. As a rule ot thumb:
* in each chapter containing theorems you want to rewrite in the appendix, add \StoreCounterValue{chapter}{thm} after \chapter,
* before every theorem that you find having an incorrect theorem number in the appendix, add \StoreCounterValue{theorem}{thm}.
The same rules applies for definitions. In case of doubt, add \StoreCounterValue and see the effect.