forked from SYSU-SCC/sysu-thesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysucode.sty
84 lines (78 loc) · 4.16 KB
/
sysucode.sty
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
% 说明:
% 本科生毕业论文规范中并未明确指出在论文中插入代码的要求,该文件定义的代码风格尽量保持简洁与美观
% 目前仅支持Python、C/C++以及终端bash,若需添加listing包所支持的其他语言,可参考本文件方法进行定义,尽量保持全文的代码风格一致
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sysucode}[2021/01/21 v0.1 code style format defined for sysuthesis]
\RequirePackage{listings}
\RequirePackage{xcolor}
% 定义不同模块所用颜色
\colorlet{keywordcolor}{green!40!black}
\colorlet{commentcolor}{purple!40!black}
\colorlet{stringcolor}{orange}
\colorlet{identifiercolor}{blue}
\colorlet{exceptioncolour}{pink!60!black}
\colorlet{magicmethodcolour}{violet}
% 定义Python代码风格
% 由于listing中自带的Python高亮模块并不完整,因此手动添加一些需要高亮的关键字
% 参考自:https://github.com/olivierverdier/python-latex-highlighting/blob/master/pythonhighlight.sty
% 使用方法 \begin{python} ... \end{python}
\lstdefinestyle{sysupython}{
language=python,
tabsize=4, % 设置indent缩进为4个空格
basicstyle=\ttfamily\footnotesize, % 设置字号和字体
breaklines=true, % 当代码过长时,自动换行
frame=L, % 设置代码显示边框
keywordstyle=\bfseries\color{keywordcolor},
commentstyle=\itshape\color{commentcolor},
stringstyle=\color{stringcolor},
emph={and, break, continue, yield, del,%
except, exec, finally, for, from, global, import, in,%
lambda, not, or, pass, raise, return, try, while, assert, with, as},
emphstyle=\bfseries\color{identifiercolor},
emph={[2]True, False, None},
emphstyle=[2]\color{identifiercolor},
emph={[3]Exception, NameError, IndexError, SyntaxError, TypeError, ValueError, OverflowError, ZeroDivisionError},
emphstyle=[3]\color{exceptioncolour},
emph={[4]ode, fsolve, sqrt, exp, sin, cos, arctan, arctan2, arccos, pi, array, norm, solve, dot, arange, isscalar, max, sum,%
flatten, shape, reshape, find, any, all, abs, plot, linspace, legend, quad, polyval, polyfit, hstack, concatenate, vstack,%
column_stack, empty, zeros, ones, rand, vander, grid, pcolor, eig, eigs, eigvals, svd, qr, tan, det, logspace, roll, min,%
ean, cumsum, cumprod, diff, vectorize, lstsq, cla, eye, xlabel, ylabel, squeeze},
emphstyle=[4]\color{identifiercolor},
emph={[5]__init__, __add__, __mul__, __div__, __sub__, __call__, __getitem__, __setitem__, __neg__, __eq__, __ne__,%
__gt__, __lt__, __ge__, __le__, __nonzero__, __rmul__, __radd__, __repr__, __str__, __get__, __truediv__,%
__pow__, __name__, __future__, __all__},
emphstyle=[5]\color{magicmethodcolour}
}
% 定义listing包中的环境
\lstnewenvironment{python}[1][]{\lstset{style=sysupython}}{}
% 定义行内代码
% 使用方法 xxx \pyinline{python code here} xxx
\newcommand*{\pyinline}{\lstinline[style=sysupython]}
% 定义C++代码风格
% 使用方法 \begin{cpp} ... \end{cpp}
\lstdefinestyle{sysucpp}{
language=C++,
tabsize=4,
basicstyle=\ttfamily\footnotesize, % 设置字号和字体
breaklines=true, % 当代码过长时,自动换行
frame=L, % 设置代码显示边框
keywordstyle=\bfseries\color{keywordcolor},
commentstyle=\itshape\color{commentcolor},
stringstyle=\color{stringcolor},
identifierstyle=\color{blue}
}
\lstnewenvironment{cpp}[1][]{\lstset{style=sysucpp}}{}
% 定义终端输出
% 使用方法 \begin{bash} ... \end{bash}
\lstdefinestyle{sysubash}{
language=bash,
tabsize=4,
basicstyle=\ttfamily\footnotesize, % 设置字号和字体
breaklines=true, % 当代码过长时,自动换行
frame=L, % 设置代码显示边框
keywordstyle=\bfseries\color{keywordcolor},
commentstyle=\itshape\color{commentcolor},
stringstyle=\color{stringcolor},
identifierstyle=\color{blue}
}
\lstnewenvironment{bash}[1][]{\lstset{style=sysubash}}{}