日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

LaTeX多文件编译的方法总结

發布時間:2023/12/31 综合教程 23 生活家
生活随笔 收集整理的這篇文章主要介紹了 LaTeX多文件编译的方法总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LaTeX多文件編譯的方法總結

在編寫LaTeX文檔的時候,由于文檔的section較多,或者section的編寫時間各不相同,我們可能碰到如下問題:

1、由于想分開編寫各個section

2、preamble太多,想專門弄一個文件放preamble

3、想用bibtex來生成參考文獻

我分別參考了這個幾個網頁:111222,再結合自己的上手體會,給出下面這個(還湊合的)解決方案。

我們首先建立一個文件夾“project”,在下面分別創建“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

現在,把各個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'.

創建個txt文件,把如上代碼復制進去,然后把txt文件的文件名改為“subfiles.sty”,放到裝“main.tex”的文件就可以使用了。

寫了這么多,應該能 +1s 吧,蛤蛤蛤!

【轉載】http://www.cnblogs.com/mashiqi

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。