github開源代碼:
https://github.com/cc1416619381/python-latex-highlighting
使用方法:
- 到github上download源文件,解壓,將 pythonhighlight.sty 文件複製到你的工程目錄下(即 .tex 文件所在目錄);
- 通過 \usepackage{pythonhighlight} 引用宏包,通過 \begin{python} 和 \end{python} 包裹python代碼,如下:
\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{pythonhighlight}
\begin{document}
\section{Code Analysis}
\begin{python}
import os
import sys
import pandas as pd
# import pandas_datareader.data as web
# import statsmodels.formula.api as smf
import statsmodels.tsa.api as smt
import statsmodels.api as sm
import scipy.stats as scs
# for installation
# pip install arch
from arch import arch_model
import numpy as np
import matplotlib.pyplot as plt
\end{python}
\end{document}
效果如下: