\usepackage{listings} \usepackage[usenames,dvipsnames]{xcolor} \colorlet{blockKeywordColor}{blue} \colorlet{blockBaseFunctionsColor}{black} \colorlet{blockStringColor}{Maroon!100!black!50!} \colorlet{blockCommentColor}{ForestGreen} \colorlet{nbKeywordColor}{blue} \colorlet{nbBaseFunctionsColor}{black} \colorlet{nbStringColor}{Maroon!50!black!50!} \colorlet{nbCommentColor}{gray} % Changed from ForestGreen %% DEFINE LANGUAGE %% % Adapted from jub0bs in StackOverflow, see % https://tex.stackexchange.com/questions/212793/how-can-i-typeset-julia-code-with-the-listings-package \lstdefinelanguage{Julia}% {morekeywords=[1]{abstract,break,case,catch,const,continue,do,else,elseif,% end,export,false,for,function,immutable,import,importall,if,in,% macro,module,otherwise,quote,return,switch,true,try,type,typealias,% using,while},% sensitive=true,% alsoother={\$},% morekeywords=[2]{exp,sum,plot,optimize,minimizer}, morecomment=[l]\#,% morecomment=[n]{\#=}{=\#},% morestring=[s]{"}{"},% morestring=[m]{'}{'},% }[keywords,comments,strings]% %% STYLES % Adapted from Marco Daniel in StackOverflow, see % https://tex.stackexchange.com/questions/34688/lstlisting-how-to-set-code-color-and-frame-color \lstdefinestyle{blockJuliaStyle}{ language = Julia, %columns=flexible, %keepspaces =true, columns = fullflexible, basicstyle = \fontfamily{pcr}\selectfont\footnotesize, %need pcr (Courier) to bold letters keywordstyle = {[1]\bfseries\color{blockKeywordColor}}, keywordstyle = {[2]\bfseries\color{blockBaseFunctionsColor}}, stringstyle = \bfseries\color{blockStringColor}, commentstyle = \slshape\color{blockCommentColor}, showstringspaces = false, numbers=none, % where to put the line-numbers numberstyle=\tiny, % the size of the fonts that are used for the line-numbers showspaces=false, % show spaces adding particular underscores showstringspaces=false, % underline spaces within strings showtabs=false, % show tabs within strings adding particular underscores frame=tb, % rule at top and bottom of code listing captionpos=b, % sets the caption-position to bottom breaklines=true, % sets automatic line breaking tabsize=2, % sets default tabsize to 2 spaces rulesepcolor=\color{gray}, rulecolor=\color{black}, breakatwhitespace=false, } % See how to define style in tcblisting % https://tex.stackexchange.com/questions/247608/problem-with-gobble-listing-option-inside-a-tcblisting \lstdefinestyle{nbJuliaStyle}{ language = Julia, basicstyle = \fontfamily{pcr}\selectfont\scriptsize, % Changed from \footnotesize %\fontfamily{pcr}\selectfont\footnotesize, keywordstyle = {[1]\bfseries\color{nbKeywordColor}}, keywordstyle = {[2]\bfseries\color{nbBaseFunctionsColor}}, stringstyle = \bfseries\color{nbStringColor}, commentstyle = \slshape\color{nbCommentColor}, showstringspaces = false, keywordstyle = {[3]\itshape\color{RedOrange}}, breaklines=true, % sets automatic line breaking } \lstset{literate= {*}{{\char42}}1 {-}{{\char45}}1 {\ }{{\copyablespace}}1 } %% COPY AND PASTABLE CODE from PDF %% % Make code so it is copy and pastable from PDF, see % https://www.monperrus.net/martin/copy-pastable-listings-in-pdf-from-latex % Also % https://tex.stackexchange.com/questions/142617/copy-pasting-leading-whitespace-and-blank-lines-in-listings-package-pdf/142765#142765 % https://tex.stackexchange.com/questions/563803/how-make-a-latex-document-that-generates-a-pdf-from-which-copy-paste-works-corre %%%% \usepackage[space=true]{accsupp} % Copy spacing at beginning and end \newcommand{\copyablespace}{\BeginAccSupp{method=hex,unicode,ActualText=00A0}\ \EndAccSupp{}} %% NOTEBOOK CELL STYLING %% % See below for tcolorbox examples % https://tex.stackexchange.com/questions/223465/ipython-notebook-cells-with-listings % https://tex.stackexchange.com/questions/340700/ipython-notebook-input-and-output-cells-with-listings %%%%% % See for styling tcblistings % https://tex.stackexchange.com/questions/247608/problem-with-gobble-listing-option-inside-a-tcblisting %%%%% \usepackage[many]{tcolorbox} \tcbuselibrary{listings} \newlength\inwd \setlength\inwd{1.3cm} \definecolor{cell-background-light-gray}{RGB}{251, 251, 251} \colorlet{nbInColor}{blue!50!black} \newtcblisting[auto counter]{nbCell}{ sharp corners, enlarge left by=\inwd, width=\linewidth-\inwd, %width=\linewidth, enhanced, boxrule=0.4pt, colback=cell-background-light-gray, listing only, top=0pt, bottom=0pt, overlay={ \node[ anchor=north east, text width=\inwd, font=\footnotesize\ttfamily\color{nbInColor}, inner ysep=2mm, inner xsep=0pt, outer sep=0pt ] at (frame.north west) % {\stepcounter{ipythcntr}In [#1]:}; {In [\thetcbcounter]:}; }, listing options={ style = nbJuliaStyle, }, }