插入代码块
插入Python代码
\begin{document}前需要的内容:
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=shadowbox,
language=Python,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,%设置行号位置none不显示行号
%numberstyle=\tiny\courier, %设置行号大小
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
escapeinside=``,%逃逸字符(1左面的键),用于显示中文例如在代码中`中文...`
tabsize=4,
extendedchars=false %解决代码跨页时,章节标题,页眉等汉字不显示的问题
}
注:在正式输入的代码块中,要把数字、字母等用``框起来,不然显示会出问题。(见下例子)
\begin{lstlisting}[language={Python}]
key=b'\x0f\x15\x71\xc9\x47\xd9\xe8\x59\x0c\xb7\xad\xd6\xaf\x7f\x67\x98'
Key=key.hex()#从字节串转成`16`进制字符串
plain=b'\x01\x23\x45\x67\x89\xab\xcd\xef\xfe\xdc\xba\x98\x76\x54\x32\x10'
Plain=plain.hex()
\end{lstlisting}
输入字符等
插入符号
异或⊕
$A\oplus B$
输出:A⊕B