1

I need to \include data from several different files, showing the contents of each file on a separate page (e.g. file1.tex on page 1, file2.tex on page 2), but cut off any extra data if the contents of the files does not fit into just one page.

I have a simple ConTeXt document like this:

\starttext
    \subject{File 1}
        \startitemize[n]
            \input file1
        \stopitemize
    \pagebreak
    \subject{File 2}
        \startitemize[n]
            \input file2
        \stopitemize
    \pagebreak
    \subject{File 3}
        \startitemize[n]
            \input file3
        \stopitemize
     ...
\stoptext

Each file contains items, with \item in front of each line. For simplicity, here is a sample contents of file1.tex (and the same in the other files):

\dorecurse{100}{\item hello}

Normally, ConTeXt will include the file, and then wrap the next items to the next page. In the example above, it gets to item #23, then puts #23-100 on later pages. If item #23 was a longer paragraph, split between pages, it should cut off at #22 (never splitting an item up).

The contents of the included files is automatically generated data, but I only want as much that fits to appear on the page, any extra data is too much data and is to be thrown away and doesn't need to be reported.

How can I get ConTeXt to just stop at item #23, the last item to fit on the first page, and stop including the rest of the document, and just to go to the next page?

  • I don't know ConTeXt, so I don't know if this will work, but one way in pdfTeX would be to have a separate document with only file1.tex, and then use pdfpages to only include the first page of that document. But that would be an extra compilation step. – Teepeemm May 3 at 2:20
3

In this solution I just box everything between \start...\stopclippage into a \vbox. Then I calculate the remaining space on the page at this point, which is \pagegoal-\pagetotal. The boxed content is split to that height and the split-off box is discarded. Finally the box is flushed. If you want to allow for some vertical stretch and shrink, use \unvbox instead of \box.

I don't think this will interact well with grid.

\unexpanded\def\startclippage{\par\setbox\scratchbox=\vbox\bgroup}
\unexpanded\def\stopclippage
    {\egroup
     \scratchdimen=\dimexpr\pagegoal-\pagetotal\relax
     \setbox\scratchbox=\vsplit\scratchbox to \scratchdimen
     \box\scratchbox}

\starttext
    \subject{File 1}
    \startclippage
        \startitemize[n]
            \input file1
        \stopitemize
    \stopclippage
    \pagebreak
    \subject{File 2}
    \startclippage
        \startitemize[n]
            \input file2
        \stopitemize
    \stopclippage
    \pagebreak
    \subject{File 3}
    \startclippage
        \startitemize[n]
            \input file3
        \stopitemize
    \stopclippage
    ...
\stoptext

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.