2

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}

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

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:

Note the <code>@par</code> after "This is the second bit: 2."

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)

1

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}

enter image description here

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}

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

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.
1
  • Works perfectly — and I learnt \meaning! Thank you.
    – imnothere
    Aug 30 '16 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.