Latex⽂件如何拆分进⾏独⽴编译?
Latex⽂件如何拆分并进⾏独⽴编译?
--latex源⽂件分批独⽴编译
最近使⽤Latex编写长⽂档,对于⽂件的组织有些困扰。
如果LaTeX⽂档⽐较⼤,可以考虑拆分为⼏个部分。⽐如编辑⼀本书的时候可以将各章独⽴为,,,然后在主⽂件中包含进来:
\documentclass{book}
\begin{document}
\title{A LaTeX Book}
\author{cohomo@blogbus}
input命令
\date{}
\maketitle
\input{chap1}
\input{chap2}
\input{chap3}
\end{document}
上⾯的input命令可以改为include,区别在于,input可以放在导⾔区和正⽂区,包含的内容不另起⼀页;⽽include只能放在正⽂区,包含的内容另起⼀页。另外CJK中还有CJKinput和CJKinclude命令。
还有个问题就是,如何使得各章既可以被包含在另⼀个⽂件中也可以独⽴编译呢?⽅法是将和作如下修改:
%
\documentclass{book}
\def\allfiles{}
\begin{document}
\title{A LaTeX Book}
\author{cohomo@blogbus}
\date{}maketitle
\input{chap1}
\input{chap2}
\input{chap3}
\end{document}
%
\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
这样编写长⽂档就很⽅便和灵活了。