1

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.

uli_1973
  • 1,920

1 Answers1

3

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

enter image description here

\documentclass{article}

\usepackage{graphicx}

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

\def\sep{%
\par
\bigskip
\cleaders\copy0\vskip\dimexpr\ht0+\dp0\relax
\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}
David Carlisle
  • 757,742
  • @MarcelKrüger yes 2 was a bit of a kludge anyway, I'll adjust thanks – David Carlisle Jun 04 '19 at 17:24
  • @MarcelKrüger updated thanks – David Carlisle Jun 04 '19 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 04 '19 at 22:30
  • 1
    @frougon your assessment is about right:-) – David Carlisle Jun 04 '19 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 https://www.latex-project.org/help/documentation doesn't include anything. Only https://www.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 05 '19 at 07:40
  • @uli_1973 it is a tex primitive so the texbook is the main documentation (or I guess the free tex-by-topic book will say something), or search for examples on this site. The usual use of leaders are in horizontal mode to make dots in tables of contents (which is where the name comes from) this vertical mode use is a bit non standard but there are examples around, I'll see if I can see another to link to – David Carlisle Jun 05 '19 at 07:48