無需額外環境即可隱藏自由文本

無需額外環境即可隱藏自由文本

為了簡化起見,我們假設我有一份僅包含文字和定理的文件。

我只想顯示定理中包含的文字。例如

    \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.一2.二定理:Bloh” 2.二

是否可以不必將文字包含在額外的環境中?

一種解決方案是透過某種技巧來抑制正常輸出,例如將字體大小設為 0(沒有設法做到這一點),除了定理之外。

謝謝

編輯:也許一種方法是用一些包自動收集定理的所有內容,不輸出主文檔,只輸出已收集的內容,但我也想有章節和章節標題......

答案1

OP 規定「假設我有一份只包含文字和定理的文檔」。

我使用tokencycle名為 的偽環境\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}

氣象局:

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

導致

在此輸入影像描述

相關內容