54

I'd like to emulate HTML's infinite page height using LaTeX/XeTeX, i.e. have the PDF pages grow higher until a manual \newpage is issued.

This could be emulated by setting a very large page height and using pdfcrop on the output (or just setting the page height manually), but I'd like a pure TeX variant and if possible support for footnotes etc at the bottom of the cropped page.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
pascal
  • 2,122

4 Answers4

41

You could use the preview package for this. It's basically the "pure (La)TeX variant of pdfcrop" you are looking for. You need to set the text height to \maxdimen e.g. using geometry and wrap every page in \begin{preview} ... \end{preview}. To do this simply have a \begin{preview} after \begin{document}, a \end{preview} before \end{document} and define a \newpage variant as \end{preview}\begin{preview}. You will loose some of the border which can be readded using the \PreviewBorder macro. However, AFAIK this doesn't support header and footer.


Here now some example code. Apparently preview already takes care to suppress automatic page breaks and the modification of the text height is not required.

\documentclass{article}

\usepackage[active,tightpage]{preview}

\renewcommand{\PreviewBorder}{1in}

\newcommand{\Newpage}{\end{preview}\begin{preview}}

\usepackage{lipsum}
\begin{document}
\begin{preview}
\lipsum
\Newpage
\lipsum[1]
\Newpage
\lipsum[1-30]
\Newpage
\lipsum[4-22]
\end{preview}
\end{document}
Martin Scharrer
  • 262,582
11

Another ConTeXt solution. This takes care of footnotes, but you need to mark the start and stop of the page.

\definestartstop[infinite]
                [before={\startTEXpage
                         \setupfootnotedefinition[location=joinedup]%
                        \startlocalfootnotes},
                 after={\placelocalfootnotes
                         \stoplocalfootnotes
                         \stopTEXpage}]

\setupTEXpage[width=\textwidth, offset=2mm]

which can then be used as

\starttext
\startinfinite
\section {Some section}
\input knuth \footnote{A random footnote}
\input ward
\stopinfinite
\stoptext
Aditya
  • 62,301
6

Thanks for the replies, I'm using Martin's solution, from my class file:

\iftrue
  \usepackage[active,tightpage,psfixbb]{preview}
  \renewcommand{\PreviewBorder}{1cm}

  \newenvironment{stretchpage}%
    {\begin{preview}\begin{minipage}{\hsize}}%
    {\end{minipage}\end{preview}}
  \AtBeginDocument{\begin{stretchpage}}
  \AtEndDocument{\end{stretchpage}}

  \newcommand{\@@newpage}{\end{stretchpage}\begin{stretchpage}}

  \let\@real@section\section
  \renewcommand{\section}{\@@newpage\@real@section}
\fi

This works for me, if I would want to print the document, I can just disable the block.

pascal
  • 2,122
1

Martin's answer works well up to a limited size, but TeX has an upper limit on every length, including the page height. This limit is fairly small, equivalent to only around 20 sheets of letter paper placed end to end. To work around this limitation, I scaled everything in the document down by 40 times, then used pdfposter to scale it back up after compiling the document.

\newcommand{\pagescale}{0.025}  % 1/40

% Use these instead of the usual units. \newlength{\PT}\setlength{\PT}{\pagescale pt} \newlength{\IN}\setlength{\IN}{\pagescale in} \newlength{\CM}\setlength{\CM}{\pagescale cm} \newlength{\MM}\setlength{\MM}{\pagescale mm}

% LaTeX defaults are almost all defined using \p@, which is supposed to be 1pt. \makeatletter \setlength{\p@}{1\PT} \makeatother

% Reset separations that were coded with pt not \p@. \setlength{\jot}{3\PT} % Math display line separation. \scriptspace=0.5\PT \hfuzz=0.1\PT \vfuzz=0.1\PT \overfullrule=5\PT \maxdepth=4\PT \delimitershortfall=5\PT \nulldelimiterspace=1.2\PT \scriptspace=0.5\PT \parindent=20\PT \parskip=0\PT plus 1\PT \abovedisplayskip=12\PT plus 3\PT minus 9\PT \abovedisplayshortskip=0\PT plus 3\PT \belowdisplayskip=12\PT plus 3\PT minus 9\PT \belowdisplayshortskip=7\PT plus 3\PT minus 4\PT \topskip=10\PT \splittopskip=10\PT \parfillskip=0\PT plus 1fil \normalbaselineskip=12\PT \normallineskip=1\PT \normallineskiplimit=0\PT \smallskipamount=3\PT plus 1\PT minus 1\PT \medskipamount =6\PT plus 2\PT minus 2\PT \bigskipamount =12\PT plus 4\PT minus 4\PT \def\fontsubfuzz{.4\PT} \unitlength = 1\PT \fboxsep = 3\PT \fboxrule = .4\PT \let\Oldhrule\hrule \def\hrule{\Oldhrule height 0.4\PT} \let\Oldvrule\vrule \def\vrule{\Oldvrule width 0.4\PT}

\documentclass{article}

\renewcommand{\baselinestretch}{\pagescale}

\newcommand{\marginsize}{2\CM} \usepackage[paperwidth=8.5\IN,paperheight=16383pt,margin=\marginsize]{geometry}

\usepackage[active,tightpage]{preview} \renewcommand{\PreviewBorder}{\marginsize}

% No point in page numbers if there is only one page. \pagenumbering{gobble}

% Need to rerun math font definitions to get the sizes right. Loading amsfonts % is sufficient. \usepackage{amsfonts}

\usepackage{amsmath,lipsum} \begin{document}

\begin{preview} \begin{minipage}[b]{\textwidth} \LaTeX

$\int_0^1 x^2 dx = \frac13$. \footnote{A footnote}

\hrule height \PT width 100\PT

\begin{align} \int_{-\infty}^\infty e^{-x^2} dx &= \sqrt{\pi} \ z &= w \end{align}

\vrule height 100\PT

\lipsum

{\huge \lipsum

}

{\tiny \lipsum

}

% Very long example text, which couldn't fit on a single page at normal scale. \newcount\foo \foo=1000 \loop \lipsum[1]\par \advance \foo -1 \ifnum \foo>0 \repeat

\end{minipage} \end{preview} \end{document}

If you have floats then you likely want to follow Andy's advise and set \setcounter{totalnumber}{100}, so that LaTeX can put more of them on a page.

The following script uses pdfposter to scale the pdf back to its usual dimensions after it has been built.

#!/bin/bash

if [ $# -ne 3 ] then echo "Usage: $0 <scale factor> <input> <output>" exit 1 fi

scale=$1 newpagesize=$(pdfinfo "$2" | awk '/Page size:/ { print ('"$scale"' * $3) "x" ('"$scale"' * $5) "pt" }')

pdfposter "$2" -s "$scale" -m "$newpagesize" $3

qbt937
  • 111
  • 3