Files
ouc_latex_template/科技报告/cls/code.cls
T

130 lines
4.0 KiB
OpenEdge ABL
Raw Normal View History

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% code listings
%% 代码块设定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{listings,verbatim}
% 代码配色不在这里定义,统一来自 cls/color.cls:
% codecolorkeywords = 海大蓝 codecolorcomments = 苍松绿
% codecolorstrings = 海大红 codecolortypes = 海大天蓝
% codecolorframe = 专银 codecolorbg = 极浅中性底
\lstdefinelanguage{JavaScript}{
keywords={do, if, in, for, let, new, try, var, case, else, enum, eval, null, this, true, void, with, await, break, catch, class, const, false, super, throw, while, yield, delete, export, import, public, return, static, switch, typeof, default, extends, finally, package, private, continue, debugger, function, arguments, interface, protected, implements, instanceof},
sensitive=true,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
\lstdefinelanguage{TypeScript}{
keywords={abstract, break, case, catch, class, const, continue, debugger, default, delete, do, else, enum, export, extends, false, finally, for, function, if, import, in, instanceof, new, null, return, super, switch, this, throw, true, try, typeof, var, void, while, with, as, implements, interface, let, package, private, protected, public, static, yield, any, boolean, constructor, declare, get, module, require, number, set, string, symbol, type, from, of},
sensitive=true,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
\lstdefinelanguage{golang}{
keywords={break, default, func, interface, select, case, defer, go, map, struct, chan, else, goto, package, switch, const, fallthrough, if, range, type, continue, for, import, return, var},
sensitive=true,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
\lstdefinestyle{mystyle}{
% Basic design
basicstyle=\linespread{1.2}\ttfamily,
frame=tb,
framesep=5pt,
framerule=.5pt,
framexleftmargin=10pt,
rulecolor=\color{codecolorframe},
abovecaptionskip=0pt,
belowcaptionskip=5pt,
aboveskip=5pt,
backgroundcolor=\color{codecolorbg},
% Code design
keywordstyle=\color{codecolorkeywords},
commentstyle=\color{codecolorcomments},
stringstyle=\color{codecolorstrings},
numberstyle=\small\color{oucmuted},
breakatwhitespace=false,
breaklines=true,
captionpos=t,
keepspaces=true,
% Line numbers
numbers=none,
numbersep=15pt,
xleftmargin=10pt,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% Code
tabsize=4,
showspaces=false,
showstringspaces=false,
showtabs=false,
breaklines=true,
}
\lstset{style=mystyle}
%% 命令行(bash 示例):浅海大蓝底 + 粗左侧海大蓝竖线
\lstdefinestyle{bashstyle}{
backgroundcolor=\color{oucblue!10!white},
basicstyle=\linespread{1.2}\ttfamily,
keepspaces=true,
numbers=none,
numbersep=10pt,
frame=l,
framerule=2pt,
framesep=5pt,
framexleftmargin=3pt,
framextopmargin=-5pt,
xleftmargin=10pt,
rulecolor=\color{oucblue},
% Code
tabsize=4,
showspaces=false,
showstringspaces=false,
showtabs=false,
breaklines=true,
}
%% 命令行输出:中性极浅底 + 专银左侧竖线
% 说明:输出是"机器吐出来的东西",语义上不该比命令更醒目,
% 所以颜色比 bashstyle 退一档,用专银而不是海大蓝。
\lstdefinestyle{bashoutputstyle}{
backgroundcolor=\color{codecolorbg},
basicstyle=\linespread{1.2}\ttfamily,
keepspaces=true,
numbers=none,
numbersep=10pt,
frame=l,
framerule=2pt,
framesep=5pt,
framexleftmargin=3pt,
framextopmargin=-5pt,
xleftmargin=10pt,
rulecolor=\color{codecolorframe},
% Code
tabsize=4,
showspaces=false,
showstringspaces=false,
showtabs=false,
breaklines=true,
}
%% 代码列表标题
\RequirePackage{caption}
\DeclareCaptionFormat{codecaptionformat}{%
%%\colorbox{black!20}{
%% \parbox{\textwidth}{#1#2\ttfamily#3}
%%}
\parbox{\textwidth}{\textcolor{ouccaption}\faCode~\textcolor{ouccaption}{#1#2}\hspace{.5em}\fzkai#3}
}
\captionsetup[lstlisting]{format=codecaptionformat}