Latex中输入python代码——定制Latex代码风格

github开源代码:
https://github.com/cc1416619381/python-latex-highlighting

使用方法:

  1. 到github上download源文件,解压,将 pythonhighlight.sty 文件复制到你的工程目录下(即 .tex 文件所在目录);
  2. 通过 \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}

效果如下:
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章