使用显示的数学公式抑制思维流环境中的分页符

使用显示的数学公式抑制思维流环境中的分页符

这是这个问题。使用,当其中只有纯文本时,环境\nowidow的分页功能可以正常工作:mindflow

\documentclass[mathlines]{article}
\usepackage[a4paper]{geometry}

\usepackage{mindflow}
\mindflowset{linenumber,rightmarker}

\usepackage{blindtext}

\begin{document}

\blindtext[5]

%% nowidow works fine
\begin{mindflow}
    \blindtext
    More text
\end{mindflow}

\end{document}

纯文本

但是,当环境以显示的方程式结束时,\nowidow似乎效果不佳。这是一个例子:

\documentclass[mathlines]{article}
\usepackage[a4paper]{geometry}

\usepackage{mindflow}
\mindflowset{linenumber,rightmarker}

\usepackage{blindtext}

\begin{document}

\blindtext[5]

%% Not working
\begin{mindflow}
    \blindtext
    \[a+b=c\]
    % More text
\end{mindflow}

\end{document}

显示数学

我该如何修复这个问题?


以下是 的当前版本mindflow.sty

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mindflow}
    [2021/05/25 mindflow environment]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
    family = @mindflow,
    prefix = @mindflow@
}
\DeclareBoolOption[true]{on}               % Turn on mindflow
\DeclareBoolOption[false]{off}             % Turn off mindflow
\DeclareBoolOption[false]{leftmarker}      % Left marker
\DeclareBoolOption[false]{rightmarker}     % Right marker
\DeclareBoolOption[false]{linenumber}      % Left line numbers
\DeclareBoolOption[false]{leftlinenumber}  % Left line numbers
\DeclareBoolOption[false]{rightlinenumber} % Right line numbers
\DeclareBoolOption[false]{twocolumn}       % Two column
\DeclareBoolOption[false]{incolumn}        % Separation line fits in column

\ProcessKeyvalOptions*\relax

\if@mindflow@on
  \@mindflow@offfalse
\fi
\if@mindflow@twocolumn
  \@mindflow@incolumntrue
\fi
\if@mindflow@linenumber
  \@mindflow@leftlinenumbertrue
\fi

%%================================
%% Initialization
%%================================
\RequirePackage{lineno}
\RequirePackage{xcolor}

\colorlet{mfSavedColor}{.}
\colorlet{mindflowLine}{mfSavedColor!30}
\colorlet{mindflowText}{mfSavedColor!30}
\colorlet{mindflowMarker}{mfSavedColor!30}
\colorlet{mindflowNum}{mfSavedColor!8}

\newcommand{\mindflowTextFont}{\footnotesize}
\newcommand{\mindflowNumFont}{\scriptsize\ttfamily}
\newcommand{\mindflowMarkerFont}{\scriptsize\ttfamily}
\newcommand{\mindflowLeft}{*}
\newcommand{\mindflowRight}{*}
\newlength{\mindflowLineHeight}
\setlength{\mindflowLineHeight}{0.4pt}

%%================================
%% The mindflow environment
%%================================
\RequirePackage{nowidow}
\RequirePackage{verbatim}
\newif\ifLNturnsON
\newcommand*{\mfSepLine}{%
  \parskip=0pt
  \nowidow[3]\par\nobreak%
  \LNturnsONfalse%
  \ifLineNumbers\LNturnsONtrue\fi\nolinenumbers%
  \vspace*{-.5\baselineskip}%
  \if@mindflow@incolumn%
    \makebox[\linewidth]{\color{mindflowLine}\rule{\linewidth}{\mindflowLineHeight}}%
  \else%
    \hspace*{-\paperwidth}%
    \makebox[\linewidth]{\color{mindflowLine}\rule{4\paperwidth}{\mindflowLineHeight}}%
  \fi%
  \nowidow[3]\par\nobreak%
  \ifLNturnsON\linenumbers\fi%
}

\newcounter{recordLN}
\newcounter{mfLN}
\setcounter{mfLN}{1}

\let\mindflowOFF=\comment
\let\endmindflowOFF=\endcomment

