LaTeX/基础

维基教科书,自由的教学读本
跳到导航 跳到搜索

文件类型[编辑]

LaTeX在处理输入文档(input file)时,首先需要的信息就是文档类型,由\documentclass这个指令来定义:

\documentclass[options]{class}

这里,"class(种类)"指定了将要被创建的文档的类型. LaTeX 也为其他种类的文件提供了额外的类型设置, 包括信件(letters)和幻灯片(slides). 选项参数(英文为options parameter, 指的应该是花括号里的内容)定义了\documentclass这个指令的行为.选项参数之间必须有逗号(comma)隔开.

例如:一个LaTeX文档可以由类似下行的样子开始。

\documentclass[11pt,twoside,a4paper]{article}

上述指令告诉 Latex 在本文档长宽 A4 纸张相同,文字采双边编排(即奇偶页左右边距正好相反),基本字体大小是 11pt。

以下是LaTeX支持的一些文档类型。

文档类型
article 科学期刊文章、演示、短小的报告、程序文档、邀请函等文档
IEEEtran for articles with the IEEE Transactions format.
proc a class for proceedings based on the article class.
minimal is as small as it can get. It only sets a page size and a base font. It is mainly used for debugging purposes.
report for longer reports containing several chapters, small books, thesis, ...
book 实体书籍写作
slides for slides. The class uses big sans serif letters.
memoir for changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it [1]
letter 信件写作
beamer for writing presentations (see LaTeX/Presentations).

The most common options for the standard document classes are listed in the following table:

Document Class Options
10pt, 11pt, 12pt 设定该文件主字体的大小,如果没有设置的话会以10pt作为预设值。
a4paper, letterpaper,... Defines the paper size. The default size is letterpaper; However, many European distributions of TeX now come pre-set for A4, not Letter, and this is also true of all distributions of pdfLaTeX. Besides that, a5paper, b5paper, executivepaper, and legalpaper can be specified.
fleqn Typesets displayed formulas left-aligned instead of centered.
leqno Places the numbering of formulae on the left hand side instead of the right.
titlepage, notitlepage Specifies whether a new page should be started after the document title or not. The article class does not start a new page by default, while report and book do.
onecolumn, twocolumn 指示LaTeX此文件要以单列(onecolumne)或双列(twocolumn)进行排版
twoside, oneside Specifies whether double or single sided output should be generated. The classes article and report are single sided and the book class is double sided by default. Note that this option concerns the style of the document only. The option twoside does not tell the printer you use that it should actually make a two-sided printout.
landscape Changes the layout of the document to print in landscape mode.
openright, openany Makes chapters begin either only on right hand pages or on the next page available. This does not work with the article class, as it does not know about chapters. The report class by default starts chapters on the next page available and the book class starts them on right hand pages.
draft makes LaTeX indicate hyphenation and justification problems with a small square in the right-hand margin of the problem line so they can be located quickly by a human. It also suppresses the inclusion of images and shows only a frame where they would normally occur.

For example, if you want a report to be in 12pt type on A4, but printed one-sided in draft mode, you would use:

\documentclass[12pt,a4paper,oneside,draft]{report}

套件[编辑]

While writing your document, you will probably find that there are some areas where basic LaTeX cannot solve your problem. If you want to include graphics, colored text or source code from a file into your document, you need to enhance the capabilities of LaTeX. Such enhancements are called packages. Packages are activated with the

\usepackage[options]{package}

command, where package is the name of the package and options is a list of keywords that trigger special features in the package. Some packages come with the LaTeX base distribution. Others are provided separately.

Modern TeX distributions come with a large number of packages pre-installed. If you are working on a Unix system, use the command texdoc for accessing package documentation. For more information, see the Packages section.

你将遇到的档案类型[编辑]

当你使用LaTeX后,很快你就会发现你会处在一堆不同副档名的档案迷宫里面,甚至于找不到这些档案来源的线索。以下表格将会解释使用TeX时最常见的档案类型。

