1

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...

3
  • 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

1 Answer 1

1

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]{%
  \ifx\chapter#1\addcytoks{#1}\gdef\addarg{T}\else
  \ifx\section#1\addcytoks{#1}\gdef\addarg{T}\else
    \gdef\addarg{F}\fi\fi
}

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\addarg{F}
\def\checktheorems{F}
\def\charson{F}
\def\thmchk{theorem}
\def\propchk{proposition}
\declaretheorem{theorem}
\declaretheorem{proposition}
\stripgroupingtrue
\tokcycleenvironment\shothms
  {\if T\charson\addcytoks{##1}\fi}
  {%
    \if T\addarg\addcytoks{{##1}}\gdef\addarg{F}\fi
    \if F\checktheorems
      \if T\charson\addcytoks{{##1}}\fi
    \else
      \gdef\tmp{##1}%
      \ifnum\testenvs{\tmp}=1\relax
        \if B\checktheorems
          \addcytoks{\begin{##1}}\gdef\charson{T}%
        \else
          \addcytoks{\end{##1}}\gdef\charson{F}%
        \fi
      \fi%
    \fi
    \gdef\checktheorems{F}
  }
  {%
    \ifx\begin##1\gdef\checktheorems{B}\else
      \ifx\end##1\gdef\checktheorems{E}\else
        \gdef\checktheorems{F}%
        \if T\charson\addcytoks{##1}\fi%
      \fi
    \fi
    \testmacros{##1}%
  }
  {\if T\charson\addcytoks{##1}\fi}
\newcommand\testmacros[1]{%
  \ifx\chapter#1\addcytoks{#1}\gdef\addarg{T}\else
  \ifx\section#1\addcytoks{#1}\gdef\addarg{T}\else
    \gdef\addarg{F}\fi\fi
}
\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}

enter image description here

ADDENDUM

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

\newcommand\testmacros[1]{%
  \ifx\chapter#1\addcytoks{\stepcounter{chapter}\par\noindent Chapter 
    \thechapter:~}\gdef\addarg{T}\else
  \ifx\section#1\addcytoks{\stepcounter{section}\par\noindent Section 
    \thesection:~}\gdef\addarg{T}\else
    \gdef\addarg{F}\fi\fi
}

resulting in

enter image description here

6
  • Ok, thanks, basically it rebuilds the whole document. I am looking for something more stable, that would work for instance with another documentclass, such as book with chapters, etc...I'm sorry I made only one MWE Sep 22, 2020 at 5:40
  • @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
  • Ok, how would you proceed to include chapters and propositions? Sep 22, 2020 at 9:56
  • @kaleidoscop Done. Sep 22, 2020 at 10:06
  • @kaleidoscop I have provided what might be a useful ADDENDUM to my answer Sep 22, 2020 at 10:32

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.