Skip to content

Instantly share code, notes, and snippets.

@YidongQIN
Last active October 17, 2024 14:29
Show Gist options
  • Save YidongQIN/a10dd4f72381362aff4257e7a5541d86 to your computer and use it in GitHub Desktop.
Save YidongQIN/a10dd4f72381362aff4257e7a5541d86 to your computer and use it in GitHub Desktop.
LaTeX Listings styles and language defination for Python
% color def
\usepackage{color}
\definecolor{darkred}{rgb}{0.6,0.0,0.0}
\definecolor{darkgreen}{rgb}{0,0.50,0}
\definecolor{lightblue}{rgb}{0.0,0.42,0.91}
\definecolor{orange}{rgb}{0.99,0.48,0.13}
\definecolor{grass}{rgb}{0.18,0.80,0.18}
\definecolor{pink}{rgb}{0.97,0.15,0.45}
% listings
\usepackage{listings}
% General Setting of listings
\lstset{
aboveskip=1em,
breaklines=true,
abovecaptionskip=-6pt,
captionpos=b,
escapeinside={\%*}{*)},
frame=single,
numbers=left,
numbersep=15pt,
numberstyle=\tiny,
}
% 0. Basic Color Theme
\lstdefinestyle{colored}{ %
basicstyle=\ttfamily,
backgroundcolor=\color{white},
commentstyle=\color{green}\itshape,
keywordstyle=\color{blue}\bfseries\itshape,
stringstyle=\color{red},
}
% 1. General Python Keywords List
\lstdefinelanguage{PythonPlus}[]{Python}{
morekeywords=[1]{,as,assert,nonlocal,with,yield,self,True,False,None,} % Python builtin
morekeywords=[2]{,__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__,}, % magic methods
morekeywords=[3]{,object,type,isinstance,copy,deepcopy,zip,enumerate,reversed,list,set,len,dict,tuple,range,xrange,append,execfile,real,imag,reduce,str,repr,}, % common functions
morekeywords=[4]{,Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError,}, % errors
morekeywords=[5]{,ode,fsolve,sqrt,exp,sin,cos,arctan,arctan2,arccos,pi, array,norm,solve,dot,arange,isscalar,max,sum,flatten,shape,reshape,find,any,all,abs,plot,linspace,legend,quad,polyval,polyfit,hstack,concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize,lstsq,cla,eye,xlabel,ylabel,squeeze,}, % numpy / math
}
% 2. New Language based on Python
\lstdefinelanguage{PyBrIM}[]{PythonPlus}{
emph={d,E,a,Fc28,Fy,Fu,D,des,supplier,Material,Rectangle,PyElmt},
}
% 3. Extended theme
\lstdefinestyle{colorEX}{
basicstyle=\ttfamily,
backgroundcolor=\color{white},
commentstyle=\color{darkgreen}\slshape,
keywordstyle=\color{blue}\bfseries\itshape,
keywordstyle=[2]\color{blue}\bfseries,
keywordstyle=[3]\color{grass},
keywordstyle=[4]\color{red},
keywordstyle=[5]\color{orange},
stringstyle=\color{darkred},
emphstyle=\color{pink}\underbar,
}
@LadislavVasina1
Copy link

Thx, for the inspiration 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment