adjustwidth 如何影响 \par 和 \write?

adjustwidth 如何影响 \par 和 \write?

使用以下代码:

\documentclass{article}
\usepackage{newfile}
\usepackage{changepage}
\begin{document}
\newoutputstream{info}
\openoutputfile{\jobname.info}{info}

\section{First}
Here's some text to fill things up.
\addtostream{info}{This is the first bit: \thesection.\par}

\begin{adjustwidth}{1cm}{1cm}
\section{Second}
Here's some text to fill things up.

\addtostream{info}{This is the second bit: \thesection.\par}
\end{adjustwidth}

\section{Third}
\begin{minipage}{.8\textwidth}
Here's some text to fill things up.
\addtostream{info}{This is the third bit: \thesection.\par}
\begin{minipage}{.8\textwidth}

\closeoutputstream{info}

\section{Extra Information}
\input{\jobname.info}
\end{document}

我得到了以下输出,其中\par第一部分和第三部分中的\addtostream正确写入输出文件。但是在第二部分中,即 内adjustwidth\par被打印为@par输出中的内容:

请注意“这是第二位:2”后面的 <code>@par</code>。

是否adjustwidth做了什么\par导致这种情况?当我处于环境中时,如何\par正确写入输出文件adjustwidth

(您可以直接在这里编辑代码:https://www.overleaf.com/6014969bzsxfx

答案1

list在环境(或基于它的环境,例如)内adjustwidth\par被重新定义,如以下代码所示

\documentclass{article}
\begin{document}

{\ttfamily\meaning\par}

\begin{list}{}{}
\item {\ttfamily\meaning\par}
\end{list}

\end{document}

在此处输入图片描述

有几个很好的理由,您可以读到source2e.pdftexdoc source2e从命令行运行)。

使用\noexpand\par

\documentclass{article}
\usepackage{newfile}
\usepackage{changepage}
\begin{document}
\newoutputstream{info}
\openoutputfile{\jobname.info}{info}

\section{First}
Here's some text to fill things up.
\addtostream{info}{This is the first bit: \thesection.\noexpand\par}

\begin{adjustwidth}{1cm}{1cm}
\section{Second}
Here's some text to fill things up.

\addtostream{info}{This is the second bit: \thesection.\noexpand\par}
\end{adjustwidth}

\section{Third}
\begin{minipage}{.8\textwidth}
Here's some text to fill things up.
\addtostream{info}{This is the third bit: \thesection.\noexpand\par}
\end{minipage}

\closeoutputstream{info}

\section{Extra Information}
\input{\jobname.info}
\end{document}

.info以下是文件的内容

This is the first bit: 1.\par 
This is the second bit: 2.\par 
This is the third bit: 3.\par 

或者,使用^^J而不是,这将在文件\noexpand\par中添加一个空白行.info

This is the first bit: 1.

This is the second bit: 2.

This is the third bit: 3.

相关内容