8

I state a theorem in the main body of a document and prove it in the appendix. I use thmtools's restatable environment to restate the theorem there. However, I now need to have my appendix in a separate pdf file (hence a separate tex document). I'm using xr and xcite to get the cross-references and bibliographical references to play nicely.

But the commands created by restatable are not carried. Is there any way to to the restating of the theorem in the appendix in a separate document?

Here's a MWE:

main document: main.tex

\documentclass{article}
\usepackage{thmtools}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{restatable}{theorem}{thmcmd}\label{thmlabel}
Here is the statement of the theorem.
\end{restatable}

The above is Theorem~\ref{thmlabel}.

In this way I can restate it:
\thmcmd*

\end{document}

appendix: appendix.tex

\documentclass{article}
\usepackage{xr}
\externaldocument{main}
\usepackage{thmtools}
\newtheorem{theorem}{Theorem}

\begin{document}

I can refer to Theorem~\ref{thmlabel}.

But I cannot restate it like this:
% \thmcmd*

\end{document}
  • Yes, there is, but I don't know how. – JPi Oct 11 '16 at 2:27
  • Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Oct 11 '16 at 5:37
  • @PeterGrill Thank you. I've added a MWE. The line that fails to compile is the call to \thmcmd* on the appendix file. – Rui Oct 11 '16 at 11:23
  • 1
    If the goal is to produce a PDF file just containing the appendix, surely there are easier ways (e.g. produce the full PDF file and then extract the relevant pages). This doesn't invalidate your question, but just to say that there are work arounds. – Willie Wong Oct 12 '16 at 5:32
1

tcolorbox package provides some macros for saving the content of boxes and use it later.

The simplest example could be:

\documentclass{article}
\usepackage[most]{tcolorbox}

\begin{document}
\begin{tcolorbox}[saveto=myfile.tex, lowerbox=ignored]
This is a nice theorem
\tcblower
This is the nice prove
\end{tcolorbox}

\begin{tcolorbox}[title=A nice theorem with its prove]
\input{myfile.tex}
\end{tcolorbox}

\end{document}

In previous code saveto option, saves the whole tcolorbox content (upper and lower parts) in file myfile.tex. It saves only the contents, not the format of the box.

Option lowerbox=ignored makes that the lower part (the prove in this case) doesn't appears, but it is saved.

Later on into the same document, or into another document, myfile.tex can be restated as a tcolorbox content.

enter image description here

More information about these commands can be found in tcolorbox documentation, sections 4.3 Upper part, 4.4 Lower part and for more complex examples in chapter 8. Recording. Some examples here: https://tex.stackexchange.com/a/257455/1952 and https://tex.stackexchange.com/a/224429/1952

Update

I'll try to show that example shown in https://tex.stackexchange.com/a/224429/1952 can be also applied with an external document. The first document will contain theorems and proofs, although only theorems will be printed, while the second one will show theorems and proofs. This solution applies an invisible box (blankest in tcolorbox nomenclature) as OP wanted.

The document with theorems and proof is called TestTheorems.tex and its content is:

\documentclass{article}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter,number within=section]{theorem}{+O{}}{ %
    enhanced, blankest,
    coltitle=black,
    title={Theorem~\thetcbcounter:},
    label={theorem@\thetcbcounter},
    attach title to upper=\quad,
    theorem style=standard,
    lowerbox=ignored,
    saveto=theorems/theorem-\thetcbcounter.tex,
    record={\string\proof{\thetcbcounter}{theorems/theorem-\thetcbcounter.tex}},
    #1
}

\begin{document}
\section{Some theorems without proof}

\tcbstartrecording

Some theorems are shown in this document. All proofs are also written here, but not printed. They will be printed in another document.

\begin{theorem}
This is the first theorem
\tcblower
This is the proof of the first theorem\end{theorem}

\begin{theorem}
This is the second theorem
\tcblower
This is the proof of the second theorem\end{theorem}

\begin{theorem}
This is the third theorem
\tcblower
This is the proof of the third theorem\end{theorem}

\begin{theorem}
This is the fourth theorem
\tcblower
This is the proof of the fourth theorem\end{theorem}

\tcbstoprecording

\end{document}

It declares a theorem tcolorbox whose contents will be saved (saveto option) in different files, one for each theorem. The name of this files is alse recorded (record option) into an auxiliary file called TestTheorems.record. This auxiliary file is created with comman \tcbstartrecording and is closed with command \tcbstoprecording.

After processing this file the result is:

enter image description here

but also a folder theorems with four files in it, one for each theorem, and the file TestTheorems.records into main folder.

The second file TestProofs.tex contains the definition of tcolorbox which will read all recorded theorems and proofs. And with xr help, they will keep their original names and numbers. Command \tcbinputrecords declares which file will be read. Being an external file, it's necessary to indicate the name as an option.

\documentclass{article}

\usepackage{xr}
\externaldocument{TestTheorems}
\usepackage[most]{tcolorbox}

\NewTotalTColorBox{\proof}{mm}{ %
    enhanced, blankest,
    coltitle=black,
    theorem style=plain,
    title={Theorem~\ref{theorem@#1}:},
    phantomlabel={proof@#1},
    attach title to upper=\par,
    before lower={Proof:\par}
}{\input{#2}}

\begin{document}
\section{Phnatom section}

\section{Theorems and proofs}

This document shows already printed theorems but it also includes all proofs.

\tcbinputrecords[TestTheorems.records]

\end{document}

The result is:

enter image description here

  • Unfortunately, it seems that this does not keep the numbering according to the original file, which is one of the main purposes of "restatable". Is it possible to do so? – Rui Oct 11 '16 at 11:34
  • @Rui. This is just a little example to show that tcolorbox provides these tools for saving ans reusing contents. In any case I think that the second link in my answer (which has been taken from chapter 8) shows that it's possible to save original numbers. – Ignasi Oct 11 '16 at 11:42
  • fair enough. Does this package allow one to have an "invisible" box. As in, having the theorem statement and proof not in a box but according to the style of the document (say, the style guidelines of a particular journal)? – Rui Oct 12 '16 at 0:36
  • @Rui I've updated the answer with an example using invisible tcolorboxes and two different files. Theorems and proofs can be printed in second file while keeping original enumeration. Hope it helps. You still will have to adapt theorem and proof format to your taste. – Ignasi Oct 12 '16 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.