1

Sometimes a discussion on a figure spills over several pages and I want to insert a copy of the figure on every even numbered page while the discusses continues.

There was a closely related question on this (inserting an image after every page) but there the required effect was to set a picture in the preample and insert it on every even numbered page throughout the document. Whereas I want to do this insertion on demand and for different figures, i.e. I need a macro which tells which figure to include on even numbered pages until I issue another macro saying that the insertion now must end.

My MWE follows but there I only expressed what I am after. I don't have the faintest idea about how to proceed.

Any suggestions?

\documentclass[12pt]{amsbook}
\usepackage{mwe,lipsum}
\begin{document}
\includegraphics[width=0.5\textwidth]{example-image-a}
%
% Now I want "example-image-a", or  a re-scaled smaller version, to be inserted at the beginning of every even numbered page until the end of \lipsum or until I say so.
%
%

\lipsum[1-18]
%

\includegraphics[width=0.5\textwidth]{example-image-b}
%
% Now I want "example-image-b", or a re-scaled smaller version, to be inserted at the beginning of every even numbered page until the end of \lipsum or until I say so.
%
%

\lipsum
%
\end{document} 
1

If you are happy with the solution you are referring to except for the features you mentioned, there is a simple fix: make the pictures macros, which you adjust.

\documentclass{article}
\usepackage{afterpage,everypage}
\usepackage{mwe,lipsum}
\AddEverypageHook{%
\ifodd\value{page}
\OddPicture%
\else%
\EvenPicture%
\fi}
\afterpage{\includegraphics{example-image-a}}  %  why this is necessary?
\newcommand{\OddPicture}{}
\newcommand{\EvenPicture}{\afterpage{\includegraphics{example-image-a}}}
\newcommand{\StopPictures}{%
\renewcommand{\OddPicture}{}
\renewcommand{\EvenPicture}{}
}
\begin{document}
\lipsum[1-18]

\StopPictures
\lipsum
\renewcommand{\OddPicture}{\afterpage{\includegraphics{example-image-b}}}
\renewcommand{\EvenPicture}{}


\lipsum

\lipsum

\StopPictures
\lipsum
\end{document}

This snippet leads to a document that has example-image-a on even pages for a while and then switches to example-image-b on odd pages.

  • Sorry but this is not what I need. I need a macro with an argument, as I explained in my short MWE, say \EvenPage{graph1} which will then add graph1 on every even page after the page on which it is issued. Then another macro say \StopEvenPage{graph1} which will relieve LaTeX from this task. – Sinan Sertoz Apr 14 '18 at 17:10
  • @SinanSertoz Sorry? You just need to do \renewcommand{\OddPicture}{} \renewcommand{\EvenPicture}{} whenever you want to stop the figures. This is in my eample. Of course you could define \newcommand{\StopFigures}{\renewcommand{\OddPicture}{} \renewcommand{\EvenPicture}{}}. – user121799 Apr 14 '18 at 17:13
  • When I run your code, the text ends on page 12 of the output but LaTeX adds another page and puts example-image-b on top of that image as if the text has spilled over to page 13. When I play with the amount of \lipsum used for example-image-a I observe similar behavior: LaTeX simply won't stop inserting these images when asked to stop. – Sinan Sertoz Apr 14 '18 at 22:23
  • @SinanSertoz OK, I made things now even more explicit. The only point of my answer was that you can simply renew the contents of the pictures during the text. Of course, if you want no pictures, then you need tell TeX that. For your convenience, I added a macro \StopPictures for that purpose. – user121799 Apr 14 '18 at 22:41
  • Please run your code and observe that \StopPictures does not stop pictures. LaTeX puts one more picture to the designated page after the command and then stops. This is what I mentioned in my previous comment and this is where I am seeking help. – Sinan Sertoz Apr 15 '18 at 9:53
0

After reading from the everypage package that "... once hooks are stacked, there is no way to unstack them, nor to clear them. ... conditionals must be included in the hook" I came up with the following solution:

\documentclass[12pt]{amsbook}
\usepackage{afterpage,everypage}
\usepackage{mwe,lipsum}
\usepackage{sidenotes}

\usepackage[dvipsnames]{xcolor} % For this example only

\AddEverypageHook{%
\ifodd\value{page}
\else%
\EvenPicture%
\fi}

\newcommand{\Picture}{}
\newcommand{\EmptyPicture}{}
\newcounter{permission}
\setcounter{permission}{0}

\afterpage{\ifnum\value{permission}=1%
 \begin{center}%
 {\includegraphics[width=0.5\textwidth]{\Picture}}
 \end{center}%
 \else\EmptyPicture\fi}
% This is needed for the first time \EvenPicture is called

\newcommand{\EvenPicture}{{\afterpage{\ifnum\value{permission}=1%
 \begin{center}%
 {\includegraphics[width=0.5\textwidth]{\Picture}}%
 \end{center}%
 \else\EmptyPicture\fi}}}

\newcommand{\StartPicture}[1]{%
 \renewcommand{\Picture}{#1}%
 \begin{center}\includegraphics{#1}\end{center}%
 \setcounter{permission}{1}%
}

\newcommand{\StopPicture}{\setcounter{permission}{0}}

\begin{document}
\lipsum[1-3]

\StartPicture{example-image-a}

\lipsum[2-13]

\StopPicture
\textcolor{red}{We terminate figure A here}

\textcolor{green}{Now we start figure B}

\StartPicture{example-image-b}

\lipsum[3-19]

\StopPicture
\textcolor{red}{We terminate figure B here}

\lipsum[1]

\textcolor{green}{Now we start figure C}

\StartPicture{example-image-c}


\lipsum[4-11]


\StopPicture
\textcolor{red}{We terminate figure C here}

\lipsum[5-15]

\end{document}

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.