追加の環境なしでフリーテキストを非表示にする

追加の環境なしでフリーテキストを非表示にする

簡単にするために、テキストと定理だけを含む文書があるとします。

定理に含まれるテキストのみを表示したい。例えば

    \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}

表示したいのは以下のみ: 1.1つ 1.1 2.2 定理:Bloh" 2.2つ

テキストを追加の環境で囲まなくても可能ですか?

1 つの解決策は、定理を除いて、フォント サイズを 0 にする (これはできませんでした) など、何らかのトリックを使用して通常の出力を抑制することです。

ありがとう

編集: おそらく、これを行う 1 つの方法は、いくつかのパッケージを使用して定理のすべての内容を自動的に収集し、メイン ドキュメントを出力せず、収集されたものだけを出力することですが、章とセクションのタイトルも表示したいです...

答え1

OP は、「テキストと定理のみを含む文書があるとします」と規定しています。

結果を得るために、tokencycleという疑似環境を使用します。この環境の 1 つのインスタンスがドキュメント全体をラップします。\shothms...\endshothms

現在編集中なので、\chapter&のインスタンス\section(オプションの引数なし)とtheorem&proposition環境のみを実行します。これらのマクロ/環境へのオプションの引数は で処理できますtokcycleが、ここで時間とコードを費やす気にはなれませんでした。埋め込みマクロの実行中に文字ごとに引数を解析する、それが実行される例。

マクロテスト(キャプチャするマクロを追加したい場合)はマクロによって実行され\testmacrosます

\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
}

環境テスト(さらに必要な場合)は、\testenvs次のようにマクロによって実行されます。

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

前文の定義を踏まえると

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

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}

ここに画像の説明を入力してください

付録

セクションのフォーマットを少なくしたい場合は、\testmacros次のように再定義できます。

\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
}

その結果

ここに画像の説明を入力してください

関連情報