# Insert something when *not* before a page break

I've tried to find a solution but obviously the right search phrases escape me ...

I need to insert something into the document which will be suppressed if it would be followed by a page break.

For some context: I'm inserting a list of images and need a graphical separator. But that separator should not be printed at page breaks. The result should be something like:

-----------
| Image 1 |
-----------
=
-----------
| Image 2 |
-----------
---pagebreak---
-----------
| Image 3 |
-----------
=
-----------
| Image 4 |
-----------


(with = being the visual separator, could be a \hrule for example).

If it makes a difference: This is done using Lua, so I can write something with tex.print() that will be suppressed by TeX, or if I can detect that state while in Lua (well, AFAICS this is less likely) I could decide what to "print" into the document.

• What have you tried so far? Can you add a MWE with some dummy images and separators? – Marcel Krüger Jun 4 at 15:44
• I haven't tried anything so far because I wasn't able to find anything that looks like conditional insert based on a pagebreak. – uli_1973 Jun 4 at 16:01
• Then just e.g. add some code which always uses the separator. Otherwise everyone who wants to answer has to create a document from scratch just to test their answer. This would most likely lead to less answers. – Marcel Krüger Jun 4 at 16:13
• Fair point. I'll do so next time. – uli_1973 Jun 5 at 7:33

You can use leaders, which are discarded at a break, like glue.

\documentclass{article}

\usepackage{graphicx}

\setbox0\centerline{$\sim$ $\sim$ $\sim$ $\sim$}

\def\sep{%
\par
\bigskip
\bigskip}

\begin{document}

\centering

\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}
\sep
\includegraphics[height=.2\textheight]{example-image}

\end{document}

• @MarcelKrüger yes 2 was a bit of a kludge anyway, I'll adjust thanks – David Carlisle Jun 4 at 17:24
• @MarcelKrüger updated thanks – David Carlisle Jun 4 at 17:26
• Nice idea. Shouldn't a \newsavebox be used instead of \box0? I mean, what guarantees that \box0 won't get modified by the document text, or even by \includegraphics (without any knowledge of its implementation)? I guess the answer is something like “this was a proof of concept and I know by heart everything that \includegraphics does, so you can trust me it won't fiddle with your beloved \box0”; however, I prefer asking in case I missed something important. Thanks. :-) – frougon Jun 4 at 22:30
• @frougon your assessment is about right:-) – David Carlisle Jun 4 at 22:41
• @DavidCarlisle Thanks. I see the concept, but I seem unable to find documentation about the use of \cleaders (or \leaders). Even the documentation referenced from latex-project.org/help/documentation doesn't include anything. Only latex-project.org/help/documentation/source2e.pdf includes three instances of \cleaders in use, but these are not more helpful than your solution. – uli_1973 Jun 5 at 7:40