## LaTeX forum ⇒ General ⇒ Add appendix of Theroems

LaTeX specific issues not fitting into one of the other forums of this category.
Posts: 42
Joined: Fri Oct 17, 2008 5:55 pm

Is there a way to make an Appendix of all the theorems i have wrote in the paper? So that all theorems appear one after another much like an index of them?

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am
I think it is not clear from your post what you are searching for. Do you want the full statement of every result or just a brief reference? As a first idea of what can be achieved, compile the following code:
\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}

Things can be greatly improved, but, at the same time, they become more complex, depending on the class of document you use, the theorem-like environments you define, their numbering, the use of starred versions of such environments, the use of their optional arguments, etc. Think precisely what you want and consider if it is worthy to invest time and effort in it.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.

Posts: 42
Joined: Fri Oct 17, 2008 5:55 pm
the preamble to my documernt is
% 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

and yes i am trying to get a total restatement of everything that is listed under the
\begin{thm} \end{thm}
and then if possible a second appendix with everything under
\begin{defn} \end{defn}

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am
Now it is more clear what you want. It is quite similar to the problem considered in this other topic, where a user wanted a list of equations. I've adapted and improved the code there to show you things which can be done. Consider the following code:

The code contains comments explaining macros and their usage. Feel free to ask if you don't understand something. Essentially, the code for theorems and definitions is stored in auxiliary files (with extension tmp) and processed two times: once, when the code appears, and later, in the appendix.

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
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.

Posts: 42
Joined: Fri Oct 17, 2008 5:55 pm
This is EXACTLY what i want. You are amazing. I am having two problems though. Right before i write to chapters that have been made i have
\appendix\chapter{Definitions}\InputTempFile{def}\chapter{Theorems}\InputTempFile{thm}\chapter{Important Graphs}

this causes
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
\StoreCounterValue{chapter}{thm}\StoreCounterValue{theorem}{thm}\StoreCounterValue{chapter}{defn}

I am not quite sure what this bit of code does, and where i should place it.

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am
Replace the comments and defintion of \InputTempFile by the following code:

I hope that now everything will work fine.

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.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.