1

Suppose I want to create an in-class text. Suppose further that as a lecturer I want my copy of the text to have copious amounts of ancillary material (notes, solutions to exercises, blackboard examples, etc.) included. The mass of additional material won't fit comfortably in the margins, so what I'd want to do is have additional insert pages that appear at the end of each section, such that if I removed them from my version of the text the resulting pages would be identical to the students' version (so that the page numbers correspond exactly).

Here's a minimum working example that simply adds or removes material in an ancillary environment:

\documentclass{article}
\usepackage{lipsum}
\usepackage{verbatim}

\newif\ifshowancil \showanciltrue

\ifshowancil
\newenvironment{ancillary}%
    {\itshape
    \newpage
    %And other stuff...
    }%
    {\newpage
    %And other stuff...
    }
\else
\newenvironment{ancillary}{\comment}{}
\fi

\begin{document}

\lipsum[1-20]

\begin{ancillary}
\textbf{Here is the beginning.}
\lipsum[21-30] 
\textbf{And the end.}
\end{ancillary}

\lipsum[31-40]

\end{document}

What I would like is for the anciltrue version to compile identical to the ancilfalse version, but with the stuff in the ancillary environment typeset independently of the rest of the document, beginning on the next page (like a float), with "temporary'' page numbering (e.g. 30a, 30b, etc. if it follows page 30).

Is such a scheme possible without too much labor? I'm thinking a solution would require tinkering with the output routine, hence the tag.

Jon
  • 189
  • I don't think you need to explicitly change the output routine. Just e.g. use afterpage or something and pageslts. – cfr Jul 25 '16 at 03:26
  • If you don't want to print the ancil content then use \color{white} inside that environment when the boolean is false, so that the pagination does not change. – Jagath Jul 25 '16 at 03:36
  • @cfr I had no idea about afterpage. I must investigate further... – Jon Jul 25 '16 at 11:20
  • @Jagath Those pages shouldn't be printed at all, so my solution requires the extra pages to appear as an even number of "full-page floats" that will pause the normal text's page numbering. – Jon Jul 25 '16 at 11:23
  • Floats cannot include page breaks. So to use floats, you'd have to chunk the material into page-sized bits. But afterpage might allow you to do without this, though I'm not certain. – cfr Jul 25 '16 at 11:26
  • @cfr Sorry, I meant float-like behavior in that it inserts itself at the next page break, not that it would be a proper float. afterpage is showing lots of promise. – Jon Jul 25 '16 at 11:59

1 Answers1

2
\documentclass{article}
\usepackage{lipsum}
\usepackage{afterpage,environ,pageslts,fancyhdr}
\AtBeginDocument{%
  \pagenumbering{arabic}%
}
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\fancyhf{}
\fancyhf[cf]{\thepage}
\fancypagestyle{fancil}{%
  \fancyhf{}%
  \fancyhf[cf]{\arabic{savepage}(\thepage)}%
}
\newcounter{savepage}

\newif\ifshowancil \showanciltrue
% \showancilfalse

\ifshowancil
  \newcommand\saveancil{}%
  \environbodyname\envancil
  \NewEnviron{ancillary}%
  {%
    \global\let\saveancil\envancil
    \setcounter{savepage}{\thepage}%
    \afterpage{%
      \pagenumbering{roman}%
      \pagestyle{fancil}%
      \itshape
      \saveancil
      \newpage
      \pagenumbering{arabic}%
      \pagestyle{fancy}%
    }%
  }
\else
  \NewEnviron{ancillary}{}{}
\fi

\begin{document}

\lipsum[1-20]

\begin{ancillary}
\textbf{Here is the beginning.}
\lipsum[21-30]
\textbf{And the end.}
\end{ancillary}

\lipsum[31-40]

\end{document}

ancillary

cfr
  • 198,882