![adjustwidth 如何影响 \par 和 \write?](https://linux22.com/image/340082/adjustwidth%20%E5%A6%82%E4%BD%95%E5%BD%B1%E5%93%8D%20%5Cpar%20%E5%92%8C%20%5Cwrite%EF%BC%9F.png)
使用以下代码:
\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
输出中的内容:
是否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.pdf
(texdoc 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.