LaTeX中常见的副档名
.aux A file that transports information from one compiler run to the next. Among other things, the .aux file is used to store information associated with cross-references.
.bbl BiBTeX产生供LaTeX使用的参考书目档
.bib 参考书目数据库档案
.blg BiBTeX纪录档
.bst BiBTeX样式档
.cls 定义文件外观的类别档,借由\documentclass指令来进行选择
.dtx Documented TeX. This is the main distribution format for LaTeX style files. If you process a .dtx file you get documented macro code of the LaTeX package contained in the .dtx file.
.ins The installer for the files contained in the matching .dtx file. If you download a LaTeX package from the net, you will normally get a .dtx and a .ins file. Run LaTeX on the .ins file to unpack the .dtx file.
.fd 告诉LaTeX新字体资讯的描述档
.dvi (Device Independent File. This is the main result of a LaTeX compile run with latex. You can look at its content with a DVI previewer program or you can send it to a printer with dvips or a similar application.
.pdf Portable Document Format. This is the main result of a LaTeX compile run with pdflatex. You can look at its content or print it with any PDF viewer.
.log Gives a detailed account of what happened during the last compiler run.
.toc Stores all your section headers. It gets read in for the next compiler run and is used to produce the table of contents.
.lof This is like .toc but for the list of figures.
.lot And again the same for the list of tables.
.idx If your document contains an index. LaTeX stores all the words that go into the index in this file. Process this file with makeindex.
.ind The processed .idx file, ready for inclusion into your document on the next compile cycle.
.ilg Logfile telling what makeindex did.
.sty LaTeX Macro package. This is a file you can load into your LaTeX document using the \usepackage command.
.tex LaTeX or TeX input file. It can be compiled with latex.

大型计划[编辑]

在进行大型文件编写时,你可能会想要把档案分成数个部分。LaTeX有三种指令在建立文件时引入另外一个档案。

最简单的是\input指令:

\input{filename}

\input会插入另外一个档案的内容,叫做filename.tex;注意.tex副档名是被省略的。 For all practical purposes, \input is no more than a simple, automated cut-and-paste of the source code in filename.tex.

The other main inclusion command is \include:

\include{filename}

The \include command is different from \input in that it's the output that is added instead of the commands from the other files. Therefore a new page will be created at every \include command, which makes it appropriate to use it for large entities such as book chapters.

Very large documents (that usually include many files) take a very long time to compile, and most users find it convenient to test their last changes by including only the files they have been working on. One option is to hunt down all \include commands in the inclusion hierarchy and to comment them out:

%\include{filename1} \include{filename2} \include{filename3} %\include{filename4}

In this case, the user wants to include only filename2.tex and filename3.tex. If the inclusion hierarchy is intricate, commenting can become error-prone: page numbering will change, and any cross references won't work. A better alternative is to retain the include calls and use the \includeonly command in the preamble:

\includeonly{filename2,filename3}

This way, only \include commands for the specified files will be executed, and inclusion will be handled in only one place. Note that there must be no spaces between the filenames and the commas.

Remember that the input file should omit all the commands referring to the main document structure, which should be kept in the original document file. This includes lines containing usepackages, document class, and everything but the code strictly referring to the section that is to be included. In this way you'll avoid finding characters of your code in the output document, or worse, not finding anything after the included file, in case you forget to erase the

\end{document}

line of your included file.

选择适合档名[编辑]

Never, ever use directories (folders) or file names that contain spaces. Although your operating system probably supports them, some don't, and they will only cause grief and tears with TeX. Make filenames as short or as long as you wish, but strictly avoid spaces. Stick to lower-case letters without accents (a-z), the digits 0-9, the hyphen (-), and the full point or period (.), (similar to the conventions for a Web URL): it will let you refer to TeX files over the Web more easily and make your files more portable. Some operating systems do not distinguish between upper-case and lower-case letters, others do. Therefore it's best not to mix them.

团队合作[编辑]

See chapter LaTeX/Collaborative Writing of LaTeX Documents/.


Previous: Absolute Beginners Index Next: Document Structure