答案1
尽管有更复杂的方法为命令提供情报,但这里有一个基本的替代方法
\def\TODO#1\TODO{#1}
然后使用
\section{\TODO Introduction $of$ \textsc{The Topic}}\TODO}
如果你不喜欢使用\TODO
作为正确的分隔符,你可以使用任何你想要的
\def\TODO#1!!!{#1}
\section{\TODO Introduction $of$ \textsc{The Topic}}!!!}
或者你只是想要\TODO
在 TeXStudio 中,而不想在文档中输出任何内容?在这种情况下,一个简单的
\def\TODO{} % or \let\TODO\relax
\section{\TODO Introduction $of$ \textsc{The Topic}}}
就足够了。
答案2
kdb 询问:
是否可以编写一个宏,将当前组的其余部分作为参数?
您说的“当前组的其余成员”是什么意思?
编写一个取括号组余数的宏很容易。
但执行该宏的时候必须有一个括号组。
在您的例子中,在扩展 -macro 时,-macro的参数\section
将作为 的一部分插入。 当 将带有参数的 插入到标记流中时,周围的括号将从未定界的参数中剥离,因此将不再有括号组表示该节标题的开始和结束。 因此,当进一步处理导致执行 时,将找不到括号组。<replacement text>
\section
<replacement text>
\TODO
\TODO
(除此之外,使用\TODO
-macro 时您需要采取预防措施以确保它在作为移动参数的一部分时能够正确运行(就像在 -command 的参数中使用它时一样,\section
它也会将其参数推送到目录和 pdf 文件的书签中)以及在 pdf 字符串中使用时(就像书签的情况一样)。)
\CopyBehindGroup
当所讨论的括号对表示宏参数时,以下宏没有任何用处。
但它是如何将标记放在一对括号之外形成局部范围的示例。
以下宏\CopyBehindGroup
采用未限定的参数和括号组的余数,并将二者推到括号组之外。这样,参数就从括号组中删除了。余数只是被复制。
\documentclass{article}
\makeatletter
%%----------------------------------------------------------------------
%% Check whether argument is empty:
%%......................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
%%
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\@secondoftwo\string{\expandafter
\@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\@secondoftwo\string}\expandafter\@firstoftwo\expandafter{\expandafter
\@secondoftwo\string}\expandafter\expandafter\@firstoftwo{ }{}%
\@secondoftwo}{\expandafter\expandafter\@firstoftwo{ }{}\@firstoftwo}%
}%
%%----------------------------------------------------------------------
%% \UD@PullOutFirstUndelimitedArgument{<action>}%
%% {<action if list is empty>}%
%% {{<e_k>}{<e_(k+1)>}..{<e_n>}}%
%% yields either
%% <action>{<e_k>}{{<e_(k+1)>}..{<e_n>}}
%% or
%% <action if list is empty>
%% ( The "list" in question is {<e_k>}{<e_(k+1)>}..{<e_n>} )
%%......................................................................
\newcommand\UD@Exchange[2]{#2#1}%
\newcommand\UD@KeepFirstTillSelDOM{}%
\long\def\UD@KeepFirstTillSelDOM#1#2\UD@SelDOM{{#1}}%
\newcommand\UD@PullOutFirstUndelimitedArgument[3]{%
\UD@CheckWhetherNull{#3}{#2}{%
\expandafter\UD@Exchange
\expandafter{%
\expandafter{%
\@firstoftwo{}#3}}{\UD@ExtractFirstListElementLoop{#3\UD@SelDOM}{#1}}%
}%
}%
\newcommand\UD@ExtractFirstListElementLoop[1]{%
\expandafter\UD@CheckWhetherNull\expandafter{\@firstoftwo{}#1}%
{\UD@Exchange{#1}}%
{%
\expandafter\UD@ExtractFirstListElementLoop
\expandafter{%
\UD@KeepFirstTillSelDOM#1}%
}%
}%
%%----------------------------------------------------------------------
%% \CopyBehindGroup
%%
%% {<token sequence A>\CopyBehindGroup{<tokens to appear only behind group}<tokens to be copied behind group>}
%% yields:
%% {<token sequence A><tokens to be copied behind group>}<tokens to appear only behind group>{<tokens to be copied behind group>}
%%......................................................................
\newcommand\CopyBehindGroup[1]{%
\romannumeral0%
\expandafter\expandafter\expandafter\UD@PullOutFirstUndelimitedArgument
\expandafter\expandafter\expandafter\@CopyBehindGroup
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter}%
\expandafter\expandafter\expandafter{%
\expandafter\@secondoftwo\string}{}%
{#1}%
}%
\newcommand\@CopyBehindGroup[2]{%
\expandafter\@secondoftwo\string{{ }#2}#1{#2}%
}%
\makeatother
\begin{document}
\frenchspacing
{%<--This starts the boldface-group
\bfseries This is boldface.
\CopyBehindGroup{This is to appear only outside the boldface-group. \textit}%
This is to be copied outside the boldface-group.
}%<--This ends the boldface-group
\end{document}