Suppose that I have a long tex file with a lot of things. In order to read the logic structure only, I want to print only text inside \begin{theorem}..\end{theorem} and \begin{lemma}..\end{lemma}.

Sure, I can embrace all the other parts incide something like \show{...} and then define \show[1] as %1 when I want to see all content and as {} if I want to see only statements.

But I am looking for a more elegant solution. =) Something like the preview package http://www.pirbot.com/mirrors/ctan/macros/latex/contrib/preview/preview.pdf

1 Answer 1


Here is a solution based on atbegshi and answers packages.

The idea is to use answers that write contents of theorem, lemma to an external file (mtfile.tex), discard all pages (all contents of the main file https://tex.stackexchange.com/a/267555/71471) and then use the external file to output only theorems.

We use a newif test \onlytrue for only theorem and \onlyfalse for normal use.

Auxiliary environments used to save the original definitions of theorem and lemma.


Complete code.




\newif\ifonly % uncomment next line

this is some bla bla in lamma
some bla bla in lamma
some bla bla in lamma
  • That's wickedly clever. The only solutions I could come up with, are much more complicated and likely less reliable. Feb 7, 2016 at 20:06
  • @NikitaKalinin you're welcom
    – touhami
    Feb 7, 2016 at 21:22
  • That's a really nice solution ! Do you think of an easy solution to keep the sectionning commands of the original document (i.e. sections, chapters, etc) ? It seems that \Newassociation only works with environments, and I don't see how to do.
    – mvienney
    Feb 22, 2017 at 17:50
  • @mvienney i think yes, i'll try :-)
    – touhami
    Feb 22, 2017 at 18:24
  • @mvienney please ask new question.
    – touhami
    Feb 23, 2017 at 13:39

You must log in to answer this question.

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