[knownledge][latex] LaTex入门

 

 

序言

最近需要写一份文档, 时间也不是特别紧.

之前一直用markdown写文档. 始终想学一下LaTex, 毕竟是学术论文界的工具.

 

在提及LaTex的内容之前. 事必是一定要首先提及高德纳的.

他用十五年写了半本书,然后发现印刷出来不好看,便又花八年时间写了Tex软件来排版,然后回去继续写书,到现在还没写完。

 

正文

 

先来一本书: 

扫描版PDF: https://github.com/wuzhouhui/misc/blob/master/LaTeX%E5%85%A5%E9%97%A8%20%E5%88%98%E6%B5%B7%E6%B4%8B.pdf

 

先选了工具套装 texlive

https://wiki.archlinux.org/index.php/TeX_Live

安装:

┬─[tong@T7:~]─[04:53:20 PM]
╰─>$ sudo pacman -S texlive-most
:: There are 12 members in group texlive-most:
:: Repository extra
   1) texlive-bibtexextra  2) texlive-core  3) texlive-fontsextra  4) texlive-formatsextra  5) texlive-games  6) texlive-humanities  7) texlive-latexextra  8) texlive-music
   9) texlive-pictures  10) texlive-pstricks  11) texlive-publishers  12) texlive-science

Enter a selection (default=all): 
The TeX Live packages are arranged into two groups in the official repositories:

texlive-most includes TeX Live applications.
texlive-lang provides various character sets and non-English features.

 

支持中文:

┬─[tong@T7:~/Temp]─[05:27:26 PM]
╰─>$ pacman -S extra/texlive-langchinese

 

官方手册:https://en.wikibooks.org/wiki/LaTeX/Introduction

前文安装的TexLive只有解释器没有编辑器, 还需要选一个编辑器

https://en.wikibooks.org/wiki/LaTeX/Installation#Editors

A. 我选了kile, 因为是KDE组件...

B. 还有一个据说比较好用的 texworks

┬─[tong@T7:~/Temp]─[06:11:08 PM]
╰─>$ yaourt -Ss texworks
aur/texworks 0.6.2-3 (84) (0.17)
    A TeX IDE inspired by TeXShop.

 

语法摘录:

1.  空格与换行

a. 空格或tab都会识别成空白字符.

b. 多个连续的空白字符会被识别为一个空白字符.

c. 一个或多个空行会被识别为换行.

 

2.  保留字

# $ % ^ & _ { } ~ \

斜杠\ 为转意字符, 如

\# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash{}

有时 [ 和 ] 也是保留字, 当用作可选参数时, 如:

\command [text]

 

3. 组

用于限定作用域, 使用命令 \bgroup 和 \egroup, 如:

\documentclass{article}
\begin{document}
normal text {\itshape walzing \bfseries Wombat} more normal text

normal text \bgroup\itshape walzing \bfseries Wombat\egroup{} more normal text
\end{document}

 

4. 环境

Anything in LaTeX can be expressed in terms of commands and environments.

\begin{environmentname}
text to be influenced
\end{environmentname}

 

5. 命令

\commandname[option1,option2,...]{argument1}{argument2}...

 

cmmand VS switch (不太理解)

 

6. 注释 

When LaTeX encounters a % character while processing an input file, it ignores the rest of the current line, the line break, and all whitespace at the beginning of the next line.

例子

┬─[tong@T7:~/Temp]─[11:46:59 AM]
╰─>$ cat tex_test.tex 
% hello.tex - Our first LaTeX example!
\documentclass{article}
\begin{document}
Hello world!
\end{document}

 

编译文档, 并查看

┬─[tong@T7:~/Temp]─[11:56:41 AM]
╰─>$ xelatex tex_test.tex 
This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017/Arch Linux) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./tex_test.tex
LaTeX2e <2017-04-15>
Babel <3.15> and hyphenation patterns for 84 language(s) loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
No file tex_test.aux.
[1] (./tex_test.aux) )
Output written on tex_test.pdf (1 page).
Transcript written on tex_test.log.
┬─[tong@T7:~/Temp]─[11:56:52 AM]
╰─>$ ls
tex_test.aux  tex_test.log  tex_test.pdf  tex_test.tex
┬─[tong@T7:~/Temp]─[11:56:53 AM]
╰─>$ okular tex_test.pdf 

 

 

到此, 就算入门了. 接着换一个中文文档, 做一些进阶学习

https://liam0205.me/2014/09/08/latex-introduction/

我们使用texworks试一下.

上图这个demo, 虽然很好. 但是并不能正常显示中文.

 

中文:

CTeX宏包

 

运行报错:

 

这个奥秘是把输出引擎选择为XeTeX. 为什么要这样做呢? 

参考上文文档的家族章节: https://liam0205.me/2014/09/08/latex-introduction/#TeX_%E5%AE%B6%E6%97%8F

之后有两种方法显示, 如下所示:

 

一个稍复杂的例子

%显示中文的第一种方法
\documentclass[UTF8]{ctexart}

