Created
July 6, 2015 10:18
-
-
Save MarioPerezEsteso/7937e4030013e7a882e9 to your computer and use it in GitHub Desktop.
Python code syntax highlighting with Latex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\definecolor{Code}{rgb}{0,0,0} | |
\definecolor{Decorators}{rgb}{0.5,0.5,0.5} | |
\definecolor{Numbers}{rgb}{0.5,0,0} | |
\definecolor{MatchingBrackets}{rgb}{0.25,0.5,0.5} | |
\definecolor{Keywords}{rgb}{0,0,1} | |
\definecolor{self}{rgb}{0,0,0} | |
\definecolor{Strings}{rgb}{0,0.63,0} | |
\definecolor{Comments}{rgb}{0,0.63,1} | |
\definecolor{Backquotes}{rgb}{0,0,0} | |
\definecolor{Classname}{rgb}{0,0,0} | |
\definecolor{FunctionName}{rgb}{0,0,0} | |
\definecolor{Operators}{rgb}{0,0,0} | |
\definecolor{Background}{rgb}{0.93,0.93,0.93} | |
\lstnewenvironment{python}[1][]{ | |
\lstset{ | |
numbers=left, | |
numberstyle=\footnotesize, | |
numbersep=1em, | |
xleftmargin=1em, | |
framextopmargin=2em, | |
framexbottommargin=2em, | |
showspaces=false, | |
showtabs=false, | |
showstringspaces=false, | |
captionpos=b, | |
frame=l, | |
tabsize=4, | |
% Basic | |
basicstyle=\ttfamily\small\setstretch{1}, | |
backgroundcolor=\color{Background}, | |
language=Python, | |
% Comments | |
commentstyle=\color{Comments}\slshape, | |
% Strings | |
stringstyle=\color{Strings}, | |
morecomment=[s][\color{Strings}]{"""}{"""}, | |
morecomment=[s][\color{Strings}]{'''}{'''}, | |
% keywords | |
morekeywords={import,from,class,def,for,while,if,is,in,elif,else,not,and,or,print,break,continue,return,True,False,None,access,as,,del,except,exec,finally,global,import,lambda,pass,print,raise,try,assert}, | |
keywordstyle={\color{Keywords}\bfseries}, | |
% additional keywords | |
morekeywords={[2]@invariant}, | |
keywordstyle={[2]\color{Decorators}\slshape}, | |
emph={self}, | |
emphstyle={\color{self}\slshape}, | |
caption={[#1]{#1}} | |
% | |
}}{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{python}[This is my caption] | |
def foo(bar): | |
print 'hello world!' | |
\end{python} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment