# Adding a cost of extra pages / forcing a page limit

TeX creates a document by solving an optimization problem, where different spacings etc. are assigned different costs, or "badness".

All writers of papers, especially for conferences proceedings have to battle with page limits. Right now it is very late and my coauthor removed a sentence, only to have the document grow beyond the page limit because TeX rearranged some figures.

Is it possible to assign an infinite "badness" to using more than a set number of pages? (I am not looking for a solution for this particular deadline, we'll solve our problem anyway)

-

## 1 Answer

It is not possible, TeX's page building algorithm optimizes the output page by page, i.e, when TeX is happy that the page text is optimized it ships it out. It is not affected by the total number of pages. Optimizing over the full source requires a tremendous amount of iteration and memory and currently there is no typesetting program that does that. (See An explanation of LaTeX's output routine for some more information)

-
It might be possible though to do it on several runs of LaTeX, automatically increasing the page size (or decreasing the size of blank spaces, etc?) if needed. The thing is, I don't know exactly where space can be gained. If anyone can help me on that, I can write the rest.something. –  Bruno Le Floch Mar 10 '11 at 10:15
Thank you for your answer. However, there must be some inter-page optimization going on, since TeX avoids pages with a single line (doesn't it?). –  Ben Mar 10 '11 at 12:08
TeX always process a complete paragraph and then decide if and where to insert a page break. That's why it can avoid widows/orphans. (It only means that you can perhaps shorten the number of pages by allowing widows/orphans. You can also try \enlargethispage to enlarge the page, and \looseness=-1 to try to shorten a paragraph.) –  Ulrike Fischer Mar 10 '11 at 12:46
@Ben @Bruno Le Floch There is no such thing as an interpage optimization, but rather a breakpoint optimization. (See books.google.com.qa/…) –  Yiannis Lazarides Mar 10 '11 at 13:38
@Yiannis: I don't think you're right with "currently there is no typesetting program that does that." From the Lout FAQ: "Lout uses Knuth's (the author of TeX, on which LaTeX is based) optimal line breaking algorithm, and has extended it to paragraph breaking across pages." –  Hendrik Vogt Mar 10 '11 at 15:06