\def\mindflowON{%
  \medskip%
  \setcounter{recordLN}{\value{linenumber}}%
  \setcounter{linenumber}{\value{mfLN}}%
  \LNturnsONfalse%
  \ifLineNumbers\LNturnsONtrue\fi\nolinenumbers%
  \mfSepLine%
  \normalfont\mindflowTextFont\color{mindflowText}%
  \linenumbers%
  \renewcommand{\makeLineNumber}{%
    \hss%
    \if@mindflow@leftlinenumber%
      \normalfont\mindflowNumFont\color{mindflowNum}\LineNumber\hspace{1em}%
    \fi%
    \color{mindflowMarker}%
    \if@mindflow@leftmarker%
      \normalfont\mindflowMarkerFont\mindflowLeft\hspace{1em}%
    \fi%
    \rlap{\hskip\textwidth%
      \if@mindflow@rightmarker%
        \hspace{1em}\mindflowRight%
      \fi%
      \if@mindflow@rightlinenumber%
        \hspace{1em}%
        \normalfont\mindflowNumFont\color{mindflowNum}\LineNumber%
      \fi%
    }%
  }%
}
\def\endmindflowON{%
  \mfSepLine%
  \ifLNturnsON\linenumbers\fi%
  \setcounter{mfLN}{\value{linenumber}}%
  \setcounter{linenumber}{\value{recordLN}}%
  \medskip%
}

\if@mindflow@off
  \let\mindflow=\mindflowOFF
  \let\endmindflow=\endmindflowOFF
\else
  \let\mindflow=\mindflowON
  \let\endmindflow=\endmindflowON
\fi

