基本结构
% 导言区
\documentclass{article}
% 正文区(文稿区)
\begin{document} % 一个latex文件(正文区)有且仅有一个document文件
Hello World!
\end{document}
上面的这段代码是一个简单的 LaTeX\LaTeXLATEX 源文件,主要由两部分组成:导言区、正文区(文稿区)。在 \documentclass
和 \begin{document}
之间的位置称为导言区,document
环境当中的内容是文档正文。
-
\documentclass
指定了文档类型,除了上面代码中的article
,还可以是book
、report
、report
等。 -
一个 LaTeX\LaTeXLATEX 源文件(正文区)有且仅有一个document文件。
编译上面的代码,可以得到如下效果:
添加标题、作者、日期,文本换行
% 导言区
\documentclass{article}
\title{My First Document}
\author{Weijian Ma}
\date{\today}
% 正文区(文稿区)
\begin{document} % 一个latex文件(正文区)有且仅有一个document文件
\maketitle % 输出标题
Hello World!
% 空行可以换行,注释不算空行,多个空行算一个空行
To be or not to be, it's just a question
\end{document}
在导言区,我们可以通过\title(你的标题)
来指定文章的标题,通过\author(作者)
来指定文章作者,通过\date{}
来指定日期,\today
指今天。必须在正文区添加\maketitle
才能显示标题。
在正文区,可使用空行来进行文本换行,其中,注释不算空行,多个空行算一个空行。
上方代码的执行结果如下:
插入数学公式
% 导言区
\documentclass{article} %article, book, report, letter(letter 不使用 \maketitle)
\title{My First Document}
\author{Weijian Ma}
\date{\today}
% 正文区(文稿区)
\begin{document} % 一个latex文件(正文区)有且仅有一个document文件
\maketitle % 输出标题
Hello World!
% 空行可以换行,注释不算空行,多个空行算一个空行
Let $f(x)$ be defined by the formula
$$f(x)=3x^2+x-1$$ which is a polynomial of degree 2.
\end{document}
-
行内公式:
$你的公式$
-
行间公式:
$$你的公式$$
上方代码执行结果如下: