1

I am taking inspiration from this post to set raggedbottom to only the content of an environment and not the other parts of the document (in a book). However, it seems that the afterpage command and/or usage of global variables does not work as I intend it to in an environment. In the MWE below, you'll see that the text "extbottomexttop" is printed to the second page so it seems that @textbottom is not read successfully. I tried using \@{textbottom} instead (which I know from other programming languages) but that did not help either.

\documentclass{book}

\usepackage{afterpage} \usepackage{lipsum} \newenvironment{chaptertitlepage}{ \raggedbottom }{% \makeatletter \afterpage{\global\let@textbottom\relax \global\let@texttop\relax} \pagebreak }

\begin{document}

\begin{chaptertitlepage} \chapter{First chapter starts here} It contains information about authors and an abstract which should all fit on the first page. \lipsum[1-2] \end{chaptertitlepage}

\section{Introduction} The other text follows after

\lipsum[3-5]

\end{document}

2 Answers2

1

The code in the question uses command names with @ in the name:

\newenvironment{chaptertitlepage}{
    \raggedbottom
}{%
    \makeatletter
    \afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}
    \pagebreak
}

The code \newenvironment{...}{...}{...} is parsed immediately, but \makeatletter is executed at a later time, when the environment will be executed. But then, the code is already parsed: \@, 't', 'e', ...

Use \makeatletter earlier during the definition of the environment:

\makeatletter
\newenvironment{chaptertitlepage}{%
    \raggedbottom
}{%
    \afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}%
    \pagebreak
}
\makeatother
Heiko Oberdiek
  • 271,626
0

It seems that you want to force a short (ragged) page break after the environment, so it is enough to call \clearpage

\documentclass{book}

\usepackage{lipsum} \newenvironment{chaptertitlepage}{\clearpage}{\clearpage}

\begin{document}

\begin{chaptertitlepage} \chapter{First chapter starts here} It contains information about authors and an abstract which should all fit on the first page. \lipsum[1-2] \end{chaptertitlepage}

\section{Introduction} The other text follows after

\lipsum[3-5]

\end{document}

enter image description here

David Carlisle
  • 757,742
  • Thanks, this seems the cleanest solution. Could you explain how that works? What does the processor do when it encouters \clearpage which then leads to not being stretched vertically? – Bram Vanroy Jan 18 '21 at 16:32
  • 1
    @BramVanroy i\clearpage or \newpage is a forced page break and leaves the page short just as \\ or \newline are a forced line break that leaves the line short. Conversely \pagebreak is like \linebreak and would force a page but not do anything special with the page so would be justified page or line if that is the current setting. – David Carlisle Jan 18 '21 at 16:36