就像声明的那样别处,通常建议使用星号\newcommand*
而不是,\newcommand
因为这有助于}
通过禁止其参数中的段落来查找缺失的 s。然而,时不时地,人们希望让这样的命令,例如\pdfmarkupcomment
,作用于多个段落(部分)+。有没有办法定义一个环境(比如,pdfmarkedup
或者环境可以共享命令的名称?),以便它自动将每个段落包装到所需的单段命令中?即
\documentclass{article}
\usepackage{pdfcomment}
\newenvironment{pdfmarkedup}{%
% insert magic here
}
\begin{document}
\begin{pdfmarkedup}[markup=Highlight]{no comment}
I'm a little paragraph short and stout.
Here is my last stop.
Here is my successor.
When I get all wrapped up,
Hear me shout!
Just write me down
and pour me out.
I'm a clever environment, yes it's true.
Here's an example of what I can do.
I can wrap my paragraphs each into a command.
Just put me around them and pour me out.
\end{pdfmarkedup}
\end{document}
应该相当于
\documentclass{article}
\usepackage{pdfcomment}
\begin{document}
\pdfmarkupcomment[markup=Highlight]{
I'm a little paragraph short and stout.
Here is my last stop.
}{No comment}
\pdfmarkupcomment[markup=Highlight]{
Here is my successor.
When I get all wrapped up,
Hear me shout!
}{No comment}
\pdfmarkupcomment[markup=Highlight]{
Just write me down
and pour me out.
}{No comment}
\pdfmarkupcomment[markup=Highlight]{
I'm a clever environment, yes it's true.
Here's an example of what I can do.
I can wrap my paragraphs each into a command.
Just put me around them and pour me out.
}{No comment}
\end{document}
+在我的例子中\pdfmarkupcomment
,在每个段落中重复相同的评论是可以接受的。
答案1
expl3
结合使用以下力量environ
:
\documentclass{article}
\usepackage{environ,xparse}
\usepackage{pdfcomment}
\ExplSyntaxOn
\NewEnviron{pdfmarkedup}[2][]
{
\kienzler_pdfmarkedup:Vnn \BODY { #1 } { #2 }
}
\seq_new:N \l_kienzler_pdfmarkedup_pars_seq
\cs_new_protected:Nn \kienzler_pdfmarkedup:nnn
{
\seq_set_split:Nnn \l_kienzler_pdfmarkedup_pars_seq { \par } { #1 }
\seq_map_inline:Nn \l_kienzler_pdfmarkedup_pars_seq
{
\tl_if_blank:nF { ##1 }
{
\pdfmarkupcomment[#2]{##1}{#3} \par
}
}
}
\cs_generate_variant:Nn \kienzler_pdfmarkedup:nnn { V }
\ExplSyntaxOff
\begin{document}
\begin{pdfmarkedup}[markup=Highlight]{no comment}
I'm a little paragraph short and stout.
Here is my last stop.
Here is my successor.
When I get all wrapped up,
Hear me shout!
Just write me down
and pour me out.
I'm a clever environment, yes it's true.
Here's an example of what I can do.
I can wrap my paragraphs each into a command.
Just put me around them and pour me out.
\end{pdfmarkedup}
\end{document}
我们用 吸收环境内容environ
,然后将其拆分为以 token 为单位的序列\par
。序列中的每个项目都传递给\pdfmarkupcomment
。