【转载请注明出处】http://www.cnblogs.com/mashiqi

2016/11/05

方法1:

按照这个网址(https://www.dickimaw-books.com/latex/thesis/html/include.html)的说明,使用 \include

方法2:

在编写LaTeX文档的时候,由于文档的section较多,或者section的编写时间各不相同,我们可能碰到如下问题:

1、由于想分开编写各个section

2、preamble太多,想专门弄一个文件放preamble

3、想用bibtex来生成参考文献

我分别参考了这个几个网页:111 222,再结合自己的上手体会,给出下面这个(还凑合的)解决方案。

我们首先建立一个文件夹“project”,在下面分别创建“main.tex”文件“sections”文件夹。在“main.tex”里面写入:

\documentclass[fleqn]{article}

\usepackage{subfiles}
\usepackage{D:/My_Preamble} %必须是绝对路径,才能让各个section*.tex在单独编译时使用到 \title{This is title}
\author{Jay Chou}
\date{\today} \begin{document} \maketitle Hello World! \subfile{sections/section1} \subfile{sections/section2} \bibliographystyle{unsrt}
\bibliography{D:/My_Reference} %必须是绝对路径。但各个section*.tex单独编译时使用不到(这是一个缺点)
\end{document}

“section1.tex”文件这样编写(文件名中不能有空格 否则编译时会出错),并放到“sections”文件夹里:

\documentclass[../main.tex]{subfiles} %两个点代表返回上一级菜单

\newcommand{\AAA}{\textbf{abcdefg}} % 这个'\AAA'命令只在这个tex文件里起作用

\begin{document}

%From there on, type whatever you want.
\section{This is section } Hello, this is section .
\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}{-.0cm}
%\setlength{\parskip}{.2cm}
\newtheorem{thm}{Theorem} \setcounter{thm}{}
\newcommand{\defn}{\overset{\Delta}{=}}
\newcommand{\st}{\textrm{~s.t.~}}
\newcommand{\supp}{\mathop{\rm 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:} ),使用相同的标号会冲突的。同时,各个“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 Federico Garcia
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{subfiles}[// Federico Garcia]
\DeclareOption*{\PackageWarning{\CurrentOption ignored}}
\ProcessOptions
\RequirePackage{verbatim}
\newcommand{\skip@preamble}{%
\let\document\relax\let\enddocument\relax%
\newenvironment{document}{}{}%
\renewcommand{\documentclass}[][subfiles]{}}
\newcommand\subfile[]{\begingroup\skip@preamble\input{#}\endgroup}
\endinput
%%
%% End of file `subfiles.sty'.

创建个txt文件,把如上代码复制进去,然后把txt文件的文件名改为“subfiles.sty”,放到装“main.tex”的文件就可以使用了。

写了这么多,应该能 +1s 吧,蛤蛤蛤!

关于分开编写多个LaTeX文件的一点微小的总结的更多相关文章

  1. Latex文件如何拆分进行独立编译?

    Latex文件如何拆分并进行独立编译? --latex源文件分批独立编译     最近使用Latex编写长文档,对于文件的组织有些困扰.   如果LaTeX文档比较大,可以考虑拆分为几个部分.比如编辑 ...

  2. property_自己编写一个读取Property文件的Util类

    读取property文件的Util类: 所需jar包: 编写PropertiesUtil类: package com.west.util.property; import java.io.InputS ...

  3. delphi 基础之三 编写和调用dll文件

    delphi 编写和调用dll文件   Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...

  4. 程序一 用记事本建立文件src.dat,其中存放若干字符。编写程序,从文件src.dat中读取数据,统计其中的大写字母、小写字母、数字、其它字符的个数,并将这些数据写入到文件test.dat中。

    用记事本建立文件src.dat,其中存放若干字符.编写程序,从文件src.dat中读取数据,统计其中的大写字母.小写字母.数字.其它字符的个数,并将这些数据写入到文件test.dat中. #inclu ...

  5. django之创建第3个项目:编写第一个模板文件

    1.django结构 2.在站点blog下创建templates文件夹,专门用于存放模板文件 3.在templates文件夹下创建index.html文件 #index.html <!DOCTY ...

  6. ******可用 SpringBoot 项目打包分开lib,配置和资源文件

    spring-boot多模块打包后,无法找到其他模块中的类https://blog.csdn.net/Can96/article/details/96172172 关于SpringBoot项目打包没有 ...

  7. 编写简单的Makefile文件

    makefile中的编写内容如下: www:hello.c x.h gcc hello.c -o hello clean: rm hello www:hello.c  x.h 表示生成www这个文件需 ...

  8. 编写who命令:文件操作,缓冲区与联机帮助

    最近阅读UULP(Understanding Unix/Linux Programming),按照书中介绍对Unix/Linux系统编程进行学习梳理,总结如下. 1. who命令能做什么 who命令用 ...

  9. 怎样将word文件转化为Latex文件:word-to-latex-2.56具体解释

    首先推荐大家读一读这篇博文:http://blog.csdn.net/ibingow/article/details/8613556 --------------------------------- ...

随机推荐

  1. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project LogTest: Compilation failure -> [Help 1]

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default ...

  2. A 标签的背景

     a {  -webkit-tap-highlight-color: transparent;  -webkit-touch-callout: none;  -webkit-user-select:  ...

  3. 【图像处理】【SEED-VPM】7.ubuntu10.04下 TFTP,NFS 安装指南

    Linux系统启动流程 程序开发调试的一般方法 1. TFTP下载内核+NFS网络文件系统.即内核和文件系统均不在板卡上.主要用于调试内核功能. 2. FLASH启动内核+NFS网络文件系统,即内核固 ...

  4. 1310. ACM Diagnostics

    http://acm.timus.ru/problem.aspx?space=1&num=1310 题目中说的 “the lexicographically increasing list” ...

  5. <java基础学习>01环境变量配置

    安装完JDK开始配置系统环境变量,在path变量里面添加java的bin目录 方法二: 配置完成后 在命令下输入javac查看是否配置成功 第一个java程序 hello world! class H ...

  6. 开启关闭keditor 过滤

    filterMode: false, K.create('#txt_content', { uploadJson: '/js/kindeditor-4.1.10/upload_json.ashx', ...

  7. 写入标题使用依赖注入Title的setTitle方法

    1. 声明 Generator的声明方式类似一般的函数声明,只是多了个*号,并且一般可以在函数内看到yield关键字 function* showWords() { yield 'one'; yiel ...

  8. Nginx配置单主机多域名

    http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; ...

  9. python导入cx_Oracle报错的问题!

    import cx_Oracle 总是报错:ImportError: DLL load failed: 找不到指定的模块. 或者:ImportError: DLL load failed: %1 不是 ...

  10. selenium+python环境搭建

    1.安装python-2.7.3.msi 2.安装pywin32-216.win32-py2.7.exe 3.下selenium包,selenium-2.35.0.tar.gz,放到D:\autote ...