Continuing Why doesn't \samepage set \predisplaypenalty (to \@M or any other value)? , let's say we wish to patch LaTeX's
\DeclareRobustCommand\samepage{\interlinepenalty\@M
\postdisplaypenalty\@M
\interdisplaylinepenalty\@M
\@beginparpenalty\@M
\@endparpenalty\@M
\@itempenalty\@M
\@secpenalty\@M
\interfootnotelinepenalty\@M}
by means of adding \predisplaypenalty\@M
somewhere (e.g., because your classes or packages (say, svmono.cls) set \predisplaypenalty
to a value less than \@M
.)
We do not plan to use \samepage
directly but rather \begin{samepage}…\end{samepage}
Which way to go?
My attempts have failed so far. Here's one example of failure:
\documentclass{svmono}% version 5.10 (08-Sep-21); cf. http://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation#toc-49268 or http://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs
% at this spot we wish to redefine the samepage environment, but this one doesn't work:
\usepackage{etoolbox}
\makeatletter
\patchcmd{\samepage}{\interfootnotelinepenalty\@M}{\interfootnotelinepenalty\@M\predisplaypenalty\@M}{}{\typeout{samepage could not be redefined}}
\makeatother
\usepackage{amssymb,mathtools,cleveref}
\begin{document}
\begin{samepage}
\strut\vskip120ex
\begin{remark}[A remark name]\label[remark]{label}
\[
\text{a formula}
\]
\begin{center}%
Table caption\\%%% probably better \nopagebreak\\ instead of \\, but anyway, samepage should better do all the job itself.
\hbox to \hsize{\hfill
\begin{tabular}[b]{|c|}
\hline
Some table\\
\hline
\end{tabular}%
\hfill\llap{$\square$}}%
\end{center}%
\end{remark}%
\end{samepage}
\end{document}
yields
samepage could not be redefined
in the log and a page break in the remark:
How to properly™ extend or redefine the samepage
environment such that we don't get a page break inside the remark?