TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know there is a package called comment, which can let latex ignore some text.

How can I do the inverse? I want to compile just a small segment of the whole tex file and let latex ignore other part.


This is desirable when I'm looking for a specific coordinate in drawing on an image.

But I do not want an solution just for handling figures.

I've been using ktikz for drawing tikz figures, and the following to generate the pdf image and the complete latex source.




echo "\
\documentclass{article} \

\usepackage{pgfplots} \

\usepackage{tikz} \

\usepackage[active,tightpage]{preview} \

\PreviewEnvironment{tikzpicture} \

\setlength\PreviewBorder{2mm} \

\begin{document} \

    \input{$1} \

\end{document}" \
> $filename

echo $filename

pdflatex $filename
share|improve this question
You can use ktikz to draw Tikz images. – giordano Jun 12 '13 at 12:01
If your document is very long, you can split it into several TeX files, use \include on the main document to join them all and \includeonly{name} on the preamble to compile just the content of name.tex. – Luan Resende Jun 12 '13 at 12:04
@giordano, Thank you. I do use ktikz. But when it's not about drawing or figures, is includeonly the only way to do this (as per @LuanResende 's comment)? – Hongying Jun 12 '13 at 12:36
@Hongying well, that's a possibility. But if you want to compile only a small region includeonly isn't really useful. You can try some editors allowing preview of regions of the document, such as Emacs+AUCTeX or TeXstudio – giordano Jun 12 '13 at 12:40
@giordano, Oh, I never know that under Emacs we can preview regions of the document. By the way, I use Latex-Box with vim, but maybe I should view Emacs+AUCTeX as a powerful latex editor rather a general text editor or an operating system (just joking. Thank you. :) ). – Hongying Jun 12 '13 at 13:00

A possible solution are Makefiles:

main = main-doc
plots-dir = plots

# all tikz-pictures in separated *.tex in folder plots
plots-tex :=  $(wildcard $(plots-dir)/*.tex)
vpath %.tex $(plots-dir)

# rule to make all plots
make_tikz_plots : $(plots-tex:.tex=-preview.pdf)

# 'packages.tex' can be the same as used in 'main-doc.tex' but should
# at least contains the needed TikZ package and desired libraries
# '\externaldocument' is from the package 'xr' which will use
# 'main-doc.aux' to create the right '\ref' etc
plots/%-preview.pdf : %.tex
    @echo Generating $<
    pdflatex --shell-escape --jobname="$(<:.tex=-preview)" \
    "\begin{document}\tikzset{external/force remake}"\

All TikZ-pictures are saved in individual *.tex-files in a directory plots. Running make will generate for every of these file a *-preview.pdf using the packages defined in packages.tex. With the package xr even references will be correctly resolved from the main document main-doc.tex.

(This is more a comment, but as a new user I can't yet add comment :/)

share|improve this answer
Thank you, a long detailed "comment" becomes an answer! :). By the way,what's the benefits (from your experience of using it)? I've noticed there are people use makefile for compiling latex file, but I've never tried that. – Hongying Jun 12 '13 at 13:07
I'm not sure, if there is any real benefit :). My main use is/was with gnuplot's epslatex or tikz terminal to test the fonts and references from the main document in descriptions individually. Maybe somebody has a more advanced Makefile using the external tikz-library (so the preview-pdfs would be the actual includeded pictures). – Hasenblut Jun 12 '13 at 13:25

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.