Skip to content

Instantly share code, notes, and snippets.

@jkulesza
Created January 18, 2018 05:43
Show Gist options
  • Save jkulesza/d76be674d902d4e65f1fbc5c9d3d56fe to your computer and use it in GitHub Desktop.
Save jkulesza/d76be674d902d4e65f1fbc5c9d3d56fe to your computer and use it in GitHub Desktop.
% Load Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\usepackage{xcolor}
% Set Code Listing Style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{codebackground}{rgb}{1,1,1}
\definecolor{codeframe}{rgb}{0,0,0}
\definecolor{codecomment}{rgb}{0,0.6,0}
\definecolor{codestring}{rgb}{0.58,0,0.82}
\definecolor{codekeyword}{rgb}{0,0,1}
\lstset{ %
backgroundcolor=\color{codebackground}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
basicstyle=\scriptsize\ttfamily, % the size of the fonts that are used for the code
commentstyle=\color{codecomment}, % comment style
numberstyle=\color{gray}\tiny\zebra{gray!10}{white}{}, % the style that is used for the line-numbers
rulecolor=\color{codeframe}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
stringstyle=\color{codestring}, % string literal style
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=t, % sets the caption-position to bottom
deletekeywords={...}, % if you want to delete keywords from the given language
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
frame=single, % adds a frame around the code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{codekeyword}, % keyword style
%language=Fortran, % the language of the code
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname, % show the filename of files included with \lstinputlisting; also try caption instead of title
}
\lstset{emph={%
pragma, omp%
},emphstyle={\color{red}}%
}%
% Alternate Line Colors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\realnumberstyle[1]{}
\makeatletter
\newcommand{\zebra}[2]{%
\begingroup
\lst@basicstyle
\ifodd\value{lstnumber}%
\color{#1}%
\else
\color{#2}%
\fi
\ifnum\value{lstnumber}>9
\rlap{\hspace*{\lst@numbersep}\hspace*{0.95em}%
\color@block{\linewidth}{\ht\strutbox}{\dp\strutbox}%
}%
\else
\rlap{\hspace*{\lst@numbersep}\hspace*{0.5em}%
\color@block{\linewidth}{\ht\strutbox}{\dp\strutbox}%
}%
\fi
\endgroup
}
\makeatother
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment