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.

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}

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

4 Answers

up vote 3 down vote accepted

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.)

share|improve this answer
add comment
\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} 
share|improve this answer
    
This is very similar to comment (yet much simpler). –  Werner Nov 19 '11 at 17:13
2  
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
add comment

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

and the links within.

share|improve this answer
add comment

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

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