6

Preparing a text book for my students, I want to let the even pages empty or dash-lined systematically, to let them write their remarks or own-work on these pages. I give at end the program used to produce 3 pages like this purpose, "hand-made".

I want to create a macro which does the same thing for all pages of documents. For example, the expressions of document, to be continued from page to page, like great equations or breakable boxes from tcolorbox, must break from odd to odd pages, with in siding the DashedPage between. Any idea ? For example, does the package everypage do things like this ?

\documentclass{article}

\usepackage{multido}

\newcommand{\DottedLines}[2][1.5]{%     %%  THE #1 ARGUMENT (MULTIPLE OF BASELINESKIP) IS OPTIONAL THE DEFAULT IS 1.5
  \par\nobreak
  \noindent\rule{0pt}{1.5\baselineskip}
  \multido{}{#2}{\noindent\makebox[\linewidth]{\rule{0pt}{#1\baselineskip}\dotfill}\\}}
\def\DashedPage{\newpage\DottedLines[2.5]{15}\newpage}

\begin{document}
A first page
\DashedPage
A second page
\end{document}

enter image description here

enter image description here

enter image description here

  • It would seem to be easier to create the odd-page part as an separate individual document and then (with a separate compilation) use pdfpages or something like that to reassemble a new document with lined pages inserted every other page. – Steven B. Segletes May 7 '18 at 10:21
  • Thank you for your answer. I have read the doc of pdfpages and found nothing for inserting odd/even pages. could you develop your comment please? – Faouzi Bellalouna May 7 '18 at 14:28
4

To have comment pages numbered, as well (see below for alternative):

Create your baseline document in the almost normal way. The only quirk is to get it to number each page by 2's, starting at 1. Here is lipsum30.tex:

\documentclass{article}
\usepackage{lipsum}
\renewcommand\thepage{\the\numexpr\value{page}+\value{page}-1\relax}
\begin{document}
\lipsum[1-30]
\end{document}

to create a 6-page lipsum30.pdf, with pages numbered 1, 3, 5, 7, 9, 11.

Once your baseline document (here lipsum30.pdf) has been created:

\documentclass{article}
\usepackage{everypage}
\usepackage{graphicx}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\usepackage{pgffor,pdfpages}
\begin{document}
\foreach\x in {1,...,6}{
  \includepdf[pages=\x]{lipsum30.pdf}
  \atxy{0in}{\paperheight}{\includegraphics[height=\paperheight]{lined-paper-template-9898}}
  \vspace*{-1.2in}\noindent\hspace{-45pt}%
  \Huge \underline{Your comments for page \the\numexpr\x+\x-1\relax:}
}
\end{document}

enter image description here

enter image description here

enter image description here

Note on page numbering

If one would like no numbering on the comment pages, with the odd (document) pages being numbered 1-6, consecutively, then just eliminate the \thepage redefinition in the base document, and in the splicing document, set \pagestyle{empty}. If you refer to pages by number, as I did on the comment pages, you will also need to revise that as well, to reflect the new numbering scheme: \Huge \underline{Your comments for page \x:}.


The file lined-paper-template-9898.jpg found at http://www.wordmstemplates.com/wp-content/uploads/2015/08/lined-paper-template-9898.jpg. If you don't like this form of paper ruling, choose another image, or just set up your own page ruling in the pgffor loop.

  • It was exactly my purpose. Many thanks for your ingenious macro – Faouzi Bellalouna May 7 '18 at 15:33
  • One question please. I'm oftenly in arabic environment, a right-to-left language, so how can I put the vertical line, in red, at the right margin, in the lined pages ? – Faouzi Bellalouna May 7 '18 at 15:43
  • @FaouziBellalouna Add a \scalebox into the \atxy call, as in \atxy{0in}{\paperheight}{\scalebox{-1}[1]{\includegraphics[height=\paperheight]{lined-paper-template-9898}}} – Steven B. Segletes May 7 '18 at 17:08
  • Good morning. I was working yesterday with your solution on my documents, and encountered a problem with "great" chapters of my textbook, with 90 pages... so I'll obtain something with 180 pages, for only one chapter. I then opted for the solution of inserting lined pages only in the end of the chapter, in exercises part. This can be done by looping from the page we want. In your example, the commands \includepdf[pages=1-2]{lipsum30.pdf} \foreach\x in {3,...,6}{ \includepdf[pages=\x]{lipsum30.pdf}.. inserts pages from page 3. Can you develop this idea for a generalized solution? – Faouzi Bellalouna May 8 '18 at 5:08
  • @FaouziBellalouna It sounds different enough from this one that you should just ask a new question, and reference this question as background for that one. – Steven B. Segletes May 8 '18 at 9:51
2

Although there is already an accepted answer, here is another approach.

Caution: Because this uses afterpage, it will not work for twocolumn documents and it's not robust, i.e. it may break easily.

This also means, while Steven B. Segletes' answer will work, this one may not do so.

This solution doesn't need pdfpages. Instead the final result is produced from one source. It also has additional features: the appearance of the comment pages can be changed mid document and comment pages can be suppressed.

There are three commands:

\EverySecondPage{...} starts adding comment pages. This command is only allowed once in the document, and not to be placed in an environment! The latter is necessary, because some environments may expand their content more then once. The argument is a command, which produces one comment page, e.g. \DashedPage.

\ChangeEverySecondPage{...} can be used to change the appearance of the comment pages by passing a different command to it.

\NomoreEverySecondPage disables adding comment pages. To re-enable them, \ChangeEverySecondPage{...} must be used.

The commands take effect beginning from the page on which they where expanded first by TeX. This means, if TeX decides to move something read on page n to the next page, it may seem as if the command takes effect too early. I.e. the point in the document where the command appeared is on page n+2, but it's effect can already be seen on comment page n+1. So it may be necessary to move the command a paragraph up or down.

The commands can be used inside, for example, a tcolorbox environment. But it's effect will be visible beginning from the page the environment started, because tcolorbox (as far as I know) reads it's whole contents, before anything is given out. The same probably applies to many other environments.

The command to set comment pages should be defined in the preamble, so \EverySecondPage and \ChangeEverySecondPage only get a simple command as argument.

Here is the code:

\documentclass[a4paper]{article}
\usepackage[breakable]{tcolorbox}
\usepackage{notespages}
\usepackage{multido}
\usepackage{afterpage}
\usepackage{lipsum}

\newcommand{\DottedLines}[2][1.5]{%     %%  THE #1 ARGUMENT (MULTIPLE OF BASELINESKIP) IS OPTIONAL THE DEFAULT IS 1.5
  \par\nobreak
  \noindent\rule{0pt}{1.5\baselineskip}% <- added to remove spurious space
  \multido{}{#2}{\noindent\makebox[\linewidth]{\rule{0pt}{#1\baselineskip}\dotfill}\\}}
\def\DashedPage{\newpage\DottedLines[2.5]{15}\newpage}

\makeatletter
% set initial contents for second pages and start it
% only to be called once!
\newcommand{\EverySecondPage}[1]{\gdef\@esp@content{#1}\@everysecondpage}
% to change the contents for second pages
\newcommand{\ChangeEverySecondPage}[1]{\gdef\@esp@content{#1}}
% suppress subsequent second pages
\newcommand{\NomoreEverySecondPage}{\global\let\@esp@content\relax}
% internal macro
\newcommand{\@everysecondpage}{\afterpage{\@esp@content\@everysecondpage}}
% necessary, otherwhise there will be two pages at the end
\AtEndDocument{\NomoreEverySecondPage}
\makeatother

\begin{document}
\EverySecondPage{\DashedPage}
\lipsum[1-12]

\ChangeEverySecondPage{\notespage[notesstyle=lines,vparts=25,titletext={Your comments:}]}
\lipsum[13-25]

\NomoreEverySecondPage
\begin{tcolorbox}[title=Just a test,breakable]
\lipsum[1-10]
\end{tcolorbox}

\ChangeEverySecondPage{\notespage[hparts=20,titletext={Your comments:}]}
\begin{tcolorbox}[title=And another test,breakable]
\lipsum[11-20]
\end{tcolorbox}
\end{document}

And this is the result:

enter image description here

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.