Latex 可选文本和脚注

Latex 可选文本和脚注

有时我会为两个读者写作。我会为普通读者准备一份完整的文档,其中包含额外的脚注和背景段落。而另一个版本会省略掉这些背景细节,而对于另一类读者来说,这些背景细节被认为是理所当然的。

有没有一种不太麻烦的方法来处理这种事情?

更新:抱歉,如果这有点不清楚。我对如何手动“注释掉”文本部分不感兴趣。我希望能够设置某种“标志”,输出带有较少脚注的精简版文档和带有附加脚注的扩展版文档。

答案1

这里使用multiaudience。对于需要背景知识的人和不需要背景知识的人,有一个受众群体。两个输出(仅在当前受众群体中发生变化):

鸭子输出那些知道的人

您甚至可以使用该包来定义仅对某些受众可见的新环境和命令(预定义的 fi\FootnoteSection)。当然,您可以根据需要定义任意数量的受众。

\documentclass{article}

\usepackage{multiaudience}

\SetNewAudience{ducks}
\SetNewAudience{thosewhoknow}
\DefCurrentAudience{thosewhoknow}

\begin{document}
    Text for all\Footnote{ducks}{Details for those who don't know}\par
    \begin{shownto}{ducks}
        Text for those who need background.
    \end{shownto}
    \showto{thosewhoknow}{Additional depth}
    \begin{Section}{ducks}{DETAILS}
        Here a real section with details
    \end{Section}
\end{document}

答案2

如果你想“关闭”一个background环境(全部?)脚注,这与注释掉大段内容,虽然最后看上去非常相似。

最简单的方法是使用以下方法定义一个新的“switch 语句”

\newif\ifComplete

然后您可以使用\ifComplete来决定是否打印或隐藏文本。使用\ifComplete环境包中,您可以定义一个background环境,该环境将在之后忽略其内容\Completefalse。要定义,您可以使用以下命令“保存”“真实”命令\footnote的副本\footnote

\let\realfootnote=\footnote

然后重新定义,\footnote这样它就会忽略其内容\Completefalse。由于\footnote需要一个可选参数,我们不妨支持这一点。

综合所有这些,我认为以下代码可以实现您想要的功能:

\documentclass{article}
\usepackage[textheight=20mm]{geometry}% for display purposes only
\newif\ifComplete% if true print the whole document
\usepackage{environ}
\NewEnviron{background}{\ifComplete\BODY\fi}% print only when \Completetrue
\let\realfootnote=\footnote% save a copy of the original \footnote
\renewcommand\footnote[2][\relax]{% hijack footnote
  \ifComplete% print foot notes only in complete document
    \ifx#1\relax\relax\realfootnote{#2}\else\realfootnote[#1]{#2}\fi%
  \fi%
}
\begin{document}

\Completetrue
\begin{background}
  This is some background material
\end{background}

This is some normal text with a footnote\footnote{What a lovely footnote!}

\end{document}

在 WME 中,\Completetrue意味着所有内容都将被打印,因此会产生:

在此处输入图片描述

如果我们改为\Completetrue\Completefalse则输出为:

在此处输入图片描述

相关内容