
%% $ nullify Emacs underscores
%% BEGIN: Footer
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand \footersetup { +m }
{
\keys_set:nn { footer } { #1 }
}
\keys_define:nn { footer }
{	
    leftside .code:n = {
\keys_set:nn { footer / leftside } { #1 }
},
rightside .code:n = {
\keys_set:nn { footer / rightside } { #1 }
},
    leftside / lone .tl_set:N = \l_footer_leftside_lone_tl,
    leftside / ltwo .tl_set:N = \l_footer_leftside_ltwo_tl,
    leftside / lthree .tl_set:N = \l_footer_leftside_lthree_tl,
    rightside / rone .tl_set:N = \l_footer_rightside_rone_tl,
    rightside / rtwo .tl_set:N = \l_footer_rightside_rtwo_tl,
    rightside / rthree .tl_set:N = \l_footer_rightside_rthree_tl,
    leftside .initial:n = {lone = , ltwo = ~, lthree = ~ },
    rightside .initial:n = {rone = ~, rtwo = ~,  rthree = ~},
    leftside .default:n = {lone = , ltwo = ~, lthree = ~ },
    rightside .default:n = {rone = ~, rtwo = ~,  rthree = ~},
}
\NewDocumentCommand \guideftr { +o }
{
  \IfValueT { #1 } 
  {
    \keys_set:nn { footer } { #1 }
  }
  \guide_ftr:
}
\cs_new_protected:Nn \guide_ftr:
{
  % Now fancy header/footer settings
  \lhead{}%
  \chead{}%
  \rhead{}%
  \renewcommand{\headrulewidth}{0pt}%
  \lfoot{}%
  \cfoot{{Page} ~ \thepage {} ~ { of } ~ {} \pageref{LastPage}}%
  \rfoot{}%

  \fancypagestyle{firststyle}%
  {%
    \lhead{}%
    \chead{}%
    \rhead{}%
    \lfoot{}%
    \cfoot{}%
    \rfoot{}%
    \renewcommand{\headrulewidth}{0pt}%
    \fancyfoot[L]{\l_footer_leftside_lone_tl {}\\%
      \l_footer_leftside_ltwo_tl {}\\%
      \l_footer_leftside_lthree_tl {}}%
    \fancyfoot[R]{\l_footer_rightside_rone_tl {}\\%
      \l_footer_rightside_rtwo_tl {}\\%
      \l_footer_rightside_rthree_tl {}}%
      \renewcommand{\footrulewidth}{.2pt}%
  }%
  \thispagestyle{firststyle}
}
\ExplSyntaxOff
%% End of fancy footer setup

