|
| 1 | +% hw-preamble.tex |
| 2 | + |
| 3 | +% geometry for A4 paper |
| 4 | +% See https://tex.stackexchange.com/a/119912/23098 |
| 5 | +\geometry{ |
| 6 | + left=20.0mm, |
| 7 | + top=20.0mm, |
| 8 | + bottom=20.0mm, |
| 9 | + textwidth=130mm, % main text block |
| 10 | + marginparsep=5.0mm, % gutter between main text block and margin notes |
| 11 | + marginparwidth=50.0mm % width of margin notes |
| 12 | +} |
| 13 | + |
| 14 | +% for colors |
| 15 | +\usepackage{xcolor} % usage: \color{red}{text} |
| 16 | +% predefined colors |
| 17 | +\newcommand{\red}[1]{\textcolor{red}{#1}} % usage: \red{text} |
| 18 | +\newcommand{\blue}[1]{\textcolor{blue}{#1}} |
| 19 | +\newcommand{\teal}[1]{\textcolor{teal}{#1}} |
| 20 | + |
| 21 | +\usepackage{todonotes} |
| 22 | + |
| 23 | +% heading |
| 24 | +\usepackage{sectsty} |
| 25 | +\setcounter{secnumdepth}{2} |
| 26 | +\allsectionsfont{\centering\huge\rmfamily} |
| 27 | + |
| 28 | +% for Chinese |
| 29 | +\usepackage{xeCJK} |
| 30 | +\usepackage{zhnumber} |
| 31 | +\setCJKmainfont[BoldFont=FandolSong-Bold.otf]{FandolSong-Regular.otf} |
| 32 | + |
| 33 | +% for fonts |
| 34 | +\usepackage{fontspec} |
| 35 | +\newcommand{\song}{\CJKfamily{song}} |
| 36 | +\newcommand{\kai}{\CJKfamily{kai}} |
| 37 | + |
| 38 | +% To fix the ``MakeTextLowerCase'' bug: |
| 39 | +% See https://github.com/Tufte-LaTeX/tufte-latex/issues/64#issuecomment-78572017 |
| 40 | +% Set up the spacing using fontspec features |
| 41 | +\renewcommand\allcapsspacing[1]{{\addfontfeature{LetterSpace=15}#1}} |
| 42 | +\renewcommand\smallcapsspacing[1]{{\addfontfeature{LetterSpace=10}#1}} |
| 43 | + |
| 44 | +% for url |
| 45 | +\usepackage{hyperref} |
| 46 | +\hypersetup{colorlinks = true, |
| 47 | + linkcolor = teal, |
| 48 | + urlcolor = teal, |
| 49 | + citecolor = blue, |
| 50 | + anchorcolor = blue} |
| 51 | + |
| 52 | +\newcommand{\me}[4]{ |
| 53 | + \author{ |
| 54 | + {\bfseries 姓名:}\underline{#1}\hspace{2em} |
| 55 | + {\bfseries 学号:}\underline{#2}\hspace{2em}\\[10pt] |
| 56 | + {\bfseries 评分:}\underline{#3\hspace{3em}}\hspace{2em} |
| 57 | + {\bfseries 评阅:}\underline{#4\hspace{3em}} |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +% Please ALWAYS Keep This. |
| 62 | +\newcommand{\noplagiarism}{ |
| 63 | + \begin{center} |
| 64 | + \fbox{\begin{tabular}{@{}c@{}} |
| 65 | + 请独立完成作业,不得抄袭。\\ |
| 66 | + 若得到他人帮助, 请致谢。\\ |
| 67 | + 若参考了其它资料,请给出引用。\\ |
| 68 | + 鼓励讨论,但需独立书写解题过程。 |
| 69 | + \end{tabular}} |
| 70 | + \end{center} |
| 71 | +} |
| 72 | + |
| 73 | +\newcommand{\goal}[1]{ |
| 74 | + \begin{center}{\fcolorbox{blue}{yellow!60}{\parbox{0.50\textwidth}{\large |
| 75 | + \begin{itemize} |
| 76 | + \item 体会``思维的乐趣'' |
| 77 | + \item 初步了解递归与数学归纳法 |
| 78 | + \item 初步接触算法概念与问题下界概念 |
| 79 | + \end{itemize}}}} |
| 80 | + \end{center} |
| 81 | +} |
| 82 | + |
| 83 | +% Each hw consists of four parts: |
| 84 | +\newcommand{\beginrequired}{\hspace{5em}\section{作业 (必做部分)}} |
| 85 | +\newcommand{\beginoptional}{\section{作业 (选做部分)}} |
| 86 | +\newcommand{\beginot}{\section{Open Topics}} |
| 87 | +\newcommand{\begincorrection}{\section{订正}} |
| 88 | +\newcommand{\beginfb}{\section{反馈}} |
| 89 | + |
| 90 | +% for math |
| 91 | +\usepackage{amsmath, mathtools, amsfonts, amssymb} |
| 92 | +\newcommand{\set}[1]{\{#1\}} |
| 93 | + |
| 94 | +% define theorem-like environments |
| 95 | +\usepackage[amsmath, thmmarks]{ntheorem} |
| 96 | + |
| 97 | +\theoremstyle{break} |
| 98 | +\theorempreskip{2.0\topsep} |
| 99 | +\theorembodyfont{\song} |
| 100 | +\theoremseparator{} |
| 101 | +\newtheorem{problem}{题目}[subsection] |
| 102 | +\renewcommand{\theproblem}{\arabic{problem}} |
| 103 | +\newtheorem{ot}{Open Topics} |
| 104 | + |
| 105 | +\theorempreskip{3.0\topsep} |
| 106 | +\theoremheaderfont{\kai\bfseries} |
| 107 | +\theoremseparator{:} |
| 108 | +\theorempostwork{\bigskip\hrule} |
| 109 | +\newtheorem*{solution}{解答} |
| 110 | +\theorempostwork{\bigskip\hrule} |
| 111 | +\newtheorem*{revision}{订正} |
| 112 | + |
| 113 | +\theoremstyle{plain} |
| 114 | +\newtheorem*{cause}{错因分析} |
| 115 | +\newtheorem*{remark}{注} |
| 116 | + |
| 117 | +\theoremstyle{break} |
| 118 | +\theorempostwork{\bigskip\hrule} |
| 119 | +\theoremsymbol{\ensuremath{\Box}} |
| 120 | +\newtheorem*{proof}{证明} |
| 121 | + |
| 122 | +% \newcommand{\ot}{\blue{\bf [OT]}} |
| 123 | + |
| 124 | +% for figs |
| 125 | +\renewcommand\figurename{图} |
| 126 | +\renewcommand\tablename{表} |
| 127 | + |
| 128 | +% for fig without caption: #1: width/size; #2: fig file |
| 129 | +\newcommand{\fig}[2]{ |
| 130 | + \begin{figure}[htbp] |
| 131 | + \centering |
| 132 | + \includegraphics[#1]{#2} |
| 133 | + \end{figure} |
| 134 | +} |
| 135 | +% for fig with caption: #1: width/size; #2: fig file; #3: caption |
| 136 | +\newcommand{\figcap}[3]{ |
| 137 | + \begin{figure}[htbp] |
| 138 | + \centering |
| 139 | + \includegraphics[#1]{#2} |
| 140 | + \caption{#3} |
| 141 | + \end{figure} |
| 142 | +} |
| 143 | +% for fig with both caption and label: #1: width/size; #2: fig file; #3: caption; #4: label |
| 144 | +\newcommand{\figcaplbl}[4]{ |
| 145 | + \begin{figure}[htbp] |
| 146 | + \centering |
| 147 | + \includegraphics[#1]{#2} |
| 148 | + \caption{#3} |
| 149 | + \label{#4} |
| 150 | + \end{figure} |
| 151 | +} |
| 152 | +% for margin fig without caption: #1: width/size; #2: fig file |
| 153 | +\newcommand{\mfig}[2]{ |
| 154 | + \begin{marginfigure} |
| 155 | + \centering |
| 156 | + \includegraphics[#1]{#2} |
| 157 | + \end{marginfigure} |
| 158 | +} |
| 159 | +% for margin fig with caption: #1: width/size; #2: fig file; #3: caption |
| 160 | +\newcommand{\mfigcap}[3]{ |
| 161 | + \begin{marginfigure} |
| 162 | + \centering |
| 163 | + \includegraphics[#1]{#2} |
| 164 | + \caption{#3} |
| 165 | + \end{marginfigure} |
| 166 | +} |
| 167 | + |
| 168 | +\usepackage{fancyvrb} |
| 169 | + |
| 170 | +% for algorithms |
| 171 | +\usepackage[]{algorithm} |
| 172 | +\usepackage[]{algpseudocode} % noend |
| 173 | +% See [Adjust the indentation whithin the algorithmicx-package when a line is broken](https://tex.stackexchange.com/a/68540/23098) |
| 174 | +\newcommand{\algparbox}[1]{\parbox[t]{\dimexpr\linewidth-\algorithmicindent}{#1\strut}} |
| 175 | +\newcommand{\hStatex}[0]{\vspace{5pt}} |
| 176 | +\makeatletter |
| 177 | +\newlength{\trianglerightwidth} |
| 178 | +\settowidth{\trianglerightwidth}{$\triangleright$~} |
| 179 | +\algnewcommand{\LineComment}[1]{\Statex \hskip\ALG@thistlm \(\triangleright\) #1} |
| 180 | +\algnewcommand{\LineCommentCont}[1]{\Statex \hskip\ALG@thistlm% |
| 181 | + \parbox[t]{\dimexpr\linewidth-\ALG@thistlm}{\hangindent=\trianglerightwidth \hangafter=1 \strut$\triangleright$ #1\strut}} |
| 182 | +\makeatother |
| 183 | + |
| 184 | +% for footnote/marginnote |
| 185 | +% see https://tex.stackexchange.com/a/133265/23098 |
| 186 | +\usepackage{tikz} |
| 187 | +\newcommand{\circled}[1]{% |
| 188 | + \tikz[baseline=(char.base)] |
| 189 | + \node [draw, circle, inner sep = 0.5pt, font = \tiny, minimum size = 8pt] (char) {#1}; |
| 190 | +} |
| 191 | +\renewcommand\thefootnote{\protect\circled{\arabic{footnote}}} |
0 commit comments