แต่หากต้องการ Highlight โค้ด Python สวย ๆ สามารถทำได้ตามนี้
เข้าไปโหลด package ชื่อ pythonhighlight ไฟล์
pythonhighlight.sty มาจาก https://github.com/olivierverdier/python-latex-highlighting มาวางไว้กับโฟลเดอร์เดียวกันกับเอกสาร LaTex ของคุณในการใช้งาน ทำได้ง่าย ๆ
\begin{python}
print("Hello,world!")
\end{python}
ผลลัพธ์
ในกรณีมีไฟล์ Python ต้องการดึงโค้ดมาใส่ในเนื้อหา ทำได้โดย
\inputpython{code/hello_world.py}{0}{1}
เริ่มบรรทัดที่ 0 ถึง บรรทัดที่ 1
และนอกจากนั้น ยังมีอีกวิธีโดยใช้ Listings Package อ่านได้ที่ https://www.quora.com/What-is-the-optimal-way-to-include-Python-code-in-a-LaTeX-document/answer/Giordon-Stark
เพียงเท่านี้ เอกสาร LaTex ที่แนบโค้ด Python ของคุณจะดูดีขึ้น

0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)