1

Consider this example (developed upon Change paper size in mid-document):

\documentclass{article}
\begin{document}
Normal page
\def\normalpdfpagewidth{\pdfpagewidth}

\eject \pdfpagewidth=17in Wide page \eject \pdfpagewidth=\normalpdfpagewidth Normal page again \end{document}

In this example I try to store the normal value of \pdfpagewidth in:

\def\normalpdfpagewidth{\pdfpagewidth}

and reapply this value in a succeeding page.

However, this trick has not worked out:

enter image description here

What is wrong?

Viesturs
  • 7,895
  • 1
    \pdfpaperwidth is a dimension, hence to store it's value you'll need \edef\normalpdfpagewidth{\the\pdfpagewidth}. – muzimuzhi Z Nov 12 '21 at 06:19

1 Answers1

2

When you write \pdfpagewidth=17in or \pdfpagewidth=\normalpdfpagewidth you're assigning one length or dimension to another length or dimension. That's the syntax used for such assignments <lenA>=<lenB> (the = is optional) and copies the length of <lenB> into <lenA>. If <lenB> changes after the assignment, <lenA> still holds the original length of <lenB>.

In your case, you're \defining some control sequence (or macro) to represent the length, as in \def<csname>{<stuff>}. And since TeX doesn't naturally expand its control sequence until its set on paper, any change in <stuff> is carried with <csname>. You either want the expanded version of the length (as mentioned by muzimuzhi)

\edef\normalpdfpagewidth{\the\pdfpagewidth}

or assign the lengths in a more natural way:

\newlength{\normalpdfpagewidth}
\setlength{\normalpdfpagewidth}{\pdfpagewidth}

enter image description here

\documentclass{article}

\newlength{\normalpdfpagewidth}

\begin{document}

Normal page

\setlength{\normalpdfpagewidth}{\pdfpagewidth}

\clearpage \setlength{\pdfpagewidth}{17in}

Wide page

\clearpage \setlength{\pdfpagewidth}{\normalpdfpagewidth}

Normal page again

\end{document}

Werner
  • 603,163