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
3  
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

4 Answers 4

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
2  
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

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:

\usepackage{filehook}
\AtEndOfIncludes{%
  \global\let\savedclearpage\clearpage
  \global\let\clearpage\relax
}
\AfterIncludes{%
  \global\let\clearpage\savedclearpage
}

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{ }`
\makeatletter
\newcommand*{\inputonly}[1]{\gdef\@inputonly{,#1,}}
\@onlypreamble\inputonly % Make it only valid in the preamble 
\newcommand*{\oinput}[1]{%
   \begingroup
   \edef\@tempa{{,#1,}{\@inputonly}}%
   \expandafter\in@\@tempa
   \ifin@
     \endgroup
     \input{#1}%
     % Dump counter values here
   \else
     \endgroup
     % maybe add a \message{ } here
     % Load counter values here
     \expandafter\ignorespaces
   \fi
}

Usage:

\documentclass{article}
% Insert or load above code

% Use `\oinput` instead of `\input`:
\inputonly{aa,bb,cc}
\begin{document}
\oinput{aa}
\oinput{bb}
\oinput{ccc}% will not be `\input`ed
\oinput{cc}
\end{document}

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
\documentclass{article}
\makeatletter
\def\inputonly#1{\inputonly@i#1,,\@nil}
\def\inputonly@i#1,#2,#3\@nil{%
  \global\@namedef{#1input}{#1}
  \ifx\relax#2\relax\else\inputonly@i#2,#3\@nil\fi}
\def\Input#1{\expandafter\ifx\csname#1input\endcsname\relax\else\input{#1}\fi}
\makeatother
\inputonly{aa,bb,cc}

\begin{document}
\Input{aa}
\Input{bb}
\Input{ccc}% will not be read
\Input{cc}
\end{document}
share|improve this answer

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:

‎\documentclass[openany]{book}‎

share|improve this answer
2  
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

Your Answer

 
discard

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.