基本结构
% 导言区
\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}
-
行内公式:
$你的公式$ -
行间公式:
$$你的公式$$
上方代码执行结果如下:

本文档介绍了LaTeX的基本结构,包括如何设置标题、作者和日期,以及如何编写行内和行间数学公式。通过示例代码展示了LaTeX的使用方法,适合初学者快速上手。
2729

被折叠的 条评论
为什么被折叠?



