├── .gitignore ├── LICENSE ├── README.md ├── fonts ├── Courier Std │ ├── CourierStd-Bold.otf │ ├── CourierStd-BoldOblique.otf │ ├── CourierStd-Oblique.otf │ └── CourierStd.otf ├── FontAwesome.otf ├── Minion Pro │ ├── MinionPro-Bold.otf │ ├── MinionPro-BoldIt.otf │ ├── MinionPro-It.otf │ └── MinionPro-Regular.otf ├── Myriad Pro │ ├── MyriadPro-Bold.otf │ ├── MyriadPro-BoldIt.otf │ ├── MyriadPro-It.otf │ └── MyriadPro-Regular.otf ├── 方正中等线_GBK.ttf ├── 方正书宋_GBK.ttf ├── 方正仿宋_GBK.ttf ├── 方正小标宋_GBK.ttf ├── 方正楷体_GBK.ttf └── 方正黑体_GBK.ttf ├── progartcn ├── figs │ ├── laravel_logo.png │ └── php-elephant-logo.png ├── progartcn.cls ├── tutorial-sample.pdf └── tutorial-sample.tex ├── progbookcn ├── book-sample.pdf ├── book-sample.tex ├── figs │ └── dependency-injection.png └── progbookcn.cls └── znote ├── booksample-The Great Gatsby.pdf ├── booksample-The Great Gatsby.tex ├── znotearticle.cls └── znotebook.cls /.gitignore: -------------------------------------------------------------------------------- 1 | *.ptc 2 | *.rel 3 | *.listing 4 | 5 | ## Core latex/pdflatex auxiliary files: 6 | *.aux 7 | *.lof 8 | *.log 9 | *.lot 10 | *.fls 11 | *.out 12 | *.toc 13 | *.fmt 14 | *.fot 15 | *.cb 16 | *.cb2 17 | .*.lb 18 | 19 | ## Intermediate documents: 20 | *.dvi 21 | *.xdv 22 | *-converted-to.* 23 | # these rules might exclude image files for figures etc. 24 | # *.ps 25 | # *.eps 26 | # *.pdf 27 | 28 | ## Generated if empty string is given at "Please type another file name for output:" 29 | .pdf 30 | 31 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 32 | *.bbl 33 | *.bcf 34 | *.blg 35 | *-blx.aux 36 | *-blx.bib 37 | *.run.xml 38 | 39 | ## Build tool auxiliary files: 40 | *.fdb_latexmk 41 | *.synctex 42 | *.synctex(busy) 43 | *.synctex.gz 44 | *.synctex.gz(busy) 45 | *.pdfsync 46 | 47 | ## Auxiliary and intermediate files from other packages: 48 | # algorithms 49 | *.alg 50 | *.loa 51 | 52 | # achemso 53 | acs-*.bib 54 | 55 | # amsthm 56 | *.thm 57 | 58 | # beamer 59 | *.nav 60 | *.pre 61 | *.snm 62 | *.vrb 63 | 64 | # changes 65 | *.soc 66 | 67 | # cprotect 68 | *.cpt 69 | 70 | # elsarticle (documentclass of Elsevier journals) 71 | *.spl 72 | 73 | # endnotes 74 | *.ent 75 | 76 | # fixme 77 | *.lox 78 | 79 | # feynmf/feynmp 80 | *.mf 81 | *.mp 82 | *.t[1-9] 83 | *.t[1-9][0-9] 84 | *.tfm 85 | 86 | #(r)(e)ledmac/(r)(e)ledpar 87 | *.end 88 | *.?end 89 | *.[1-9] 90 | *.[1-9][0-9] 91 | *.[1-9][0-9][0-9] 92 | *.[1-9]R 93 | *.[1-9][0-9]R 94 | *.[1-9][0-9][0-9]R 95 | *.eledsec[1-9] 96 | *.eledsec[1-9]R 97 | *.eledsec[1-9][0-9] 98 | *.eledsec[1-9][0-9]R 99 | *.eledsec[1-9][0-9][0-9] 100 | *.eledsec[1-9][0-9][0-9]R 101 | 102 | # glossaries 103 | *.acn 104 | *.acr 105 | *.glg 106 | *.glo 107 | *.gls 108 | *.glsdefs 109 | 110 | # gnuplottex 111 | *-gnuplottex-* 112 | 113 | # gregoriotex 114 | *.gaux 115 | *.gtex 116 | 117 | # htlatex 118 | *.4ct 119 | *.4tc 120 | *.idv 121 | *.lg 122 | *.trc 123 | *.xref 124 | 125 | # hyperref 126 | *.brf 127 | 128 | # knitr 129 | *-concordance.tex 130 | # TODO Comment the next line if you want to keep your tikz graphics files 131 | *.tikz 132 | *-tikzDictionary 133 | 134 | # listings 135 | *.lol 136 | 137 | # makeidx 138 | *.idx 139 | *.ilg 140 | *.ind 141 | *.ist 142 | 143 | # minitoc 144 | *.maf 145 | *.mlf 146 | *.mlt 147 | *.mtc 148 | *.mtc[0-9]* 149 | *.slf[0-9]* 150 | *.slt[0-9]* 151 | *.stc[0-9]* 152 | 153 | # minted 154 | _minted* 155 | *.pyg 156 | 157 | # morewrites 158 | *.mw 159 | 160 | # nomencl 161 | *.nlg 162 | *.nlo 163 | *.nls 164 | 165 | # pax 166 | *.pax 167 | 168 | # pdfpcnotes 169 | *.pdfpc 170 | 171 | # sagetex 172 | *.sagetex.sage 173 | *.sagetex.py 174 | *.sagetex.scmd 175 | 176 | # scrwfile 177 | *.wrt 178 | 179 | # sympy 180 | *.sout 181 | *.sympy 182 | sympy-plots-for-*.tex/ 183 | 184 | # pdfcomment 185 | *.upa 186 | *.upb 187 | 188 | # pythontex 189 | *.pytxcode 190 | pythontex-files-*/ 191 | 192 | # thmtools 193 | *.loe 194 | 195 | # TikZ & PGF 196 | *.dpth 197 | *.md5 198 | *.auxlock 199 | 200 | # todonotes 201 | *.tdo 202 | 203 | # easy-todo 204 | *.lod 205 | 206 | # xmpincl 207 | *.xmpi 208 | 209 | # xindy 210 | *.xdy 211 | 212 | # xypic precompiled matrices 213 | *.xyc 214 | 215 | # endfloat 216 | *.ttt 217 | *.fff 218 | 219 | # Latexian 220 | TSWLatexianTemp* 221 | 222 | ## Editors: 223 | # WinEdt 224 | *.bak 225 | *.sav 226 | 227 | # Texpad 228 | .texpadtmp 229 | 230 | # Kile 231 | *.backup 232 | 233 | # KBibTeX 234 | *~[0-9]* 235 | 236 | # auto folder when using emacs and auctex 237 | ./auto/* 238 | *.el 239 | 240 | # expex forward references with \gathertags 241 | *-tags.tex 242 | 243 | # standalone packages 244 | *.sta 245 | 246 | # generated if using elsarticle.cls 247 | *.spl 248 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Hu Zhifei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # My Ready-to-edit LaTeX Templates 2 | My ready-to-edit LaTeX templates, for books, articles, and notes, using XeLaTeX, specified both for Chinese and English documents. 3 | 4 | ## Templates for Books 5 | 6 | ### [progbookcn](./progbookcn) 7 | 8 | Yet Another LaTeX Template for Programming or Technical Books 9 | 10 | **Features** 11 | 12 | - Specified for programming or technical books, could be used to write English or Chinese books. 13 | - Using `Minion Pro`, `Myriad Pro` and `Courier Std` as English font families, and using FZ series for Chinese. 14 | - Customizing the styles of titlepage, partpage, chapter/section/subsection, hdr, etc. 15 | - Defining styles for languages not predefined in `listings`: JavaScript/ES6, TypeScript, golang. 16 | - Creating new framed boxes environments using `tcolorbox`: titledbox, information, keypoint, exclamation, question. 17 | 18 | **Testing platforms** 19 | - OS platform: 20 | Windows 10, macOS 21 | - TeX Systems: 22 | TeXLive 2016/2017, MacTeX 2018 23 | - Softwares: 24 | Emacs + AUCTeX, TeXstudio, WinEdt 25 | 26 | 27 | ## Templates for Note-taking 28 | 29 | ### znotebook 30 | 31 | znotebook 32 | 33 | ### znotearticle 34 | 35 | znotearticle 36 | 37 | ## Templates for Articles or Tutorials 38 | 39 | ### [progartcn](./progartcn) 40 | 41 | Yet Another LaTeX Template for Programming or Technical Articles or Tutorials 42 | 43 | **Features** 44 | 45 | - Specified for programming or technical articles or tutorials. 46 | - Using `Minion Pro`, `Myriad Pro` and `Courier Std` as English font families, and using FZ series for Chinese. 47 | - Customizing the styles of abstract, section/subsection/subsubsection, table, hdr, etc. 48 | - Defining a set of colors: primary, secondary, success, danger, info, warning, light, and dark. 49 | - Defining styles for languages not predefined in `listings`: JavaScript/ES6, TypeScript, golang. 50 | - Defining boxes for shell commands and output result, such as `shellBox` and `invertedShellBox`. 51 | - Creating new boxes environments using `tcolorbox`: noteBox, importantBox, tipBox, and warningBox. 52 | 53 | ## Templates for Presentations (Beamer) 54 | 55 | ### [GoogleBlue](https://github.com/WisdomFusion/latex-beamer-teamplates) 56 | 57 | ## Declarations 58 | 59 | **ALL FONTS INCLUDED IN THIS REPOSITORY ARE FOR TESTING AND STUDY ONLY.** 60 | 61 | ## Contributions 62 | 63 | If you'd like to help to improve these templates, just create a [Pull Request](https://github.com/WisdomFusion/latex-templates/pulls). Feel free to report bugs and issues [here](https://github.com/WisdomFusion/latex-templates/issues/new). -------------------------------------------------------------------------------- /fonts/Courier Std/CourierStd-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Courier Std/CourierStd-Bold.otf -------------------------------------------------------------------------------- /fonts/Courier Std/CourierStd-BoldOblique.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Courier Std/CourierStd-BoldOblique.otf -------------------------------------------------------------------------------- /fonts/Courier Std/CourierStd-Oblique.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Courier Std/CourierStd-Oblique.otf -------------------------------------------------------------------------------- /fonts/Courier Std/CourierStd.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Courier Std/CourierStd.otf -------------------------------------------------------------------------------- /fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /fonts/Minion Pro/MinionPro-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Minion Pro/MinionPro-Bold.otf -------------------------------------------------------------------------------- /fonts/Minion Pro/MinionPro-BoldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Minion Pro/MinionPro-BoldIt.otf -------------------------------------------------------------------------------- /fonts/Minion Pro/MinionPro-It.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Minion Pro/MinionPro-It.otf -------------------------------------------------------------------------------- /fonts/Minion Pro/MinionPro-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Minion Pro/MinionPro-Regular.otf -------------------------------------------------------------------------------- /fonts/Myriad Pro/MyriadPro-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Myriad Pro/MyriadPro-Bold.otf -------------------------------------------------------------------------------- /fonts/Myriad Pro/MyriadPro-BoldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Myriad Pro/MyriadPro-BoldIt.otf -------------------------------------------------------------------------------- /fonts/Myriad Pro/MyriadPro-It.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Myriad Pro/MyriadPro-It.otf -------------------------------------------------------------------------------- /fonts/Myriad Pro/MyriadPro-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/Myriad Pro/MyriadPro-Regular.otf -------------------------------------------------------------------------------- /fonts/方正中等线_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正中等线_GBK.ttf -------------------------------------------------------------------------------- /fonts/方正书宋_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正书宋_GBK.ttf -------------------------------------------------------------------------------- /fonts/方正仿宋_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正仿宋_GBK.ttf -------------------------------------------------------------------------------- /fonts/方正小标宋_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正小标宋_GBK.ttf -------------------------------------------------------------------------------- /fonts/方正楷体_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正楷体_GBK.ttf -------------------------------------------------------------------------------- /fonts/方正黑体_GBK.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/fonts/方正黑体_GBK.ttf -------------------------------------------------------------------------------- /progartcn/figs/laravel_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/progartcn/figs/laravel_logo.png -------------------------------------------------------------------------------- /progartcn/figs/php-elephant-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/progartcn/figs/php-elephant-logo.png -------------------------------------------------------------------------------- /progartcn/progartcn.cls: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %% progartcn - Yet Another LaTeX Template for Programming or Technical Articles or Tutorials 3 | %% WisdomFusion@gmail.com 4 | %% July, 2018 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | \NeedsTeXFormat{LaTeX2e} 8 | \ProvidesClass{progartcn}[July, 2018 Yet Another LaTeX Template for Technical Articles or Tutorials] 9 | \LoadClass[a4paper]{ctexart} 10 | 11 | \RequirePackage{xunicode} 12 | 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | %% colors 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | \RequirePackage[dvipsnames]{xcolor} 18 | 19 | % primary 20 | \definecolor{colorPrimary}{HTML}{007bff} 21 | \definecolor{colorPrimaryBorder}{HTML}{b8daff} 22 | \definecolor{colorPrimaryBackground}{HTML}{cce5ff} 23 | \definecolor{colorPrimaryText}{HTML}{004085} 24 | 25 | % secondary 26 | \definecolor{colorSecondary}{HTML}{6c757d} 27 | \definecolor{colorSecondaryBorder}{HTML}{d6d8db} 28 | \definecolor{colorSecondaryBackground}{HTML}{e2e3e5} 29 | \definecolor{colorSecondaryText}{HTML}{383d41} 30 | 31 | % success 32 | \definecolor{colorSuccess}{HTML}{28a745} 33 | \definecolor{colorSuccessBorder}{HTML}{c3e6cb} 34 | \definecolor{colorSuccessBackground}{HTML}{d4edda} 35 | \definecolor{colorSuccessText}{HTML}{155724} 36 | 37 | % info 38 | \definecolor{colorInfo}{HTML}{17a2b8} 39 | \definecolor{colorInfoBorder}{HTML}{bee5eb} 40 | \definecolor{colorInfoBackground}{HTML}{d1ecf1} 41 | \definecolor{colorInfoText}{HTML}{0c5460} 42 | 43 | % danger 44 | \definecolor{colorDanger}{HTML}{dc3545} 45 | \definecolor{colorDangerBorder}{HTML}{f5c6cb} 46 | \definecolor{colorDangerBackground}{HTML}{f8d7da} 47 | \definecolor{colorDangerText}{HTML}{721c24} 48 | 49 | % warning 50 | \definecolor{colorWarning}{HTML}{ffc107} 51 | \definecolor{colorWarningBorder}{HTML}{ffeeba} 52 | \definecolor{colorWarningBackground}{HTML}{fff3cd} 53 | \definecolor{colorWarningText}{HTML}{856404} 54 | 55 | % light 56 | \definecolor{colorLight}{HTML}{f8f9fa} 57 | \definecolor{colorLightBorder}{HTML}{fdfdfe} 58 | \definecolor{colorLightBackground}{HTML}{fefefe} 59 | \definecolor{colorLightText}{HTML}{818182} 60 | 61 | % dark 62 | \definecolor{colorDark}{HTML}{343a40} 63 | \definecolor{colorDarkBorder}{HTML}{c6c8ca} 64 | \definecolor{colorDarkBackground}{HTML}{d6d8d9} 65 | \definecolor{colorDarkText}{HTML}{1b1e21} 66 | 67 | 68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 | %% hyperref settings 70 | %% 超链接设定 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 72 | \RequirePackage{hyperref} 73 | \hypersetup{ 74 | bookmarksnumbered, 75 | colorlinks, 76 | linkcolor={black}, 77 | citecolor={black}, 78 | urlcolor={black} 79 | } 80 | 81 | \RequirePackage[open,openlevel=0,atend]{bookmark} 82 | 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 84 | %% graphicx settings 85 | %% 图片设定 86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 87 | \RequirePackage{graphicx} 88 | \RequirePackage{graphbox} 89 | \RequirePackage{wrapfig} 90 | \graphicspath{{./figs/}{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}} 91 | 92 | 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 94 | %% geometry settings 95 | %% 页面设定 96 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 97 | \RequirePackage{geometry} 98 | \geometry{ 99 | textwidth=138mm, 100 | textheight=215mm, 101 | left=27mm, 102 | %% or 103 | %% inner=23mm, 104 | right=27mm, 105 | %% or 106 | %% outer=18mm, 107 | top=25.4mm, bottom=25.4mm, 108 | headheight=2.17cm, 109 | headsep=4mm, 110 | footskip=12mm, 111 | heightrounded, 112 | } 113 | 114 | 115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 116 | %% fonts settings 117 | %% 字体设定 118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 119 | \RequirePackage{fontspec} 120 | %% \usepackage{ebgaramond} 121 | 122 | %% 开明式:句末点号用占一个汉字宽度,标号和句内点号占半个汉字宽度 123 | %\punctstyle{kaiming} 124 | 125 | \setmainfont{Minion Pro} 126 | \setsansfont{Myriad Pro} 127 | \setmonofont{Courier Std} 128 | 129 | \setCJKmainfont[BoldFont={方正小标宋_GBK}, ItalicFont={方正楷体_GBK}, BoldItalicFont={方正仿宋_GBK}]{方正书宋_GBK} 130 | \setCJKsansfont{方正黑体_GBK} 131 | \setCJKmonofont{方正中等线_GBK} 132 | 133 | \XeTeXlinebreaklocale "zh" 134 | \XeTeXlinebreakskip = 0pt plus 1pt 135 | 136 | \setCJKfamilyfont{fzss}{方正书宋_GBK} 137 | \newcommand{\fzss}{\CJKfamily{fzss}} 138 | 139 | \setCJKfamilyfont{fzxbs}{方正小标宋_GBK} 140 | \newcommand{\fzxbs}{\CJKfamily{fzxbs}} 141 | 142 | \setCJKfamilyfont{fzhei}{方正黑体_GBK} 143 | \newcommand{\fzhei}{\CJKfamily{fzhei}} 144 | 145 | \setCJKfamilyfont{fzkai}{方正楷体_GBK} 146 | \newcommand{\fzkai}{\CJKfamily{fzkai}} 147 | 148 | \setCJKfamilyfont{fzfs}{方正仿宋_GBK} 149 | \newcommand{\fzfs}{\CJKfamily{fzfs}} 150 | 151 | \setCJKfamilyfont{fzzdx}{方正中等线_GBK} 152 | \newcommand{\fzzdx}{\CJKfamily{fzzdx}} 153 | 154 | 155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 156 | %% titlesec 157 | %% 标题设定 158 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 159 | \RequirePackage{titlesec} 160 | \RequirePackage{zhnumber} 161 | 162 | 163 | %% \renewcommand\abstractname{Summary} 164 | \renewenvironment{abstract}{\noindent\rule{\textwidth}{.5pt}\\[2ex] \centering\begin{minipage}{.97\textwidth}{\zihao{-4}\sffamily\bfseries\abstractname}\\} 165 | {\par\noindent\end{minipage}\\[2ex] \rule{\textwidth}{.5pt}} 166 | 167 | %% section 168 | \titleformat{\section} 169 | [hang] 170 | {\sffamily} 171 | {\centering\zihao{-3}\bfseries\thesection\enspace} 172 | {1pt} 173 | {\zihao{-3}\bfseries} 174 | 175 | %% subsection 176 | \titleformat{\subsection} 177 | [hang] 178 | {\sffamily} 179 | {\zihao{4}\bfseries\thesubsection\enspace} 180 | {1pt} 181 | {\zihao{4}\bfseries\filright} 182 | 183 | %% subsubsection 184 | \titleformat{\subsubsection} 185 | [hang] 186 | {\sffamily} 187 | {\zihao{-4}\bfseries\thesubsubsection\enspace} 188 | {1pt} 189 | {\zihao{-4}\bfseries\filright} 190 | 191 | \titlespacing{\section}{0pt}{2.5ex plus 1ex minus .2ex}{1.3ex plus .2ex} 192 | %\titlespacing{\section}{0pt}{\parskip}{-\parskip} 193 | \titlespacing{\subsection}{0pt}{\parskip}{-\parskip} 194 | \titlespacing{\subsubsection}{0pt}{\parskip}{-\parskip} 195 | 196 | 197 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 198 | %% boxes 199 | %% 信息框 200 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 201 | \RequirePackage[many]{tcolorbox} 202 | \RequirePackage{fontawesome} 203 | 204 | %% 带标题的文本框 205 | \newtcolorbox{titledBox}[1]{% 206 | tikznode boxed title, 207 | enhanced, 208 | arc=3pt, 209 | interior style={white}, 210 | attach boxed title to top center = {yshift=-\tcboxedtitleheight/2}, 211 | fonttitle=\normalfont, 212 | colbacktitle=white,coltitle=black, 213 | boxed title style={size=normal,colframe=white,boxrule=0pt}, 214 | boxrule=.5pt, 215 | left=5pt, right=5pt, top=5pt, bottom=0pt, 216 | boxsep=5pt, 217 | title={#1}, 218 | halign=left, 219 | fontupper=\fzkai 220 | } 221 | 222 | 223 | %% Note 224 | \newtcolorbox{noteBox}{% 225 | enhanced, 226 | arc=2pt, 227 | boxrule=.5pt, 228 | left=5pt, right=5pt, top=0pt, bottom=0pt, 229 | boxsep=5pt, 230 | colframe=colorInfoBorder, 231 | colback=colorInfoBackground, 232 | colbacktitle=colorInfoBackground, 233 | coltext=colorInfoText, 234 | title={\textcolor{colorInfoText}{\faStickyNoteO\hspace{.5em}\bfseries{\textsc{Note}}}}, 235 | titlerule=0pt, 236 | halign=left, 237 | fontupper=\fzkai 238 | } 239 | 240 | %% Important 241 | \newtcolorbox{importantBox}{% 242 | enhanced, 243 | arc=2pt, 244 | boxrule=.5pt, 245 | left=5pt, right=5pt, top=0pt, bottom=0pt, 246 | boxsep=5pt, 247 | colframe=colorWarningBorder, 248 | colback=colorWarningBackground, 249 | colbacktitle=colorWarningBackground, 250 | coltext=colorWarningText, 251 | title={\textcolor{colorWarningText}{\faExclamationCircle\hspace{.5em}\bfseries{\textsc{Important}}}}, 252 | titlerule=0pt, 253 | halign=left, 254 | fontupper=\fzkai 255 | } 256 | 257 | %% Tip 258 | \newtcolorbox{tipBox}{% 259 | enhanced, 260 | arc=2pt, 261 | boxrule=.5pt, 262 | left=5pt, right=5pt, top=0pt, bottom=0pt, 263 | boxsep=5pt, 264 | colframe=colorSuccessBorder, 265 | colback=colorSuccessBackground, 266 | colbacktitle=colorSuccessBackground, 267 | coltext=colorSuccessText, 268 | title={\textcolor{colorSuccessText}{\faCheckCircle\hspace{.5em}\bfseries{\textsc{Tip}}}}, 269 | titlerule=0pt, 270 | halign=left, 271 | fontupper=\fzkai 272 | } 273 | 274 | %% Warning 275 | \newtcolorbox{warningBox}{% 276 | enhanced, 277 | arc=2pt, 278 | boxrule=.5pt, 279 | left=5pt, right=5pt, top=0pt, bottom=0pt, 280 | boxsep=5pt, 281 | colframe=colorDangerBorder, 282 | colback=colorDangerBackground, 283 | colbacktitle=colorDangerBackground, 284 | coltext=colorDangerText, 285 | title={\textcolor{colorDangerText}{\faExclamationTriangle\hspace{.5em}\bfseries{\textsc{Warning}}}}, 286 | titlerule=0pt, 287 | halign=left, 288 | fontupper=\fzkai 289 | } 290 | 291 | 292 | %% verbatim 环境无法直接在新环境中使用 293 | %% 换用 \VerbatimEnvironment \begin{Verbatim} 294 | \RequirePackage{fancyvrb} 295 | 296 | %% 命令行 297 | \newenvironment{shellBox} 298 | {% 299 | \VerbatimEnvironment 300 | \begin{tcolorbox}[ 301 | enhanced, 302 | arc=2pt, 303 | boxrule=.5pt, 304 | left=5pt, right=5pt, top=0pt, bottom=0pt, 305 | boxsep=5pt, 306 | colframe=colorSecondaryBorder, 307 | colback=colorSecondaryBackground, 308 | coltext=colorSecondaryText, 309 | title={}, 310 | fontupper=\linespread{1.2} 311 | ]% 312 | \begin{Verbatim} 313 | } 314 | {% 315 | \end{Verbatim} 316 | \end{tcolorbox} 317 | } 318 | 319 | %% 命令行 320 | \newenvironment{invertedShellBox} 321 | {% 322 | \VerbatimEnvironment 323 | \begin{tcolorbox}[ 324 | enhanced, 325 | arc=2pt, 326 | boxrule=.5pt, 327 | left=5pt, right=5pt, top=0pt, bottom=0pt, 328 | boxsep=5pt, 329 | colframe=colorSecondary, 330 | colback=colorSecondary, 331 | coltext=white, 332 | title={}, 333 | fontupper=\linespread{1.2} 334 | ]% 335 | \begin{Verbatim} 336 | } 337 | {% 338 | \end{Verbatim} 339 | \end{tcolorbox} 340 | } 341 | 342 | 343 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 344 | %% head and foot 345 | %% 页眉页脚 346 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 347 | \RequirePackage{fancyhdr} 348 | \RequirePackage{zhnumber} 349 | 350 | \pagestyle{fancy} 351 | \fancyhf{} 352 | \renewcommand\headrulewidth{.5pt} 353 | \renewcommand\footrulewidth{0pt} 354 | %\futurelet\TMPheadrule\def\headrule{{\color{violet}\TMPheadrule}} 355 | 356 | \renewcommand{\sectionmark}[1]{\markright{#1}} 357 | 358 | \fancyhead[L]{\fzkai{\rightmark}} 359 | \fancyhead[R]{\thepage} 360 | 361 | 362 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 363 | %% code listings 364 | %% 代码块设定 365 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 366 | \RequirePackage{listings,verbatim} 367 | 368 | \lstdefinelanguage{JavaScript}{ 369 | 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}, 370 | sensitive=true, 371 | comment=[l]{//}, 372 | morecomment=[s]{/*}{*/}, 373 | morestring=[b]', 374 | morestring=[b]" 375 | } 376 | 377 | \lstdefinelanguage{TypeScript}{ 378 | 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}, 379 | sensitive=true, 380 | comment=[l]{//}, 381 | morecomment=[s]{/*}{*/}, 382 | morestring=[b]', 383 | morestring=[b]" 384 | } 385 | 386 | \lstdefinelanguage{golang}{ 387 | 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}, 388 | sensitive=true, 389 | comment=[l]{//}, 390 | morecomment=[s]{/*}{*/}, 391 | morestring=[b]', 392 | morestring=[b]" 393 | } 394 | 395 | \lstdefinestyle{mystyle}{ 396 | % Basic design 397 | basicstyle=\linespread{1.2}\ttfamily, 398 | frame=tb, 399 | framesep=5pt, 400 | framerule=.5pt, 401 | framexleftmargin=10pt, 402 | rulecolor=\color{black}, 403 | abovecaptionskip=0pt, 404 | belowcaptionskip=5pt, 405 | aboveskip=5pt, 406 | backgroundcolor=\color{black!5!white}, 407 | % Code design 408 | keywordstyle=\color{colorPrimary}, 409 | commentstyle=\color{colorSuccess}, 410 | stringstyle=\color{colorSecondary}, 411 | numberstyle=\small\color{gray}, 412 | breakatwhitespace=false, 413 | breaklines=true, 414 | captionpos=t, 415 | keepspaces=true, 416 | % Line numbers 417 | numbers=none, 418 | numbersep=15pt, 419 | xleftmargin=10pt, 420 | stepnumber=1, 421 | firstnumber=1, 422 | numberfirstline=true, 423 | % Code 424 | tabsize=4, 425 | showspaces=false, 426 | showstringspaces=false, 427 | showtabs=false, 428 | breaklines=true, 429 | } 430 | \lstset{style=mystyle} 431 | 432 | %% 命令行 433 | \lstdefinestyle{bashInputStyle}{ 434 | backgroundcolor=\color{colorInfoBackground}, 435 | basicstyle=\linespread{1.2}\ttfamily\color{colorDark}, 436 | keepspaces=true, 437 | numbers=none, 438 | numbersep=10pt, 439 | frame=l, 440 | framerule=2pt, 441 | framesep=5pt, 442 | framexleftmargin=3pt, 443 | framextopmargin=-5pt, 444 | xleftmargin=10pt, 445 | rulecolor=\color{colorInfo}, 446 | % Code 447 | tabsize=4, 448 | showspaces=false, 449 | showstringspaces=false, 450 | showtabs=false, 451 | breaklines=true, 452 | } 453 | 454 | %% 命令行输出 455 | \lstdefinestyle{bashOutputStyle}{ 456 | backgroundcolor=\color{black!5!white}, 457 | basicstyle=\linespread{1.2}\ttfamily\color{colorDark}, 458 | keepspaces=true, 459 | numbers=none, 460 | numbersep=10pt, 461 | frame=l, 462 | framerule=2pt, 463 | framesep=5pt, 464 | framexleftmargin=3pt, 465 | framextopmargin=-5pt, 466 | xleftmargin=10pt, 467 | rulecolor=\color{colorSecondary}, 468 | % Code 469 | tabsize=4, 470 | showspaces=false, 471 | showstringspaces=false, 472 | showtabs=false, 473 | breaklines=true, 474 | } 475 | 476 | %% 代码列表标题 477 | \RequirePackage{caption} 478 | \DeclareCaptionFormat{codecaptionformat}{% 479 | %%\colorbox{black!20}{ 480 | %% \parbox{\textwidth}{#1#2\ttfamily#3} 481 | %%} 482 | \parbox{\textwidth}{\textcolor{violet}\faCode~\textcolor{violet}{#1#2}\hspace{.5em}\fzkai #3} 483 | } 484 | \captionsetup[lstlisting]{format=codecaptionformat} 485 | 486 | 487 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 488 | %% Chinese names 489 | %% 中文名称 490 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 491 | \renewcommand{\figurename}{图} 492 | \renewcommand{\tablename}{表} 493 | \renewcommand{\lstlistingname}{CODE} 494 | \renewcommand{\abstractname}{摘要} 495 | 496 | 497 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 498 | %% global settings 499 | %% 以下是全局格式设定 500 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 501 | 502 | %% 添加首行缩进,两个字符 503 | \RequirePackage{indentfirst} 504 | \setlength{\parindent}{2em} 505 | 506 | %% 行距 507 | \linespread{1.5} 508 | 509 | %% captions 510 | \RequirePackage[singlelinecheck=false]{caption} 511 | \DeclareCaptionFont{kai}{\fzkai} 512 | \captionsetup[table]{belowskip=0pt,aboveskip=5pt,labelfont=kai,textfont=kai} 513 | \captionsetup[figure]{belowskip=0pt,aboveskip=5pt,format=hang,labelfont=kai,textfont=kai} 514 | -------------------------------------------------------------------------------- /progartcn/tutorial-sample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/progartcn/tutorial-sample.pdf -------------------------------------------------------------------------------- /progartcn/tutorial-sample.tex: -------------------------------------------------------------------------------- 1 | %!TEX program = xelatex 2 | 3 | \documentclass{progartcn} 4 | \usepackage{graphicx} 5 | \usepackage[dvipsnames]{xcolor} 6 | \usepackage{wrapfig} 7 | \usepackage{enumerate} 8 | \usepackage{amsmath,mathrsfs,amsfonts} 9 | \usepackage{booktabs} 10 | \usepackage{tabularx} 11 | \usepackage{colortbl} 12 | \usepackage{multirow,makecell} 13 | \usepackage{multicol} 14 | \usepackage{ulem} % \uline 15 | \usepackage{listings} 16 | \usepackage{tikz} 17 | \usepackage{tcolorbox} 18 | \usepackage{fontawesome} 19 | 20 | 21 | \title{\bfseries\sffamily 22 | Sample: Angular 6 快速入门\\ 23 | \normalfont\zihao{-3} 24 | One framework. Mobile \& desktop. 25 | } 26 | \author{WisdomFusion \\ \faGithubAlt~ https://github.com/WisdomFusion} 27 | \date{} 28 | 29 | 30 | \begin{document} 31 | 32 | \sloppy % 解决中英文混排文字超出边界问题 33 | 34 | 35 | \maketitle 36 | \thispagestyle{empty} 37 | 38 | 39 | \begin{abstract} 40 | \noindent 只是样例填充的文字,内容都不相干的!Laravel 5.6 在 Laravel 5.5 的基础上继续进行优化,包括\textbf{日志系统}、\textit{单机任务调度}、\textbf{\textit{模型序列化优化}}、动态频率限制、广播频道类、API 资源控制器生成、Eloquent 日期格式化优化、Blade 组件别名、Argon2 密码哈希支持、引入 Collision 扩展包等等等等。此外,所有的前端脚手架代码都已升级到 Bootstrap 4,Laravel 底层使用的 Symfony 组件都已升级到 Symfony $\sim$4.0 版本。 41 | 42 | \vspace{2ex} 43 | \noindent \textbf{关键字:}LISP,\hspace{.5em}PHP,\hspace{.5em}学习环境 44 | \end{abstract} 45 | 46 | \section{什么是 Angular?} 47 | \label{newfeatures} 48 | 49 | Angular 是一个开发平台。它能帮你更轻松的构建 Web 应用。Angular 集声明式模板、依赖注入、端到端工具和一些最佳实践于一身,为你解决开发方面的各种挑战。Angular 为开发者提升构建 Web、手机或桌面应用的能力。 50 | 51 | \section{架构概览} 52 | 53 | Angular 是一个用 HTML 和 TypeScript 构建客户端应用的平台与框架。Angular 本身使用 TypeScript 写成的。它将核心功能和可选功能作为一组 TypeScript 库进行实现,你可以把它们导入你的应用中。 54 | 55 | Angular 的基本构造块是 NgModule,它为组件提供了编译的上下文环境。 NgModule 会把相关的代码收集到一些功能集中。Angular 应用就是由一组 \verb|NgModule| 定义出的。 应用至少会有一个用于引导应用的根模块,通常还会有很多特性模块。 56 | 57 | \begin{itemize} 58 | \item 组件定义\textbf{视图}。视图是一组可见的屏幕元素,Angular 可以根据你的程序逻辑和数据来选择和修改它们。 每个应用都至少有一个根组件。 59 | 60 | \item 组件使用\textbf{服务}。服务会提供那些与视图不直接相关的功能。服务提供商可以作为依赖被注入到组件中, 这能让你的代码更加模块化、可复用,而且高效。 61 | \end{itemize} 62 | 63 | \section{\ttfamily @NgModule \sffamily{元数据}} 64 | 65 | \verb|NgModule| 是一个带有 \verb|@NgModule| 装饰器的类。\verb|@NgModule| 装饰器是一个函数,它接受一个元数据对象,该对象的属性用来描述这个模块。其中最重要的属性如下。 66 | 67 | \begin{itemize} 68 | \item \verb|declarations|(可声明对象表) —— 那些属于本 \verb|NgModule| 的组件、指令、管道。 69 | 70 | \item \verb|exports|(导出表) —— 那些能在其它模块的组件模板中使用的可声明对象的子集。 71 | 72 | \item \verb|imports|(导入表) —— 那些导出了本模块中的组件模板所需的类的其它模块。 73 | 74 | \item \verb|providers| —— 本模块向全局服务中贡献的那些服务的创建器。 这些服务能被本应用中的任何部分使用。(你也可以在组件级别指定服务提供商,这通常是首选方式。) 75 | 76 | \item \verb|bootstrap| —— 应用的主视图,称为根组件。它是应用中所有其它视图的宿主。只有根模块才应该设置这个 \verb|bootstrap| 属性。 77 | \end{itemize} 78 | 79 | 80 | 下面是一个简单的根 NgModule 定义: 81 | 82 | \begin{lstlisting}[language=TypeScript,caption={src/app/app.module.ts}] 83 | import { NgModule } from '@angular/core'; 84 | import { BrowserModule } from '@angular/platform-browser'; 85 | @NgModule({ 86 | imports: [ BrowserModule ], 87 | providers: [ Logger ], 88 | declarations: [ AppComponent ], 89 | exports: [ AppComponent ], 90 | bootstrap: [ AppComponent ] 91 | }) 92 | export class AppModule { } 93 | \end{lstlisting} 94 | 95 | \begin{lstlisting}[style=bashInputStyle] 96 | cd my-app 97 | ng serve --open 98 | \end{lstlisting} 99 | 100 | \begin{lstlisting}[style=bashOutputStyle] 101 | blablabla 102 | \end{lstlisting} 103 | 104 | \section{快速上手} 105 | 106 | Angular CLI是一个命令行界面工具,它可以创建项目、添加文件以及执行一大堆开发任务,比如测试、打包和发布。 107 | 108 | 本章的目标是构建并运行一个超级简单的 TypeScript Angular 应用。使用 Angular CLI 来让每个 Angular 应用从风格指南的那些建议中获益。 109 | 110 | 在本章的末尾,你会对用 CLI 进行开发有一个最基本的理解,并将其作为其它文档范例以及真实应用的基础。 111 | 112 | \subsection{步骤 1. 设置开发环境} 113 | 114 | 在开始工作之前,你必须设置好开发环境。 115 | 116 | 如果你的电脑里没有 Node.js®和 npm,请安装它们。 117 | 118 | \begin{invertedShellBox} 119 | npm install -g @angular/cli 120 | \end{invertedShellBox} 121 | 122 | \subsection{步骤 2. 创建新项目} 123 | 124 | 打开终端窗口。 125 | 126 | 运行下列命令来生成一个新项目以及默认的应用代码: 127 | 128 | \begin{invertedShellBox} 129 | ng new my-app 130 | \end{invertedShellBox} 131 | 132 | \subsection{步骤 3. 启动开发服务器} 133 | 134 | 进入项目目录,并启动服务器。 135 | 136 | \begin{invertedShellBox} 137 | cd my-app 138 | ng serve --open 139 | \end{invertedShellBox} 140 | 141 | 你的应用代码位于 \verb|src| 文件夹中。 所有的 Angular 组件、模板、样式、图片以及你的应用所需的任何东西都在那里。 这个文件夹之外的文件都是为构建应用提供支持用的。 142 | 143 | \begin{lstlisting}[style=bashOutputStyle] 144 | src 145 | app 146 | app.component.css 147 | app.component.html 148 | app.component.spec.ts 149 | app.component.ts 150 | app.module.ts 151 | assets 152 | .gitkeep 153 | environments 154 | environment.prod.ts 155 | environment.ts 156 | browserslist 157 | favicon.ico 158 | index.html 159 | ... 160 | \end{lstlisting} 161 | 162 | \noindent 163 | \begin{table}[htp] 164 | \caption{sample table 表 }\label{table:1} 165 | \begin{tabularx}{\textwidth}{>{\hsize=.6\hsize\raggedright\arraybackslash}X>{\raggedright\arraybackslash}X}\toprule 166 | \bfseries{文件} & \bfseries{用途}\\ \midrule 167 | \verb|app/app.component.{ts,html,css,spec.ts}| & 使用 HTML 模板、CSS 样式和单元测试定义 \verb|AppComponent| 组件。 它是根组件,随着应用的成长它会成为一棵组件树的根节点。\\ 168 | \verb|app/app.module.ts| & 定义 \verb|AppModule|,根模块为 Angular 描述如何组装应用。 目前,它只声明了 \verb|AppComponent|。 不久,它将声明更多组件。\\ \bottomrule 169 | \end{tabularx} 170 | \end{table} 171 | blabla 172 | 173 | \clearpage 174 | 175 | \section{boxes} 176 | 177 | \noindent\verb|\begin{titledBox}{} <content> \end{titledBox}| 178 | 179 | \begin{titledBox}{HTTP/Console 内核} 180 | HTTP 内核继承自 \verb|Illuminate\Foundation\Http\Kernel| 类,该类定义了一个 \verb|bootstrappers| 数组,这个数组中的类在请求被执行前运行,这些 \verb|bootstrappers| 配置了错误处理、日志、检测应用环境以及其它在请求被处理前需要执行的任务。 181 | \end{titledBox} 182 | 183 | \noindent\verb|\begin{noteBox} <content> \end{noteBox}| 184 | 185 | \begin{noteBox} 186 | HTTP 内核继承自 \verb|Illuminate\Foundation\Http\Kernel| 类,该类定义了一个 \verb|bootstrappers| 数组,这个数组中的类在请求被执行前运行,这些 \verb|bootstrappers| 配置了错误处理、日志、检测应用环境以及其它在请求被处理前需要执行的任务。 187 | \end{noteBox} 188 | 189 | \noindent\verb|\begin{importantBox} <content> \end{importantBox}| 190 | 191 | \begin{importantBox} 192 | HTTP 内核继承自 \verb|Illuminate\Foundation\Http\Kernel| 类,该类定义了一个 \verb|bootstrappers| 数组,这个数组中的类在请求被执行前运行,这些 \verb|bootstrappers| 配置了错误处理、日志、检测应用环境以及其它在请求被处理前需要执行的任务。 193 | \end{importantBox} 194 | 195 | \noindent\verb|\begin{tipBox} <content> \end{tipBox}| 196 | 197 | \begin{tipBox} 198 | HTTP 内核继承自 \verb|Illuminate\Foundation\Http\Kernel| 类,该类定义了一个 \verb|bootstrappers| 数组,这个数组中的类在请求被执行前运行,这些 \verb|bootstrappers| 配置了错误处理、日志、检测应用环境以及其它在请求被处理前需要执行的任务。 199 | \end{tipBox} 200 | 201 | \noindent\verb|\begin{warningBox} <content> \end{warningBox}| 202 | 203 | \begin{warningBox} 204 | HTTP 内核继承自 \verb|Illuminate\Foundation\Http\Kernel| 类,该类定义了一个 \verb|bootstrappers| 数组,这个数组中的类在请求被执行前运行,这些 \verb|bootstrappers| 配置了错误处理、日志、检测应用环境以及其它在请求被处理前需要执行的任务。 205 | \end{warningBox} 206 | 207 | \noindent\verb|\begin{shellBox} <content> \end{shellBox}| 208 | 209 | \begin{shellBox} 210 | cd my-app 211 | ng serve --open 212 | \end{shellBox} 213 | 214 | \noindent\verb|\begin{invertedShellBox} <content> \end{invertedShellBox}| 215 | 216 | \begin{invertedShellBox} 217 | cd my-app 218 | ng serve --open 219 | \end{invertedShellBox} 220 | 221 | 222 | \section{服务容器3} 223 | 224 | Laravel 服务容器是一个用于管理类依赖和执行依赖注入的强大工具。依赖注入听上去很花哨,其实质是通过构造函数或者某些情况下通过 \verb|setter| 方法将类依赖注入到类中。 225 | 226 | \begin{lstlisting}[language=PHP,caption={PHP 代码样例}] 227 | <?php 228 | namespace App\Http\Controllers; 229 | 230 | use App\User; 231 | use App\Repositories\UserRepository; 232 | use App\Http\Controllers\Controller; 233 | 234 | class UserController extends Controller 235 | { 236 | /** 237 | * The user repository implementation. 238 | * 239 | * @var UserRepository 240 | */ 241 | protected $users; 242 | 243 | /** 244 | * Create a new controller instance. 245 | * 246 | * @param UserRepository $users 247 | * @return void 248 | */ 249 | public function __construct(UserRepository $users) 250 | { 251 | $this->users = $users; 252 | } 253 | 254 | ... 255 | } 256 | \end{lstlisting} 257 | 258 | \centering{ 259 | \includegraphics[width=5cm,align=c]{laravel_logo.png} 260 | \qquad 261 | \includegraphics[width=5cm,align=c]{php-elephant-logo.png} 262 | } 263 | 264 | 265 | \end{document} 266 | -------------------------------------------------------------------------------- /progbookcn/book-sample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/progbookcn/book-sample.pdf -------------------------------------------------------------------------------- /progbookcn/book-sample.tex: -------------------------------------------------------------------------------- 1 | %!TEX program = xelatex 2 | 3 | \documentclass{progbookcn} 4 | \usepackage{wrapfig} 5 | \usepackage{enumerate} 6 | \usepackage{amsmath,mathrsfs,amsfonts} 7 | \usepackage{tabularx} 8 | \usepackage{booktabs} 9 | \usepackage{colortbl} 10 | \usepackage{multirow,makecell} 11 | \usepackage{multicol} 12 | \usepackage{ulem} % \uline 13 | \usepackage{listings} 14 | \usepackage{tikz} 15 | \usepackage{tcolorbox} 16 | \usepackage{fontawesome} 17 | \usepackage[open,openlevel=0,atend]{bookmark} 18 | 19 | \usepackage{imakeidx} 20 | \makeindex[% 21 | intoc=true, 22 | columns=2, 23 | columnsep=1cm, 24 | columnseprule=true 25 | ] 26 | 27 | 28 | \begin{document} 29 | 30 | %% title page 31 | \begin{titlepage} 32 | \vspace*{25ex} 33 | 34 | \hspace{0.05\textwidth}\begin{minipage}{.9\textwidth} 35 | \flushright 36 | 37 | %%中文书名 38 | {\zihao{1}\textbf{中文书名:Angular 应用安全编程}} 39 | 40 | \rule{\linewidth}{.5pt} 41 | 42 | \vspace{2ex} 43 | 44 | %% 英文书名 45 | {\zihao{2}\textsf{Book Title: Securing Angular Applications}} \\ 46 | 47 | \vspace{20ex} 48 | 49 | %% 作者 50 | {\zihao{4}\textit{Google Angular Team}~编著} 51 | \end{minipage} 52 | 53 | \vfill 54 | 55 | \centering 56 | {\zihao{4}北京 ~$\bullet$ ~BEIJING} 57 | \end{titlepage} 58 | \thispagestyle{empty} 59 | 60 | 61 | \frontmatter 62 | 63 | 64 | \chapter{序} 65 | 66 | Angular 是一个开发平台。它能帮你更轻松的构建 Web 应用。Angular 集声明式模板、依赖注入、端到端工具和一些最佳实践于一身,为你解决开发方面的各种挑战。Angular 为开发者提升构建 Web、手机或桌面应用的能力。 67 | 68 | \chapter{前言} 69 | 70 | Web 应用程序的安全涉及到很多方面。针对常见的漏洞和攻击,比如跨站脚本攻击,Angular 提供了一些内置的保护措施。 71 | 72 | %% 目录 73 | \clearpage 74 | { 75 | \hypersetup{hidelinks} 76 | \tableofcontents 77 | } 78 | 79 | 80 | \mainmatter 81 | 82 | \part{Angular 应用基础} 83 | 84 | 85 | \chapter{核心知识} 86 | 87 | Angular 是一个用 HTML 和 TypeScript 构建客户端应用的平台与框架。 Angular 本身使用 TypeScript 写成的。它将核心功能和可选功能作为一组 TypeScript 库进行实现,你可以把它们导入你的应用中。 88 | 89 | 90 | \section{架构概览} 91 | 92 | Angular 的基本构造块是 NgModule,它为组件提供了编译的上下文环境。 NgModule 会把相关的代码收集到一些功能集中。Angular 应用就是由一组 NgModule 定义出的。 应用至少会有一个用于引导应用的根模块,通常还会有很多特性模块。 93 | 94 | \begin{itemize} 95 | \item 组件定义\textbf{视图}。视图是一组可见的屏幕元素,Angular 可以根据你的程序逻辑和数据来选择和修改它们。 每个应用都至少有一个根组件。 96 | \item 组件使用\textbf{服务}。服务会提供那些与视图不直接相关的功能。服务提供商可以作为依赖被注入到组件中, 这能让你的代码更加模块化、可复用,而且高效。 97 | \end{itemize} 98 | 99 | 强行在这里插入一个公式: 100 | 101 | \begin{equation} 102 | \label{eq:1} 103 | \lim_{x\to 0}{\frac{e^x-1}{2x}} 104 | \overset{\left[\frac{0}{0}\right]}{\underset{\mathrm{H}}{=}} 105 | \lim_{x\to 0}{\frac{e^x}{2}}={\frac{1}{2}} 106 | \end{equation} 107 | 108 | 109 | \subsection{模块} 110 | 111 | Angular 定义了 NgModule,它和 JavaScript(ES2015) 的模块不同而且有一定的互补性。 NgModule 为一个组件集声明了编译的上下文环境,它专注于某个应用领域、某个工作流或一组紧密相关的能力。 NgModule 可以将其组件和一组相关代码(如服务)关联起来,形成功能单元。 112 | 113 | \index{Test@\textsf{""Test}|(textbf} 114 | 115 | 每个 Angular 应用都有一个根模块,通常命名为 AppModule。根模块提供了用来启动应用的引导机制。 一个应用通常会包含很多功能模块。 116 | 117 | 像 JavaScript 模块一样,NgModule 也可以从其它 NgModule 中导入功能,并允许导出它们自己的功能供其它 NgModule 使用。 比如,要在你的应用中使用路由器(Router)服务,就要导入 Router 这个 NgModule。 118 | 119 | 把你的代码组织成一些清晰的功能模块,可以帮助管理复杂应用的开发工作并实现可复用性设计。 另外,这项技术还能让你获得惰性加载(也就是按需加载模块)的优点,以尽可能减小启动时需要加载的代码体积。 120 | 121 | 然后,我在这里强行引用上述公式\ref{eq:1}。 122 | 123 | \subsection{模板、指令和数据绑定} 124 | 125 | 模板会把 HTML 和 Angular 的标记(markup)组合起来,这些标记可以在 HTML 元素显示出来之前修改它们。 模板中的指令会提供程序逻辑,而绑定标记会把你应用中的数据和 DOM 连接在一起。 126 | 127 | \begin{itemize} 128 | \item \textbf{事件绑定}让你的应用可以通过更新应用的数据来响应目标环境下的用户输入。 129 | \item \textbf{属性绑定}让你将从应用数据中计算出来的值插入到 HTML 中。 130 | \end{itemize} 131 | 132 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 133 | 134 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 135 | 136 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 137 | 138 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 139 | 140 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 141 | 142 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 143 | 144 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 145 | 146 | 在视图显示出来之前,Angular 会先根据你的应用数据和逻辑来运行模板中的指令并解析绑定表达式,以修改 HTML 元素和 DOM。 Angular 支持\textbf{双向数据绑定},这意味着 DOM 中发生的变化(比如用户的选择)同样可以反映回你的程序数据中。 147 | 148 | \begin{lstlisting}[% 149 | language=JavaScript, 150 | caption={src/app/app.module.ts} 151 | ] 152 | import { BrowserModule } from '@angular/platform-browser'; 153 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 154 | import { NgModule } from '@angular/core'; 155 | import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; 156 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 157 | 158 | import { NgZorroAntdModule, NZ_I18N, zh_CN } from 'ng-zorro-antd'; 159 | // 配置 angular i18n 160 | import { registerLocaleData } from '@angular/common'; 161 | import zh from '@angular/common/locales/zh'; 162 | registerLocaleData(zh); 163 | 164 | @NgModule({ 165 | imports: [ BrowserModule ], 166 | providers: [ Logger ], 167 | declarations: [ AppComponent ], 168 | exports: [ AppComponent ], 169 | bootstrap: [ AppComponent ] 170 | }) 171 | export class AppModule { } 172 | \end{lstlisting} 173 | 174 | NgModule 系统与 JavaScript(ES2015)用来管理 JavaScript 对象的模块系统不同,而且也没有直接关联。 这两种模块系统不同但互补。你可以使用它们来共同编写你的应用。 175 | 176 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 177 | 178 | 179 | \clearpage 180 | 181 | \section{NgModule 和 JavaScript 的模块} 182 | 183 | NgModule 系统与 JavaScript(ES2015)用来管理 JavaScript 对象的模块系统不同,而且也没有直接关联。 这两种模块系统不同但互补。你可以使用它们来共同编写你的应用。 184 | 185 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 186 | 187 | 188 | \begin{titledbox}{JavaScript 模块} 189 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 190 | 191 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 192 | \end{titledbox} 193 | 194 | \begin{information} 195 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 196 | 197 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 198 | \end{information} 199 | 200 | 201 | \begin{question} 202 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 203 | \end{question} 204 | 205 | \begin{keypoint} 206 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 207 | \end{keypoint} 208 | 209 | \begin{exclamation} 210 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。 211 | \end{exclamation} 212 | 213 | 214 | JavaScript 中,每个文件是一个模块,文件中定义的所有对象都从属于那个模块。 通过 export 关键字,模块可以把它的某些对象声明为公共的。 其它 JavaScript 模块可以使用import 语句来访问这些公共对象。\footnote{JavaScript 模块可以使用import 语句来访问这些公共对象。} 215 | 216 | \chapter{服务与依赖注入} 217 | 218 | 服务是一个广义的概念,它包括应用所需的任何值、函数或特性。狭义的服务是一个明确定义了用途的类。它应该做一些具体的事,并做好。 219 | 220 | 221 | \section{服务} 222 | 223 | 服务是一个广义的概念,它包括应用所需的任何值、函数或特性。狭义的服务是一个明确定义了用途的类。它应该做一些具体的事,并做好。 224 | 225 | \begin{lstlisting}[% 226 | language=JavaScript, 227 | caption={src/app/app.module.ts} 228 | ] 229 | export class Logger { 230 | log(msg: any) { console.log(msg); } 231 | error(msg: any) { console.error(msg); } 232 | warn(msg: any) { console.warn(msg); } 233 | } 234 | \end{lstlisting} 235 | 236 | 服务也可以依赖其它服务。比如,这里的 \verb|HeroService| 就依赖于 \verb|Logger| 服务,它还用 \verb|BackendService| 来获取英雄数据。\verb|BackendService| 还可能再转而依赖 \verb|HttpClient| 服务来从服务器异步获取英雄列表。 237 | 238 | \section{依赖注入(dependency injection)} 239 | 240 | 241 | 组件是服务的消费者,也就是说,你可以把一个服务注入到组件中,让组件类得以访问该服务类。 242 | 243 | 在 Angular 中,要把一个类定义为服务,就要用 @Injectable 装饰器来提供元数据,以便让 Angular 可以把它作为依赖注入到组件中。 244 | 245 | \begin{wrapfigure}{r}{5cm} 246 | \centering 247 | \includegraphics[scale=.7]{dependency-injection.png} 248 | \caption{Dependency Injection} 249 | \label{fig:di} 250 | \end{wrapfigure} 251 | 252 | 同样,也要使用 @Injectable 装饰器来表明一个组件或其它类(比如另一个服务、管道或 NgModule)拥有一个依赖。 依赖并不必然是服务,它也可能是函数或值等等。 253 | 254 | 同样,也要使用 @Injectable 装饰器来表明一个组件或其它类(比如另一个服务、管道或 NgModule)拥有一个依赖。 依赖并不必然是服务,它也可能是函数或值等等。 255 | 256 | 同样,也要使用 @Injectable 装饰器来表明一个组件或其它类(比如另一个服务、管道或 NgModule)拥有一个依赖。 依赖并不必然是服务,它也可能是函数或值等等。 257 | 258 | 依赖注入(通常简称 DI)被引入到 Angular 框架中,并且到处使用它,来为新建的组件提供所需的服务或其它东西。如图\ref{fig:di}。 259 | 260 | \begin{itemize} 261 | \item 注入器是主要的机制。你不用自己创建 Angular 注入器。Angular 会在启动过程中为你创建全应用级注入器。 262 | \item 该注入器维护一个包含它已创建的依赖实例的容器,并尽可能复用它们。 263 | \item 提供商是一个创建依赖的菜谱。对于服务来说,它通常就是这个服务类本身。你在应用中要用到的任何类都必须使用该应用的注入器注册一个提供商,以便注入器可以使用它来创建新实例。 264 | \end{itemize} 265 | 266 | 267 | \part{Angular 应用安全防范} 268 | 269 | 270 | \chapter{最佳实践} 271 | 272 | Web 应用程序的安全涉及到很多方面。针对常见的漏洞和攻击,比如跨站脚本攻击,Angular 提供了一些内置的保护措施。 273 | 274 | \section{最佳实践} 275 | 276 | \begin{itemize} 277 | \item 及时把 Angular 包更新到最新版本。 我们会频繁的更新 Angular 库,这些更新可能会修复之前版本中发现的安全漏洞。查看 Angular 的更新记录,了解与安全有关的更新。 278 | \item 不要修改你的 Angular 副本。 私有的、定制版的 Angular 往往跟不上最新版本,这可能导致你忽略重要的安全修复与增强。反之,应该在社区共享你对 Angular 所做的改进并创建 Pull Request。 279 | \item 避免使用本文档中带``安全风险''标记的 Angular API。 280 | \end{itemize} 281 | 282 | \section{防范跨站脚本(XSS)攻击} 283 | 284 | 跨站脚本(XSS)允许攻击者将恶意代码注入到页面中。这些代码可以偷取用户数据 (特别是它们的登录数据),还可以冒充用户执行操作。它是 Web 上最常见的攻击方式之一。 285 | 286 | 为了防范 XSS 攻击,你必须阻止恶意代码进入 DOM。比如,如果某个攻击者能骗你把 \verb|<script>| 标签插入到 DOM,就可以在你的网站上运行任何代码。 除了 \verb|<script>|,攻击者还可以使用很多 DOM 元素和属性来执行代码,比如 \verb|<img onerror="...">|、\verb|<a href="javascript:...">|。 如果攻击者所控制的数据混进了 DOM,就会导致安全漏洞。 287 | 288 | \subsection{Angular 的``跨站脚本安全模型''} 289 | 290 | 为了系统性的防范 XSS 问题,Angular 默认把所有值都当做不可信任的。 当值从模板中以属性(Property)、DOM 元素属性(Attribte)、CSS 类绑定或插值表达式等途径插入到 DOM 中的时候, Angular 将对这些值进行无害化处理(Sanitize),对不可信的值进行编码。 291 | 292 | Angular 的模板同样是可执行的:模板中的 HTML、Attribute 和绑定表达式(还没有绑定到值的时候)会被当做可信任的。这意味着应用必须防止把可能被攻击者控制的值直接编入模板的源码中。永远不要根据用户的输入和原始模板动态生成模板源码!使用离线模板编译器是防范这类``模板注入''漏洞的有效途径。 293 | 294 | \subsection{listings examples} 295 | 296 | \noindent{}C\# code sample 297 | 298 | \begin{lstlisting}[% 299 | language={[Sharp]C}, 300 | caption={C\# code sample}, 301 | label=lst:csharphelloworld 302 | ] 303 | // A Hello World! program in C#. 304 | using System; 305 | namespace HelloWorld 306 | { 307 | class Hello 308 | { 309 | static void Main() 310 | { 311 | Console.WriteLine("Hello World!"); 312 | 313 | // Keep the console window open in debug mode. 314 | Console.WriteLine("Press any key to exit."); 315 | Console.ReadKey(); 316 | } 317 | } 318 | } 319 | \end{lstlisting} 320 | 321 | \noindent{}PHP code sample 322 | 323 | \begin{lstlisting}[% 324 | language=PHP, 325 | caption={PHP code sample}, 326 | label=lst:phpsample 327 | ] 328 | <?php 329 | namespace App; 330 | use Illuminate\Database\Eloquent\Model; 331 | 332 | class Comment extends Model 333 | { 334 | /** 335 | * Get all of the owning commentable models. 336 | */ 337 | public function commentable() 338 | { 339 | return $this->morphTo(); 340 | } 341 | } 342 | 343 | class Post extends Model 344 | { 345 | /** 346 | * Get all of the post's comments. 347 | */ 348 | public function comments() 349 | { 350 | return $this->morphMany('App\Comment', 'commentable'); 351 | } 352 | } 353 | 354 | class Video extends Model 355 | { 356 | /** 357 | * Get all of the video's comments. 358 | */ 359 | public function comments() 360 | { 361 | return $this->morphMany('App\Comment', 'commentable'); 362 | } 363 | } 364 | \end{lstlisting} 365 | 366 | \noindent{}JavaScript/ES6 code sample 367 | 368 | \begin{lstlisting}[% 369 | language=JavaScript, 370 | caption={JavaScript code sample}, 371 | label=lst:jsexample 372 | ] 373 | // module "my-module.js" 374 | function cube(x) { 375 | return x * x * x; 376 | } 377 | const foo = Math.PI + Math.SQRT2; 378 | var graph = { 379 | options:{ 380 | color:'white', 381 | thickness:'2px' 382 | }, 383 | draw: function(){ 384 | console.log('From graph draw function'); 385 | } 386 | } 387 | export { cube, foo, graph }; 388 | \end{lstlisting} 389 | 390 | \noindent{}TypeScript code sample 391 | 392 | \begin{lstlisting}[% 393 | language=TypeScript, 394 | caption={TypeScript code sample}, 395 | label=lst:tsexample 396 | ] 397 | abstract class Department { 398 | 399 | constructor(public name: string) { 400 | } 401 | 402 | printName(): void { 403 | console.log("Department name: " + this.name); 404 | } 405 | 406 | abstract printMeeting(): void; // must be implemented in derived classes 407 | } 408 | 409 | class AccountingDepartment extends Department { 410 | 411 | constructor() { 412 | super("Accounting and Auditing"); // constructors in derived classes must call super() 413 | } 414 | 415 | printMeeting(): void { 416 | console.log("The Accounting Department meets each Monday at 10am."); 417 | } 418 | 419 | generateReports(): void { 420 | console.log("Generating accounting reports..."); 421 | } 422 | } 423 | 424 | let department: Department; // ok to create a reference to an abstract type 425 | department = new Department(); // error: cannot create an instance of an abstract class 426 | department = new AccountingDepartment(); // ok to create and assign a non-abstract subclass 427 | department.printName(); 428 | department.printMeeting(); 429 | department.generateReports(); // error: method doesn't exist on declared abstract type 430 | \end{lstlisting} 431 | 432 | \noindent{}golang code sample 433 | 434 | \begin{lstlisting}[% 435 | language=golang, 436 | caption={golang code sample}, 437 | label=lst:golangexample 438 | ] 439 | // Go supports [_anonymous functions_](http://en.wikipedia.org/wiki/Anonymous_function), 440 | // which can form <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)"><em>closures</em></a>. 441 | // Anonymous functions are useful when you want to define 442 | // a function inline without having to name it. 443 | 444 | package main 445 | 446 | import "fmt" 447 | 448 | // This function `intSeq` returns another function, which 449 | // we define anonymously in the body of `intSeq`. The 450 | // returned function _closes over_ the variable `i` to 451 | // form a closure. 452 | func intSeq() func() int { 453 | i := 0 454 | return func() int { 455 | i++ 456 | return i 457 | } 458 | } 459 | 460 | func main() { 461 | 462 | // We call `intSeq`, assigning the result (a function) 463 | // to `nextInt`. This function value captures its 464 | // own `i` value, which will be updated each time 465 | // we call `nextInt`. 466 | nextInt := intSeq() 467 | 468 | // See the effect of the closure by calling `nextInt` 469 | // a few times. 470 | fmt.Println(nextInt()) 471 | fmt.Println(nextInt()) 472 | fmt.Println(nextInt()) 473 | 474 | // To confirm that the state is unique to that 475 | // particular function, create and test a new one. 476 | newInts := intSeq() 477 | fmt.Println(newInts()) 478 | } 479 | \end{lstlisting} 480 | 481 | 482 | 为了系统性的防范 XSS 问题,Angular 默认把所有值都当做不可信任的。 当值从模板中以属性(Property)、DOM 元素属性(Attribte)、CSS 类绑定或插值表达式等途径插入到 DOM 中的时候, Angular 将对这些值进行无害化处理(Sanitize),对不可信的值进行编码。 483 | 484 | Angular 的模板同样是可执行的:模板中的 HTML、Attribute 和绑定表达式(还没有绑定到值的时候)会被当做可信任的。这意味着应用必须防止把可能被攻击者控制的值直接编入模板的源码中。永远不要根据用户的输入和原始模板动态生成模板源码!使用离线模板编译器是防范这类``模板注入''漏洞的有效途径。 485 | 486 | 487 | \bookmarksetup{startatroot} 488 | 489 | 490 | %% 附录 491 | \appendix 492 | \cleardoublepage 493 | 494 | 495 | %% appendix chapter style 496 | \titleformat{\chapter}[display] 497 | {\bfseries} 498 | {\flushright\zihao{4}附录\thechapter} 499 | {1ex} 500 | { 501 | \hrule width \hsize height .5pt 502 | \vspace{-2ex}\flushright\zihao{2} 503 | }[\vspace{5ex}] 504 | 505 | 506 | \chapter{Angular CLI} 507 | 508 | \begin{lstlisting}[language=bash,style=shellstyle] 509 | ng new appname --style scss --skip-install 510 | \end{lstlisting} 511 | 512 | 513 | \backmatter 514 | 515 | 516 | \cleardoublepage 517 | %% 索引 518 | \printindex 519 | 520 | %% 参考文献 521 | \bibliographystyle{plain} 522 | 523 | \end{document} 524 | 525 | %%% Local Variables: 526 | %%% mode: latex 527 | %%% TeX-master: t 528 | %%% End: 529 | -------------------------------------------------------------------------------- /progbookcn/figs/dependency-injection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/progbookcn/figs/dependency-injection.png -------------------------------------------------------------------------------- /progbookcn/progbookcn.cls: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %% progbookcn - Yet Another LaTeX Template for Programming or Technical Books 3 | %% WisdomFusion@gmail.com 4 | %% Jun, 2018 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | \NeedsTeXFormat{LaTeX2e} 8 | \ProvidesClass{progbookcn}[Jun, 2018 Yet Another LaTeX Template for Programming or Technical Books] 9 | \LoadClass[a4paper,twoside]{ctexbook} 10 | 11 | \RequirePackage{xunicode} 12 | \RequirePackage{color,xcolor} 13 | 14 | 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | %% hyperref settings 17 | %% 超链接设定 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | \RequirePackage{hyperref} 20 | \hypersetup{ 21 | bookmarksnumbered, 22 | colorlinks, 23 | linkcolor={black}, 24 | citecolor={black}, 25 | urlcolor={black} 26 | } 27 | 28 | 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | %% graphicx settings 31 | %% 图片设定 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33 | \RequirePackage{graphicx} 34 | \RequirePackage{graphbox} 35 | \RequirePackage{wrapfig} 36 | \graphicspath{{./figs/}{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}} 37 | 38 | 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 | %% geometry settings 41 | %% 页面设定 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | \RequirePackage{geometry} 44 | \geometry{ 45 | textwidth=138mm, 46 | textheight=215mm, 47 | %% left=27mm, 48 | %% or 49 | inner=23mm, 50 | %% right=27mm, 51 | %% or 52 | outer=18mm, 53 | top=25.4mm, bottom=25.4mm, 54 | headheight=2.17cm, 55 | headsep=4mm, 56 | footskip=12mm, 57 | heightrounded, 58 | } 59 | 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 61 | %% fonts settings 62 | %% 字体设定 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 64 | \RequirePackage{fontspec} 65 | %% \usepackage{ebgaramond} 66 | 67 | %% 开明式:句末点号用占一个汉字宽度,标号和句内点号占半个汉字宽度 68 | \punctstyle{kaiming} 69 | 70 | \setmainfont[Ligatures=TeX]{Minion Pro} 71 | \setsansfont{Myriad Pro} 72 | \setmonofont{Courier Std} 73 | 74 | \setCJKmainfont[BoldFont={方正小标宋_GBK}, ItalicFont={方正楷体_GBK}, BoldItalicFont={方正仿宋_GBK}]{方正书宋_GBK} 75 | \setCJKsansfont{方正黑体_GBK} 76 | \setCJKmonofont{方正中等线_GBK} 77 | 78 | \XeTeXlinebreaklocale "zh" 79 | \XeTeXlinebreakskip = 0pt plus 1pt 80 | 81 | \setCJKfamilyfont{fzss}{方正书宋_GBK} 82 | \newcommand{\fzss}{\CJKfamily{fzss}} 83 | 84 | \setCJKfamilyfont{fzxbs}{方正小标宋_GBK} 85 | \newcommand{\fzxbs}{\CJKfamily{fzxbs}} 86 | 87 | \setCJKfamilyfont{fzhei}{方正黑体_GBK} 88 | \newcommand{\fzhei}{\CJKfamily{fzhei}} 89 | 90 | \setCJKfamilyfont{fzkai}{方正楷体_GBK} 91 | \newcommand{\fzkai}{\CJKfamily{fzkai}} 92 | 93 | \setCJKfamilyfont{fzfs}{方正仿宋_GBK} 94 | \newcommand{\fzfs}{\CJKfamily{fzfs}} 95 | 96 | \setCJKfamilyfont{fzzdx}{方正中等线_GBK} 97 | \newcommand{\fzzdx}{\CJKfamily{fzzdx}} 98 | 99 | 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 101 | %% titlesec 102 | %% 标题设定 103 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 104 | \RequirePackage[clearempty]{titlesec} 105 | \RequirePackage{zhnumber} 106 | 107 | %% Define a HUGE 108 | \newcommand\HUGE{\@setfontsize\Huge{48}{60}} 109 | 110 | %% part 111 | \titleformat{\part} % command 112 | [display] % shape 113 | {\bfseries} % format 114 | { 115 | \parbox[t]{7em}{\textcolor{gray}{\HUGE \textit{PART~\thepart}}} \hfill \zihao{4}第{\zhnum{part}}部分 116 | %\rule[3ex]{\textwidth}{.5pt} 117 | \vspace{1ex} 118 | \hrule width \hsize height .5pt 119 | } % label 120 | {1pt} % sep 121 | {\vspace{-7ex}\flushright\zihao{2}} % before-code 122 | [] % after-code 123 | 124 | %% chapter 125 | \titleformat{\chapter} % command 126 | [display] % shape 127 | {\bfseries} % format 128 | { 129 | \flushright\zihao{4}第\zhnum{chapter}章 130 | } % label 131 | {1ex} % sep 132 | { 133 | \hrule width \hsize height .5pt 134 | \vspace{-2ex}\flushright\zihao{2} 135 | } % before-code 136 | [ 137 | \vspace{5ex} 138 | ] % after-code 139 | 140 | 141 | %% section 142 | \titleformat{\section} 143 | [hang] 144 | {\rmfamily} 145 | {\centering\zihao{-3}\bfseries\thesection\enspace} 146 | {1pt} 147 | {\zihao{-3}\bfseries} 148 | 149 | %% subsection 150 | \titleformat{\subsection} 151 | [hang] 152 | {\rmfamily} 153 | {\zihao{-4}\bfseries\thesubsection\enspace} 154 | {1pt} 155 | {\zihao{4}\bfseries\filright} 156 | 157 | 158 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 159 | %% head and foot 160 | %% 页眉页脚 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 162 | \RequirePackage{fancyhdr} 163 | \RequirePackage{zhnumber} 164 | 165 | \pagestyle{fancy} 166 | \fancyhf{} 167 | \renewcommand\headrulewidth{0pt} 168 | \renewcommand\footrulewidth{.5pt} 169 | \futurelet\TMPfootrule\def\footrule{{\color{violet}\TMPfootrule}} 170 | 171 | \renewcommand{\chaptermark}[1]{\markboth{第\zhnum{chapter}章\hspace{1em}#1}{}} 172 | %\renewcommand{\sectionmark}[1]{\markright{\thesection\hspace{1em}#1}} 173 | \renewcommand{\sectionmark}[1]{\markright{#1}} 174 | 175 | \fancyfoot[LE]{\thepage\quad\vrule\quad\leftmark} 176 | \fancyfoot[RO]{\rightmark\quad\vrule\quad\thepage} 177 | 178 | 179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 180 | %% code listings 181 | %% 代码块设定 182 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 183 | \RequirePackage{listings,verbatim} 184 | 185 | \definecolor{codecolorkeywords}{rgb}{0,0,1} 186 | \definecolor{codecolorcomments}{rgb}{0,0.5,0} 187 | \definecolor{codecolorxmlcomments}{rgb}{0.5,0.5,0.5} 188 | \definecolor{codecolorstrings}{rgb}{0.64,0.08,0.08} 189 | \definecolor{codecolortypes}{rgb}{0.17,0.57,0.68} 190 | 191 | \lstdefinelanguage{JavaScript}{ 192 | 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}, 193 | sensitive=true, 194 | comment=[l]{//}, 195 | morecomment=[s]{/*}{*/}, 196 | morestring=[b]', 197 | morestring=[b]" 198 | } 199 | 200 | \lstdefinelanguage{TypeScript}{ 201 | 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}, 202 | sensitive=true, 203 | comment=[l]{//}, 204 | morecomment=[s]{/*}{*/}, 205 | morestring=[b]', 206 | morestring=[b]" 207 | } 208 | 209 | \lstdefinelanguage{golang}{ 210 | 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}, 211 | sensitive=true, 212 | comment=[l]{//}, 213 | morecomment=[s]{/*}{*/}, 214 | morestring=[b]', 215 | morestring=[b]" 216 | } 217 | 218 | \lstdefinestyle{mystyle}{ 219 | % Basic design 220 | basicstyle=\ttfamily, 221 | frame=tb, 222 | %framesep=5pt, 223 | framerule=.5pt, 224 | rulecolor=\color{violet}, 225 | abovecaptionskip=0pt, 226 | belowcaptionskip=5pt, 227 | % Code design 228 | keywordstyle=\color{codecolorkeywords}, 229 | commentstyle=\color{codecolorcomments}, 230 | stringstyle=\color{codecolorstrings}, 231 | numberstyle=\small\color{gray}, 232 | breakatwhitespace=false, 233 | breaklines=true, 234 | captionpos=t, 235 | keepspaces=true, 236 | % Line numbers 237 | numbers=left, 238 | numbersep=10pt, 239 | %xleftmargin=.5em, 240 | stepnumber=1, 241 | firstnumber=1, 242 | numberfirstline=true, 243 | % Code 244 | tabsize=4, 245 | showspaces=false, 246 | showstringspaces=false, 247 | showtabs=false, 248 | breaklines=true, 249 | } 250 | \lstset{style=mystyle} 251 | 252 | 253 | \lstdefinestyle{shellstyle}{ 254 | numbers=none 255 | } 256 | 257 | 258 | %% 代码列表标题 259 | \RequirePackage{caption} 260 | \DeclareCaptionFormat{codecaptionformat}{% 261 | %%\colorbox{black!20}{ 262 | %% \parbox{\textwidth}{#1#2\ttfamily#3} 263 | %%} 264 | \parbox{\textwidth}{\faCode #1#2\hspace{.5em}#3} 265 | } 266 | \captionsetup[lstlisting]{format=codecaptionformat} 267 | 268 | 269 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 270 | %% boxes 271 | %% 信息框 272 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 273 | \RequirePackage[many]{tcolorbox} 274 | \RequirePackage{fontawesome} 275 | 276 | %% 带标题的文本框 277 | \newtcolorbox{titledbox}[1]{% 278 | tikznode boxed title, 279 | enhanced, 280 | arc=3pt, 281 | interior style={white}, 282 | attach boxed title to top center = {yshift=-\tcboxedtitleheight/2}, 283 | fonttitle=\normalfont, 284 | colbacktitle=white,coltitle=black, 285 | boxed title style={size=normal,colframe=white,boxrule=0pt}, 286 | boxrule=.5pt, 287 | left=0pt, right=0pt, top=2pt, bottom=0pt, 288 | boxsep=10pt, 289 | colframe=violet, 290 | title={#1} 291 | } 292 | 293 | %% 信息 294 | \newtcolorbox{information}{% 295 | enhanced, 296 | arc=3pt, 297 | interior style={white}, 298 | boxrule=.5pt, 299 | left=40pt, right=0pt, top=2pt, bottom=0pt, 300 | boxsep=10pt, 301 | colframe=violet, 302 | overlay={ 303 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 304 | { 305 | \zihao{2}\faInfoCircle 306 | }; 307 | } 308 | } 309 | 310 | %% 关键点 311 | \newtcolorbox{keypoint}{% 312 | enhanced, 313 | arc=3pt, 314 | interior style={white}, 315 | boxrule=.5pt, 316 | left=40pt, right=0pt, top=2pt, bottom=0pt, 317 | boxsep=10pt, 318 | colframe=violet, 319 | overlay={ 320 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 321 | { 322 | \zihao{2}\faKey 323 | }; 324 | } 325 | } 326 | 327 | %% 警告信息 328 | \newtcolorbox{exclamation}{% 329 | enhanced, 330 | arc=3pt, 331 | interior style={white}, 332 | boxrule=.5pt, 333 | left=40pt, right=0pt, top=2pt, bottom=0pt, 334 | boxsep=10pt, 335 | colframe=violet, 336 | overlay={ 337 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 338 | { 339 | \zihao{2}\faExclamationTriangle 340 | }; 341 | } 342 | } 343 | 344 | %% 问题信息 345 | \newtcolorbox{question}{% 346 | enhanced, 347 | arc=3pt, 348 | interior style={white}, 349 | boxrule=.5pt, 350 | left=40pt, right=0pt, top=2pt, bottom=0pt, 351 | boxsep=10pt, 352 | colframe=violet, 353 | overlay={ 354 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 355 | { 356 | \zihao{2}\faQuestionCircle 357 | }; 358 | } 359 | } 360 | 361 | 362 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 363 | %% Chinese names 364 | %% 中文名称 365 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 366 | \renewcommand{\contentsname}{目\hspace{1em}录} 367 | \renewcommand{\figurename}{图} 368 | \renewcommand{\tablename}{表} 369 | \renewcommand{\partname}{部分} 370 | \renewcommand{\listfigurename}{插图目录} 371 | \renewcommand{\listtablename}{表格目录} 372 | \renewcommand{\bibname}{参考文献} 373 | \renewcommand{\appendixname}{附录} 374 | \renewcommand{\indexname}{索引} 375 | % listings 376 | \renewcommand{\lstlistingname}{代码} 377 | \renewcommand{\lstlistlistingname}{\lstlistingname 列表} 378 | 379 | 380 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 381 | %% global settings 382 | %% 以下是全局格式设定 383 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 384 | 385 | %% 添加首行缩进,两个字符 386 | \RequirePackage{indentfirst} 387 | \setlength{\parindent}{2em} 388 | 389 | %% 行距 390 | \linespread{1.5} 391 | -------------------------------------------------------------------------------- /znote/booksample-The Great Gatsby.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wisdomfusion/latex-templates/3a194790b456bc023abc8ec4011e0252c4db505a/znote/booksample-The Great Gatsby.pdf -------------------------------------------------------------------------------- /znote/znotearticle.cls: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %% znotebook - LaTeX Template Customized for Note-Taking with Article Document Structures 3 | %% WisdomFusion@gmail.com 4 | %% July, 2018 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | \NeedsTeXFormat{LaTeX2e} 8 | \ProvidesClass{znotearticle}[Jul, 2018 znotebook - LaTeX Template Customized for Note-Taking with Article Document Structures] 9 | \LoadClass[a4paper]{ctexart} 10 | 11 | \RequirePackage{xunicode} 12 | \RequirePackage[dvipsnames]{xcolor} 13 | 14 | 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | %% hyperref settings 17 | %% 超链接设定 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | \RequirePackage{hyperref} 20 | \hypersetup{ 21 | bookmarksnumbered, 22 | colorlinks, 23 | linkcolor={black}, 24 | citecolor={black}, 25 | urlcolor={black} 26 | } 27 | 28 | \RequirePackage[open,openlevel=0,atend]{bookmark} 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | %% graphicx settings 32 | %% 图片设定 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | \RequirePackage{graphicx} 35 | \RequirePackage{graphbox} 36 | \RequirePackage{wrapfig} 37 | \graphicspath{{./figs/}{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}} 38 | 39 | 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 | %% geometry settings 42 | %% 页面设定 43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 | \RequirePackage{geometry} 45 | \geometry{ 46 | textwidth=138mm, 47 | textheight=215mm, 48 | left=27mm, 49 | %% or 50 | %% inner=23mm, 51 | right=27mm, 52 | %% or 53 | %% outer=18mm, 54 | top=25.4mm, bottom=25.4mm, 55 | headheight=2.17cm, 56 | headsep=4mm, 57 | footskip=12mm, 58 | heightrounded, 59 | } 60 | 61 | 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 63 | %% fonts settings 64 | %% 字体设定 65 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 66 | \RequirePackage{fontspec} 67 | %% \usepackage{ebgaramond} 68 | 69 | %% 开明式:句末点号用占一个汉字宽度,标号和句内点号占半个汉字宽度 70 | %\punctstyle{kaiming} 71 | 72 | \setmainfont{Minion Pro} 73 | \setsansfont{Myriad Pro} 74 | \setmonofont{Courier Std} 75 | 76 | \setCJKmainfont[BoldFont={方正小标宋_GBK}, ItalicFont={方正楷体_GBK}, BoldItalicFont={方正仿宋_GBK}]{方正书宋_GBK} 77 | \setCJKsansfont{方正黑体_GBK} 78 | \setCJKmonofont{方正中等线_GBK} 79 | 80 | \XeTeXlinebreaklocale "zh" 81 | \XeTeXlinebreakskip = 0pt plus 1pt 82 | 83 | \setCJKfamilyfont{fzss}{方正书宋_GBK} 84 | \newcommand{\fzss}{\CJKfamily{fzss}} 85 | 86 | \setCJKfamilyfont{fzxbs}{方正小标宋_GBK} 87 | \newcommand{\fzxbs}{\CJKfamily{fzxbs}} 88 | 89 | \setCJKfamilyfont{fzhei}{方正黑体_GBK} 90 | \newcommand{\fzhei}{\CJKfamily{fzhei}} 91 | 92 | \setCJKfamilyfont{fzkai}{方正楷体_GBK} 93 | \newcommand{\fzkai}{\CJKfamily{fzkai}} 94 | 95 | \setCJKfamilyfont{fzfs}{方正仿宋_GBK} 96 | \newcommand{\fzfs}{\CJKfamily{fzfs}} 97 | 98 | \setCJKfamilyfont{fzzdx}{方正中等线_GBK} 99 | \newcommand{\fzzdx}{\CJKfamily{fzzdx}} 100 | 101 | 102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 103 | %% titlesec 104 | %% 标题设定 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106 | \RequirePackage{titlesec} 107 | \RequirePackage{zhnumber} 108 | 109 | 110 | %% \renewcommand\abstractname{Summary} 111 | \renewenvironment{abstract}{\noindent\rule{\textwidth}{.5pt}\\[2ex] \centering\begin{minipage}{.97\textwidth}{\zihao{-4}\sffamily\bfseries\abstractname}\\} 112 | {\par\noindent\end{minipage}\\[2ex] \rule{\textwidth}{.5pt}} 113 | 114 | %% section 115 | \titleformat{\section} 116 | [hang] 117 | {\sffamily} 118 | {\centering\zihao{-3}\bfseries\thesection\enspace} 119 | {1pt} 120 | {\zihao{-3}\bfseries} 121 | 122 | %% subsection 123 | \titleformat{\subsection} 124 | [hang] 125 | {\sffamily} 126 | {\zihao{4}\bfseries\thesubsection\enspace} 127 | {1pt} 128 | {\zihao{4}\bfseries\filright} 129 | 130 | %% subsubsection 131 | \titleformat{\subsubsection} 132 | [hang] 133 | {\sffamily} 134 | {\zihao{-4}\bfseries\thesubsubsection\enspace} 135 | {1pt} 136 | {\zihao{-4}\bfseries\filright} 137 | 138 | 139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 140 | %% boxes 141 | %% 信息框 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 143 | \RequirePackage[many]{tcolorbox} 144 | \RequirePackage{fontawesome} 145 | 146 | %% 带标题的文本框 147 | \newtcolorbox{titledbox}[1]{% 148 | tikznode boxed title, 149 | enhanced, 150 | arc=3pt, 151 | interior style={white}, 152 | attach boxed title to top center = {yshift=-\tcboxedtitleheight/2}, 153 | fonttitle=\normalfont, 154 | colbacktitle=white,coltitle=black, 155 | boxed title style={size=normal,colframe=white,boxrule=0pt}, 156 | boxrule=.5pt, 157 | left=5pt, right=5pt, top=5pt, bottom=0pt, 158 | boxsep=5pt, 159 | title={#1}, 160 | halign=left, 161 | fontupper=\fzkai 162 | } 163 | 164 | %% Note 165 | \newtcolorbox{notebox}{% 166 | enhanced, 167 | arc=2pt, 168 | boxrule=.5pt, 169 | left=5pt, right=5pt, top=0pt, bottom=0pt, 170 | boxsep=5pt, 171 | colframe=NavyBlue, 172 | colback=NavyBlue!5!White, 173 | colbacktitle=NavyBlue!5!White, 174 | coltext=NavyBlue, 175 | title={\textcolor{NavyBlue}{\faStickyNoteO\hspace{.5em}\bfseries{\textsc{Note}}}}, 176 | halign=left, 177 | fontupper=\fzkai 178 | } 179 | 180 | %% Important 181 | \newtcolorbox{importantbox}{% 182 | enhanced, 183 | arc=2pt, 184 | boxrule=.5pt, 185 | left=5pt, right=5pt, top=0pt, bottom=0pt, 186 | boxsep=5pt, 187 | colframe=Orange, 188 | colback=Orange!5!White, 189 | colbacktitle=Orange!5!White, 190 | coltext=Orange, 191 | title={\textcolor{Orange}{\faExclamationCircle\hspace{.5em}\bfseries{\textsc{Important}}}}, 192 | halign=left, 193 | fontupper=\fzkai 194 | } 195 | 196 | %% verbatim 环境无法直接在新环境中使用 197 | %% 换用 \VerbatimEnvironment \begin{Verbatim} 198 | \RequirePackage{fancyvrb} 199 | 200 | %% 命令行 201 | \newenvironment{shellbox} 202 | {% 203 | \VerbatimEnvironment 204 | \begin{tcolorbox}[ 205 | enhanced, 206 | arc=2pt, 207 | boxrule=.5pt, 208 | left=5pt, right=5pt, top=0pt, bottom=0pt, 209 | boxsep=5pt, 210 | colframe=black, 211 | colback=white, 212 | coltext=black, 213 | title={}, 214 | fontupper=\linespread{1.2} 215 | ]% 216 | \begin{Verbatim} 217 | } 218 | {% 219 | \end{Verbatim} 220 | \end{tcolorbox} 221 | } 222 | 223 | %% 命令行 224 | \newenvironment{invertedshellbox} 225 | {% 226 | \VerbatimEnvironment 227 | \begin{tcolorbox}[ 228 | enhanced, 229 | arc=2pt, 230 | boxrule=.5pt, 231 | left=5pt, right=5pt, top=0pt, bottom=0pt, 232 | boxsep=5pt, 233 | colframe=black!70!white, 234 | colback=black!70!white, 235 | coltext=white, 236 | title={}, 237 | fontupper=\linespread{1.2} 238 | ]% 239 | \begin{Verbatim} 240 | } 241 | {% 242 | \end{Verbatim} 243 | \end{tcolorbox} 244 | } 245 | 246 | 247 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 248 | %% head and foot 249 | %% 页眉页脚 250 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 251 | \RequirePackage{fancyhdr} 252 | \RequirePackage{zhnumber} 253 | 254 | \pagestyle{fancy} 255 | \fancyhf{} 256 | \renewcommand\headrulewidth{.5pt} 257 | \renewcommand\footrulewidth{0pt} 258 | %\futurelet\TMPheadrule\def\headrule{{\color{violet}\TMPheadrule}} 259 | 260 | \renewcommand{\sectionmark}[1]{\markright{#1}} 261 | 262 | \fancyhead[L]{\fzkai{\rightmark}} 263 | \fancyhead[R]{\thepage} 264 | 265 | 266 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 267 | %% code listings 268 | %% 代码块设定 269 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 270 | \RequirePackage{listings,verbatim} 271 | 272 | \definecolor{codecolorkeywords}{rgb}{0,0,1} 273 | \definecolor{codecolorcomments}{rgb}{0,0.5,0} 274 | \definecolor{codecolorxmlcomments}{rgb}{0.5,0.5,0.5} 275 | \definecolor{codecolorstrings}{rgb}{0.64,0.08,0.08} 276 | \definecolor{codecolortypes}{rgb}{0.17,0.57,0.68} 277 | 278 | \lstdefinelanguage{JavaScript}{ 279 | 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}, 280 | sensitive=true, 281 | comment=[l]{//}, 282 | morecomment=[s]{/*}{*/}, 283 | morestring=[b]', 284 | morestring=[b]" 285 | } 286 | 287 | \lstdefinelanguage{TypeScript}{ 288 | 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}, 289 | sensitive=true, 290 | comment=[l]{//}, 291 | morecomment=[s]{/*}{*/}, 292 | morestring=[b]', 293 | morestring=[b]" 294 | } 295 | 296 | \lstdefinelanguage{golang}{ 297 | 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}, 298 | sensitive=true, 299 | comment=[l]{//}, 300 | morecomment=[s]{/*}{*/}, 301 | morestring=[b]', 302 | morestring=[b]" 303 | } 304 | 305 | \lstdefinestyle{mystyle}{ 306 | % Basic design 307 | basicstyle=\linespread{1.2}\ttfamily, 308 | frame=tb, 309 | framesep=5pt, 310 | framerule=.5pt, 311 | framexleftmargin=10pt, 312 | rulecolor=\color{black}, 313 | abovecaptionskip=0pt, 314 | belowcaptionskip=5pt, 315 | aboveskip=5pt, 316 | backgroundcolor=\color{black!5!white}, 317 | % Code design 318 | keywordstyle=\color{codecolorkeywords}, 319 | commentstyle=\color{codecolorcomments}, 320 | stringstyle=\color{codecolorstrings}, 321 | numberstyle=\small\color{gray}, 322 | breakatwhitespace=false, 323 | breaklines=true, 324 | captionpos=t, 325 | keepspaces=true, 326 | % Line numbers 327 | numbers=none, 328 | numbersep=15pt, 329 | xleftmargin=10pt, 330 | stepnumber=1, 331 | firstnumber=1, 332 | numberfirstline=true, 333 | % Code 334 | tabsize=4, 335 | showspaces=false, 336 | showstringspaces=false, 337 | showtabs=false, 338 | breaklines=true, 339 | } 340 | \lstset{style=mystyle} 341 | 342 | %% 命令行 343 | \lstdefinestyle{bashstyle}{ 344 | backgroundcolor=\color{NavyBlue!10!white}, 345 | basicstyle=\linespread{1.2}\ttfamily, 346 | keepspaces=true, 347 | numbers=none, 348 | numbersep=10pt, 349 | frame=l, 350 | framerule=2pt, 351 | framesep=5pt, 352 | framexleftmargin=3pt, 353 | framextopmargin=-5pt, 354 | xleftmargin=10pt, 355 | rulecolor=\color{NavyBlue}, 356 | % Code 357 | tabsize=4, 358 | showspaces=false, 359 | showstringspaces=false, 360 | showtabs=false, 361 | breaklines=true, 362 | } 363 | 364 | %% 命令行输出 365 | \lstdefinestyle{bashoutputstyle}{ 366 | backgroundcolor=\color{black!10!white}, 367 | basicstyle=\linespread{1.2}\ttfamily, 368 | keepspaces=true, 369 | numbers=none, 370 | numbersep=10pt, 371 | frame=l, 372 | framerule=2pt, 373 | framesep=5pt, 374 | framexleftmargin=3pt, 375 | framextopmargin=-5pt, 376 | xleftmargin=10pt, 377 | rulecolor=\color{black!70!white}, 378 | % Code 379 | tabsize=4, 380 | showspaces=false, 381 | showstringspaces=false, 382 | showtabs=false, 383 | breaklines=true, 384 | } 385 | 386 | %% 代码列表标题 387 | \RequirePackage{caption} 388 | \DeclareCaptionFormat{codecaptionformat}{% 389 | %%\colorbox{black!20}{ 390 | %% \parbox{\textwidth}{#1#2\ttfamily#3} 391 | %%} 392 | \parbox{\textwidth}{\textcolor{violet}\faCode~\textcolor{violet}{#1#2}\hspace{.5em}\fzkai #3} 393 | } 394 | \captionsetup[lstlisting]{format=codecaptionformat} 395 | 396 | 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 398 | %% Chinese names 399 | %% 中文名称 400 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 401 | \renewcommand{\figurename}{图} 402 | \renewcommand{\tablename}{表} 403 | \renewcommand{\lstlistingname}{CODE} 404 | \renewcommand{\abstractname}{摘要} 405 | 406 | 407 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 408 | %% global settings 409 | %% 以下是全局格式设定 410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 411 | 412 | %% 添加首行缩进,两个字符 413 | \RequirePackage{indentfirst} 414 | \setlength{\parindent}{2em} 415 | 416 | %% 行距 417 | \linespread{1.5} 418 | 419 | %% captions 420 | \RequirePackage[singlelinecheck=false]{caption} 421 | \DeclareCaptionFont{kai}{\fzkai} 422 | \captionsetup[table]{belowskip=0pt,aboveskip=5pt,labelfont=kai,textfont=kai} 423 | \captionsetup[figure]{belowskip=0pt,aboveskip=5pt,format=hang,labelfont=kai,textfont=kai} 424 | -------------------------------------------------------------------------------- /znote/znotebook.cls: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %% znotebook - LaTeX Template Customized for Note-Taking with Book Document Structures 3 | %% WisdomFusion@gmail.com 4 | %% Jun, 2018 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | \NeedsTeXFormat{LaTeX2e} 8 | \ProvidesClass{znotebook}[Jul, 2018 znotebook, LaTeX Template Customized for Note Taking with Book Document Structures] 9 | \LoadClass[a4paper,twosides,12pt]{ctexbook} 10 | 11 | \RequirePackage{xunicode} 12 | \RequirePackage{color,xcolor} 13 | \RequirePackage{lettrine} 14 | 15 | 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | %% hyperref settings 18 | %% 超链接设定 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | \RequirePackage{hyperref} 21 | \hypersetup{ 22 | bookmarksnumbered, 23 | colorlinks, 24 | linkcolor={black}, 25 | citecolor={black}, 26 | urlcolor={black} 27 | } 28 | 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | %% graphicx settings 32 | %% 图片设定 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | \RequirePackage{graphicx} 35 | \RequirePackage{graphbox} 36 | \RequirePackage{wrapfig} 37 | \graphicspath{{./figs/}{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}} 38 | 39 | 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 | %% geometry settings 42 | %% 页面设定 43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 | \RequirePackage{geometry} 45 | %\RequirePackage{showframe} 46 | \geometry{ 47 | textwidth=125mm, 48 | textheight=215mm, 49 | left=20mm, 50 | %%left=27mm, 51 | %% or 52 | %%inner=23mm, 53 | %%right=20mm, 54 | %% or 55 | %%outer=18mm, 56 | top=25.4mm, bottom=25.4mm, 57 | headheight=2.17cm, 58 | headsep=4mm, 59 | footskip=12mm, 60 | heightrounded, 61 | } 62 | 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 64 | %% fonts settings 65 | %% 字体设定 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 67 | \RequirePackage{fontspec} 68 | %% \usepackage{ebgaramond} 69 | 70 | %% 开明式:句末点号用占一个汉字宽度,标号和句内点号占半个汉字宽度 71 | \punctstyle{kaiming} 72 | 73 | \setmainfont[Ligatures=TeX]{Minion Pro} 74 | \setsansfont{Myriad Pro} 75 | \setmonofont{Courier Std} 76 | 77 | \setCJKmainfont[BoldFont={方正小标宋_GBK}, ItalicFont={方正楷体_GBK}, BoldItalicFont={方正仿宋_GBK}]{方正书宋_GBK} 78 | \setCJKsansfont{方正黑体_GBK} 79 | \setCJKmonofont{方正中等线_GBK} 80 | 81 | \XeTeXlinebreaklocale "zh" 82 | \XeTeXlinebreakskip = 0pt plus 1pt 83 | 84 | \setCJKfamilyfont{fzss}{方正书宋_GBK} 85 | \newcommand{\fzss}{\CJKfamily{fzss}} 86 | 87 | \setCJKfamilyfont{fzxbs}{方正小标宋_GBK} 88 | \newcommand{\fzxbs}{\CJKfamily{fzxbs}} 89 | 90 | \setCJKfamilyfont{fzhei}{方正黑体_GBK} 91 | \newcommand{\fzhei}{\CJKfamily{fzhei}} 92 | 93 | \setCJKfamilyfont{fzkai}{方正楷体_GBK} 94 | \newcommand{\fzkai}{\CJKfamily{fzkai}} 95 | 96 | \setCJKfamilyfont{fzfs}{方正仿宋_GBK} 97 | \newcommand{\fzfs}{\CJKfamily{fzfs}} 98 | 99 | \setCJKfamilyfont{fzzdx}{方正中等线_GBK} 100 | \newcommand{\fzzdx}{\CJKfamily{fzzdx}} 101 | 102 | 103 | \RequirePackage{titletoc} 104 | 105 | \titlecontents{chapter}[0em]{\smallskip\bfseries}%\vspace{1cm}% 106 | {}% 107 | {\bfseries}%numberless% 108 | {\dotfill\contentspage}[\medskip]% 109 | 110 | 111 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 112 | %% titlesec 113 | %% 标题设定 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 115 | \RequirePackage[clearempty]{titlesec} 116 | \RequirePackage{zhnumber} 117 | 118 | %% Define a HUGE 119 | \newcommand\HUGE{\@setfontsize\Huge{48}{60}} 120 | 121 | %% part 122 | \titleformat{\part} % command 123 | [display] % shape 124 | {\bfseries} % format 125 | { 126 | \parbox[t]{7em}{\textcolor{gray}{\HUGE \textit{PART~\thepart}}} \hfill \zihao{4}第{\zhnum{part}}部分 127 | %\rule[3ex]{\textwidth}{.5pt} 128 | \vspace{1ex} 129 | \hrule width \hsize height .5pt 130 | } % label 131 | {1pt} % sep 132 | {\vspace{-7ex}\flushright\zihao{2}} % before-code 133 | [] % after-code 134 | 135 | %% chapter 136 | \titleformat{\chapter} % command 137 | [display] % shape 138 | {\bfseries} % format 139 | { 140 | %\flushright\zihao{4}第\zhnum{chapter}章 141 | } % label 142 | {1ex} % sep 143 | { 144 | \hrule width \hsize height 1pt 145 | \vspace{-2ex}\flushright\zihao{2} 146 | } % before-code 147 | [ 148 | \vspace{.5ex} 149 | \hrule width \hsize height .5pt 150 | \vspace{5ex} 151 | ] % after-code 152 | 153 | 154 | %% section 155 | \titleformat{\section} 156 | [hang] 157 | {\rmfamily} 158 | {\centering\zihao{-3}\bfseries\thesection\enspace} 159 | {1pt} 160 | {\zihao{-3}\bfseries} 161 | 162 | %% subsection 163 | \titleformat{\subsection} 164 | [hang] 165 | {\rmfamily} 166 | {\zihao{-4}\bfseries\thesubsection\enspace} 167 | {1pt} 168 | {\zihao{4}\bfseries\filright} 169 | 170 | 171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 172 | %% head and foot 173 | %% 页眉页脚 174 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 175 | \RequirePackage{fancyhdr} 176 | \RequirePackage{zhnumber} 177 | 178 | \pagestyle{fancy} 179 | \fancyhf{} 180 | \renewcommand\headrulewidth{0pt} 181 | \renewcommand\footrulewidth{0pt} 182 | %%\futurelet\TMPfootrule\def\footrule{{\color{violet}\TMPfootrule}} 183 | 184 | \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}} 185 | %\renewcommand{\sectionmark}[1]{\markright{\thesection\hspace{1em}#1}} 186 | \renewcommand{\sectionmark}[1]{\markright{#1}} 187 | 188 | \fancyhead[CE,CO]{\leftmark} 189 | \fancyfoot[CE,CO]{\thepage} 190 | 191 | 192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 193 | %% code listings 194 | %% 代码块设定 195 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 196 | \RequirePackage{listings,verbatim} 197 | 198 | \definecolor{codecolorkeywords}{rgb}{0,0,1} 199 | \definecolor{codecolorcomments}{rgb}{0,0.5,0} 200 | \definecolor{codecolorxmlcomments}{rgb}{0.5,0.5,0.5} 201 | \definecolor{codecolorstrings}{rgb}{0.64,0.08,0.08} 202 | \definecolor{codecolortypes}{rgb}{0.17,0.57,0.68} 203 | 204 | \lstdefinelanguage{JavaScript}{ 205 | 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}, 206 | sensitive=true, 207 | comment=[l]{//}, 208 | morecomment=[s]{/*}{*/}, 209 | morestring=[b]', 210 | morestring=[b]" 211 | } 212 | 213 | \lstdefinelanguage{TypeScript}{ 214 | 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}, 215 | sensitive=true, 216 | comment=[l]{//}, 217 | morecomment=[s]{/*}{*/}, 218 | morestring=[b]', 219 | morestring=[b]" 220 | } 221 | 222 | \lstdefinelanguage{golang}{ 223 | 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}, 224 | sensitive=true, 225 | comment=[l]{//}, 226 | morecomment=[s]{/*}{*/}, 227 | morestring=[b]', 228 | morestring=[b]" 229 | } 230 | 231 | \lstdefinestyle{mystyle}{ 232 | % Basic design 233 | basicstyle=\ttfamily, 234 | frame=tb, 235 | %framesep=5pt, 236 | framerule=.5pt, 237 | rulecolor=\color{violet}, 238 | abovecaptionskip=0pt, 239 | belowcaptionskip=5pt, 240 | % Code design 241 | keywordstyle=\color{codecolorkeywords}, 242 | commentstyle=\color{codecolorcomments}, 243 | stringstyle=\color{codecolorstrings}, 244 | numberstyle=\small\color{gray}, 245 | breakatwhitespace=false, 246 | breaklines=true, 247 | captionpos=t, 248 | keepspaces=true, 249 | % Line numbers 250 | numbers=left, 251 | numbersep=10pt, 252 | %xleftmargin=.5em, 253 | stepnumber=1, 254 | firstnumber=1, 255 | numberfirstline=true, 256 | % Code 257 | tabsize=4, 258 | showspaces=false, 259 | showstringspaces=false, 260 | showtabs=false, 261 | breaklines=true, 262 | } 263 | \lstset{style=mystyle} 264 | 265 | 266 | \lstdefinestyle{shellstyle}{ 267 | numbers=none 268 | } 269 | 270 | 271 | %% 代码列表标题 272 | \RequirePackage{caption} 273 | \DeclareCaptionFormat{codecaptionformat}{% 274 | %%\colorbox{black!20}{ 275 | %% \parbox{\textwidth}{#1#2\ttfamily#3} 276 | %%} 277 | \parbox{\textwidth}{\faCode #1#2\hspace{.5em}#3} 278 | } 279 | \captionsetup[lstlisting]{format=codecaptionformat} 280 | 281 | 282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 283 | %% boxes 284 | %% 信息框 285 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 286 | \RequirePackage[many]{tcolorbox} 287 | \RequirePackage{fontawesome} 288 | 289 | %% 带标题的文本框 290 | \newtcolorbox{titledbox}[1]{% 291 | tikznode boxed title, 292 | enhanced, 293 | arc=3pt, 294 | interior style={white}, 295 | attach boxed title to top center = {yshift=-\tcboxedtitleheight/2}, 296 | fonttitle=\normalfont, 297 | colbacktitle=white,coltitle=black, 298 | boxed title style={size=normal,colframe=white,boxrule=0pt}, 299 | boxrule=.5pt, 300 | left=0pt, right=0pt, top=2pt, bottom=0pt, 301 | boxsep=10pt, 302 | colframe=violet, 303 | title={#1} 304 | } 305 | 306 | %% 信息 307 | \newtcolorbox{information}{% 308 | enhanced, 309 | arc=3pt, 310 | interior style={white}, 311 | boxrule=.5pt, 312 | left=40pt, right=0pt, top=2pt, bottom=0pt, 313 | boxsep=10pt, 314 | colframe=violet, 315 | overlay={ 316 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 317 | { 318 | \zihao{2}\faInfoCircle 319 | }; 320 | } 321 | } 322 | 323 | %% 关键点 324 | \newtcolorbox{keypoint}{% 325 | enhanced, 326 | arc=3pt, 327 | interior style={white}, 328 | boxrule=.5pt, 329 | left=40pt, right=0pt, top=2pt, bottom=0pt, 330 | boxsep=10pt, 331 | colframe=violet, 332 | overlay={ 333 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 334 | { 335 | \zihao{2}\faKey 336 | }; 337 | } 338 | } 339 | 340 | %% 警告信息 341 | \newtcolorbox{exclamation}{% 342 | enhanced, 343 | arc=3pt, 344 | interior style={white}, 345 | boxrule=.5pt, 346 | left=40pt, right=0pt, top=2pt, bottom=0pt, 347 | boxsep=10pt, 348 | colframe=violet, 349 | overlay={ 350 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 351 | { 352 | \zihao{2}\faExclamationTriangle 353 | }; 354 | } 355 | } 356 | 357 | %% 问题信息 358 | \newtcolorbox{question}{% 359 | enhanced, 360 | arc=3pt, 361 | interior style={white}, 362 | boxrule=.5pt, 363 | left=40pt, right=0pt, top=2pt, bottom=0pt, 364 | boxsep=10pt, 365 | colframe=violet, 366 | overlay={ 367 | \node[anchor=north west,outer sep=10pt] at (frame.north west) 368 | { 369 | \zihao{2}\faQuestionCircle 370 | }; 371 | } 372 | } 373 | 374 | 375 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 376 | %% Chinese names 377 | %% 中文名称 378 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 379 | \renewcommand{\contentsname}{Contents} 380 | \renewcommand{\figurename}{图} 381 | \renewcommand{\tablename}{表} 382 | \renewcommand{\partname}{部分} 383 | \renewcommand{\listfigurename}{插图目录} 384 | \renewcommand{\listtablename}{表格目录} 385 | \renewcommand{\bibname}{参考文献} 386 | \renewcommand{\appendixname}{附录} 387 | \renewcommand{\indexname}{索引} 388 | % listings 389 | \renewcommand{\lstlistingname}{代码} 390 | \renewcommand{\lstlistlistingname}{\lstlistingname 列表} 391 | 392 | 393 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 394 | %% global settings 395 | %% 以下是全局格式设定 396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 397 | 398 | %% 添加首行缩进,两个字符 399 | \RequirePackage{indentfirst} 400 | \setlength{\parindent}{2em} 401 | 402 | %% 行距 403 | \linespread{1.5} 404 | --------------------------------------------------------------------------------