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:
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時最常見的檔案類型。
.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. |
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/.