hide free text without additional environment

to simplify let us say I have a document with only text and theorems.

I want to display only the text contained in theorems. For instance

    \documentclass[10pt]{book}

\usepackage{amsthm}

\theoremstyle{definition}
\newtheorem{theorem}{Definition}

\begin{document}
\chapter{One}
\section{One}
blah
\section{Two}
\begin{theorem}
Blo
\end{theorem}
\chapter{Two}
Blih

\end{document}


I want only to have displayed: 1.One 1.One 2.Two Theorem:Bloh" 2.Two

Is it possible without having to enclose the text in an additional environment?

One solution would be somehow to suppress the normal output with some trick, e.g. putting font size to 0 (didn't manage to do that), except in the theorems.

Thanks

EDIT: maybe one way to do it would be to automatically collect all the contents of theorems with some packages, not ouput the main document, and only output what has been collected, but I would also like to have chapter and section titles...

• What documentclass and packages are you loading? Please edit your question to provide a minimum working example. Sep 21, 2020 at 15:27
• There you go (I edited the post). I'm looking for something that works for different kinds of environments (not only theorems), and maybe for different kind of documentclass Sep 21, 2020 at 16:17
• I have revised and undeleted my prior solution. Sep 21, 2020 at 18:22

The OP stipulates "let us say I have a document with only text and theorems".

I use a tokencycle pseudo-environment named \shothms...\endshothms, one instance of which is wrapped around the whole document, to achieve the result.

As currently EDITED, it will only execute instances of \chapter & \section (without optional arguments) and theorem & proposition environments. Note that optional arguments to these macros/environments can be dealt with via tokcycle, but I did not feel like investing the time and code here. See Parse Argument by Character while Executing Embedded Macros, for an example where it is done.

The macro tests (if one wanted to add additional macros to capture) is performed by the \testmacros macro

\newcommand\testmacros[1]{%
}


The environment tests (if more are needed) are performed by the \testenvs macro, given as

\newcommand\testenvs[1]{%
\ifx\thmchk#1 1\else
\ifx\propchk#1 1\else
0\fi\fi
}


given the preamble definitions

\def\thmchk{theorem}
\def\propchk{proposition}


The MWE:

\documentclass{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tokcycle}
\def\checktheorems{F}
\def\charson{F}
\def\thmchk{theorem}
\def\propchk{proposition}
\declaretheorem{theorem}
\declaretheorem{proposition}
\stripgroupingtrue
\tokcycleenvironment\shothms
{%
\if F\checktheorems
\else
\gdef\tmp{##1}%
\ifnum\testenvs{\tmp}=1\relax
\if B\checktheorems
\else
\fi
\fi%
\fi
\gdef\checktheorems{F}
}
{%
\ifx\begin##1\gdef\checktheorems{B}\else
\ifx\end##1\gdef\checktheorems{E}\else
\gdef\checktheorems{F}%
\fi
\fi
\testmacros{##1}%
}
\newcommand\testmacros[1]{%
}
\newcommand\testenvs[1]{%
\ifx\thmchk#1 1\else
\ifx\propchk#1 1\else
0\fi\fi
}
\begin{document}
\shothms
\chapter{My Chapter}

Chapter text

\section{One}

blah blah
\section{Two}

\begin{theorem}
Bloh \textbf{Blah} \today
\end{theorem}

blih blih \textit{blow}

more blah

\begin{proposition}
Blah$^2$
\end{proposition}
Finis
\endshothms
\end{document}


If one wanted less formatting of the sectioning, one could redefine \testmacros as

\newcommand\testmacros[1]{%

• @kaleidoscop This approach is perfectly stable. The issue is that one has to inform it which macros to ignore and which to process. As presented, it only processes \section and theorem environments. Others could be added, with additional code Sep 22, 2020 at 9:54