%!TEX TS-program = pdflatexmk
%this will be based on the amsart class, which probably causes more pain than necessary
%but gets a lot of the formatting the way I like it
%look for !!!EDIT comments
\documentclass[oneside,12pt]{amsart}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amsfonts,amsthm,amssymb} %provides all math symbols etc.
%graphics
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[margin=0.1cm,textfont=it]{caption}
%set 1" margins:
\usepackage[left=1in,top=1in,right=1in,bottom=1in,footskip = 0.333in]{geometry}
%provide additional table capability
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} %define left justified column type
%pdf handling (only needed if including PDFs)
%\usepackage{pdflscape} 
%\usepackage{rotating}
\usepackage{pdfpages}
%provides nice verbatim environment and allows verbatim in footnotes
%uncomment as needed
%\usepackage{fancyvrb} 
%control enumerate/itemize spacing
\usepackage{enumitem} 
%for editing phase only:
%\usepackage{todonotes}
%\usepackage{draftwatermark}
%\SetWatermarkText{DRAFT}
%\SetWatermarkScale{5}
%no reason spacing should be anything other than single
%\renewcommand{\baselinestretch}{1}\normalsize %single spaced
%set up header (this has to come before the section patching)
\usepackage{fancyhdr}
\setlength{\headheight}{0.2in}
\pagestyle{fancy}
\fancyhf{}
\lhead{\small \sc Program} %!!!EDIT
\chead{\small \sc \rightmark}
\rhead{\footnotesize \thepage}
\renewcommand{\headrulewidth}{0pt}
% need to redefine section to allow rightmark to work with amsart
\let\origsection\section
\renewcommand{\section}[1]{\sectionmark{#1}\origsection{#1}}
% redefine sectionmark
\renewcommand\sectionmark[1]{\markboth{#1}{#1}}
%fix toc
\setcounter{tocdepth}{3}% to get subsubsections in toc
\makeatletter
\renewcommand{\@pnumwidth}{2em}% default is 1.55em -accommodates wider page numbers
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \leftskip#3\relax \advance\leftskip\@tempdima\relax
    \rightskip\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima
      \ifcase #1
       \or\or \hskip 1em \or \hskip 2em \else \hskip 3em \fi%
      #6\nobreak\relax
    \dotfill\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
\makeatother
%section numbering
\renewcommand{\thesubsection}{\alph{subsection}}
\renewcommand{\thesubsubsection}{\roman{subsubsection}}
\makeatletter
\renewcommand{\p@subsection}{\thesection.}
\renewcommand{\p@subsubsection}{\thesection.\thesubsection.}
\makeatother
%Define invisible section and subsection for including PDF docs
\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \refstepcounter{page}  %%only if numbering pages within sections
  \addcontentsline{toc}{section}{\protect{\thesection.}{\hskip 1em}#1}%
  \sectionmark{#1}}
  
\newcommand\invisiblesubsection[1]{%
  \refstepcounter{subsection}%
  \addcontentsline{toc}{subsection}{\thesubsection.{\hskip 1em}#1}%
  }
  
%page numbering by section
\numberwithin{page}{section}
\renewcommand{\thepage}{\thesection-\arabic{page}}
%% Make sure that page starts from 1 with every \section
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@sect}% <cmd>
  {\protected@edef}% <search>
  {\def\arg{#1}\def\arg@{section}%
   \ifx\arg\arg@\stepcounter{page}\fi%
   \protected@edef}% <replace>
  {}{}% <success><failure>
\makeatother
%hyperref load has to come after section  patching
\usepackage[breaklinks=true,colorlinks=true,citecolor=red]{hyperref}
\newcommand{\nlhref}[1]{\href{#1}{\nolinkurl{#1}}} %automatically create exact url with href
%create boolean for toggling inclusion of backmatter
\providetoggle{backmatter}
\settoggle{backmatter}{false} %set to true to toggle on/false off %!!!EDIT
%bibliography handling
\usepackage[citestyle=authoryear-comp,bibstyle=numeric, natbib=true, backend=bibtex,hyperref=true,maxbibnames=99,maxcitenames=2]{biblatex}
\addbibresource{Main.bib, local.bib} %!!!EDIT
% private defs
\def\mf{\mathbf}
\def\mb{\mathbb}
\def\mc{\mathcal}
\newcommand{\bbar}[1]{\mf{\bar{#1}}}
\newcommand{\bhat}[1]{\mf{\hat{#1}}}
\newcommand{\refeq}[1]{Equation  (\ref{#1})}
\newcommand{\refsec}[1]{\S\ref{#1}} 
\newcommand{\reftable}[1]{Table \ref{#1}} 
\newcommand{\refch}[1]{Chapter  \ref{#1}} 
\newcommand{\reffig}[1]{Figure \ref{#1}}
\newcommand{\refcode}[1]{Listing \ref{#1}}
\newcommand{\intd}[1]{\ensuremath{\,\mathrm{d}#1}}
\newcommand{\leftexp}[2]{{\vphantom{#2}}^{#1}\!{#2}}
\newcommand{\leftsub}[2]{{\vphantom{#2}}_{#1}\!{#2}}
\newcommand{\fddt}[1]{\ensuremath{\leftexp{\mathcal{#1}}{\frac{\mathrm{d}}{\mathrm{d}t}}}}
\newcommand{\fdddt}[1]{\ensuremath{\leftexp{\mathcal{#1}}{\frac{\mathrm{d}^2}{\mathrm{d}t^2}}}}
\newcommand{\omegarot}[2]{\ensuremath{\leftexp{\mathcal{#1}}{\boldsymbol{\omega}}^{\mathcal{#2}}}}
\DeclareMathOperator{\rank}{rank}
\begin{document}
\begin{center}
\textsc{\textbf{Title}\\  %!!!EDIT
PI: \\
PI Institution
}
\end{center}
\section{Table of Contents}
\renewcommand\contentsname{}
\tableofcontents
\clearpage
\section{Scientific/Technical/Management}
\subsection{Objectives and Expected Significance}\label{sec:objectives}
\subsection{Perceived Impact}\label{sec:impact}
\subsection{Relevance of Proposed Work}\label{sec:relevance}
\subsection{Technical Approach and Methodology}\label{sec:tech}
\subsection{Potential Risks and Mitigation Strategies}\label{sec:risks}
\subsection{Proposal Team Roles, Capabilities and Available Facilities}\label{sec:capab}
\subsection{Plan of Work and Management Structure}\label{sec:work}
%NB: some ROSES elements want this here, some want a separate DMP
\subsection{Data Sharing Plan}\label{sec:data}
%\subsection{Student Participation}\label{sec:student}
\clearpage
\section{References}
\printbibliography[heading=none]
%NB: this is not required for some ROSES elements
\clearpage
\section{Data Management Plan}\label{sec:dmp}
%backmatter starts here
\iftoggle{backmatter}{
\invisiblesection{Biographical Sketches}
\invisiblesubsection{Name1}
%\includepdf[pages=-,pagecommand={}]{cv1}
\clearpage
\invisiblesubsection{Name2}
%\includepdf[pages=-,pagecommand={}]{cv2}
\clearpage
\section{Personnel and Work Effort Table}
\noindent\begin{tabularx}{\linewidth}{| L{0.33\textwidth} | L{0.2\textwidth} | L{0.175\textwidth} | X |}
\hline
\textbf{Person/Role}  & \textbf{Time charged to this proposal} &\textbf{Time not charged to this proposal}& \textbf{Total Time per person/year} \\
\hline
PI &
\begin{minipage}{\columnwidth}
1 months academic \\
1 months summer\\
\end{minipage}&
N/A &
2 months/year\\
\hline
co-I &
0.1 FTE&
N/A &
0.1 FTE/year\\
\hline
Graduate Student &
\begin{minipage}{\columnwidth}
9 months academic \\
3 months summer\\
\end{minipage}&
N/A&
12 months/year
\\
\hline
Graduate Student 2 (TBD) &
\begin{minipage}{\columnwidth}
9 months academic \\
3 months summer\\
\end{minipage}&
N/A&
12 months/year
\\
\hline
Collaborator  & N/A & \emph{de minimis} &  \emph{de minimis}\\
\hline
\end{tabularx}
\clearpage
\invisiblesection{Current and Pending Support}
\invisiblesubsection{Name1}
%\includepdf[pages=-,pagecommand={}]{c_and_p}
\invisiblesubsection{Name2}
%\includepdf[pages=-,pagecommand={}]{c_and_p}
\clearpage
\section{Statements of Commitment and Letters of Support}
Statements of commitment are acknowledged electronically through NSPIRES.
\clearpage
\invisiblesection{Budget Justification}
%\includepdf[pages=-,pagecommand={}]{budget_justification}
\clearpage
\section{Facilities and Equipment}
\clearpage
\invisiblesection{Detailed Budget}
%\includepdf[pages=-,pagecommand={}]{detailed_budget} 
}{}%closes iftoggle on backmatter
\end{document}