# How does adjustwidth affect \par and \write?

With the following code:

\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}

\section{Second}
Here's some text to fill things up.

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

\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}


I get the following output, where the \par in the first and third section's \addtostream are written to the output file correctly. However in the second section, which is within a adjustwidth, the \par gets printed as @par in the output:

Is adjustwidth doing anything to \par that's causing this? How can I write \par to the output file correctly when I'm in an adjustwidth environment?

(You can edit the code here directly: https://www.overleaf.com/6014969bzsxfx)

Inside a list environment (or one based on it, such as adjustwidth), \par is redefined, as testified by the following code

\documentclass{article}
\begin{document}

{\ttfamily\meaning\par}

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

\end{document}


There are several good reasons for this, that you can read in source2e.pdf (run texdoc source2e from a command line).

Use \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}

\section{Second}
Here's some text to fill things up.

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

\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}


Here's the contents of the .info file

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


Alternatively, use ^^J instead of \noexpand\par, which will add a blank line in the .info file

This is the first bit: 1.

This is the second bit: 2.

This is the third bit: 3.

• Works perfectly — and I learnt \meaning! Thank you. Aug 30 '16 at 16:36