\輸入 - \返回命令

\輸入 - \返回命令

我正在尋找一個命令,\return可以使用它手動退出 TeX 文件,該文件包含在\input.

(在我的 TeX 檔案的末尾有一些通知,我有時想列印,有時不想列印。)

答案1

使用\endinput。之後的所有內容都將被忽略。

答案2

我建議您使用環境或\ifdefined選擇是否顯示通知:

在此輸入影像描述

使用“環境”版本,您可以使用\DisableMyNotices\EnableMyNotices來切換​​是否要查看通知。


代碼:\ifdefined

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}

\usepackage{filecontents}
\begin{filecontents*}{MyInput.tex}
This is text I want always included.

\ifdefined\IncludeNotices
    \fcolorbox{red}{yellow!40}{%
    These are notices that I only want sometimes.%
    }%
\fi
\end{filecontents*}

\begin{document}
Using normal input I get just the text\par

\begin{mdframed}
    \input{MyInput}
\end{mdframed}

\bigskip 

But with \verb|\IncludeNotices| defined:\par
\def\IncludeNotices{}
\begin{mdframed}
    \input{MyInput}
\end{mdframed}

\end{document}

程式碼: 環境版本:

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{environ}

\NewEnviron{MyNotices}{}%
\newcommand{\EnableMyNotices}{\RenewEnviron{MyNotices}{\BODY}}
\newcommand{\DisableMyNotices}{\RenewEnviron{MyNotices}{}}

\usepackage{filecontents}
\begin{filecontents*}{MyInput.tex}
This is text I want always included.

\begin{MyNotices}
    \fcolorbox{red}{yellow!40}{%
    These are notices that I only want sometimes.%
    }%
\end{MyNotices}
\end{filecontents*}

\begin{document}
\DisableMyNotices
With \verb|\DisableMyNotices| defined:\par

\begin{mdframed}
    \input{MyInput}
\end{mdframed}

\bigskip 

\EnableMyNotices
But with \verb|\EnableMyNotices| defined:\par
\begin{mdframed}
    \input{MyInput}
\end{mdframed}

\end{document}

相關內容