![在 PythonTeX 上设计 Pygments](https://linux22.com/image/476891/%E5%9C%A8%20PythonTeX%20%E4%B8%8A%E8%AE%BE%E8%AE%A1%20Pygments.png)
我可以在 PythonTeX 上使用 pygmentize 样式和 Pygments 吗?让 MWE 像这样:
\documentclass{article}
\usepackage{pythontex}
\begin{document}
\begin{pygments}[style= murphy]{python} % murpyhy is style from pygmentize
#!/usr/bin/env python
import Tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
app = Application()
app.master.title('Sample application')
app.mainloop()
\end{pygments}
\end{document}
我将获得如下风格的 Pygmentize:
\documentclass{article}
\usepackage{minted}
\usemintedstyle{murphy}
\begin{document}
\begin{minted}[mathescape]{python}
#!/usr/bin/env python
import Tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
app = Application()
app.master.title('Sample application')
app.mainloop()
\end{minted}
\end{document}
上面的结果使用 minted 包,但我需要使用 pythontex 包,因为我的文档很简单,并且屏幕截图结果:
有什么办法可以解决它吗?
答案1
我不知道是否可以在文档中间更改样式,但是这是可行的:
\documentclass{article}
\usepackage[pygopt={style=murphy}]{pythontex}
\begin{document}
\begin{pygments}{python}
#!/usr/bin/env python
import Tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
app = Application()
app.master.title('Sample application')
app.mainloop()
\end{pygments}
\end{document}