Last active
October 12, 2017 08:08
-
-
Save davidwessman/223e4f989a1a673340a6 to your computer and use it in GitHub Desktop.
Import Python to LaTeX
This file contains 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
% Default fixed font does not support bold face | |
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold | |
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal | |
% Custom colors | |
\usepackage{color} | |
\definecolor{deepblue}{rgb}{0,0,0.5} | |
\definecolor{deepred}{rgb}{0.6,0,0} | |
\definecolor{deepgreen}{rgb}{0,0.5,0} | |
% https://www.ctan.org/pkg/listings | |
\usepackage[procnames]{listings} | |
% Python style for highlighting | |
\newcommand\pythonstyle{\lstset{ | |
language=Python, | |
basicstyle=\ttm, | |
otherkeywords={self}, % Add keywords here | |
keywordstyle=\ttb\color{deepblue}, | |
emph={MyClass,__init__}, % Custom highlighting | |
emphstyle=\ttb\color{deepred}, % Custom highlighting style | |
stringstyle=\color{deepgreen}, | |
frame=tb, % Any extra options here | |
showstringspaces=false % | |
}} | |
% Python environment | |
\lstnewenvironment{python}[1][] | |
{ | |
\pythonstyle | |
\lstset{ | |
1,literate={ö}{{\"o}}1 | |
{ä}{{\"a}}1 | |
{å}{{\aa}}1 | |
{Å}{{\AA}}1 | |
{Ä}{{\"A}}1 | |
{Ö}{{\"O}}1 | |
{~}{{\tilde}}1 | |
{é}{{\´{e}}}1 | |
{É}{{\´{E}}}1 | |
} | |
} | |
{} | |
% Python for external files | |
\newcommand\pythonexternal[2][]{{ | |
\pythonstyle | |
\lstinputlisting[#1]{#2}}} | |
% Python for inline | |
\newcommand\pythoninline[1]{{\pythonstyle\lstinline!#1!}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really good work! could you please tell me how can I import the first 100 lines of the external code into my text ?