点击文件File中New,建立新文件,以*.tex为扩展名,命名“Latex模板.tex”。该窗口分为三部分:菜单部分、输入部分(源文件),运行结果部分(Console).

每个源文件都有一定的结构,都要以如下命令开始:

documentclass[options]{class}

该命令的作用是源文件的类型, options可以定制文档的属性,不同的选项之间用逗号隔开如纸张类型 (a4paper,a5paper,b5paper,letterpaper)、单双栏(onecolumn,twocolumn)、单双面(oneside,twoside)、字体大小(10pt,11pt,12pt)等;class制定想要的文档类型如article(期刊)、book(书籍)、report(报告)、slides(幻灯片) 。为Latex增加新特性的宏包, 可以用下面命令加载宏包:

usepackage{…}

当完成所有的设置后,开始文档的内容,用如下命令

begin{document}

在文章末尾使用下面命令表示结束

end{document}

注意:该命令后所有内容运行后不会出现。

称documentclass{…}到begin{document}之间的部分为导言区。

1|最简单的Latex源文件

例如:输入

documentclass{article}

begin{document}

A simple Latex file

end{document}

点击PDFLaTeX运行,如果在左下角出现Errors: 0 Warnings:0 Bad Boxes: 0,说明该Latex源程序正常运行,不存在错误,这时可以点击pdf按钮查看。

点击后会出现一个Latex模板 .pdf文件,文件中就是在源文件输入“A simple Latex file”,有些pdf文件可以自动弹出,有时候需要手动点击一下。一个最简单的Latex源文件就写好了!

结果演示:一个带有”A simple Latex file”的Latex模板.pdf就生成了。

2|简单的Latex源文件

简单的Latex源文件包括页面的设置、作者、标题、目录、章节等。”%”在latex表示注释,不会出现在文档中,可做解释说明作用。在上面“Latex模板.tex”进行修改即可。输入:

documentclass[a4paper, 11pt]{article} %页面设置:A4纸, 11磅大小字体,

author{H. Part} %定义作者名称

title{My Latex} %定义论文标题

begin{document} %文档开始

maketitle %论文标题结束

tableofcontents %目录命令,目录及页码PDFLaTeX运行两次

section{Introduction} %小节及小节标题

section{Some interesting words} %小节及小节标题

A simple Latex file %输入内容

end{document} %文档结束

点击PDFLaTeX运行,如果在左下角出现Errors: 0 Warnings:0 Bad Boxes: 0,说明该Latex源程序正常运行,不存在错误,这时可以点击pdf按钮查看。

结果演示:一个带有标题”My Latex”、作者H.Part、写作日期December 28, 2022年、目录Contents及页码、第一节及标题、第二节及标题,以及文档内容”A simple Latex file”的Latex模板.pdf就生成了。

这个内容也不难,不会出错,很容易操作,就是有点不好看。不好看的主要原因是在于这个仅仅是个框架,内容不够充实,没有任何具体内容。另外还有一点,这些命名是Latex源文件的基本要素,还有更多的命令需要掌握。

3|难度一般的Latex源文件

要想让Latex源文件展现更多的命令,就需要加载宏包usepackage{…}。也可以自定义命令方面后面用避免重复。

例如:

usepackage{mathrsfs},usepackage{amsfonts},usepackage{amsmath}等是主要特殊的数学符号和字体对应的宏包。

usepackage{graphic, multirow},usepackage{tabularx},usepackage{multicol}等是图或表格格式对应的宏包。

usepackage{color}表示在文本中显示有颜色的字体,这里定义了两个defblue{color{blue}}及defred{color{red}},前者可以让字体变蓝,后者变红。

newtheorem{thm}{bf Theorem},newtheorem{cor}{bf Corollary},newtheorem{lem}{bf Lemma},newtheorem{prop}{bf Proposition},newtheorem{remark}{bf Remark},newtheorem{exam}{bf Example} 等主要用来描述定理、推论等排版格式。

主要的命令格式为:

begin{thm}… end{thm} %定理格式

bgein{cor}…end{cor} %推论格式

begin{lem}…end{lem} %引理格式

begin{prop}…end{prop} %命题格式

begin{remark}…end{remark} %注记格式

begin{exam}…end{exam} %例子格式

有些Latex模板中也有自带格式,不用自定义格式。

例如:输入

documentclass[a4paper, 11pt]{article}

usepackage{mathrsfs}

usepackage{amsfonts}

usepackage{amsmath}

usepackage{tabularx}

usepackage{multicol}

usepackage{color}

defblue{color{blue}}

defred{color{red}}

newtheorem{thm}{bf Theorem}

newtheorem{cor}{bf Corollary}

newtheorem{lem}{bf Lemma}

newtheorem{prop}{bf Proposition}

newtheorem{remark}{bf Remark}

newtheorem{exam}{bf Example}

author{H. Part}

title{My Latex}

begin{document}

maketitle

tableofcontents

section{Introduction}

section{Some interesting words}

begin{thm} %定理格式开始

A simple Latex file

end{thm} %定理格式结束

begin{cor} %推论格式开始

{blue A simple Latex file} %给字体加蓝色

end{cor} %推论格式结束

begin{lem} %引理格式开始

A simple Latex file

end{lem} %引理格式结束

begin{exam} %例子格式结束

{red A simple Latex file } %给字体加红色

end{exam} %例子格式结束

end{document}

输出:

上面介绍了Latex源文件的基本命令并进行简单的应用,包括论文的格式、文档环境、文档题目及作者、文档内容、文档结束这些部分组成。关于数学公式、表格、插图将在后续论述。