\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mathpage}[2021/01/01 v2.0]

\ProcessOptions\relax

\newif\ifmathpage\mathpagefalse
\newif\ifnomathpage\ifmathpage\nomathpagefalse\else\nomathpagetrue\fi

%\RequirePackage{shellesc}
%
%\ifnomathpage
%  \ifcase\ShellEscapeStatus
%    \PackageWarning{shellesc}{Shell escape disabled}
%    \PackageInfo   {shellesc}{Package minted not loaded}
%  \or
%    \PackageInfo   {shellesc}{Unrestricted shell escape enabled}
%    \RequirePackage{minted}
%  \else
%    \PackageInfo   {shellesc}{Restricted shell escape enabled}
%    \PackageInfo   {shellesc}{Package minted not loaded}
%  \fi
%\else
%  \RequirePackage{minted}
%\fi

\RequirePackage{amsmath,amsthm,amssymb}
\RequirePackage{latexsym}
\RequirePackage{makeidx}
\RequirePackage{graphicx}
\RequirePackage{framed}
\RequirePackage{multicol}
\RequirePackage{xspace}
\RequirePackage{indentfirst}
\RequirePackage{mathdots}
\RequirePackage{answers}
\RequirePackage{fancyvrb}
\RequirePackage{minted}
\RequirePackage{url}

% environment mathpagenote
\ifnomathpage
\newenvironment{mathpagenote}[1]{\par}{}
\fi

% environment sol: for solutions
\ifmathpage
\newenvironment{sol}{\begin{mathpagenote}{restricted, clickable}}{\end{mathpagenote}}
\else
\Newassociation{sol}{solution}{solutions}
\fi
\renewenvironment{solution}[1]{\noindent{\bfseries \hypertarget{sol:#1}{}\hyperlink{exer:#1}{#1}}}{\par}

% environment note: visible only to instructor
\ifmathpage
\newenvironment{note}{\begin{mathpagenote}{restricted}}{\end{mathpagenote}}
\else
\newenvironment{note}{\par}{}
\fi

% environment closed note: initially hidden but viewable when clicked
\ifmathpage
\newenvironment{closed}{\begin{mathpagenote}{restricted, clickable}}{\end{mathpagenote}}
\else
\newenvironment{closed}{\par}{}
\fi

% environment covered note: initially covered but viewable when hovered
\ifmathpage
\newenvironment{covered}{\begin{mathpagenote}{hoverable}}{\end{mathpagenote}}
\else
\newenvironment{covered}{\par}{}
\fi

% environment folded note: initially folded but viewable when clicked
\ifmathpage
\newenvironment{folded}{\begin{mathpagenote}{clickable}}{\end{mathpagenote}}
\else
\newenvironment{folded}{\par}{}
\fi

% macro \VerbatimEnvironment is defined in the fancyvrb package loaded by the minted package
\ifnomathpage
% environment displaycode: display the code in programming language #1
\newenvironment{displaycode}[1]{\VerbatimEnvironment\begin{minted}[frame=single]{#1}}{\end{minted}}
% environment evaluatecode: save the code to be used by \UseVerbatim{#1code}
\newenvironment{evaluatecode}[1]{\begin{framed}\centering Output\end{framed}%
\VerbatimEnvironment\begin{SaveVerbatim}{#1code}}{\end{SaveVerbatim}}
\fi

\ifnomathpage
% command \includemedia: for embedding videos and audios
\newcommand{\includemedia}[1]{\fbox{\url{#1}}}
% command \includefile: for embedding file download links
\newcommand{\includefile}[1]{\fbox{\url{#1}}}
% command \includewebpage: for embedding webpages
\newcommand{\includewebpage}[1]{\fbox{\url{#1}}}
\fi

% command \actuarialangle: actuarial angle accent
\ifmathpage
  \def\actuarialangle#1{\enclose{actuarial}{#1}}
\else
  \def\actuarialangle#1{{\leavevmode\hbox{\vtop{\vbox{\hrule\kern1pt\hbox{{$\scriptstyle #1$}\kern.5pt}}\kern.5pt}\vrule}\kern1pt}}
\fi
