latex 初體驗
first latex doc
原文:first-latex-doc.pdf
全文分五個部分:Preamble、Get it to work、Get more out、Get math、Get it?
Preamble
這不是一個教程,它只是帶你建立第一個文件。如果它使你想知道更多,那麼你已經準備好去瀏覽一個教程了。因為這只是一個小小的初體驗,我們會略過很多東西。
環境:Windows 10 & TeX live 2018
工具:TeXworks Editer
Get it to work
1、建一個目錄: latex-first
2、在該目錄下,新建檔案: latex-first.tex
(請注意副檔名!別是 .tex.txt
),輸入以下的文字:(這就是一個樣本檔案)

新建檔案
\documentclass{article} \begin{document} hello world! \end{document}
3、返回命令列視窗,進入相應目錄,敲命令: pdflatex latex-first

命令列生成pdf
Get more out
1、接下來我們建立一個更長更復雜的文件。同樣的,建立資料夾: latex-second
並建立檔案 latex-second.tex
。
\documentclass{article} \usepackage{lipsum} \begin{document} This is some preamble text that you enter yourself. Below is a command that will automatically generate seven paragraphs of text that is commonly used for examples in this field. \lipsum[1-7] \end{document}

命令列執行pdflatex

生成的PDF
- lipsum : 輕鬆訪問Lorem Ipsum虛擬文字 ,lipsum – access to 150 paragraphs of Lorem ipsum dummy text。To load the package specify :
\usepackage{lipsum}
,For example,\lipsum[4-57]
typesets the paragraphs 4 to 57 and accordingly。具體說明文件可見安裝檔案:C:/texlive/2018/texmf-dist/doc/latex/lipsum/lipsum.pdf
。 特別注意:C:/texlive/2018/doc.html
該文件列出了TeX Live中包含的包和指南的所有HTML和PDF檔案的連結,按包名稱排序。
2、繼續修改你的 latex-second.tex
檔案:
\documentclass{article} \usepackage{lipsum} \begin{document} This is some preamble text that you enter yourself. \section{Text for the first section} \lipsum[1] \subsection{Text for a subsection of the first section} \lipsum[2-3] \subsection{Another subsection of the first section} \lipsum[4-5] \section{The second section} \lipsum[6] \subsection{Title of the first subsection of the second section} \lipsum[7] \end{document}

生成的PDF
3、注意到2中的自動編號,現在我們繼續修改,完成交叉引用:
\documentclass{article} \usepackage{lipsum} \begin{document} This is some preamble text that you enter yourself. \section{Text for the first section} \lipsum[1] \subsection{Text for a subsection of the first section} \lipsum[2-3] \label{labelone} \subsection{Another subsection of the first section} \lipsum[4-5] \label{labeltwo} \section{The second section} \lipsum[6] Refer again to \ref{labelone}. Note also the discussion on page \pageref{labeltwo}. \subsection{Title of the first subsection of the second section} \lipsum[7] \end{document}

編譯兩次顯示正確結果
我們常常需要引用文件中 section、subsection、figure、table 等物件的編號,這種功能叫作交叉引用(cross referencing)。可以用 \label{marker}
命令來定義一個標記,標記名可以是 任意字串,但是在全文中須保持唯一 。之後可以用 \ref{marker}
命令來 引用標記處章節或圖表的編號 ,用 \pageref{marker}
來 引用標記處的頁碼 。文件中新增交叉引用後,第一次執行 latex 或 pdflatex 編譯命令時會得到類似下面的警告資訊。因為第一次編譯只會掃描出有交叉引用的地方, 第二次編譯才能得到正確結果 。——出自 LaTeX.Notes

第一次編譯掃描出有交叉引用的地方,顯示出警告

第二次編譯得到正確結果
4、我們將以新增腳註(footnotes), 目錄(a table of contents), 和 參考文獻(bibliography)作為Get more out的結束(要想連結可用,我們要使用巨集包 hyperref
),繼續修改 latex-second.tex
檔案:
\documentclass{article} \usepackage{lipsum} \usepackage{hyperref} \title{Test document} \author{dfface \\\url{www.dfface.com}} \date{2019-Apr-4} \begin{document} \maketitle \tableofcontents \newpage This is some preamble text that you enter yourself.\footnote{First footnote.}\footnote{Second footnote. } \section{Text for the first section} \lipsum[1] \subsection{Text for a subsection of the first section} \lipsum[2-3] \label{labelone} \subsection{Another subsection of the first section} \lipsum[4-5] \label{labeltwo} \section{The second section} \lipsum[6] Refer again to \ref{labelone}.\cite{ConcreteMath} Note also the discussion on page \pageref{labeltwo}. \subsection{Title of the first subsection of the second section} \lipsum[7] \begin{thebibliography}{9} \bibitem{ConcreteMath} Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, \textit{Concrete Mathmatics}, Addison-Wesley, Reading, MA, 1995. \end{thebibliography} \end{document}

