Pagination /
Pagination with raw CSS and Functional Javascript

This script produces a pdf-like paged document from basic HTML. For the prototype I decided to use the last draft of my ill-fated Masters thesis on the history of self-esteem. Some readers may find this content as or more interesting than the code itself. Special thanks to Timothy Verhoeven and Michael Hau for the feedback that helped shape this draft. It is available for viewing [here](, along with the [PDF](

Note: it should work best on Chrome, Chromium or Firefox. It is not written to work on Internet Explorer due to the browser's prehistoric Javascript support. It may however work with other browsers. There exists an issue where zooming can alter the distribution of text and push some text out of view, especially with older versions of Firefox. If this happens, hit F5 afterwards to re-render the pages. The text flow will still be altered, but there should be no missing text. Obviously then, for anyone wishing to cite the content, the page numbers cannot be relied on for consistency. Only the PDF is reliable.

The CSS standard has long covered the display of HTML on discrete pages like a book, but implementation of this feature has been lacking. The [PagedJS]( project has created a Javascript library to fill this gap. I studied this project in order to understand how the implementation works. I then developed a very different implementation from the perspective of functional programming. In doing so I adhered very closely to the wisdom of Luis Atencio's [Functional Programming in Javascript](, the book that sold me on the functional paradigm. This book and the PagedJS project are thus the two influences reflected in this code and warmly acknowledged.

The code mainly focuses on dividing the content across pages intelligently. I have taken great pains to prevent single lines, including headings, appearing in isolation at the tops and bottoms of pages. To my judgment, I have succeeded in making my history writing look almost as nice as the concise and declarative compositions and recursion-based machinery behind it.