VScode+texlive打造win10下的Latex编译环境

一时兴起

  最近开始准备学校的毕业设计相关的事情了,在写开题报告的时候看到密密麻麻整整七页的论文格式要求,瞬间头都大了,虽然引用文献部分能通过Mendeley直接找到国标进行排版,而且我引用的基本都是外文文献,一查doi就可以自动导入,但那些关于标点,字体,页间距的要求,让我都不敢随便下笔。
  所以毅然决然打开google,学习怎么使用VScode+tex进行编写环境配置,因为曾经在linux上用atom+texlive的组合进行过搭建,所以心里觉得应该或多或少会遇到一些麻烦,没想到Windows下一路都是下一步下一步,除了环境变量那里可能有些人不知道以外,简直就是傻瓜操作。不过既然图都截了,干脆就写成blog以备哪天不知道要重装系统了重新设置用。

安装VScode+texlive

  选用VScode的原因在于习惯了微软家VScode的高颜值,原本文本编辑器主力用的是Notepad++,但它浓郁的上个年代的代码高亮让我在第一次接触到VScode之后就转投VScode的怀抱。没办法,这个微软,还是太香了

VScode安装

  登录这个网站,直接下载,安装,打开能看到这个画面就ok了:

texlive安装

  登录这个网站,这个网站页面真的…一言难尽。找到其中的超链接:install-tl-windows.exe,下载,解压,安装。安装的过程会十分~~漫~~长~~,你会看到下面这个窗口慢慢地滚动安装组件:

  我装了1个多小时才装完,看到这个窗口就差不ok了:

  最后在我的电脑右键->属性->高级系统设置->环境变量->用户的用户变量->Path里看到安装位置\texlive\年份\bin\win32就算ok了,如果没有找到,可以试着去系统变量里面的path找一下,如果还没有,请手动添加安装位置的\bin\win32文件夹进系统变量。我的变量:

配置VScode和一些小技巧

在VScode里面安装拓展插件Latex Workshop

  打开VScode,点击左下角扩展选项或者Ctrl+Shift+X打开扩展库,搜索Latex Workshop,点击安装,等一会就安装好了。

使用技巧

  对.tex进行编译使用快捷键:crtl+alt+b,有问题会进行报错,无问题会在相同的文件夹生成PDF文件。
  在VScode里进行预览按钮使用快捷键:crtl+alt+v,可以预览.tex生成的pdf文件。

一个helloworld文档

  因为要对安装好的编译环境进行测试,这里分别对英文tex文档和中英混合tex文档进行测试。
  对纯英文文档的测试可以输入以下代码:

1
2
3
4
5
\documentclass{article}
% 这里是导言区
\begin{document}
Hello, world!
\end{document}

  使用编译和查看,结果如下:

  对存在中文的文档的测试,需要调用ctexart包,并使用UTF-8编码实现:

1
2
3
4
5
6
7
\documentclass[UTF8]{ctexart}
% 这里是导言区
\begin{document}
Hello, world!

你好呀
\end{document}

  使用编译和查看,结果如下:

在tex中更改引用文献的格式

  因为我们学校的文献著录要求是使用国标:GB/T 7714-2015,所以要在导言取区域添加如下命令才能成功更改著录格式:

1
\usepackage[authoryear]{gbt7714}

  具体文献的输入格式请参考http://ctan.math.illinois.edu/biblio/bibtex/contrib/gbt7714/gbt7714.pdf

自用模板

一个英文LaTex文档模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
\documentclass{article}
% 这里是导言区
% bracket
\usepackage{braket}
% Package for the layout
\usepackage{geometry}
\geometry{letterpaper,scale=0.85}
% Package for author-related
\usepackage{authblk}
% Package for math formula
\usepackage{amsfonts}
% swash math fonts
\usepackage{mathrsfs}
%\usepackage{BOONDOX-cal}
% formula related
\usepackage{amsmath}
\usepackage{amsopn}
\usepackage{amssymb}
% Cite picture
\usepackage{caption}
\usepackage{graphicx}
\usepackage{subcaption}
% Hyper refer
\usepackage[colorlinks=true,linkcolor=blue,anchorcolor=blue,citecolor=red]{hyperref}
% appendix
\usepackage[title,titletoc,header]{appendix}
% table
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{longtable}
% pic position
\usepackage{float}
% introduce two space
\usepackage{indentfirst}
\setlength{\parindent}{2em}
% code package
\usepackage{listings}
\usepackage{xcolor}
% enumerate numbers
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{animate}
% draw diagram
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
% date
\usepackage[en-GB]{datetime2}