正文開頭和目錄

腳註和參考文獻
- 腳註(footnote)的一般用法:
這裡是一段正文。\footnote{這裡是一段腳註。}
- 用
\tableofcontents
命令來生成整個文件的目錄,LaTeX 會自動設定目錄包含的章節層次,也可以用\setcounter
命令來指定目錄層次深度,例如\setcounter{tocdepth}{2}
。介紹一下,七種層次結構:article 中沒有 chapter,而 report 和 book 則支援所有層次。如果不想讓某個章節標題出現在目錄中,可以使用帶 * 的命令來宣告章節,例如\chapter*{...}
。類似地,我們也可以用\listoffigures
、\listoftables
命令生成插圖和表格的目錄。
\part{...} %Level -1 \chapter{...} %Level 0 \section{...} %Level 1 \subsection{...} %Level 2 \subsubsection{...} %Level 3 \paragraph{...} %Level 4 \subparagraph{...} %Level 5
-
thebibliography
環境和\bibitem
命令可以用來定義參考文獻條目及其列表顯示格式,\cite
命令用來在正文中引用參考文獻條目。但是我們不推薦這樣做,因為它把內容和格式混在一起,使用者需要為每個條目設定格式,很繁瑣且易出錯。
\begin{thebibliography}{編號樣本} \bibitem[記號]{引用標誌}文獻條目1 \bibitem[記號]{引用標誌}文獻條目2 …… \end{thebibliography}
其中文獻條目包括:作者,題目,出版社,年代,版本,頁碼等。引用時候要可以採用: \cite{引用標誌1,引用標誌2,…}
。注意要編譯兩次才能產生正常的引用標號!其中begin{thebibliography}{9}, 這個數字9指的是參考文獻的專案按照數字進行編號, 並且 最多為9個 , 如果你有更多的專案, 把這個數字改大一點就行了。
BibTEX 把參考文獻的資料放在一個 .bib
檔案中,顯示格式放在 .bst
檔案中。普通使用者一般不需要改動 .bst
,只須維護 .bib
資料庫。 .bib
檔案可以用普通文字編輯器來編輯,也可以用專門的文獻管理軟體來提高效率。前文中我們提到含有 交叉引用的文件需要編譯兩遍 。含有參考文獻的文件更麻煩,它需要依次執行 latex
、 bibtex
、 latex
、 latex
等四次編譯操作。

參考文獻的四次編譯

BibTeX的編譯
- 通常 LaTeX 會自動換行、換頁。使用者也可以用
\\
或\newline
來 強制換行 ;用\newpage
來 強制換頁 。
Get math
1、在導言區新增 American Math Society’s packages:
\usepackage{amsmath}
2、在參考文獻之前,新增:
There are $\binom{2 n +1}{ n }$ sequences with $ n $ occurrences of $ -1$ and $ n +1$ occurrences of $+1$ , and Raney ’ s lemma tells us that exactly $\frac{1}{2 n +1}$ of these sequences have all partial sums positive .

結果1
Elementary calculus suffices to evaluate $ C $ if we are clever enough to look at the double integral \begin{equation*} C^2 =\int_{-\infty}^{+\infty} e^{-x^2} \mathrm{ d } x \int_{-\infty}^{+\infty} e^{-y^2} \mathrm{ d } y \;. \end{equation*}

結果2
The Comprehensive LATEX Symbols List shows the widely-available symbols.
Got it ?
你現在已經對LaTeX有了一個感覺。 要繼續?看教程: The Not-So-Short Guide to LATEX2e(一份不太簡短的LATEX2介紹) 。更多的參考: LATEX Document Pointer ,還有: Getting started with TeX, LaTeX, and friends 。以下只是網上提供的一些主要TeX文件。還有更完整的文件連結列表。
- LaTeX Documentation Pointers 引用了許多常見LaTeX任務的文件(作者:Jim Hefferon)。
- 第一篇LaTeX文件將帶您首次編寫帶有文字和數學的小文件(由Jim Hefferon撰寫)。
- LaTeX入門,文字,數學和基本格式的入門(David Wilkins撰寫)。
- 線上LaTeX教程,一個畢業系列(由安迪羅伯茨)。
- LaTeX2e的一份不太簡短的介紹 是一本關於編寫LaTeX的更全面的手冊(由Tobias Oetiker等人翻譯成多種語言)。
- LaTeX Cheat Sheet,兩頁快速參考(由Winston Chang撰寫)。
Plain TeX: 由Teicician's Reference主題的TeX ,作者:Victor Eijkhout。
字型:可單獨 提供有關可與TeX一起使用 的字型的討論。
——
2019.4.5 完