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
這樣編寫長文檔就很方便和靈活了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM