日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

LaTeX多文件编译的方法总结

發(fā)布時(shí)間:2023/12/31 30 生活家
生活随笔 收集整理的這篇文章主要介紹了 LaTeX多文件编译的方法总结 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

LaTeX多文件編譯的方法總結(jié)

在編寫(xiě)LaTeX文檔的時(shí)候,由于文檔的section較多,或者section的編寫(xiě)時(shí)間各不相同,我們可能碰到如下問(wèn)題:

1、由于想分開(kāi)編寫(xiě)各個(gè)section

2、preamble太多,想專門(mén)弄一個(gè)文件放preamble

3、想用bibtex來(lái)生成參考文獻(xiàn)

我分別參考了這個(gè)幾個(gè)網(wǎng)頁(yè):111222,再結(jié)合自己的上手體會(huì),給出下面這個(gè)(還湊合的)解決方案。

我們首先建立一個(gè)文件夾“project”,在下面分別創(chuàng)建“main.tex”文件“sections”文件夾。在“main.tex”里面寫(xiě)入:

documentclass[fleqn]{article}

usepackage{subfiles}  
usepackage{D:/My_Preamble} %必須是絕對(duì)路徑,才能讓各個(gè)section*.tex在單獨(dú)編譯時(shí)使用到

	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} %必須是絕對(duì)路徑。但各個(gè)section*.tex單獨(dú)編譯時(shí)使用不到(這是一個(gè)缺點(diǎn))
end{document}

“section1.tex”文件這樣編寫(xiě),并放到“sections”文件夾里:

documentclass[../main.tex]{subfiles} %兩個(gè)點(diǎn)代表返回上一級(jí)菜單


ewcommand{AAA}{	extbf{abcdefg}} % 這個(gè)'AAA'命令只在這個(gè)tex文件里起作用

egin{document}

%From there on, type whatever you want.
section{This is section 1}

Hello, this is section 1.
end{document} 

其他的section的tex文件照著這個(gè)格式寫(xiě)就行了。“My_preamble.sty”文件如下編寫(xiě),并放到D盤(pán)目錄下:

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)在,把各個(gè)section共同的preamble都寫(xiě)到“My_Preamble.sty”文件中,然后將這個(gè)文件放到一個(gè)路徑下,然后在“main.tex”文件中像4行那樣使用這個(gè)sty。為什么必須是絕對(duì)路徑,這是為了讓之后的各個(gè)“section*.tex”文件也能找到這個(gè)文件在哪,從而使用里面的命令。 在各個(gè)“section*.tex”文件中,你可以再附加一個(gè)本section獨(dú)有的preamble,就想第三行的“AAA”那樣。但這個(gè)“AAA”只能在本tex文件中使用。

然后是bibtex。各個(gè)“section*.tex”在單獨(dú)編譯的時(shí)候無(wú)法找到參考文件,及時(shí)在“main.tex”中bib文件的路徑是絕對(duì)路徑。這算是一個(gè)小瑕疵(很慚愧)。將bib文件單獨(dú)拿出來(lái)放在一個(gè)地方的作用是使得每次收集bibtex信息可以集中在一起。

之后,我們可以編譯這個(gè)“main.tex”文件,得到包含各個(gè)section的總文件,也可以單獨(dú)編譯各個(gè)“section*.tex”文件,并且各個(gè)“section*.tex”文件可以使用My_Preamble這個(gè)preamble,很方便。但不足之處是,單獨(dú)編譯各個(gè)“section*.tex”文件時(shí),若文件中應(yīng)用了bib文件中的條目,輸出結(jié)果是顯示不出來(lái)的,之后在編譯總文件時(shí)才能正確顯示。

關(guān)于label的引用:各個(gè)“section*.tex”內(nèi)部最好不要使用同名的label標(biāo)號(hào)(例如label{eq:1}),使用相同的標(biāo)號(hào)會(huì)沖突的。同時(shí),各個(gè)“section*.tex”之間可以相互應(yīng)用對(duì)方的標(biāo)號(hào),當(dāng)編譯“main.tex”時(shí),這些相互引用的標(biāo)號(hào)就會(huì)顯示出來(lái)(單獨(dú)編譯某個(gè)“section*.tex”顯示不出來(lái))。

最后是這個(gè)“subfiles.sty”文件,它的內(nèi)容如下:

%% 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)建個(gè)txt文件,把如上代碼復(fù)制進(jìn)去,然后把txt文件的文件名改為“subfiles.sty”,放到裝“main.tex”的文件就可以使用了。

寫(xiě)了這么多,應(yīng)該能 +1s 吧,蛤蛤蛤!

【轉(zhuǎn)載】http://www.cnblogs.com/mashiqi

總結(jié)

以上是生活随笔為你收集整理的LaTeX多文件编译的方法总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。