LaTeX多文件编译的方法总结
LaTeX多文件編譯的方法總結
在編寫LaTeX文檔的時候,由于文檔的section較多,或者section的編寫時間各不相同,我們可能碰到如下問題:
1、由于想分開編寫各個section
2、preamble太多,想專門弄一個文件放preamble
3、想用bibtex來生成參考文獻
我分別參考了這個幾個網(wǎng)頁:111222,再結合自己的上手體會,給出下面這個(還湊合的)解決方案。
我們首先建立一個文件夾“project”,在下面分別創(chuàng)建“main.tex”文件“sections”文件夾。在“main.tex”里面寫入:
documentclass[fleqn]{article}
usepackage{subfiles}
usepackage{D:/My_Preamble} %必須是絕對路徑,才能讓各個section*.tex在單獨編譯時使用到
itle{This is title}
author{Jay Chou}
date{ oday}
egin{document}
maketitle
Hello World!
subfile{sections/section1}
subfile{sections/section2}
ibliographystyle{unsrt}
ibliography{D:/My_Reference} %必須是絕對路徑。但各個section*.tex單獨編譯時使用不到(這是一個缺點)
end{document}
“section1.tex”文件這樣編寫,并放到“sections”文件夾里:
documentclass[../main.tex]{subfiles} %兩個點代表返回上一級菜單
ewcommand{AAA}{ extbf{abcdefg}} % 這個'AAA'命令只在這個tex文件里起作用
egin{document}
%From there on, type whatever you want.
section{This is section 1}
Hello, this is section 1.
end{document}
其他的section的tex文件照著這個格式寫就行了。“My_preamble.sty”文件如下編寫,并放到D盤目錄下:
ProvidesPackage{msqmypreamble}
usepackage{amsmath, amssymb, amsthm}
usepackage{cite}
%usepackage{graphicx, graphics} % Allows including images
% etc
% etc
% etc
%setlength{voffset}{-2.0cm}
%setlength{parskip}{0.2cm}
ewtheorem{thm}{Theorem} setcounter{thm}{0}
ewcommand{defn}{overset{Delta}{=}}
ewcommand{st}{ extrm{~s.t.~}}
ewcommand{supp}{mathop{m supp}}
% etc
% etc
% etc
現(xiàn)在,把各個section共同的preamble都寫到“My_Preamble.sty”文件中,然后將這個文件放到一個路徑下,然后在“main.tex”文件中像4行那樣使用這個sty。為什么必須是絕對路徑,這是為了讓之后的各個“section*.tex”文件也能找到這個文件在哪,從而使用里面的命令。 在各個“section*.tex”文件中,你可以再附加一個本section獨有的preamble,就想第三行的“AAA”那樣。但這個“AAA”只能在本tex文件中使用。
然后是bibtex。各個“section*.tex”在單獨編譯的時候無法找到參考文件,及時在“main.tex”中bib文件的路徑是絕對路徑。這算是一個小瑕疵(很慚愧)。將bib文件單獨拿出來放在一個地方的作用是使得每次收集bibtex信息可以集中在一起。
之后,我們可以編譯這個“main.tex”文件,得到包含各個section的總文件,也可以單獨編譯各個“section*.tex”文件,并且各個“section*.tex”文件可以使用My_Preamble這個preamble,很方便。但不足之處是,單獨編譯各個“section*.tex”文件時,若文件中應用了bib文件中的條目,輸出結果是顯示不出來的,之后在編譯總文件時才能正確顯示。
關于label的引用:各個“section*.tex”內部最好不要使用同名的label標號(例如label{eq:1}),使用相同的標號會沖突的。同時,各個“section*.tex”之間可以相互應用對方的標號,當編譯“main.tex”時,這些相互引用的標號就會顯示出來(單獨編譯某個“section*.tex”顯示不出來)。
最后是這個“subfiles.sty”文件,它的內容如下:
%% This is file `subfiles.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% subfiles.dtx (with options: `package')
%%
%% Copyright 2002 Federico Garcia
%%
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{subfiles}[2002/06/08 Federico Garcia]
DeclareOption*{PackageWarning{CurrentOption ignored}}
ProcessOptions
RequirePackage{verbatim}
ewcommand{skip@preamble}{%
letdocumentelaxletenddocumentelax%
ewenvironment{document}{}{}%
enewcommand{documentclass}[2][subfiles]{}}
ewcommandsubfile[1]{egingroupskip@preambleinput{#1}endgroup}
endinput
%%
%% End of file `subfiles.sty'.
創(chuàng)建個txt文件,把如上代碼復制進去,然后把txt文件的文件名改為“subfiles.sty”,放到裝“main.tex”的文件就可以使用了。
寫了這么多,應該能 +1s 吧,蛤蛤蛤!
【轉載】http://www.cnblogs.com/mashiqi
總結
以上是生活随笔為你收集整理的LaTeX多文件编译的方法总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 25 个超棒的免费手写字体
- 下一篇: 自定义hive url parse函数