\documentclass[12pt,twocolumn]{article}
\usepackage[a4paper]{geometry}
\title{\texttt{rotpages.sty} --- Multiple page rotation in \LaTeX}
\author{Sergio Callegari}
\date{January 25th, 2002}

\begin{document}
\maketitle
\thispagestyle{empty}

\begin{abstract}
  This latex package permits to format documents where small sets of
  pages are rotated by 180 degrees and rearranged, so that they can be
  read by turning the printed copy upside-down. It was primarly meant
  for collecting exercises and solutions, to train students before
  exams. The package permits to print the exercise texts normally and
  the solutions rotated. The idea is to make it a bit harder for the
  students to unintentionally read the solutions before trying to
  solve the exercises autonomously. Other uses might obviously be
  possible.
\end{abstract}


\section{Introduction}
%%
The package \emph{rotpages.sty} is meant to be used when parts of a
document should be made purposely difficult to read or obfuscated.  An
obvious way to make it difficult to read something is to print it
upside down. This is well known by all those keen on puzzles and
cross-words: on the puzzle magazines the solutions are often printed
``the wrong way'' in order to prevent the readers form spoiling the
pleasure of the quiz by unintentionally reading the solutions before
having made sufficient attempts at finding them on their own.
  
A similar situation emerges in collecting exercises and solutions as
an aid for students training for exams. The solutions must be there,
so that the students can check their results and avoid getting stuck
when they cannot answer some question. At the same time the solutions
should not be easily readable, otherwise the temptation to read them
even before attempting to solve a problem is too strong. A typical
format for exercise collections consists in putting all the exercises
at the beginning of a booklet all the answers at the end.  However,
this makes people flap pages back and forth all the time.  Having the
solutions close to the relevant exercises and obfuscating them by page
rotation can possibly be a better practice.

In latex, it is very easy to rotate small amounts of text. The package
\emph{graphics} is a valid aid in this sense. However, it is not easy
to deal with large amounts of text. If the rotated material has to
span many pages, it cannot be put in a \verb|\rotatebox| command.
Furthermore, if many pages need to be rotated, it is not sufficient to
flip them individually: they must also be rearranged so that they
appear in the proper order when the printed copy of the document is
read ``upside down''.

The package \texttt{rotpages.sty} permits to rotate a few pages,
rearranging them consistently and preserving the normal latex
algorithm for breaking the material into pages.


\section{Usage}
%%
The package defines only two commands: \verb|\rotboxpages| and
\verb|\endrotboxpages|, which take no arguments.

The command \verb|\rotboxpages| closes the current page and starts
delimiting the text which needs typesetting ``the wrong way
round''. The command \verb|\endrotboxpages| marks the end of the
region which is typeset bottom-up, makes sure that the rotated pages
are flushed onto the \texttt{dvi} file and opens a fresh page.
The rotated material is printed surrounded by a frame.  Page headers
and footers continue display the proper way.

When used in two-column mode, the package correctly rotates the
columns independently, rearranging them if necessary. The rotated
columns get individually framed.

The file \texttt{rotpages-example.tex} provides an example.


\section{Known bugs and quirks}
%%
The package is relatively young and no bugs are known so far.  It
should be observed that the \texttt{.dvi} files produced with
\texttt{rotpages.sty} cannot be viewed properly with \texttt{xdvi},
\texttt{kdvi} and probably other dvi previewers. However, this
is not a problem of \texttt{rotpages.sty}, rather of \texttt{xdvi}
which does not understand correctly some of the \verb|\special|s
produced by the \texttt{graphics} package which is internally invoked
by \texttt{rotpages} for the page rotation. The postscript files
produced by \texttt{dvips} display and print correctly.

In order to re-arrange the pages which are rotated, the shipping of
the formatted material to the \texttt{dvi} file needs to be deferred
until all the rotated pages are processed. This puts a limit on the
number of pages which can be rotated at once, since the deferring
mechanisms uses a stack which eats up latex memory. 

\section{Internal operation}
%%
The package works by redefining the \verb|\@makecol| macro, which is
normally used by latex to format and ship a page to the dvi
file. Particularly, at the \verb|\rotboxpages| command, the
\verb|\@opcol| and the \verb|\@startcolumn| macros are temporarily
disabled, so that no page gets shipped to the \texttt{dvi} file and no
page number can be updated. Furthermore, the \verb|\@makecol| macro is
temporarily modified, so that the formatted pages get framed, rotated
and accumulated in a stack.

At the \verb|\endrotboxpages| command, the behaviour of latex gets
reset to the standard. After that, the pages that had previously been
accumulated onto the \texttt{rotpages} stack are flushed to the
\texttt{dvi} file. The stack mechanism assures that the pages get to
the \texttt{dvi} file in the correct (rearranged) order.

For the page rotation, \texttt{rotpages.sty} relies on the standard
graphics package. However, page rotation is delicate. When the
graphics package flips a page vertically, its measures can often get
rounded. One must force them to the correct value, otherwise latex
complains about overfull/underfull boxes.

\section{To-do}
%%
\begin{itemize}
\item Allow the package to pass options to the underlying graphics
  package, particularly concerning the drivers (dvips, xdvi, etc.) to
  use.
\item Make the package more flexible with regard to the formatting of
  rotated pages. Now they are unconditionally framed. Options to
  control this behaviour will probably be introduced in the next
  release.
\end{itemize}
\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
