0

The mindflow environment provided by the package "mindflow" wraps text in two wide lines \mfSepLine, which is defined by

\newcommand*{\mfSepLine}{%
  \parskip=0pt
  \LNturnsONfalse%
  \ifLineNumbers\LNturnsONtrue\fi\nolinenumbers%
  \par\noindent\nopagebreak%
  \if@mindflow@incolumn%
    \makebox[\linewidth]{\rule{\linewidth}{\mindflowLineHeight}}%
  \else%
    \hspace*{-\paperwidth}%
    \makebox[\linewidth]{\rule{4\paperwidth}{\mindflowLineHeight}}%
  \fi%
  \nopagebreak\par%
  \ifLNturnsON\linenumbers\fi%
}

However, even with two \nopagebreaks before and after the line, sometimes the separation line is still located on a new page. Below is an example when the second separation line is on the next page alone:

\documentclass{article}

\usepackage[a4paper]{geometry} \usepackage{mindflow} \usepackage{blindtext}

\begin{document}

\blindtext[5] \begin{mindflow} \blindtext More text % \nopagebreak \end{mindflow}

\end{document}

which produces:

enter image description here

How should I fix this behavior?

By the way, is it possible to make sure that there are at least two lines of text with this separation line when it is near the page break?

Jinwen
  • 8,518
  • I edited my answer below due to a mistake I didn't notice. And I have simplified the code. – Ivan May 25 '21 at 10:15
  • @Ivan Would you mind having a look at this question: https://tex.stackexchange.com/q/598440/194994? BTW, I didn't place \break and \nowidow in the same place of yours (I inserted them in \mfSepLine instead of \endmindflow), so if there's any error then the fault is on me. – Jinwen May 25 '21 at 10:20

1 Answers1

1

You have to add two \nobreak and one \widowpenalty10000 in the mindflow environment. At least, this is my attempt to solve the problem. You can redefine the environment directly:

\makeatletter
\renewcommand{\endmindflow}{%
  \widowpenalty10000%<---MODIFIED
  \par\nobreak%<---MODIFIED
    \vspace{-.5\baselineskip}\color{mindflowLine}\nobreak\mfSepLine%<---MODIFIED
    \ifLNturnsON\linenumbers\fi%
    \setcounter{mfLN}{\value{linenumber}}%
    \setcounter{linenumber}{\value{recordLN}}%
}
\makeatother

or using etoolbox, like in the following MWE :

\documentclass{article}

\usepackage[a4paper]{geometry} \usepackage{mindflow} \usepackage{blindtext}

\usepackage{etoolbox} \patchcmd{\endmindflow} {\par\vspace{-.5\baselineskip}\color{mindflowLine}\mfSepLine} {\widowpenalty10000 \par\nobreak\vspace{-.5\baselineskip}\color{mindflowLine}\nobreak\mfSepLine} {} {}

\begin{document}

\blindtext[5] \begin{mindflow} \blindtext More text% \end{mindflow}

\end{document}

If you prefer, you can load the nowidow package and replace \widowpenalty10000 with \nowidow[2]. The advantage is that if you want to keep three lines together instead of two it will be enough: \nowidow[3].

enter image description here

Ivan
  • 4,368