% 显示中文的第二种方法
%\documentclass{article}
%\usepackage{xeCJK}

\title{你好, world!}
\author{Tong}
\date{\today}


\begin{document}
\maketitle
\tableofcontents

\section{你好中国}
中国在East Asia.
\subsection{Hello Beijing}
北京是Capital of China.
\subsubsection{Hello Dongcheng district}
\paragraph{Tian'anmen Square}
is in the center of Beijing
\subparagraph{Chairman Mao}
is in the center of 天安门广场。
\subsection{Hello 山东}
\paragraph{山东大学} is one of the best university in 山东。

Hello World!



你好LaTeX的世界!

\end{document}
例子

 

一个效果图。。。。

 

如你所见, 上边那个图实在是太丑了。

于是我又去了解了一下pandoc,又试图对比了一下markdown,详见:

[daily] pandoc

然后再回到latex的话题, 其实丑不丑的还在于个人设置。比如,不用CTex而换成Xelatex之后。如下图:

其实也还好吧,细致的调整一下相信也不会丑。

于是要提到的是, 到底XeLaTex是什么?

http://blog.jqian.net/post/xelatex.html

中文问题还是很复杂的,详细内容,推荐阅读下面这个章节:

https://en.wikibooks.org/wiki/LaTeX/Internationalization

https://en.wikibooks.org/wiki/LaTeX/Internationalization#Chinese

 

跟排版,页面,页边距等有关的内容:

https://en.wikibooks.org/wiki/LaTeX/Page_Layout

 

简历文档类:https://www.xiangsun.org/tex/notes-on-moderncv

 

至此,读文档,知识之类的工作基本差不多了。

接下来就是一边实践一边继续深入学习了。

 

语法那么多。所以实践学习阶段,需要一份速查手册。

TeXLive是自带的,一个命令texdoc。但是由于我的TeXlive不是通过官方工具安装的,而是通过arch源。目前源里面还没有texdoc的文档内容。

索性找到了online的texdoc:http://texdoc.net/

texdoc里面有好多文档,其中一份作为日常的简明速查手册已经足够

http://texdoc.net/texmf-dist/doc/latex/latex2e-help-texinfo/latex2e.pdf

另外还有一个,内容应该是一样的:

https://latex.org/know-how/latex/55-latex-general/424-latex-reference-manual

 

TODO:

https://en.wikibooks.org/wiki/LaTeX/Counters

 

------------------------------------- update @ 2018-03-12 -------------------------------

生产PDF时候链接颜色巨丑,怎么破?

 

 很简单,加入下面一行。。。。

\usepackage[colorlinks,urlcolor=blue]{hyperref}

然后,漂亮多了。。。。

--------------------------------------------------------------------------------------------------------

如何设置首行缩进?

在导言区加入宏包首行 \usepackage{indentfirst} 就可以了.

使用命令 设置 缩进的距离 \setlength{\parindent}{2em},

http://blog.sina.com.cn/s/blog_5e16f1770100fve2.html

 

-------------------------------------------------------------------------------------------------------

如何设置行间距

http://blog.csdn.net/u010297791/article/details/54232542

\usepackage{setspace}
\setlength{\baselineskip}{20pt}

不知道是不是因为我用来\clearpage,第二行需要写到正文里才能生效。

 

---------------------------------------------------------------------------------------------------------

默认生成目录的标题是 “contents”, 我要把它修改为中文的“目录”, 如何做?

\renewcommand{\contentsname}{目录}

需要写在 tableofcontents 之前。

需要注意的是,\renewcommand{\contentsname}{...} 不能写在导言区,要写在 \tableofcontents 之前。
其它预设名如下
\abstractname         Abstract
\alsoname         see also (makeidx package)
\appendixname         Appendix
\bibname         Bibliography (report,book)
\ccname         cc (letter)
\chaptername         Chapter (report,book)
\contentsname         Contents
\enclname         encl (letter)
\figurename         Figure (for captions)
\headtoname         To (letter)
\indexname         Index
\listfigurename         List of Figures
\listtablename         List of Tables
\pagename         Page (letter)
\partname         Part
\refname         References (article)
\seename         see (makeidx package)
\tablename         Table (for caption)


如:
\renewcommand{\contentsname}{\small Contents}
\tableofcontents

 

---------------------------------------------------------------------------------

设置了行间距之后,itemize之间的距离就变大了。那么如何控制itemize直接的距离呢?

 

两个方法,一个在导言区全局设置:

\usepackage{enumitem}
\setenumerate[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=5pt}
\setitemize[1]{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=5pt}
\setdescription{itemsep=0pt,partopsep=0pt,parsep=\parskip,topsep=5pt}

一个是针对单个item,单独设置:

begin{itemize}
\setlength{\itemsep}{0pt}
\setlength{\parsep}{0pt}
\setlength{\parskip}{0pt}
\item ...
\item ...
\end{itemize}

 

见:http://www.voidcn.com/article/p-sdcrpatl-re.html

 

posted on 2018-02-26 10:20  toong  阅读(731)  评论(0编辑  收藏  举报