我可以在 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}