Commit d3faa80f authored by liziwl's avatar liziwl
Browse files

加入源代码高亮包示例,并修复listing环境标号

parent 3a0c6ac1
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -153,3 +153,26 @@
  EP.B.8 & 126.74 & 0.003 & 0.017 & 0.005 & 0.083 & 1656 \\
  \bottomrule[1.5pt]
\end{longtable}


\section{源代码环境}

推荐使用 \pkg{listing} 环境嵌入 \pkg{minted}高亮代码。\verb|linenos| 参数控制代码行号显示。引用效果如代码 \ref{lst:sample-code-minted}

\begin{listing}[!ht]
\caption{C++ 代码示例}
\label{lst:sample-code-minted}
\begin{minted}[xleftmargin=20pt,linenos]{cpp}
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
unsigned short i;
int main() {
  for (i = 0; i <= 5; i++) {
    // whatever
  }
  return 0;
}
\end{minted}
\end{listing}
+3 −0
Original line number Diff line number Diff line
@@ -128,3 +128,6 @@

% 跨页表格,必须在 hyperref 之后使用否则会报错。
\usepackage{longtable}

% 源代码高亮
\usepackage{minted}
+4 −1
Original line number Diff line number Diff line
@@ -5736,7 +5736,10 @@ Thesis for the degree of \degree@level@en@noun \ of \thu@degree@domain@en%
%
%    \begin{macrocode}
\AtEndOfPackageFile*{minted}{
  \g@addto@macro\appendix{\renewcommand*{\thelisting}{\thechapter-\arabic{listing}}}%
  \AtBeginDocument{
    \renewcommand*{\thelisting}{\thechapter-\arabic{listing}}
  }% 不知道为啥下面这行不起作用,改用此种注入。
  %\g@addto@macro\appendix{\renewcommand*{\thelisting}{\thechapter-\arabic{listing}}}%
  \newcommand\thu@set@listing@language{%
    \ifthu@language@chinese
      \floatname{listing}{代码}%