Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I really like the \input command, but what I really like more is the \includeonly command. Is there a way to have the best of these worlds? (i.e. an \inputonly or an \include without page-breaks?)

share|improve this question
The way that \include works is tied very much to forcing a new page (to ensure that items go to the correct .aux file at shipout). –  Joseph Wright Aug 26 '10 at 12:51
add comment

4 Answers

You won't get the behaviour that \include gives, where it saves the missing page numbers, chapter/footnote/equation/theorem/etc counters, bibliographic citations, etc, but if all you want is the ability to conditionally select which pieces of the document you want to compile, then there are several options, as discussed in the FAQ. The comment, version, optional, versions packages allow this.

share|improve this answer
Thanks for that. Unfortunately what I'd really like is the behaviour of \include. Just like to avoid those nasty pagebreaks! –  slackenerny Aug 26 '10 at 7:47
Which behavior of \include is it that you want? –  TH. Aug 26 '10 at 9:28
I guess references are the thing I'd care most about. Of course counters would also be very much appreciated. –  slackenerny Aug 26 '10 at 13:31
Is it even possible? That \include keeps tracks of counters and references is tied to the fact that it generates a separate .aux for each included file. Perhaps the easiest thing it to just modify your work flow: forget about page breaks in the drafting stage and use \include and once the content is set, recompile using \input? –  Willie Wong Aug 26 '10 at 14:52
@Willie: That is my current strategy. But since I was hanging around here I thought I might ask for a different solution. –  slackenerny Aug 26 '10 at 15:16
add comment

If your really want to suppress the page break, which is caused by a \clearpage at the end of \include, then your can temporarily redefine this macro.

The filehook package can be used for this:


I'm not sure right now if \global is required here but it will not hurt.

As already mentioned it is not guaranteed anymore that \includeonly gives correct results, e.g. page numbers, because the last page wasn't flushed.

If you only want to suppress certain input files, then you need a \inputonly macro:

% You can put this into a `.sty` file and load it with `\usepackage{ }`
\@onlypreamble\inputonly % Make it only valid in the preamble 
     % Dump counter values here
     % maybe add a \message{ } here
     % Load counter values here


% Insert or load above code

% Use `\oinput` instead of `\input`:
\oinput{ccc}% will not be `\input`ed

The \input macro is also used by packages to read a lot of other files, so it cannot safely be overwritten. A different name, e.g. \oinput, must be used instead.

If you want to keep counter values you have to dump and load them by yourself. See the code of \include how it is done.

share|improve this answer
add comment

\Input{ccc}% will not be read
share|improve this answer
add comment

I think I have understand what you need. If you don't like the bothersome pagebreaks at the end of your chapters, you should use "openany" like following:


share|improve this answer
The openany class option does not prevent page breaks before chapters - it only allows that new chapters start on left-hand (even) pages. –  lockstep Aug 26 '10 at 12:52
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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