开发者

Latex, TikZ and separate compilation of chapters and figures

I have fairly large Latex document with a lot of TikZ figures inside. I have a habit of frequent recompilation and it takes forever to compile it using pdflatex. Figures in TikZ take most of the time.

My question is what is the best way to split the document into separate tex files (figures/chapters) to achieve separate co开发者_高级运维mpilation of figures and chapters, separate chapter pdfs, and a whole document pdf file ?


Have you tried compiling each picture on its own and then including them in your tex file as pdf rather than the tikz code? You can use the package standalone so that the picture will be the exact size you need. So :

\documentclass{standalone}

\usepackage{tikz,pgf} %and any other packages or tikzlibraries your picture needs

\begin{document}

\begin{tikzpicture}

%your tikz code here

\end{tikzpicture}

\end{document}

The good thing about this is that you can either include the compile this document directly to get a pdf figure to include in your document, or you can use the command \input to include it in your main document as a tikz code by adding

\usepackage{standalone}

in your main document (together with the tikz packages and libraries), and then

\begin{figure}
\input{tikzfile.tex}
\end{figure}


There is a possibly better way (imho) to cache tikz-pictures. Add the following lines in your preamble:

\usetikzlibrary{external}
\tikzexternalize[prefix=i/]

After a pdflatex-run you'll see all pictures in the subdirectory ./i . If you update the code of a tikz-picture simply throw away its corresponding pdf-file and it will be regenerated. For more info see the manual of PFG/TikZ section 32.4 Externalizing Graphics and possibly 32.5 Using External Graphics Without pgf Installed.


How about putting each chapter in a separate file and then using \include to put them into some master file? Then you can use \includeonly to only compile the chapter you're currently working on. That should save some time at least.

I expect some sort of makefile based solution would be even better than this, but I don't know anything about makefiles...


The way I generally do this is to apply Latex to just part of the file: Emacs and several other Latex editors allow you to compiler regions: with Auctex, you can run TeX-pin-region to specify the current chapter, and then TeX-command-region to run Latex on the selected region.

The traditional way to do this is cut parts of the big file into smaller parts that are \included, and then either comment out parts you don't want to work on, or put some macrology at the beginning and end of each file that allows them to be compiled separately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