\RequirePackage[small,compact]{titlesec}
\RequirePackage{jbw-prog-util}

\let\oldttl@format@iii=\ttl@format@iii
\def\ttl@format@iii#1#2#3#4#5[#6]{%
  \expandafter\let\expandafter\ttl@format@aux\csname ttlf@\ttl@a\endcsname
  \expandafter
  \usetemplate\expandafter{\ttl@format@aux}
    {\oldttl@format@iii{#1}{#2}{#3}{#4}{#5}[#6]}}
\let\oldttl@spacing@ii=\ttl@spacing@ii
\def\ttl@spacing@ii#1#2#3#4[#5]{%
  \expandafter\let\expandafter\ttl@spacing@aux\csname ttls@\ttl@a\endcsname
  \expandafter
  \usetemplate\expandafter{\ttl@spacing@aux}
    {\oldttl@spacing@ii{#1}{#2}{#3}{#4}[#5]}}

% After the above changes, these commands should effectively do nothing:
%
%\titleformat{\section}{##2}{##3}{##4}{##5}[#6]
%\titleformat{\subsection}{##2}{##3}{##4}{##5}[#6]
%\titleformat{\subsubsection}{##2}{##3}{##4}{##5}[#6]
%\titlespacing{\subsubsection}{##1}{##3}{##4}[#2]

\newcommand{\jbwtitlesecEPSRCProposalFormat}
  {%
   \titleformat{\section}{####2}{\thesection.}{1em}{####5\filright}[##6]%
   \titleformat{\subsection}{####2}{\Alph{subsection}.}{1em}{####5}[##6]%
   %\titleformat{\subsubsection}[runin]{####2}{}{0pt}{####5}[##6.]%
   \titleformat{\subsubsection}{####2}{\Alph{subsection}.\arabic{subsubsection}.}{1em}{####5}[##6]%
   \titleformat{\paragraph}[runin]{####2}{####3}{####4}{####5}[##6.]%
   \titleformat{\subparagraph}[runin]{\normalfont\itshape}{####3}{####4}{####5}[##6.]%
   %
   % So references will look okay.
   \renewcommand{\thesubsection}{\thesection.\Alph{subsection}}%
   % So PDF bookmarks will look okay.
   \renewcommand{\thesubsubsection}{}%
   %
   \titlespacing*{\section}{####1}{1.5ex plus 0.3ex minus 0.05ex}{0.7ex plus 0.1ex minus 0pt}[##2]%
   \titlespacing*{\subsection}{####1}{1ex plus 0.3ex minus 0.05ex}{0.5ex plus 0.05ex minus 0pt}[##2]%
   \titlespacing*{\subsubsection}{####1}{1ex plus 0.3ex minus 0.05ex}{0.3ex plus .03ex}[##2]%
  }

\newcommand{\jbwtitlesecEPSRCIGRFormat}
  {%
   \titleformat{\section}{####2}{\thesection.}{1em}{####5\filright}[##6]%
   \titleformat{\subsection}{####2}{\thesubsection.}{1em}{####5}[##6]%
   %\titleformat{\subsubsection}[runin]{####2}{}{0pt}{####5}[##6.]%
   \titleformat{\subsubsection}{####2}{\thesubsubsection.}{1em}{####5}[##6]%
   \titleformat{\paragraph}[runin]{####2}{####3}{####4}{####5}[##6.]%
   \titleformat{\subparagraph}[runin]{\normalfont\itshape}{####3}{####4}{####5}[##6.]%
   %
   % So references will look okay.
   %\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}%
   % So PDF bookmarks will look okay.
   %\renewcommand{\thesubsubsection}{}%
   %
   \titlespacing*{\section}{####1}{1.5ex plus 0.3ex minus 0.05ex}{0.7ex plus 0.1ex minus 0pt}[##2]%
   \titlespacing*{\subsection}{####1}{1ex plus 0.3ex minus 0.05ex}{0.5ex plus 0.05ex minus 0pt}[##2]%
   \titlespacing*{\subsubsection}{####1}{1ex plus 0.3ex minus 0.05ex}{0.3ex plus .03ex}[##2]%
  }