%%================================
%% \mindflowset
%%================================
\define@key{mindflow}{on}[true]{%
  \csname @mindflow@on#1\endcsname%
  \if@mindflow@off%
    \let\mindflow=\mindflowOFF%
    \let\endmindflow=\endmindflowOFF%
  \else%
    \let\mindflow=\mindflowON%
    \let\endmindflow=\endmindflowON%
  \fi%
}
\define@key{mindflow}{off}[true]{%
  \csname @mindflow@off#1\endcsname%
  \if@mindflow@off%
    \let\mindflow=\mindflowOFF%
    \let\endmindflow=\endmindflowOFF%
  \else%
    \let\mindflow=\mindflowON%
    \let\endmindflow=\endmindflowON%
  \fi%
}
\define@key{mindflow}{leftmarker}[true]{\csname @mindflow@leftmarker#1\endcsname}
\define@key{mindflow}{rightmarker}[true]{\csname @mindflow@rightmarker#1\endcsname}
\define@key{mindflow}{linenumber}[true]{\csname @mindflow@linenumber#1\endcsname}
\define@key{mindflow}{leftlinenumber}[true]{\csname @mindflow@leftlinenumber#1\endcsname}
\define@key{mindflow}{rightlinenumber}[true]{\csname @mindflow@rightlinenumber#1\endcsname}
\define@key{mindflow}{twocolumn}[true]{\csname @mindflow@twocolumn#1\endcsname}
\define@key{mindflow}{incolumn}[true]{\csname @mindflow@incolumn#1\endcsname}
\define@key{mindflow}{linecolor}{\colorlet{mindflowLine}{#1}}
\define@key{mindflow}{textcolor}{\colorlet{mindflowText}{#1}}
\define@key{mindflow}{numcolor}{\colorlet{mindflowNum}{#1}}
\define@key{mindflow}{markercolor}{\colorlet{mindflowMarker}{#1}}
\define@key{mindflow}{textfont}{\renewcommand{\mindflowTextFont}{#1}}
\define@key{mindflow}{numfont}{\renewcommand{\mindflowNumFont}{#1}}
\define@key{mindflow}{markerfont}{\renewcommand{\mindflowMarkerFont}{#1}}
\define@key{mindflow}{left}{\renewcommand{\mindflowLeft}{#1}}
\define@key{mindflow}{right}{\renewcommand{\mindflowRight}{#1}}
\define@key{mindflow}{lineheight}{\setlength{\mindflowLineHeight}{#1}}
\newcommand{\mindflowset}[1]{%
  \setkeys{mindflow}{#1}%
  \if@mindflow@twocolumn%
    \@mindflow@incolumntrue%
  \fi%
  \if@mindflow@linenumber%
    \@mindflow@leftlinenumbertrue%
  \fi%
}

%%================================
%% lineno patch
%%================================
\ifdefined\linenomathpatch\else
  \RequirePackage{amsmath}
  \RequirePackage{etoolbox}
  \newcommand*\linenomathpatch[1]{%
    \cspreto{#1}{\linenomath}%
    \cspreto{#1*}{\linenomath}%
    \csappto{end#1}{\endlinenomath}%
    \csappto{end#1*}{\endlinenomath}%
  }
  \newcommand*\linenomathpatchAMS[1]{%
    \cspreto{#1}{\linenomathAMS}%
    \cspreto{#1*}{\linenomathAMS}%
    \csappto{end#1}{\endlinenomath}%
    \csappto{end#1*}{\endlinenomath}%
  }
  \expandafter\ifx\linenomath\linenomathWithnumbers
    \let\linenomathAMS\linenomathWithnumbers
    \patchcmd\linenomathAMS{\advance\postdisplaypenalty\linenopenalty}{}{}{}
  \else
    \let\linenomathAMS\linenomathNonumbers
  \fi
  \linenomathpatch{equation}
  \linenomathpatchAMS{gather}
  \linenomathpatchAMS{multline}
  \linenomathpatchAMS{align}
  \linenomathpatchAMS{alignat}
  \linenomathpatchAMS{flalign}
\fi
\endinput

答案1

你需要

\def\mindflowON{%
\postdisplaypenalty=10000
...

为了找到这个解决方案,我不得不重写一些代码以便更好地理解它(现在我认为它更容易理解,至少对我来说)。这个 MWE 包含修改后的文件mindflow.sty(当然有些方面需要改进/纠正,特别是\linenomath...我没有考虑到的宏。我仍然希望它会有用):

\begin{filecontents}[overwrite]{mindflow.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mindflow}
    [2021/05/25 mindflow environment]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
    family = @mindflow,
    prefix = @mindflow@
}
\DeclareBoolOption[true]{on}               % Turn on mindflow
\DeclareBoolOption[false]{off}             % Turn off mindflow
\DeclareBoolOption[false]{leftmarker}      % Left marker
\DeclareBoolOption[false]{rightmarker}     % Right marker
\DeclareBoolOption[false]{linenumber}      % Left line numbers
\DeclareBoolOption[false]{leftlinenumber}  % Left line numbers
\DeclareBoolOption[false]{rightlinenumber} % Right line numbers
\DeclareBoolOption[false]{twocolumn}       % Two column
\DeclareBoolOption[false]{incolumn}        % Separation line fits in column

\ProcessKeyvalOptions*\relax

\if@mindflow@twocolumn
  \@mindflow@incolumntrue
\fi
\if@mindflow@linenumber
  \@mindflow@leftlinenumbertrue
\fi

%%================================
%% Initialization
%%================================
\RequirePackage{lineno}
\RequirePackage{xcolor}

\colorlet{mfSavedColor}{.}
\colorlet{mindflowLine}{mfSavedColor!30}
\colorlet{mindflowText}{mfSavedColor!30}
\colorlet{mindflowMarker}{mfSavedColor!30}
\colorlet{mindflowNum}{mfSavedColor!8}

\newcommand{\mindflowTextFont}{\footnotesize}
\newcommand{\mindflowNumFont}{\scriptsize\ttfamily}
\newcommand{\mindflowMarkerFont}{\scriptsize\ttfamily}
\newcommand{\mindflowLeft}{*}
\newcommand{\mindflowRight}{*}
\newlength{\mindflowLineHeight}
\setlength{\mindflowLineHeight}{0.4pt}

%%================================
%% The mindflow environment
%%================================
\RequirePackage{nowidow}
\RequirePackage{verbatim}
\newcommand*{\mfSepLine}{%
  \if@mindflow@incolumn%
    \makebox[\linewidth]{\color{mindflowLine}\rule{\linewidth}{\mindflowLineHeight}}%
  \else%
    \hspace*{-\paperwidth}%
    \makebox[\linewidth]{\color{red}\rule{4\paperwidth}{\mindflowLineHeight}}%
  \fi%
}

\newcounter{recordLN}
\newcounter{mfLN}
\setcounter{mfLN}{1}

\if@mindflow@off
  \let\mindflow\comment
  \let\endmindflow\endcomment
\else
\newenvironment{mindflow}{
\postdisplaypenalty=10000
  \smallskip

  \parskip=0pt
  \setcounter{recordLN}{\value{linenumber}}%
  \setcounter{linenumber}{\value{mfLN}}%

  \par\nopagebreak\mfSepLine\smallskip

  \linenumbers
  \normalfont\mindflowTextFont\color{mindflowText}%
  \renewcommand{\makeLineNumber}{%
    \hss%
    \if@mindflow@leftlinenumber%
      \normalfont\mindflowNumFont\color{mindflowNum}\LineNumber\hspace{1em}%
    \fi%
    \color{mindflowMarker}%
    \if@mindflow@leftmarker%
      \normalfont\mindflowMarkerFont\mindflowLeft\hspace{1em}%
    \fi%
    \rlap{\hskip\textwidth%
      \if@mindflow@rightmarker%
        \hspace{1em}\mindflowRight%
      \fi%
      \if@mindflow@rightlinenumber%
        \hspace{1em}%
        \normalfont\mindflowNumFont\color{mindflowNum}\LineNumber%
      \fi%
    }%
  }%
}{\nowidow[3]%
  \par\nopagebreak\mfSepLine
  \nolinenumbers

  \setcounter{mfLN}{\value{linenumber}}%
  \setcounter{linenumber}{\value{recordLN}}%
  \medskip%
}
\fi

\newcommand{\mindflowset}[1]{%
  \setkeys{mindflow}{#1}%
  \if@mindflow@twocolumn%
    \@mindflow@incolumntrue%
  \fi%
  \if@mindflow@linenumber%
    \@mindflow@leftlinenumbertrue%
  \fi%
}

\define@key{mindflow}{leftmarker}[true]{\csname @mindflow@leftmarker#1\endcsname}
\define@key{mindflow}{rightmarker}[true]{\csname @mindflow@rightmarker#1\endcsname}
\define@key{mindflow}{linenumber}[true]{\csname @mindflow@linenumber#1\endcsname}
\define@key{mindflow}{leftlinenumber}[true]{\csname @mindflow@leftlinenumber#1\endcsname}
\define@key{mindflow}{rightlinenumber}[true]{\csname @mindflow@rightlinenumber#1\endcsname}
\define@key{mindflow}{twocolumn}[true]{\csname @mindflow@twocolumn#1\endcsname}
\define@key{mindflow}{incolumn}[true]{\csname @mindflow@incolumn#1\endcsname}
\define@key{mindflow}{linecolor}{\colorlet{mindflowLine}{#1}}
\define@key{mindflow}{textcolor}{\colorlet{mindflowText}{#1}}
\define@key{mindflow}{numcolor}{\colorlet{mindflowNum}{#1}}
\define@key{mindflow}{markercolor}{\colorlet{mindflowMarker}{#1}}
\define@key{mindflow}{textfont}{\renewcommand{\mindflowTextFont}{#1}}
\define@key{mindflow}{numfont}{\renewcommand{\mindflowNumFont}{#1}}
\define@key{mindflow}{markerfont}{\renewcommand{\mindflowMarkerFont}{#1}}
\define@key{mindflow}{left}{\renewcommand{\mindflowLeft}{#1}}
\define@key{mindflow}{right}{\renewcommand{\mindflowRight}{#1}}
\define@key{mindflow}{lineheight}{\setlength{\mindflowLineHeight}{#1}}

%%================================
%% lineno patch
%%================================
\ifdefined\linenomathpatch\else
  \RequirePackage{amsmath}
  \RequirePackage{etoolbox}
  \newcommand*\linenomathpatch[1]{%
    \cspreto{#1}{\linenomath}%
    \cspreto{#1*}{\linenomath}%
    \csappto{end#1}{\endlinenomath}%
    \csappto{end#1*}{\endlinenomath}%
  }
  \newcommand*\linenomathpatchAMS[1]{%
    \cspreto{#1}{\linenomathAMS}%
    \cspreto{#1*}{\linenomathAMS}%
    \csappto{end#1}{\endlinenomath}%
    \csappto{end#1*}{\endlinenomath}%
  }
  \expandafter\ifx\linenomath\linenomathWithnumbers
    \let\linenomathAMS\linenomathWithnumbers
    \patchcmd\linenomathAMS{\advance\postdisplaypenalty\linenopenalty}{}{}{}
  \else
    \let\linenomathAMS\linenomathNonumbers
  \fi
  \linenomathpatch{equation}
  \linenomathpatchAMS{gather}
  \linenomathpatchAMS{multline}
  \linenomathpatchAMS{align}
  \linenomathpatchAMS{alignat}
  \linenomathpatchAMS{flalign}
\fi
\endinput
\end{filecontents}


\documentclass[mathlines]{article}
\usepackage[a4paper]{geometry}

\usepackage[on]{mindflow}
\mindflowset{linenumber,rightmarker}

\usepackage{blindtext}

\begin{document}

\blindtext[5]

\begin{mindflow}
\blindtext
    \[a+b=c\]
    % More text
\end{mindflow}
\blindtext

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

\end{document}

在此处输入图片描述

相关内容