• 星期二, 十月 17, 2006

    分章撰写及编译LaTeX文档的方法
    body
    为了分章写论文,查阅了CTex论坛的文章,并且做了试验。整理在这里。

    分章撰写方法:
    假定该书由chapter1, chapter2,chapter3组成,将相应部分存为chapter1.tex,
    chapter2.tex,chapter3.tex,主文件假定为main.tex。然后在main.tex的
    preamble中使用\ includeonly命令,大致如下:

    \documentclass{...}
    \usepackage{...}
    ...
    ...
    \includeonly{chapter2}

    \begin{document}
    ...
    ...
    \include{chapter1}
    \include{chapter2}
    \include{chapter3}
    ...
    ...
    \end{document}

    这样将只编译chapter2,并保持一切交叉引用。

    分章编译:
    1)将main.tex中没有加入\includeonly命令时编译2-3遍。
    2)在main.tex的preamble加入\includeonly{}编译以产生封面、目录,手动将产
    生的main.dvi改名为 contents.dvi(或任何其它名字)。
    3)将以上main.tex中的\includeonly{}改为\includeonly{chapter1,chapter2},
    去掉titlepage 和table of contents的内容,编译生成第一、二章,手动将产生
    的main.dvi改名为chap1-2.dvi(或任何其它名字)。
    4)将3)的main.tex中的\includeonly{chapter1,chapter2}改为\includeonly
    {chapter3}编译生成第三章,手动将产生的main.dvi改名为chap3.dvi(或任何其
    它名字)。
    5)dvipdfm contents.dvi, dvipdfm chap1-2.dvi, dvipdfm chap3.dvi得到相
    应的pdf文件就是你所要的。

    注意:为使单独章节编译后保持正确的交叉引用,需要事先正确编译所有的章节。
    交叉引用的信息来源于其它章节的最后一次编译,也就是.aux文件。其实这相当于
    \tableofcontents,只编译一次马上看结果看到的完全不是那么回事,需要编译两
    次。所以必须修改 main.tex但一直用main.tex的文件名来编译,然后手动修改出
    来的main.dvi文件名,因为只有这样自始至终在用由以上1)产生的 main.aux的信息。
    至于hyperlink,引用的页码、公式号等肯定都对,但点击当然不会起作用了,因
    为链结更本就在别的文件。


    There is an RSS Feed for comments on this post.
    Post a Comment
  •