latex附录中放python代码_在Latex中插入Python代码
這里指的插入是指最終能在生成的pdf中顯示高亮的Python代碼。
在Latex中插入Python代碼,需要一個第三發的宏包pythonhighlight:
https://github.com/olivierverdier/python-latex-highlighting
下載pythonhighlight.sty后,將它放到你的.tex文件所在目錄下。
然后聲明要使用pythonhighlight,在tex文件內的導言區
\usepackage{graphicx}
\usepackage{pythonhighlight}
之后既可以在正文
添加代碼了
\begin{python}
#
from pyx import *
g = graph.graphxy(width=8)
g.plot(graph.data.function("y(x)=sin(x)/x", min=-15, max=15))
g.writePDFfile("function")
print r'\includegraphics{function}'
\end{python}
\end{document}
截圖:
完整示例:
\documentclass{article}
\usepackage{graphicx}
\usepackage{pythonhighlight}
\begin{document}
\begin{python}
#
from pyx import *
g = graph.graphxy(width=8)
g.plot(graph.data.function("y(x)=sin(x)/x", min=-15, max=15))
g.writePDFfile("function")
print r'\includegraphics{function}'
\end{python}
\end{document}
總結
以上是生活随笔為你收集整理的latex附录中放python代码_在Latex中插入Python代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学生网页设计代码成品 大学生汽车网页代做
- 下一篇: CentOS8 安装图形界面后,怎么转换