# Indirect control of behavior: how do I lengthen some pages and not others?

I'd like to be able to control the behavior of latex indirectly. Let me try to explain what I mean. I've got a large document, generated by a program. We can assume that each page (or page group) includes \oversize{12} or \oversize{22}, or something similar, where the 12 and 22 are section indicators, and \oversize is a macro I'll be writing. My goal is for \oversize to do nothing in general, but to evaluate to \enlargethispage{3\baselineskip} in special cases.

I'd like to describe these special cases in either a text file, which might look like

5
37
289


to indicate that for those particular pages, I need to enlarge the page, or might look like \newcommand{\bigpages}{5 37 289} or something like that.

The key thing is to be able to indicate which pages/page-groups need enlarging in some way AFTER the latex file has been produced. (The preamble of the produced latex document can input or include the relevant list of pages.)

I don't understand enough of TeX/LaTeX as a programming language to know what kinds of constructs are available for this. In most languages, I'd do something silly like make an array or list of page-groups that need fixing, and if the argument to \oversize appeared in the list, I'd emit the \enlargethispage command, and otherwise would emit nothing.

We're talking here about a 500 page document in which something like 8 pages are going to be enlarged, so a O(nk) solution, where n is the number of pages and k is the number of enlargements, is totally OK. Can someone point me in the right direction?

• Something like \usepackage{xstring} \usepackage{everypage} \newcommand{\bigpages}{ 5 37 289 } \AddEverypageHook{% \IfSubStr{\bigpages}{ \thepage\space}{\enlargethispage{3\baselineskip}}{}% } almost works. It correctly sees which page to enlarge. But it doesn't actually enlarge the page. – Teepeemm Jul 7 at 4:06

The package xstring is actually enough to solve the problem. A minimal example for the solution is

\documentclass{scrartcl}
\usepackage{xstring}
\usepackage{lipsum}

\newcommand{\oversize}[1]{%
\IfSubStr{\bigpages}{\space#1\space}{
% if part
\enlargethispage{3\baselineskip}
}{
% else part
}
}

\newcommand{\bigpages}{ 1 3 }

\begin{document}
\oversize{1}
\lipsum[1-6]
\newpage

\oversize{2}
\lipsum[1-6]
\newpage

\oversize{3}
\lipsum[1-6]

\end{document}


On compiling this example, one sees that pages 1 and 5 are enlarged because the corresponding marks are given in \bigpages while page 3 is not.

Here's a somewhat fancied-up version of the same thing, allowing one to say how MUCH to expand each page by. It clearly owes a great deal to @MHvM's answer, but I thought that the very basic key-value pair decoding might help someone in the future.

\documentclass{scrartcl}
\usepackage{xstring}
\usepackage{lipsum}

% Define "pageexpansions" here: for each page-header % identifier, % n, write n:k,
% surrounded by spaces, to indicate that the page headed
% by person n should be lengthened by k lines. The following,
% for instance, says that item 1 should be lengthened by 4
% lines; item 3 by 4 lines, and item 4 by 2 lines.

\newcommand{\pageexpansions}{ 1:4 3:4 4:2 }
\newcommand{\optionalexpand}[1]{%
\IfSubStr{\pageexpansions}{\space#1:}{
% if part
\StrCut{\pageexpansions}{\space#1:}\csA\csB
\StrCut{\csB}{\space}\crA\crB
\enlargethispage{\crA\baselineskip}
}{
% else part
}
}
\begin{document}

\optionalexpand{1}
\lipsum[1-6]
\newpage

\optionalexpand{2}
\lipsum[1-6]
\newpage

\optionalexpand{3}
\lipsum[1-6]
\newpage

\end{document}