如何不渲染文件的一部分(純 LaTeX)

如何不渲染文件的一部分(純 LaTeX)

我有一個很大的 LaTeX 文件,想要隱藏 PDF 中的大部分內容,但保留定理的原始編號等display:none

環境comment沒有幫助,因為它根本不處理內容。它只能用於隱藏定理之外的文字。

\hphantom\vphantom不要包裝像\begin{theorem}.

更準確地說,假設我有以下內容:

% I want to hide from here ...
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}
% ... to here
\begin{theorem}
Second
\end{theorem}

我只想查看 PDF 中原始編號的第二個定理:Theorem 1.1.2

我的問題非常類似於這個,但該問題的作者與 Sage 合作,據我所知,接受的答案是 Sage 特定的。

如果沒有通用的方法來實現這種效果,如果有辦法隱藏以下對象,我會很高興:

  • 章節/小節標題
  • 定理/引理等
  • 人物

我還考慮過將輸出“重定向”到另一個文件(不是 PDF),但我找不到解決方案。

最後的選擇是“硬編碼”定理的編號,但我想避免這種情況。

答案1

如果您想要排除的所有內容都在命令的參數內或包裝在環境中,那麼這只是一種嘗試。如果您確切地知道要排除什麼。

左圖是沒有隱藏的,右圖是有隱藏的。

在此輸入影像描述 在此輸入影像描述

這個想法是重新定義所有命令和環境以吞嚥參數的內容,但仍然執行計數器算術。

\documentclass{article}
\usepackage{environ}
\newtheorem{theorem}{Theorem}
\newenvironment{hide}%
  {\renewcommand\section[1]{\refstepcounter{section}}%
   \renewcommand\subsection[1]{\refstepcounter{subsection}}%
   \RenewEnviron{theorem}{\refstepcounter{theorem}}%
  }%
  {}
\begin{document}
% i want to hide from here ...
\begin{hide}
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}
\end{hide}
% ... to here
\begin{theorem}
Second
\end{theorem}
\subsection{Subsection 1.2}
\section{Section 2}
\begin{theorem}
Third
\end{theorem}
\end{document}

答案2

如果您執行此文檔,然後取消註釋 includeonly 並再次運行它,您將獲得一個單頁文檔,其中第 2 頁僅包含定理 2。

在此輸入影像描述

\begin{filecontents}{zzzz1.tex}
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}

\end{filecontents}
\begin{filecontents}{zzzz2.tex}
\begin{theorem}
Second
\end{theorem}
\end{filecontents}

\documentclass{article}
\newtheorem{theorem}{Theorem}

%\includeonly{zzzz2}

\begin{document}
% i want to hide from here ...
\include{zzzz1}
% ... to here
\include{zzzz2}
\end{document}

答案3

我喜歡格諾特的答案,但在看到他的答案之前我已經開始這樣做了,所以不妨發布它:

\documentclass{article}
\newif\ifskipstuff

\skipstufffalse
%\skipstufftrue

\usepackage{amsmath}
\begin{document}

\ifskipstuff
    \refstepcounter{section}
    \refstepcounter{subsection}
    \refstepcounter{equation}
\else
    \section{Section 1}
    \subsection{Subsection 1.1}
    \begin{equation}
        First
    \end{equation}
\fi

\section{A Section}
\subsection{Subsection}
\begin{equation}
    Second
\end{equation}

\end{document}

缺點是您始終需要手動增加所有計數器。不是很好(特別是如果子句中有很多東西\else。也許可以進一步細化(\ifskipstuff可能通過在重新定義的環境中包含檢查,以便它們自己進行檢查)。好處是您可以全局設置如果您想通過在\skipstufffalse和之間進行更改來包含或不包含您的材料\skipstufftrue,那麼這可能是一個好處,具體取決於您的用例。

\skipstufftrue:

跳過內容真實

\skipstufffalse:

跳過內容錯誤

相關內容