abenori / jlreq

Other
125 stars 18 forks source link

\color after headings allow page break #102

Open minamotorin opened 2 years ago

minamotorin commented 2 years ago

If there are \color immediately after headings, page breaks are not prohibited.

This happens with both (u)pLaTeX and LuaLaTeX. I couldn't find version of jlreq which doesn't cause this problem.

% This program is in the public domain.
%<jlreq>\documentclass{jlreq}
%<classes>\documentclass{article}
\usepackage{color}
\begin{document}
\makeatletter
\@tempcnta\z@
%<jlreq>\@whilenum\@tempcnta<34\do{
%<classes>\@whilenum\@tempcnta<42\do{
  aaaaa\par
  \advance\@tempcnta\@ne
}
\makeatother

\section{bbbbb}

\color{black}

ccccc

\end{document}

The cause seems to be that \special (same for \write) allows page break there. In classes or jclasses, inserting \addpenalty{-300} solves this and \color immediately after headings are no problem. However, in jsclasses or jlreq, \addpenalty doesn't solve this. I don't know why.

% This program is in the public domain.
%<jsclasses>\documentclass{jsarticle}
%<jclasses>\documentclass{jarticle}
%<classes>\documentclass{article}
\begin{document}
\makeatletter
\@tempcnta\z@
%<jsclasses>\@whilenum\@tempcnta<39\do{
%<jclasses>\@whilenum\@tempcnta<38\do{
%<classes>\@whilenum\@tempcnta<45\do{
  aaaaa\par
  \advance\@tempcnta\@ne
}
\makeatother

\addpenalty{-300}

bbbbb

\nopagebreak

\write16{ccccc}

ddddd

\end{document}

Thanks.

abenori commented 2 years ago

As one can see the following example, it is possible to have a break after \section with article class.

%#!uplatex
\documentclass[dvipdfmx]{article}
\usepackage[vmargin=0pt,hmargin=0pt,paperwidth=50pt,paperheight=55pt]{geometry}
\usepackage{color}
\begin{document}
aaaaa
\section{bbbbb}
\color{black}
ccccc
\end{document}

Above results is a consequence of the TeX's (complicated) calculation to determine the position of page break. I'll try to use the same penalties as article class around \section etc.