\ProvidesPackage{mrstbook}
% ---------- Fonts, colors, basic setup  --------------------------------------
\usepackage[T1]{fontenc}
\usepackage{newtxtext}        % default setup of fronts
\usepackage{newtxmath}        % selects Times Roman as basic font
%                               % activate next three lines if you do not have newtxt packages
% \usepackage{mathptmx}         % selects Times Roman as basic font
% \usepackage{helvet}           % selects Helvetica as sans-serif font
% \usepackage{courier}          % selects Courier as typewriter font
%
% \usepackage{type1cm}          % activate if neither of the above fonts are
%                               % available on your system
\usepackage{amsmath,amssymb}  % extra mathematics from AMS
\usepackage{color}            % colors
\usepackage{latexsym}         % extra symbols from LaTeX 2.09
\usepackage{xspace}           % define commands that appear not to eat spaces
\usepackage[bottom]{footmisc} % places footnotes at page bottom

% ---------- Figures, subcaptions, etc.  --------------------------------------
\usepackage{graphicx}         % include graphics files
\usepackage{tikz}             % in case authors want to use tikz

% ---------- Tables, arrays, etc. ---------------------------------------------
\usepackage{booktabs}         % publication quality tables in LaTeX
\usepackage{array}            % extend the array class, "programmable" formats

% ---------- Referencing ------------------------------------------------------
\usepackage[numbers,sort]{natbib}   % flexible bibliography support
\usepackage{doi}                    % include DOI numbers
\usepackage{url}                    % specification of URLs
\urlstyle{tt}
\usepackage{varioref}               % intelligent page references
\labelformat{equation}{(#1)}
\renewcommand{\eqref}[1]{\ref{#1}}
\usepackage{hyperref} % cross-referencing with hyperlinks
%\usepackage{showlabels}                % show labels in margin: useful during writing 

% ---------- Inclusion of MATLB/MRST code -------------------------------------
% MATLAB commands should be included using the listings package. See the
% author sample file for more details
\definecolor{lightgray}{gray}{0.3}
\usepackage{fancyvrb}               % sophisticated verbatim text used for MATLAB output
\fvset{fontsize=\small\color{lightgray},xleftmargin=\parindent}
\usepackage{framed}                 % framed boxes around a region   
\usepackage{listings}
\usepackage{styles/matlab-prettifier}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.95,0.95,0.92}
\lstdefinelanguage{MRST}{%
  style=Matlab-editor,
  alsoletter={...},%
  comment=[l]\%,%                             % comments
  morecomment=[l]...,%                        % comments
  morestring=[m]',%                           % strings
}[keywords,comments,strings]%
\lstset{
  xleftmargin= 4pt,
  xrightmargin=4pt,
  backgroundcolor=\color{lbcolor},
  tabsize=4,
  language=MRST,
  moredelim=**[is][\color{red}]{@@}{@@},
  upquote=true,
  aboveskip={0.5\baselineskip},
  columns=flexible,
  showstringspaces=false,
  extendedchars=true,
  prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
  frame=single,
  rulecolor=,
  showtabs=false,
  showspaces=false,
  showstringspaces=false,
  identifierstyle=\ttfamily,
  keywordstyle=\color[rgb]{0,0,1},
  commentstyle=\color[rgb]{0.133,0.545,0.133},
  stringstyle=\color[rgb]{0.627,0.126,0.941},
  literate={~}{{\raisebox{0.5ex}{\texttildelow}}}1 % vert. centered tilde
}
% Make monospaced code listings. The fontsize is also
% adjusted to not take up more horizontal space than before.
\makeatletter
\newcommand\codesize{\@setfontsize\codesize{9}{11}}
\makeatother
\lstset{
  basicstyle=\lst@ifdisplaystyle\codesize\fi\ttfamily\upshape,
  columns=fixed,
  basewidth={0.44em,0.45em}
}
\newcommand{\mcode}[1]{\lstinline|#1|}

% ---------- Index ------------------------------------------------------------
% The book will have two 2-column index lists at the end: one for general keyword
% and one for MRST (and MATLAB) commands. Entries into the first index are
% included through the usual \index{My new keyword} command. In addition, we
% provides a new command \moduleindex{modulename} that will collect references
% to MRST modules as subentries of a keyword called "Modules". Entries into the
% second index are entered through the \mrstindex{myMrstCommandName} command.
% To generate the two index lists, you must run two passes of \texttt{makeindex}
%     makeindex -s styles/mrstsvind.ist mrst-book-II
%     makeindex -s styles/mrstsvind.ist mrst-book-II.mii -o mrst-book-II.mio
\usepackage{multicol}                  % for the index
\usepackage{index}                     % To produce index a the end of the book
\makeatother
\makeindex
\newindex{mrst}{mii}{mio}{Usage of MRST Functions}
\newcommand{\mrstindex}[1]{\index[mrst]{#1@\texttt{#1}}}
\newcommand{\moduleindex}[1]{\index{Modules!#1@\texttt{#1}}}


% --------- Mathematical operators ------------------------------------------
\newcommand{\vect}[1]{\boldsymbol{#1}}
\newcommand{\mat}[1]{\boldsymbol{#1}}
\newcommand{\K}{\ensuremath{\tens{K}}}
\newcommand{\grad}{\nabla}%
\newcommand{\dive}{\nabla\cdot}%
\newcommand{\ddiv}{\texttt{\upshape div}\xspace}%
\newcommand{\dgrad}{\texttt{\upshape grad}\xspace}%
\newcommand{\sgn}{\ensuremath{\operatorname}{sign}}
\newcommand{\abs}[1]{\ensuremath{\left\lvert{#1}\right\rvert}}%