Latex文件如何拆分进行独立编译?

Latex文件如何拆分并进行独立编译?

--latex源文件分批独立编译


 
 
最近使用Latex编写长文档,对于文件的组织有些困扰。
 
如果LaTeX文档比较大,可以考虑拆分为几个部分。比如编辑一本书的时候可以将各章独立为chap1.tex,chap2.tex,chap3.tex,然后在主文件main.tex中包含进来:
\documentclass{book}
\begin{document}
\title{A LaTeX Book}
\author{cohomo@blogbus}
\date{}
\maketitle
\input{chap1}
\input{chap2}
\input{chap3}
\end{document}
上面的input命令可以改为include,区别在于,input可以放在导言区和正文区,包含的内容不另起一页;而include只能放在正文区,包含的内容另起一页。另外CJK中还有CJKinput和CJKinclude命令。
 
还有个问题就是,如何使得各章既可以被包含在另一个文件中也可以独立编译呢?方法是将main.tex和chap1.tex作如下修改:
 
% main.tex
 \documentclass{book}
\def\allfiles{}
\begin{document}
\title{A LaTeX Book}
\author{cohomo@blogbus}
\date{}maketitle
\input{chap1}
\input{chap2}
\input{chap3}
\end{document}
 
% chap1.tex 
\ifx\allfiles\undefined
\documentclass{article}
\begin{document}
\title{Something in Title}
\author{cohomo@blogbus}
\date{}
\maketitle
\else
\chapter{Chap1's Title}
\fi
\section{First Section}
\section{Second Section}
\ifx\allfiles\undefined
\end{document}
\fi
这样编写长文档就很方便和灵活了。
posted @ 2017-02-12 01:50  Tsingke  阅读(8575)  评论(0编辑  收藏  举报