tsingke

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
这样编写长文档就很方便和灵活了。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-04-09
  • 2022-12-23
  • 2021-08-27
  • 2022-01-09
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2021-07-06
  • 2021-09-25
  • 2021-12-05
  • 2022-12-23
  • 2021-09-17
  • 2021-09-27
相关资源
相似解决方案