\输入-\返回命令

\输入-\返回命令

我正在寻找一个类似的命令\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}

相关内容