# Compile just a part of the contents in a .tex file [duplicate]

Possible Duplicate:
How can I ignore everything except a specified environment?

I am looking for a package or a command, say compileonly, that can do the following task:

For a .tex file as following,

\begin{document}

This is A.

\begin{compileonly}
This is B
\end{compileonly}

This is C

\end{document}


The result will be This is B.

Does such a thing exist?

Thanks all the reply. Finally, the best solution is to use xcomment package and define a new environment \compileconly and use \begin{compileonly} and \end{compileonly} inside \begin{xcomment}{compileonly} and \end{xcomment}

-
Consider the comment package. –  Werner Nov 19 '11 at 16:43
It seems that what I need is the complement of this package, since if one uses this package, one needs to comment out several places to just compile a part. –  user565739 Nov 19 '11 at 16:51
It is possible to do this using separate files with \include and \includeonly. Is this an option? –  Werner Nov 19 '11 at 16:52
I don't prefer to do so. In fact, I am using Gummi to have a real-time preview. But if the .tex file gets bigger, then it would be slow. So I would like to have an easy way to comment out anything but only one place ( small section, for example). –  user565739 Nov 19 '11 at 17:01
Have a look at tex.stackexchange.com/questions/17816/…, which seems to be a duplicate. –  Martin Scharrer Nov 20 '11 at 8:23

## marked as duplicate by lockstep, Jake, Joseph Wright♦Nov 23 '11 at 8:35

See this: How can I ignore everything _except_ a specified environment? (I don't know how to mark this question as a possible duplicate; also, I'd prefer the OP to confirm that.)

-
\begin{document}
\iffalse
This is A.

\else
This is B
\fi

\iffalse
This is C
\else
% nothing in this part
\fi
\end{document}


or

\begin{document}
\iffalse
This is A.

\fi
This is B

\iffalse
This is C
\fi
\end{document}

-
This is very similar to comment (yet much simpler). –  Werner Nov 19 '11 at 17:13
The comment package is safer than an \iffalse solution. See the TeX FAQ for details. –  Aditya Nov 19 '11 at 21:00
and the possibility that one uses \verb+\iftrue+ in his document is how big?? ;-) –  Herbert Nov 19 '11 at 21:09

Here's a solution using the comment package. It's not exactly as you would like, as it requires that you specify two environments: dontcompile and compileonly

\documentclass{article}

\usepackage{comment}
\excludecomment{dontcompile}
\includecomment{compileonly}

\begin{document}

\begin{dontcompile}
This is A.
\end{dontcompile}

\begin{compileonly}
This is B
\end{compileonly}

% will always be compiled as it's not within dontcompile or compileonly
This is C

\end{document}


The \includecomment and \excludecomment can be toggled back and forth.

An alternative to this approach is to break your document into multiple files, and then \include them, as mentioned in the comments, and described on this post:

Skip compilation of parts of a document

-

The simplest way to achieve this is to specify a comment environment that starts from \begin{document} and ends at \begin{compileonly}. Unfortunately, AFAIK, none of the LaTeX comment packages allow you to specify the end marker.

In ConTeXt, you can use buffers to easily achieve the desired result. For example:

\def\starttext
{\dostartbuffer[ignore][starttext][startcompileonly]}

\def\startcompileonly{\ctxcommand{starttext()}}
\def\stopcomileonly  {\ctxcommand{stoptext()}}


Using this the following test file works as expected.

\starttext

Text to be ignore
\iffalse
\undefined

\startcompileonly
Only compile this
\stopcomileonly

Text to be ignore
\iffalse
\undefined

\stoptext

-