0

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:

output

How to properly™ extend or redefine the samepage environment such that we don't get a page break inside the remark?

0

1 Answer 1

1

etoolbox cannot patch commands defined using \DeclareRobustCommand. You can use package xpatch to append code to a robust command with \xapptocmd. Here you can see, that the patch is used:

\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{xpatch}
\makeatletter
\xapptocmd{\samepage}{\predisplaypenalty\@M}{}{\PatchFailure}
\makeatother
\usepackage{amssymb,mathtools,cleveref}
\begin{document}
\begin{samepage}
  \strut\vskip120ex
  \begin{remark}[A remark name]\label[remark]{label}
    \verb|\predisplaypenalty| is \the\predisplaypenalty
    \[
      \text{a formula}
    \]
    \begin{center}%
      A table\\%%% 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}

\predisplaypenatly is 10000

But if you have a look at the whole thing, you can also see, that this does not prevent the page break after the remark head:

unwanted page break after remark head

And even, if you mode the \begin{samepage} after \strut\vskip120ex you would get the same result

So the root of your problem is not the \predisplaypentalty. If you really don't want a page break inside a remark, I would suggest to use a minipage:

\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{amssymb,mathtools,cleveref}
\begin{document}
  \strut\vskip120ex
\noindent\begin{minipage}{\textwidth}
  \begin{remark}[A remark name]\label[remark]{label}
    \[
      \text{a formula}
    \]
    \begin{center}%
      A table\\%%% 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{minipage}
\end{document}

If you only not want a page break at the beginning of the remark, use package needspace.

3
  • Thx! Any idea why we still get a page break inside the samepage environment after your change?
    – AlMa0
    Mar 21 at 18:58
  • @AlMa0 samepage is more a kind of: “prevent implicit page breaks, if possible” and not “prevent all kind of page breaks”, because it does not prevent explicitly allowed page breaks. So using samepage to prevent all kind of page breaks is simply wrong. You have to inspect the definition of remark in svmono to find out, why and where it allows page breaks, e.g., because of using \item inside a trivlist or adding vertical space. In other words: You can use a knife to remove screws, but will not always succeed. The proper screwdriver is the better tool.
    – cabohah
    Mar 22 at 8:08
  • I see. The class svmono.cls defines remark via \spn@wtheorem, which I mostly don't understand :-(.
    – AlMa0
    Mar 22 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .