I want to include some Python code to my Latex document. I have read this Tex Stackexchange question and added the following code to get syntax highlights:
\usepackage{color}
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\newcommand\pythonstyle{\lstset{
language=Python,
basicstyle=\ttm,
otherkeywords={self},
keywordstyle=\ttb\color{deepblue},
emph={__init__},
emphstyle=\ttb\color{deepred},
stringstyle=\color{deepgreen},
frame=tb,
showstringspaces=false
}}
\newcommand\pythonexternal[2][]{{
\pythonstyle
\lstinputlisting[#1]{#2}}
}
Using the above code, the Python code in the Latex document is extremely large and it also goes far outside the right margin.
I only have a basic knowledge of Latex and don't really know how I can fix these issues.
\small
or some other size to make it smaller, or you can adjust the python code by hand breaking the lines in a language aware manner to keep less than 80 (or whatever) characters per line. All are possible but you need to choose what happens...