Advertisement
yusufbrima

Adding code snippet in a tex file

Nov 14th, 2020
1,751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.12 KB | None | 0 0
  1. %import these packages at the top of your tex file
  2.  
  3. \usepackage{listings}
  4. \usepackage{xcolor}
  5.  
  6. %define this color scheme for syntax coloring
  7.  
  8. \definecolor{codegreen}{rgb}{0,0.6,0}
  9. \definecolor{codegray}{rgb}{0.5,0.5,0.5}
  10. \definecolor{codepurple}{rgb}{0.58,0,0.82}
  11. \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
  12.  
  13. %set this preamble in for the lstlisting preamble
  14.  
  15. \lstdefinestyle{mystyle}{
  16.    backgroundcolor=\color{backcolour},  
  17.    commentstyle=\color{codegreen},
  18.    keywordstyle=\color{magenta},
  19.    numberstyle=\tiny\color{codegray},
  20.    stringstyle=\color{codepurple},
  21.    basicstyle=\ttfamily\footnotesize,
  22.    breakatwhitespace=false,        
  23.    breaklines=true,                
  24.    captionpos=b,                    
  25.    keepspaces=true,                
  26.    numbers=left,                    
  27.    numbersep=2pt,                  
  28.    showspaces=false,                
  29.    showstringspaces=false,
  30.    showtabs=false,                  
  31.    tabsize=2
  32. }
  33.  
  34. \lstset{style=mystyle}
  35.  
  36. %finally put this in Exercise 2 b
  37.  
  38.  \begin{lstlisting}[language=Python]
  39.  %your python code goes here
  40.  
  41.  \end{lstlisting}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement