我正在编写一份文档,最终将分成不同长度的不同版本。大部分差异只是不同版本中包含哪些材料。有没有办法构建一个可以在序言中更改的设置,以确定构建中包含哪些文本部分?例如,类似这样的内容:
This sentence is always included.
\level[2]{This sentence is included in the medium and long versions
\level[3]{, while this section is only in the long version}.}
这将产生:
\setlevel{1}
:
这句话始终包含在内。
\setlevel{2}
:
这句话始终包含在内。中篇和长篇版本中均包含这句话。
\setlevel{3}
:
这句话总是包含在内。这句话在中版和长版中都有,而此部分仅在长版中才有。
答案1
如果您愿意添加一些标点或间距调整,那么以下内容将满足您的需要:
\documentclass{article}
\makeatletter
\newcommand{\setlevel}[1]{\gdef\@level{#1}}
\newcommand{\level}[2][\relax]{%
\unskip
\ifx\relax#1\else
\ifnum\@level<#1\else
#2%
\fi
\fi
}
\makeatother
\begin{document}
\setlevel{1}
This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}
\setlevel{2}
This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}
\setlevel{3}
This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}
\end{document}
当然,嵌套\level[<a>]
在\level[<b>]
where <a>
<里面<b>
是没有帮助的。