Easy fix:
\documentclass[12pt]{article}
\usepackage{pdfpages}
\usepackage{tikz}
\begin{document}
\includepdf[pages=-,pagecommand={\begin{tikzpicture}[remember picture, overlay]
\node at (0.5, 1) {overlayed text};
\end{tikzpicture}}]{filename}
\end{document}
I would suggest using the background
package and a little trickery. The following defines a new command \installbackgrounds[]{}
. The first argument is optional and sets the total number of pages in the file of backgrounds. The second, mandatory argument specifies the file. If no total is specified, the number defaults to 1
.
\documentclass[a4paper]{report}
\usepackage{graphicx}
\usepackage{background, etoolbox, kantlipsum}
\newcounter{mypagebackground}
\setcounter{mypagebackground}{0}
\newcounter{mypagebackgroundpages}
\setcounter{mypagebackgroundpages}{0}
\newcommand*\myinstallbackground[1]{\relax}
\newcommand*\installbackgrounds[2][1]{%
\setcounter{mypagebackground}{0}%
\setcounter{mypagebackgroundpages}{#1}%
\gdef\mybackgroundfile{#2}%
}
\AddEverypageHook{\stepcounter{mypagebackground}}
\backgroundsetup{%
contents={%
\AddEverypageHook{% adapted from pp. 6-7 of background manual
\ifnumless{\value{mypagebackgroundpages}}{\value{mypagebackground}}{}{%
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.center) {\includegraphics[page=\themypagebackground]{\mybackgroundfile}};
\end{tikzpicture}}%
}%
}%
}
\begin{document}
\kant[1-5]
\installbackgrounds[7]{mypages.pdf}
\kant[1-30]
\installbackgrounds{example-image-a.pdf}
\kant[1-5]
\end{document}
mypages.pdf
is a PDF consisting of 7 pages, one for each colour of the rainbow.

EDIT: Looping Effects
This a response to the discussion in comments. It is not an answer. It is intended to help understand what is going on. Run this code and compare the different effects.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \i in {10,20,...,100}
\node [minimum width=\i mm, minimum height=\i mm, draw=red!\i] at (current page.center) {};
\end{tikzpicture}
\clearpage
\foreach \i in {10,20,...,100}{%
\begin{tikzpicture}[remember picture, overlay]
\node [minimum width=\i mm, minimum height=\i mm, draw=blue!\i] at (current page.center) {};
\end{tikzpicture}}
Some text on this page.
\clearpage
\foreach \i in {10,20,...,100}{%
\begin{tikzpicture}
\node [minimum width=\i mm, minimum height=\i mm, draw=green!\i] at (current page.center) {};
\end{tikzpicture}}
\foreach \i in {10,20,...,100}{%
\begin{tikzpicture}
\node [minimum width=\i mm, minimum height=\i mm, draw=orange!\i] {};
\end{tikzpicture}
Some text on page \thepage.
\clearpage}
\end{document}

Notice that the first orange square is on the page with the green squares because there is no \clearpage
after the final green square (which is well off the page).
Best Answer
Here are a couple of suggestions:
When using
pdfpages
each included page will be scaled from the source document -completenotes310pages.pdf
in your case - to the destination document<jobname>.pdf
unless you specify thenoautoscale
key. Even if you do not specify this, or if the pages you're importing are of the exact size that you're currently working on, once a page is full, LaTeX will ship it out, and move on to the following page. This is the case with the MWE, even though you had hopedhello
would be printed on page 1. This leads to the following suggestion...You will have to include the pages on an as-needed basis in order to "pause" LaTeX momentarily and add content to the page. For example, you may have a document sequence that looks like this:
where
<some stuff>
and<some more stuff>
detail your mathematical addition.If the original document is NOT typeset in LaTeX, and it has whitespace that is actually a picture, you may have to typeset the page in the background, before overlaying it with LaTeX mathematics. For this, I would suggest using the
everyshi
package that provides\AtNextShipout{...}
or theeso-pic
package command\AddToShipoutBG{...}
. Actually, I think the latter option would work better in this case. And you could switch to using the foreground or background options...FG
or...BG
depending on whether you're placing the math content or the page.Here is a practical example illustrating some of the suggestions above:
Consider the following source document, called
source.tex
and outputsource.pdf
:You'll notice the gap that requires some filling. This is how I would do it: