为什么 \narrower 在 LaTeX 中不能像在普通 TeX 中那样工作?

为什么 \narrower 在 LaTeX 中不能像在普通 TeX 中那样工作?

在 TeXbook(第 100 页)中,\narrower进行了描述并提供了以下示例,它在纯 TeX 中运行良好。

{\narrower\smallskip\noindent
This paragraph will have narrower lines than
the surrounding paragraphs do, because it
uses the ``narrower'' feature of plain \TeX.
The former margins will be restored after
this group ends.\smallskip}

然而,这在 LaTeX 中不起作用。\par段落末尾的附加内容\narrower可以解决这个问题。

\documentclass{article}

\begin{document}\makeatletter

This is a normal paragraph.

{\narrower\smallskip\noindent
  This should be a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature as described in the \TeX book.
  However, it does not really appear to be narrower.
  \smallskip
}

{\narrower\smallskip\noindent
  This is a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature with a trailing \verb|\par|.
  Nowadays, you should use a \LaTeX\ environment, though.
  \par\smallskip
}

This is a normal paragraph again.
Let's make it a bit longer, in order to see its right margin.

\end{document}

MWE 输出

这是为什么?即使没有(就像在纯 TeX 中一样),难道不应该\smallskip结束段落吗?\par

答案1

区别在于 的定义(和 的定义也\smallskip一样)。普通的 TeX 定义\medskip\bigskip

\def\smallskip{\vskip\smallskipamount}

而 LaTeX

\def\smallskip{\vspace\smallskipamount}

现在,\vskip是一个 TeX 基元,在(不受限制的)水平模式下发布时会结束当前段落。另一端\vspace是一个 LaTeX 宏,它扩展了\vskip 处于垂直模式时\vadjust否则。因此,第一个示例中的段落在组关闭之前并未结束。

答案2

在 LaTeX 中定义的\narrower是偶然的,不应依赖。这是因为原始 LaTeX 格式基于 的略微修改版本,plain.tex以便于从纯 TeX 文档过渡到 LaTeX 文档。

campa 已经解释了为什么\smallskip在 LaTeX 中与在普通 TeX 中工作方式不同。但是真实的解决方案是使用 LaTeX 功能(例如)定义您自己的环境\addvspace,因此两个连续的环境不会添加两倍的空间,并且您不需要手动添加或删除\smallskip

\documentclass{article}

\newenvironment{latexnarrower}
  {\par\addvspace{\smallskipamount}\narrower\noindent\ignorespaces}
  {\par\addvspace{\smallskipamount}}

\begin{document}

This is a normal paragraph.

{\smallskip\narrower\noindent
  This should be a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature as described in the \TeX book.
  but corrected for \LaTeX{} usage. And you see that it is indeed narrower, because
  we added \verb|\par| at the end.\par\smallskip
}

{\smallskip\narrower\noindent
  This should be a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature as described in the \TeX book.
  but corrected for \LaTeX{} usage. And you see that it is indeed narrower, because
  we added \verb|\par| at the end.\par\smallskip
}

This is a normal paragraph, long enough to wrap across lines. Let's just make it
long enough. Perhaps this does the job.

\begin{latexnarrower}
  This is a narrower paragraph.
  It was created using a proper \LaTeX{} environment. Which is surely a better
  way to do the job.
\end{latexnarrower}

\begin{latexnarrower}
  This is a narrower paragraph.
  It was created using a proper \LaTeX{} environment. Which is surely a better
  way to do the job.
\end{latexnarrower}

This is a normal paragraph, long enough to wrap across lines. Let's just make it
long enough. Perhaps this does the job.

\end{document}

在此处输入图片描述

您看得出来差别吗?

更好的是,您可以使用,list这样您就可以使用其他 LaTeX 功能。

\documentclass{article}

\newenvironment{latexnarrower}
 {\list{}{\topsep=\smallskipamount\leftmargin=\parindent\rightmargin=\parindent}\item}
 {\endlist}

\begin{document}

This is a normal paragraph.

{\smallskip\narrower\noindent
  This should be a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature as described in the \TeX book.
  but corrected for \LaTeX{} usage. And you see that it is indeed narrower, because
  we added \verb|\par| at the end.\par\smallskip
}

{\smallskip\narrower\noindent
  This should be a narrower paragraph.
  It was created using plain \TeX's ``narrower'' feature as described in the \TeX book.
  but corrected for \LaTeX{} usage. And you see that it is indeed narrower, because
  we added \verb|\par| at the end.\par\smallskip
}

This is a normal paragraph, long enough to wrap across lines. Let's just make it
long enough. Perhaps this does the job.

\begin{latexnarrower}
  This is a narrower paragraph.
  It was created using a proper \LaTeX{} environment. Which is surely a better
  way to do the job.
\end{latexnarrower}

\begin{latexnarrower}
  This is a narrower paragraph.
  It was created using a proper \LaTeX{} environment. Which is surely a better
  way to do the job.
\end{latexnarrower}

This is a normal paragraph, long enough to wrap across lines. Let's just make it
long enough. Perhaps this does the job.

\begin{latexnarrower}
  This is a narrower paragraph.
  It was created using a proper \LaTeX{} environment. Which is surely a better
  way to do the job.
\end{latexnarrower}
This is a normal paragraph, long enough to wrap across lines. Let's just make it
long enough. You see it has no indentation, because there was no blank line
between \verb|\end{latexnarrower}| and the following text.

\end{document}

在此处输入图片描述

相关内容