如何看待以下段落

如何看待以下段落

我是 TeX 新手,有点迷茫。有人能告诉我这个应该怎么写吗(代码中标记为“此处存在问题”)

情况:当参数 #2 是空格(空段落)时,我想使用下一段

\def\adjustParagraph#1\par{...some code here (which works ok)...}

\def\headline#1#2\par      % takes headline (#1) and the paragraph which follows (#2)
   {\myFont#1\par      % headline
   \if #2 {\adjustParagraph}   % if argument #2 is a space (empty paragraph) <= PROBLEM HERE
   \else{\adjustParagraph#2\par}   % argument #2 is text
   \fi}

\headline{This is headline}
Lorem ipsum dolor sit amet consectetuer ...

\headline{Another headline}

This time, argument 2 is that blank space above this line...

答案1

我不会使用分隔参数。此外,这\headline会与输出例程冲突,因此我改用\Headline您的宏。

\def\adjustParagraph#1\par{...some code here (which works ok)...}

\def\Headline#1#2\par      % takes headline (#1) and the paragraph which follows (#2)
  {\myFont#1\par      % headline
   \expandafter\ifx\space#2
     \expandafter\adjustParagraph
   \else
     \adjustParagraph#2\par   % argument #2 is text
   \fi
}

\Headline{This is headline}
Lorem ipsum dolor sit amet consectetuer ...

\Headline{Another headline}

This time, argument 2 is that blank space above this line...

\bye

需要注意两点:

  1. \expandafter\ifx\space#2将检测是否#2以空格标记开头(如果不是,其余部分将被忽略)。

  2. \expandafter\adjustParagraph必须在“真实”分支中使用才能摆脱\else

相关内容