\newcommand{\degree}{^\circ}%角度
\newcommand{\myvec}[0]{\overrightarrow}%向量箭头
\newcommand{\sat}{\operatorname{sat}}
\newcommand{\rank}{\operatorname{rank}}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\newtheorem{assumption}{Assumption}
\newtheorem{lemma}{Lemma}
% tikz initialization
\tikzstyle{block} = [draw, fill=white, rectangle,
minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=white, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\allowdisplaybreaks[4]
\lstset{
breaklines,
columns=flexible,
numbers=left, % 在左侧显示行号
numberstyle=\tiny\color{gray}, % 设定行号格式
frame=none, % 不显示背景边框
backgroundcolor=\color[RGB]{245,245,244}, % 设定背景颜色
keywordstyle=\color[RGB]{40,40,255}, % 设定关键字颜色
numberstyle=\footnotesize\color{darkgray},
commentstyle=\it\color[RGB]{0,96,96}, % 设置代码注释的格式
stringstyle=\rmfamily\slshape\color[RGB]{128,0,0}, % 设置字符串格式
showstringspaces=false, % 不显示字符串中的空格
language=Matlab, % 设置语言
}
% Title
\title{Title}
% Author
\author{Name}
\begin{document}
\maketitle
\section{Section Sample}
\subsection{Subsection Sample}
% table
Table:
\begin{table}[htbp]
\centering
\caption{table caption 1}
% table with equal column width
\begin{tabularx}{.6\textwidth}{X<{\centering}|X<{\centering}|X<{\centering}}
first column & second column & third column \\
\hline
1 & 2 & 3 \\
\end{tabularx}

% table with adaptive column width, this is a standard three-line table
\caption{table caption 2}
\begin{tabular}{ccc}
\toprule
first column & this is a very very long sentence & third column \\
\midrule
item 1 & item 2 & item 3 \\
\bottomrule
\end{tabular}
\end{table}

Enumerate:
\begin{enumerate}[label*=\arabic*.]
\item Topic
\begin{enumerate}[label*=\arabic*.]
\item First Subtopic
\item Second Subtopic
\begin{enumerate}[label*=\arabic*.]
\item First Sub-Subtopic
\item Second Sub-Subtopic
\end{enumerate}
\end{enumerate}
\end{enumerate}

Tikzpicture:
\begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {Controller};
\node [block, right of=controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {System};
% We draw an edge between the controller and system block to
% calculate the coordinate u. We need it to place the measurement block.
\draw [->] (controller) -- node[name=u] {$u$} (system);
\node [output, right of=system] (output) {};
\node [block, below of=u] (measurements) {Measurements};

% Once the nodes are placed, connecting them is easy.
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (measurements) -| node[pos=0.99] {$-$}
node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{center}

\end{document}

效果:

一个英文Beamer演讲模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
\documentclass{beamer}
\usepackage{mathrsfs}
%\usepackage{BOONDOX-cal}
\usepackage{amsmath}
\usepackage{amssymb}
%\usepackage[UTF8]{ctex}
\usepackage{beamerthemesplit}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
% Package for the citation format
\usepackage{gbt7714}
% Cite picture
\usepackage{caption}
\usepackage{graphicx}
\usepackage{subcaption}
% font
\usepackage{type1cm}
\usepackage{times}
% color
\usepackage{color}
% table
\usepackage{tabularx}
\usepackage{booktabs}
% formula font
\usefonttheme[onlymath]{serif}

%\usepackage[T1]{fontenc}
%\graphicspath{/Dropbox/InternationalMacro/}
\mode<presentation> {
%\usetheme{default}
%\usetheme{AnnArbor}
%\usetheme{Antibes}
%\usetheme{Bergen}
%\usetheme{Berkeley}
%\usetheme{Berlin}
%\usetheme{Boadilla}
%\usetheme{CambridgeUS}
%\usetheme{Copenhagen}
%\usetheme{Darmstadt}
%\usetheme{Dresden}
%\usetheme{Frankfurt}
%\usetheme{Goettingen}
%\usetheme{Hannover}
%\usetheme{Ilmenau}
%\usetheme{JuanLesPins}
%\usetheme{Luebeck}
%\usetheme{Madrid}
%\usetheme{Malmoe}
%\usetheme{Marburg}
%\usetheme{Montpellier}
%\usetheme{PaloAlto}
%\usetheme{Pittsburgh}
%\usetheme{Rochester}
%\usetheme{Singapore}
%\usetheme{Szeged}
\usetheme{Warsaw}

%\usecolortheme{albatross}
%\usecolortheme{beaver}
%\usecolortheme{beetle}
%\usecolortheme{crane}
%\usecolortheme{dolphin}
%\usecolortheme{dove}
%\usecolortheme{fly}
%\usecolortheme{lily}
%\usecolortheme{orchid}
%\usecolortheme{rose}
%\usecolortheme{seagull}
%\usecolortheme{seahorse}
\usecolortheme{whale}
%\usecolortheme{wolverine}
}

%\newtheorem{problem}{问题描述}
\setbeamercovered{transparent}
\setcounter{tocdepth}{2}
\title[Title]{Title}
\author{Yicheng Xu}

\begin{document}


\frame{\titlepage}
\begin{frame}
\frametitle{Brief of presentation}
\tableofcontents
\end{frame}
\section{section1}
\begin{frame}
\frametitle{This is frame title}
These are words.
\end{frame}

\begin{frame}[allowframebreaks]
\frametitle{Reference}
\tiny
\bibliography{Reference.bib}
\bibliographystyle{unsrt}
\end{frame}
\end{document}

效果: