% \iffalse meta-comment
%
% Copyright (C) 2021 by Philippe Faist <philippe.faist@bluewin.ch>
% -------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX 
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{phfextendedabstract.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesClass{phfextendedabstract}
%<*package>
    [2021/09/08 v1.0 phfextendedabstract class]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{xcolor}
\usepackage[preset=xpkgdoc]{phfnote}
\usepackage{needspace}

\makeatletter
\newsavebox\phfeaDocVirtualPage@contents
\newenvironment{phfeaDocVirtualPage}{%
  \par%
  \begingroup%
  \makeatletter%
  \begin{lrbox}{\phfeaDocVirtualPage@contents}%
  \begin{minipage}{12cm}\relax%
    \def\rmdefault{cmr}\def\sfdefault{cmbr}\normalfont%
    \def\shortlipsum{Lorem ipsum dolor sit amet, consectetuer
      adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
      adipiscing vitae, felis. Curabitur dictum gravida
      mauris. Nam arcu libero, nonummy eget, consectetuer id,
      vulputate a, magna.}%
    \let\RequirePackage\@gobble%
    \def\morepagecontents{\par\vspace{1em}\centering\ldots}%
    \ignorespaces%
  }%
  {%
  \end{minipage}%
  \end{lrbox}%
  %%\centering%
  \begin{tcolorbox}[text width=6cm,sharp corners,%
    before={\par\vspace{5pt}\centering\nopagebreak\parindent=0pt},after={\par\vspace{5pt}},%
    leftrule=0.4pt,toprule=0.4pt,rightrule=0.6pt,bottomrule=0.6pt,%
    colframe=black,colback=white]%
    \scalebox{0.5}{\usebox{\phfeaDocVirtualPage@contents}}%
  \end{tcolorbox}%
  %%\par%
  \endgroup%
}
\def\phfeaSectionDecoration{% only for doc purposes
  \raisebox{0.2ex}{{%
      \notesmaller[0.4]\phfeaSectionDecorationSymbol}}%
  \hspace*{1.5ex}%
}
\def\phfeaSectionDecorationSymbol{\ensuremath{\blacksquare}}% only for doc purposes
\def\phfeaParagraphDecoration{% only for doc purposes
  \raisebox{0.2ex}{{%
      \notesmaller[0.6]\phfeaParagraphDecorationSymbol}}%
  \hspace*{1ex}%
}
\def\phfeaParagraphDecorationSymbol{\ensuremath{\triangleright}}% only for doc purposes

\def\eqsign@{=}
\def\eqsign{\protect\eqsign@}
\robustify\eqsign
\makeatother

\def\RevTeX{{\small R\raise-0.2ex\hbox{\textsc{ev}}}\TeX}

\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{phfextendedabstract.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2021/07/29}{Initial version}
%
% \GetFileInfo{phfextendedabstract.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\def,\gdef,\edef,\xdef,\if,\else,\fi,\ifx}
% 
% \title{\phfqitltxPkgTitle{phfextendedabstract}}
% \author{Philippe Faist\quad\email{philippe.faist@bluewin.ch}}
% \date{\pkgfmtdate\filedate}
%
% \maketitle
%
% \begin{abstract}
%   \pkgname{phfextendedabstract}---Typeset extended abstracts for conferences,
%   such as often encountered in quantum information theory.
% \end{abstract}
%
% \inlinetoc
%
% \section{Introduction}
%
% Several conferences in Quantum Information Theory (and presumably in other
% fields, too) require the submission of \emph{extended abstracts}.  An extended
% abstract is a summary of a scientific result, presented at a high level, and
% consisting of at most a small handful of pages.
%
% I found myself repeatedly copying my \LaTeX\ preamble from one submission to
% another with definitions for a format that I elaborated and liked.  So at some
% point I collected the main definitions into this class file.
% 
% The \pkgname{phfextendedabstract} class sets up the document for an extended
% abstract submission as a single-column document, typeset by default at 11
% point size, with at most two sectioning levels (|\section|\,s and
% |\paragraph|\,s).  It is based on the \RevTeX\ class.
%
% The extended abstract style looks approximately like this:
% \nopagebreak
% \iffalse COMMENT: Spacings are copied/emulated ! They might appear wrong!! \fi
% \begin{phfeaDocVirtualPage}
%   {\parskip=8pt\relax
%     {\sffamily\Large\centering Title of my extended abstract\par}
%     {\centering Author One,\ \ Author Two,\ \  and\ \ Author Three\par}
%   }\vspace{0.2cm}
%   \parskip=3pt\relax
%   
%   \noindent{\normalfont\normalsize\sffamily\fontseries{sb}\selectfont
%     \makebox[0pt][r]{\phfeaSectionDecoration}Introduction.}
%   \shortlipsum
%   
%   \noindent{\normalfont\normalsize\sffamily\fontseries{sb}\selectfont
%     \makebox[0pt][r]{\phfeaSectionDecoration}Results.}
%   \shortlipsum
%   
%   \noindent{\normalfont\normalsize\sffamily\small
%     \makebox[0pt][r]{\phfeaParagraphDecoration}First result.}
%   \ldots
%
%   \noindent{\normalfont\normalsize\sffamily\small
%     \makebox[0pt][r]{\phfeaParagraphDecoration}Second result.}
%   \ldots
%
%   \noindent{\normalfont\normalsize\sffamily\fontseries{sb}\selectfont
%     \makebox[0pt][r]{\phfeaSectionDecoration}Discussion.}
%   \shortlipsum   
%  \hspace*{1.5ex}%
%
% \end{phfeaDocVirtualPage}
%
%
% \section{Main features}
%
% Here are the main features of the \pkgname{phfextendedabstract} class:
% \begin{itemize}
% \item The class \pkgname{phfextendedabstract} loads the \pkgname{revtex4-2}
%   class, so you can directly use \RevTeX's features such as author
%   affiliations, etc.
%
% \item Only two sectioning commands are enabled: |\section| and |\paragraph|.
%   Both have run-in headings.  If you find yourself needing additional
%   sectioning levels, it might be that your extended abstract is too detailed
%   and you might want to think about how to keep it at a higher level.  It
%   might also be that \pkgname{phfextendedabstract} is too limited for your
%   needs.
%
%   By default, section and paragraphs have ``decorations'' (by default a symbol
%   in the margin) to guide the reader through the overall high-level structure
%   of the document.  (Disable them with the |noheadingdecorations| class
%   option.)
%
% \item You can easily scale all vertical spacing dimensions (section and
%   paragraph spacing, vertical space around theorems and list environments,
%   etc.) by a common factor with a class option.  Do you have those extra two
%   lines that make you exceed your 3-page limit?  Try squeezing everything
%   together with a class option like |compressverticalspacing=0.7|.
%
% \item The \pkgname{phfnote} package is loaded in order to provide a set of
%   default \LaTeX\ packages and set up hyperlinks.  A generous default set of
%   standard LaTeX packages are loaded, including \pkgname{caption} and
%   \pkgname{enumitem}; see \pkgname{phfnote}'s documentation for the option
%   |pkgset=extended|.
%
%   \textbf{You are expected to include
%   \phfverb{\usepackage}\phfverb{{hyperref}} somewhere in your preamble.}  We
%   deliberately don't include \pkgname{hyperref} when loading the class in
%   order to give you greater control of package loading order (most packages
%   you might want to use must be loaded before \pkgname{hyperref}).
%
% \item The page margins are tweaked with the \pkgname{geometry} package.
%   (Simply call |\geometry{...}| if you'd like to further change them.  Refer
%   to the \pkgname{geometry} package's documentation.)
%
% \item Lists, i.e.\@ the |itemize| and |enumerate| environments, are customized
%   using the \pkgname{enumitem} package so that they take up less space.  You
%   also get a |enumerate*| environment that typesets its items in-line, in a
%   single paragraph.
%   
%   (Note that this customization won't work if you choose to load a package set
%   via a |pkgset=| option that doesn't include \pkgname{enumitem}.)
%
% \item By default we load the \pkgname{phfthm} package and set a customized
%   theorem style so that it stands out but also so that it contrasts well with
%   the section and paragraph headings.
%
% \end{itemize}
%
% Check out the class option documentation in \autoref{sec:class-options} to get
% a better idea of how to customize \pkgname{phfextendedabstract}'s behavior!
%
%
% \section{Example Usage}
%
% Here's a simple template:
% \begin{verbatim}
% \documentclass[papertype=a4paper]{phfextendedabstract}
%
% \usepackage{hyperref}
%
% \begin{document}
% \title{Title goes here}
% \author{Author 1}
% \author{Author 2}
% \maketitle
% 
% \section{Introduction.}
% Lorem ipsum ...
%
% \section{Results.}
% We had some cool results about
% \begin{enumerate*} % inline enumeration
% \item a first result,
% \item a second result, % and
% \item a final result.
% \end{enumerate*}
%
% \paragraph{First result.}
% Here's a first result ...
%
% \paragraph{Second result.}
% Here's another result ...
%
% ...
%
% \end{document}
% \end{verbatim}
%
% (Try it out!)
%
%
% \section{Class options}
% \label{sec:class-options}
%
% Here is a summary of class options:
% \begin{pkgoptions}
% \item[papertype=a4paper,letterpaper,\meta{paper type},\meta{empty}] Specify
%   the paper type to use (A4 or letter).  The argument given to this option is
%   directly specified as an option to the underlying \RevTeX\ class.
% \item[ptsize=10pt,11pt,12pt] Default font size to use.  Again the argument
%   given to this option is directly specified as an option to the underlying
%   \RevTeX\ class.
% \item[sectiondecorations=\meta{true or false}] Whether or not to ``decorate''
%   section headings, by default with a small black square typeset in the margin
%   of the section heading.
% \item[paragraphdecorations=\meta{true or false}] Whether or not to
%   ``decorate'' paragraph headings, by default with a small right-pointing
%   outlined triangle typeset in the margin of the paragraph heading.
% \item[noheadingdecorations] Shorthand for
%   |sectiondecorations=false,paragraphdecorations=false|.
% \item[compressverticalspacing=\meta{factor}] Real factor by which to multiply
%   the vertical spacing between sections, paragraphs, theorems, paragraphs,
%   list environments such as |itemize| and |enumerate|, etc.  If you need to
%   compress the sections a bit to fit more content on a fixed number of pages
%   (e.g.\@ because of page number constraints), you can set this option to a
%   factor that's less than one.  A \meta{factor} that's less than one
%   compresses sections together, a \meta{factor} equal to |1| does nothing, and
%   a \meta{factor} greater than one expands the sections further apart.
% \item[loadtheorems=\meta{true or false}] If |loadtheorems=true| (the default),
%   then the \pkgname{phfthm} package is loaded with some suitable default
%   options and a custom theorem style.  (The theorem style
%   |phfextendedabstractthm| is defined regardless of this package option.)
% \item[sansstyle=\meta{true or false}] Use sans serif style by default for the
%   main title as well as for section and paragraph headings.  For greater
%   degree of control, see \autoref{sec:customize-title-and-headings-style}.
% \item[usehyperref=\meta{true or false}] Should we set up the document for use
%   with the \pkgname{hyperref} package or not?  This option influences how we
%   load the \pkgname{phfnote} package.  If this option is set to |true| (the
%   default), then the \pkgname{phfnote} package is loaded with
%   |hyperrefdefs={defer,noemail}|.  This means that the document is set up for
%   use with \pkgname{hyperref}, although you will still need to say
%   |\usepackage{hyperref}| somewhere in your preamble.  If |usehyperref=false|,
%   then the \pkgname{phfnote} package is loaded with hyperref options disabled.
%
%   (The |noemail| option is specified to \pkgname{phfnote} to avoid
%   interference with \RevTeX's own |\email| command used to specify email
%   addresses for individual authors.)
% \item[pkgset=\meta{\pkgname{phfnote} package set name}] The \pkgname{phfnote}
%   package (which we load internally) loads a bunch of standard packages for
%   your convenience, such as \pkgname{enumitem} or \pkgname{microtype}.  You
%   can influence this behavior by specifying a ``package set'' to load.  By
%   default, the |pkgset=extended| package set is loaded.  If you don't want to
%   load any additional packages beyond those that are strictly necessary, use
%   |pkgset=none| or |pkgset=minimal|.  See \pkgname{phfnote}'s documentation
%   for the package option |pkgset=...| for more information and a list of
%   possible package set names.
% \end{pkgoptions}
% 
%
% \section{Macros and environments}
%
% \subsection{Sections and paragraphs}
%
% \DescribeMacro{\section} \DescribeMacro{\paragraph} This class only provides
% two sectioning levels: |\section| and |\paragraph|.  Both produce run-in
% headings.
%
% By default, sections and paragraphs produce a small ``decoration'' in the left
% margin, to guide the reader's eye through the document's high-level structure.
%
% You can disable/enable section and paragraph decorations with the
% |sectiondecorations|, |paragraphdecorations| and |noheadingdecorations| class
% options.
%
% The |\section| and |\paragraph| macros also accept a special syntax: If they
% are immediately followed by an exclamation mark (|!|), then they do not
% produce the corresponding decoration.  E.g.:
% \begin{verbatim}
% \section!{A section heading without its decoration}
% \end{verbatim}
%
% Also, section and paragraphs will not produce any horizontal space if the
% title is empty.  You can use this feature to produce the spacing and
% decoration of a section, but not the heading:
% \begin{verbatim}
% \section{} This line has the vertical spacing and decoration
% associated with a section, but with no run-in heading.
%
% \section!{} This line has the vertical spacing associated
% with a section, but with no decoration or run-in heading.
% \end{verbatim}
%
% You can also use the additional syntax |<|\emph{\ldots}|>| to specify a custom
% decoration instead of the default one.  (But you should only use this
% sparingly! Redefine |\phfeaSectionDecorationSymbol| if you want to change the
% symbol for all sections!)  For instance:
%
% \begin{verbatim}
% \section<\guilsinglright>{} \emph{Manuscript in preparation.}
% \end{verbatim}
%
% Here's a summary of the argument structure for |\section| and |\paragraph|:
%
% |\section|{\large\textbar}|\paragraph|
% \emph{[} |*| \emph{]} \emph{[} |!| \emph{]}
% \emph{[} |<|\meta{decoration}|>| \emph{]}
% \emph{[} \oarg{alt title} \emph{]}
% \marg{title}
% 
% The optional star and optional alternative title are passed on to the standard
% \LaTeX\ sectioning commands.  The alternative title is typically used for the
% table of contents and for PDF bookmarks.
%
% \DescribeMacro{\phfeaSectionDecoration}
% \DescribeMacro{\phfeaParagraphDecoration} You can use the
% |\phfeaSectionDecoration{<symbol>}| and |\phfeaParagraphDecoration{<symbol>}|
% to manually place a section or paragraph decoration at any place:
% \begin{verbatim}
% \phfeaSectionDecoration{$\to$} Check out our website at
% \href{https://github.com/phfaist/phfqitltx}{github.com/phfaist/phfqitltx}
% \end{verbatim}
%
% If the |sectiondecorations=false| class option was specified, the macro
% |\phfeaSectionDecoration{...}| produces no output.  Similarly,
% |\phfeaParagraphDecoration{...}| does nothing if |paragraphdecoration=false|
% was specified.
%
% \DescribeMacro{\phfeaSectionDecorationSymbol}
% \DescribeMacro{\phfeaParagraphDecorationSymbol}
% The default section and paragraph symbols (including size and vertical
% adjustments) are stored in the |\phfeaSectionDecorationSymbol| and
% |\phfeaParagraphDecorationSymbol| macros.  You can redefine these macros to
% set custom decoration symbols:
% \begin{verbatim}
% \renewcommand{\phfeaSectionDecorationSymbol}{\Large$\Rightarrow$}
% \renewcommand{\phfeaParagraphDecorationSymbol}{\raisebox{1pt}{\tiny $>$}}
% \end{verbatim}
%
% You can customize section and paragraph headings, including spacing and style,
% by redefining the following macros.
%
% \DescribeMacro{\phfeaSectionBeforeSkip}
% \DescribeMacro{\phfeaSectionAfterHSkip} The macro |\phfeaSectionBeforeSkip|
% (it's a macro, not a length) is used to specify the vertical spacing before a
% new section heading.  The macro (not length) |\phfeaSectionAfterHSkip| is the
% horizontal space between the end of the section heading and the beginning of
% the section text contents.  You can redefine these macros to set your custom
% spacings.  (If you're looking to compress the vertical spacings to save on the
% number of pages, look at the |compressverticalspacings=| class option and the
% |\phfeaVerticalSpacingCompressionFactor| macro.)
%
% \DescribeMacro{\phfeaParagraphBeforeSkip}
% \DescribeMacro{\phfeaParagraphAfterHSkip} The macros
% |\phfeaParagraphBeforeSkip| and |\phfeaParagraphAfterHSkip| behave similarly
% for paragraphs.
%
% \DescribeMacro{\phfeaSectionStyle} \DescribeMacro{\phfeaParagraphStyle} The
% macros |\phfeaSectionStyle| and |\phfeaParagraphStyle| are used to set the
% style of the section and paragraph headings.  By default, the default
% sans/heading style is used at the normal size and in bold face series for
% sections, and the normal sans style is used at a smaller size for paragraph
% headings.
%
% \DescribeMacro{\phfeaSectionFormatHeading}
% \DescribeMacro{\phfeaParagraphFormatHeading} The macros
% |\phfeaSectionFormatHeading{...}| and |\phfeaParagraphFormatHeading{...}| can
% be redefined to format the section and paragraph headings, respectively.  You
% can redefine these macros to add punctuation, to capitalize the title, etc.
% For instance:
% \begin{verbatim}
% \renewcommand\phfeaSectionFormatHeading[1]{\MakeUppercase{#1}\ ---}
% \end{verbatim}
%
% The macros |\phfeaSectionFormatHeading{...}| and
% |\phfeaParagraphFormatHeading{...}| are not called if the section/paragraph
% title argument is empty.
%
%
% \subsection{Vertical spacing}
%
% \DescribeMacro{\phfeaVerticalSpacingCompressionFactor} To
% conveniently globally adjust the vertical spacings in the document (including
% the section and paragraph vertical spacings, as well as the spacing above and
% below theorems, itemize, and enumerate environments), you can also use the
% |compressverticalspacing=X| class option.  Alternatively, you can redefine the
% macro |\phfeaVerticalSpacingCompressionFactor| to the desired compression
% factor:
% \begin{verbatim}
% \renewcommand\phfeaVerticalSpacingCompressionFactor{0.7}
% \end{verbatim}
%
% \DescribeMacro{\phfeaDefineTheoremStyle} Because the theorem style
% |phfextendedabstracthm| is defined at the time that the class is loaded, any
% customization of |\phfeaVerticalSpacingCompressionFactor| and
% |\phfeaListsVerticalSkip| that happen later in the preamble aren't taken into
% account.  If you change these values in your preamble, you should call
% |\phfeaDefineTheoremStyle| to redefine the theorem style after your
% customization.
%
% \DescribeMacro{\phfeaDisplayVerticalSpacingFactorWeight} The
% vertical spacing factor also affects the vertical spacing around equations,
% but to a lesser extent. (Compressing the space around the equations by too
% much would not look nice.) For the spacing between equations, we take the
% weighted average of $1$ and the vertical spacing compression factor, where the
% weight is given in the macro |\phfeaDisplayVerticalSpacingFactorWeight|.  A
% weight of |0| means the vertical compression factor doesn't affect the
% vertical spacing around equations at all; a weight of |1| means the spacing
% around the equations is scaled exactly by the vertical compression factor.
%
% \DescribeMacro{\phfeaParskipVerticalSpacingFactorWeight} A similar mechanism
% happens for how we adjust |\parskip|, the spacing between paragraphs.
%
%
% \subsection{List environments}
%
% \DescribeEnv{enumerate*} This class provides an |enumerate|-like
% environment which typesets its items inline, as a list.  For example, here is
% an inline paragraph with (a) one, (b) two, and (c) three points.
% \iffalse yeah, I cheated for this doc code, whatever \fi
%
% The |enumerate*| can be used exactly like you'd use the |enumerate|
% environment from the \pkgname{enumitem} package, for instance:
% \begin{verbatim}
% here is an inline paragraph with \begin{enumerate*}[label=(\alph*)]
% \item one,
% \item two,
% \item three
% \end{enumerate*}
% points.
% \end{verbatim}
%
% Check \pkgname{enumitem}'s documentation for inline lists.  You can specify
% for instance the keys |before={{}}|, |itemjoin={{ }}|, and \relax\relax\relax
% |itemjoin*={{ and }}| either as an optional argument to
% |\begin{enumerate*}| \iffalse\end{enumerate*}\fi or using
% |\setlist|:
% \begin{verbatim}
% \setlist[enumerate*]{%
%   itemjoin*={{ et }}%
% }
% \end{verbatim}
%
% \DescribeMacro{\phfeaListsVerticalSkip} \DescribeMacro{\phfeaListsItemSep}
% \DescribeMacro{\phfeaListsParSep} For (non-inline) list environments such as
% |itemize| and |enumerate|, you can redefine |\phfeaListsVerticalSkip|,
% |\phfeaListsItemSep|, and |\phfeaListsParSep| to set the |topsep|, |itemsep|
% and |parsep| properties of all of \pkgname{enumitem}'s list environments.
% These correspond to the vertical space above and below lists, the space
% between items, and the space between paragraphs within an item.  All these
% spacings automatically get compressed according to the
% |\phfeaVerticalSpacingCompressionFactor|.
%
% Note that |\phfeaListsVerticalSkip| is also used for the spacing above and
% below theorem environments.
%
%
% \subsection{Customization of the main title and general headings style}
% \label{sec:customize-title-and-headings-style}
%
% \DescribeMacro{\phfeaHeadingStyle} The macro |\phfeaHeadingStyle| is defined to be
% |\sffamily|, unless the |sansstyle=false| class option is provided
% in which case the macro expands to nothing.  You can redefine it to give a
% different general style to your main title and your section and paragraph
% headings.
%
% \DescribeMacro{\phfeaTitleStyle} The macro |\phfeaTitleStyle| sets the font
% style for the main document title.  By default the macro is defined to
% |\phfeaHeadingStyle\Large|.  Redefine this macro to change the title style.
%
% For instance, if you prefer \RevTeX's own simple boldface title, you can use:
% \begin{verbatim}
% \renewcommand\phfeaTitleStyle{\bfseries}
% \end{verbatim}
%
%
%
%
%
% \StopEventually{\vskip 3cm plus 2cm minus 2cm\relax\PrintChanges
%     \vskip 3cm plus 2cm minus 2cm\relax\PrintIndex}
%
%
%
% \section{Implementation}
%
% Here come the gory details.
%
%
% \paragraph{Class options}
% We process these first, to see which options we should pass on to
% \RevTeX.
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
  family=phfea,%
  prefix=phfeaopt@%
}
\DeclareStringOption[]{papertype}
\DeclareStringOption[11pt]{ptsize}
\DeclareBoolOption[true]{sectiondecorations}
\DeclareBoolOption[true]{paragraphdecorations}
\DeclareVoidOption{noheadingdecorations}{%
  \phfeaopt@sectiondecorationsfalse
  \phfeaopt@paragraphdecorationsfalse
}
\DeclareBoolOption[true]{loadtheorems}
\DeclareBoolOption[true]{sansstyle}
\DeclareStringOption[1]{compressverticalspacing}
\DeclareBoolOption[true]{usehyperref}
\DeclareStringOption[extended]{pkgset}
\ProcessKeyvalOptions*
%    \end{macrocode}
%
%
% \paragraph{Load \RevTeX, the base class}
%
%    \begin{macrocode}
\providecommand\phfea@revtexopts{%
  aps,pra,%
  notitlepage,reprint,%
  onecolumn,tightenlines,%
  superscriptaddress,%
  nofootinbib%
}
\PassOptionsToClass{%
  \phfea@revtexopts,%
  \phfeaopt@ptsize,%
  \phfeaopt@papertype,%
}{revtex4-2}
\LoadClass{revtex4-2}
%    \end{macrocode}
%
% We will also need the \pkgname{xparse} command for defining some of our
% commands.
%    \begin{macrocode}
\RequirePackage{xparse}
%    \end{macrocode}
% 
% \paragraph{Load \pkgname{phfnote} for the basic document setup}
%
%    \begin{macrocode}
\PassOptionsToPackage{%
  preset=reset,%
  pkgset=\phfeaopt@pkgset,%
  \ifphfeaopt@usehyperref
    hyperrefdefs={defer,noemail},%
  \fi
}{phfnote}
\RequirePackage{phfnote}
%    \end{macrocode}
%
%
% \paragraph{Page geometry}
%
% Set a default page geometry.  Works both for A4 paper and for letter paper.
% It's optimized for 11pt size, though.
%    \begin{macrocode}
\RequirePackage{geometry}
\geometry{hmargin=0.75in,vmargin=0.75in,marginparwidth=0.5in,marginparsep=0.125in}
%    \end{macrocode}
% 
%
% \paragraph{Default sans serif font}
%
% \begin{macro}{\phfeaHeadingStyle}
%   Unless instructed not to do so, \iffalse load the ``Source Sans Pro'' font
%   as default sans serif font, using the semibold glyphs in place of bold.  By
%   default, this font will \else set the sans serif font family to \fi be used
%   for section headings and the main title.
%    \begin{macrocode}
\ifphfeaopt@sansstyle
  \def\phfeaHeadingStyle{\sffamily}
\else
  \def\phfeaHeadingStyle{}
\fi
%    \end{macrocode}
% \end{macro}
%
%
% \paragraph{Default title format}
%
% \begin{macro}{\phfeaTitleStyle}
%   Change \RevTeX\ title format.  Title style can be customized by redefining
%   |\phfeaTitleStyle|.
%    \begin{macrocode}
\def\phfeaTitleStyle{\phfeaHeadingStyle\Large}
\def\frontmatter@title@format{\phfeaTitleStyle\centering\parskip\z@skip}
%    \end{macrocode}
% \end{macro}
%
%
% \paragraph{Vertical spacing compression factor}
%
% Define a general factor by which the section and paragraph spacings will be
% compressed.  This macro is set by the |compressverticalspacing=X| package
% option.
%    \begin{macrocode}
\edef\phfeaVerticalSpacingCompressionFactor{\phfeaopt@compressverticalspacing}
%    \end{macrocode}
%
% Tool for scaling glue expressions (for use with our vertical compression
% factor):\footnote{Thanks \url{https://tex.stackexchange.com/a/198966/32188}\,!}
%    \begin{macrocode}
\def\phfea@scaleglue#1#2{% {factor}{glueexpr}
  \glueexpr#2*\numexpr\dimexpr#1pt\relax\relax/65536\relax
}
\def\phfea@scalegluedpt#1#2{% {factor given as dimexpr in pt}{glueexpr}
  \glueexpr#2*\numexpr#1\relax/65536\relax
}
%    \end{macrocode}
%
% Adjust spacing around display equations according to the vertical compression
% factor.  Do this only at the beginning of the document, since the user might
% still want to adjust |\phfeaVerticalSpacingCompressionFactor| in their
% preamble.
%
% \begin{macro}{\phfeaDisplayVerticalSpacingFactorWeight}
% We only apply a fraction of the scaling, because it's ugly if we compress
% equations too much.  Define |\phfeaDisplayVerticalSpacingFactorWeight| as $w$ and
% $\alpha$ as the vertical scaling factor.  The new skips are computed as
% \begin{equation*}
%   \phfverb{oldskip}\quad\rightarrow\quad
%     (1-w)\,\phfverb{oldskip} + w\,\alpha\,\phfverb{oldskip}\ .
% \end{equation*}
% (For $w=0$ we have $\phfverb{oldskip}\rightarrow\phfverb{oldskip}$.  For $w=1$
% the full scaling factor is applied,
% $\phfverb{oldskip}\rightarrow \alpha\,\phfverb{oldskip}$.)  By default,
% $w=1/2$:
%    \begin{macrocode}
\def\phfeaDisplayVerticalSpacingFactorWeight{.5}
%    \end{macrocode}
% \end{macro}
% Tool to compute the new spacing for each of the relevant display-related
% skips:
%    \begin{macrocode}
\def\phfea@adjustskipweighted#1#2{%
  #1=\glueexpr
    \phfea@scalegluedpt{%
      \dimexpr 1\p@ - #2\p@\relax
    }{#1}%
    +
    \phfea@scaleglue{%
      #2%
    }{%
      \phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor
      }{%
        #1
      }%
    }%
    \relax
}
%    \end{macrocode}
% And schedule this adjustment to be carried out at the beginning of the
% document.
%    \begin{macrocode}
\AtBeginDocument{%
  \phfea@adjustskipweighted\abovedisplayskip\phfeaDisplayVerticalSpacingFactorWeight
  \phfea@adjustskipweighted\belowdisplayskip\phfeaDisplayVerticalSpacingFactorWeight
  \phfea@adjustskipweighted\abovedisplayshortskip\phfeaDisplayVerticalSpacingFactorWeight
  \phfea@adjustskipweighted\belowdisplayshortskip\phfeaDisplayVerticalSpacingFactorWeight
}
%    \end{macrocode}
%
% \begin{macro}{\phfeaParskipVerticalSpacingFactorWeight}
%   A similar mechanism affects how we adjust the paragraph skip length
%   |\parskip|.
%    \begin{macrocode}
\def\phfeaParskipVerticalSpacingFactorWeight{1}
\AtBeginDocument{%
  \phfea@adjustskipweighted\parskip\phfeaParskipVerticalSpacingFactorWeight
}
%    \end{macrocode}
% \end{macro}
% 
% \paragraph{Setup specific for sectioning}
%
% By design, there are only two sectioning levels in a
% \pkgname{phfextendedabstract} document: sections (|\section|) and paragraphs
% (|\paragraph|).  Any other sectioning command (e.g., |\subsection|) will
% produce an error.
%
% Neither of these two section levels is numbered.
%    \begin{macrocode}
\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{1}
%    \end{macrocode}
%
% \begin{macro}{\phfeaSectionBeforeSkip}
% \begin{macro}{\phfeaSectionAfterHSkip}
% \begin{macro}{\phfeaSectionStyle}
% \begin{macro}{\phfeaSectionDecoration}
% \begin{macro}{\phfeaSectionDecorationSymbol}
%   Some helper and customization macros for |\section|.
%    \begin{macrocode}
\def\phfeaSectionBeforeSkip{1.5ex plus 0.8ex minus 0.25ex}
\def\phfeaSectionAfterHSkip{1em plus 0.2em}
\def\phfeaSectionStyle{\normalfont\normalsize\phfeaHeadingStyle\bfseries}
\def\phfeaSectionFormatHeading#1{#1}
\def\phfeaSectionDecorationSymbol{%
  \raisebox{0.2ex}{{\notesmaller[0.4]{\ensuremath{\blacksquare}}}}}
\ifphfeaopt@sectiondecorations
  \def\phfeaSectionDecoration#1{%
    \makebox[\z@][r]{{#1}\hspace*{1.5ex}}%
  }
\else
  \def\phfeaSectionDecoration#1{}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \needspace{5\baselineskip}
% \begin{macro}{\phfeaParagraphBeforeSkip}
% \begin{macro}{\phfeaParagraphAfterHSkip}
% \begin{macro}{\phfeaParagraphStyle}
% \begin{macro}{\phfeaParagraphDecoration}
% \begin{macro}{\phfeaParagraphDecorationSymbol}
%   Same helper and customization macros, now for |\paragraph|.
%    \begin{macrocode}
\def\phfeaParagraphBeforeSkip{0.6ex plus 0.4ex minus 0.1ex}
\def\phfeaParagraphAfterHSkip{0.75em plus 0.15em}
\def\phfeaParagraphStyle{\normalfont\normalsize\phfeaHeadingStyle\small}
\def\phfeaParagraphFormatHeading#1{#1}
\def\phfeaParagraphDecorationSymbol{%
  \raisebox{0.2ex}{{\notesmaller[0.6]{\ensuremath{\triangleright}}}}}
\ifphfeaopt@paragraphdecorations
  \def\phfeaParagraphDecoration#1{%
    \makebox[\z@][r]{{#1}\hspace*{1ex}}%
  }
\else
  \def\phfeaParagraphDecoration#1{}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% Now we redefine |\section| and |\paragraph| for formatting.  Also allow
% |\section!| and |\paragraph!| that remove the decoration and |\section<...>|
% and |\paragraph<...>| that replace the decoration.  In all cases, the indent
% is removed if the main argument (section/paragraph title) is an empty
% argument.  We also accept a starred version and an optional argument, and pass
% those on to |\@startsection|; these options are sometimes useful in order to
% work around fragile tokens in the title, etc.
%
% We start with the generic code that will call |\@startsection| for both
% sections and paragraphs.  The generic code will be given the level number (|1|
% or |2|) and will produce the correct |\@startsection| code for that level,
% fetching its information from the correctly named macros.  We first define
% some simple definitions that specify where to look for those level-specific
% macros.
%    \begin{macrocode}
\def\phfea@ss@levelname#1{\ifcase#1\or section\or paragraph\fi}
\def\phfea@ss@levelName#1{\ifcase#1\or Section\or Paragraph\fi}
\def\phfea@ss@get#1#2{% <levelno><MacroPostfixName>
  \csname phfea\phfea@ss@levelName{#1}#2\endcsname}
\def\phfea@ss@getnoexpand#1#2{% <levelno><MacroPostfixName>
  \expandafter\noexpand\csname phfea\phfea@ss@levelName{#1}#2\endcsname}
%    \end{macrocode}
%
% \begin{macro}{\phfea@startsection}
%   We now define the main internal |\phfea@startsection| macro which will
%   produce the correct |\@startsection| command for the given section level.
%   The arguments to |\phfea@startsection| are:
%   \begin{itemize}[itemsep=0pt,topsep=0pt]
%   \item[\#1:] level number, |1| or |2|;
%   \item[\#2:] an optional star;
%   \item[\#3:] an optional |!| character (meaning, don't display the decoration);
%   \item[\#4:] an optional |<|\meta{decoration tokens}|>| argument to
%     replace the decoration;
%   \item[\#5:] an optional argument, the alternative title to write in the AUX
%     file (e.g.\@ for use in the table of contents);
%   \item[\#6:] a mandatory argument, the title of the section/paragraph.
%   \end{itemize}
%    \begin{macrocode}
\newtoks\phfea@ss@decorationtoks
\newtoks\phfea@ss@alttitle
\newtoks\phfea@ss@title
\NewDocumentCommand{\phfea@startsection}{m s t! d<> o m}{%
%    \end{macrocode}
% Store the alternative title and title in token registers.
%    \begin{macrocode}
  \phfea@ss@decorationtoks={#4}%
  \phfea@ss@alttitle={#5}%
  \phfea@ss@title={#6}%
%    \end{macrocode}
% Inform the user in case of option inconsistencies or redundancies.
%    \begin{macrocode}
  \IfNoValueF{#4}{%
    \IfBooleanT{#3}{%
      \PackageWarning{phfextendedabstract}{section/paragraph: `!'
        modifier ignored when custom decoration `<...>' is specified}%
    }%
  }%
%    \end{macrocode}
% Now define a temporary macro |\x| that will contain the correct code for a
% call to \LaTeX' low-level |\@startsection| command.  Remember to prefix all
% macros by |\noexpand| unless they should be expanded in the preparation of
% that code for |\@startsection|.  \LaTeX' |\@startsection| takes a lot of
% arguments, let's be careful not to miss any.  Also, we can use the convenient
% construct |\phfea@ss@getnoexpand{#1}{XyzProperty}| which in this |\edef| will
% expand to
% |\noexpand\phfea|\emph{$\langle$}|Section|\emph{\textbar}\relax
% |Paragraph|\emph{$\rangle$}|XyzProperty|.
%    \begin{macrocode}
  \edef\x{%
    \noexpand\@startsection{\phfea@ss@levelname{#1}}%
%    \end{macrocode}
% First come the \meta{level number} and \meta{indent} arguments:
%    \begin{macrocode}
      {#1}%
      {\z@}%
%    \end{macrocode}
% Then comes the \meta{before skip} argument.  Use |\phfea@scaleglue| to account for
% the vertical compression factor.
%    \begin{macrocode}
      {%
        \noexpand\phfea@scaleglue{\noexpand\phfeaVerticalSpacingCompressionFactor}{%
          \noexpand\glueexpr\phfea@ss@getnoexpand{#1}{BeforeSkip}\noexpand\relax
        }%
      }%
%    \end{macrocode}
% Then comes the \meta{after skip} argument.  Set the after skip to zero if the
% title is empty, otherwise specify the given
% |\phfeaSection/ParagraphAfterHSkip| as a negative value to indicate we want a
% run-in heading.  Note that while the syntax `|1.5\glueexpr...|' doesn't
% preserve plus/minus stretchability components as it coerces the glue to a
% dimen, the syntax `|-\glueexpr...|' does preserve these components (presumably
% because $-1$ is integer?).
%    \begin{macrocode}
      {\if\relax\detokenize{#6}\relax
          \noexpand\z@
        \else
          -\noexpand\glueexpr\phfea@ss@getnoexpand{#1}{AfterHSkip}\noexpand\relax
        \fi}%
%    \end{macrocode}
% The \meta{style} argument to specify the section heading's font style.  We
% provide a decoration, possibly a custom decoration if provided with the
% |<...>| syntax; we remove the default decoration if the no-decoration argument
% (a |!| character) was specified.
%    \begin{macrocode}
      {%
        \IfNoValueTF{#4}{%
          \IfBooleanTF{#3}{% with "!", no custom decoration --> nothing
          }{% no "!", no custom decoration
            \phfea@ss@getnoexpand{#1}{Decoration}%
            \phfea@ss@getnoexpand{#1}{DecorationSymbol}%
          }%
        }{% with custom decoration (ignores "!" argument)
          \phfea@ss@getnoexpand{#1}{Decoration}%
          {\the\phfea@ss@decorationtoks}%
        }%
        \phfea@ss@getnoexpand{#1}{Style}%
      }%
%    \end{macrocode}
% An optional |*| indicates the starred version of the sectioning commands.  If
% the user increased the |secnumcounter| to have numbered sections, then the
% starred variant gives a section heading without any section number or TOC
% entry.
%    \begin{macrocode}
      \IfBooleanT{#2}{*}%
%    \end{macrocode}
% Now comes the optional \meta{alternative title} argument that will be written
% to the AUX file.  We always provide this argument to |\@startsection|,
% specifying by default the main title argument |#6| (non-starred variant) or an
% empty argument (for a starred variant).  We do this because otherwise,
% |\@startsection| will copy all the other commands we add in its argument
% (e.g., title formatting, etc.) and will write them to the AUX file.
%    \begin{macrocode}
      \IfValueTF{#4}{[\the\phfea@ss@alttitle]}{%
        \IfBooleanTF{#2}{[]}{[\the\phfea@ss@title]}%
      }%
%    \end{macrocode}
% Finally, this is the main \meta{section title} argument.  
% If the title is not empty, we also provide the title wrapped in a
% corresponding |\phfeaSection/ParagraphFormatHeading| macro call.  Everything
% should be protected in |\texorpdfstring| calls to avoid \emph{pdflatex} from
% complaining about invalid junk in PDF bookmark strings.
%    \begin{macrocode}
      {%
        \if\relax\detokenize{#6}\relax\else
          \noexpand\texorpdfstring{%
            \phfea@ss@getnoexpand{#1}{FormatHeading}{\the\phfea@ss@title}%
          }{%
            \the\phfea@ss@title
          }%
        \fi
      }%
  }%
  %\message{**** EMITTING @startsection: |\detokenize\expandafter{\x}| ***}%
  \x
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\section}
% \begin{macro}{\paragraph}
%   Define |\section| and |\paragraph| as sectioning levels 1 and 2.
%    \begin{macrocode}
\def\section{\phfea@startsection{1}}
\def\paragraph{\phfea@startsection{2}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% Provide an explanative error message if the user attempts to use
% |\subsection|, |\subsubsection| or |\subparagraph|.
%    \begin{macrocode}
\def\phfea@nosectioncmd#1{%
  \ClassError{phfextendedabstract}{%
    %
    There is no `\string#1' command in `phfextendedabstract'
    documents.  You can only use `\string\section' and
    `\string\paragraph'.  If you find yourself needing additional
    sectioning levels, it might be that your extended abstract is too
    detailed and you should stick to a higher level description of
    your results.  If you do need additional section levels, it is
    likely that you will be better off with a different document
    class.  If you'd like to stick with `phfextendedabstract' and you
    really know what you're doing, then you could redefine the
    sectioning commands as necessary based on `\string\@startsection'
    as is done in standard LaTeX classes.  Good luck!
    %
  }{}%
}
\def\phfea@nosectioncmd@def#1{%
  \def#1{\phfea@nosectioncmd#1}%
}
\phfea@nosectioncmd@def\part
\phfea@nosectioncmd@def\chapter
\phfea@nosectioncmd@def\subsection
\phfea@nosectioncmd@def\subsubsection
\phfea@nosectioncmd@def\subparagraph
%    \end{macrocode}
%
%
% \paragraph{Set up itemization and enumeration environments}
%
% Provide customizable lengths for lists via macros (item sep,
% paragraph sep and vertical skip above and below list environments).
% \begin{macro}{\phfeaListsVerticalSkip}
% \begin{macro}{\phfeaListsItemSep}
% \begin{macro}{\phfeaListsParSep}
%    \begin{macrocode}
\def\phfeaListsVerticalSkip{0.6ex plus 0.4ex minus 0.1ex}
\def\phfeaListsItemSep{0.3ex plus 0.15ex minus 0.1ex}
\def\phfeaListsParSep{0.7\parskip}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% Prepare the commands to run to configure \pkgname{enumitem} correctly in an
% internal macro which we will call if \pkgname{enumitem} is indeed loaded.
%    \begin{macrocode}
\def\phfea@setup@enumitem{%
%    \end{macrocode}
% Apply the spacings.
%    \begin{macrocode}
  \setlist{%
    itemsep={%
      \phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor}{\phfeaListsItemSep}},
    parsep={%
      \phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor}{\phfeaListsParSep}},
    topsep={%
      \phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor}{\phfeaListsVerticalSkip}},
  }%
%    \end{macrocode}
% \begin{environment}{enumerate*}
% Create the |enumerate*| list enumeration environment.
%    \begin{macrocode}
  \newlist{enumerate*}{enumerate*}{1}
  \setlist[enumerate*]{
    label={(\roman*)},
    before={},
    itemjoin={{ }},
    itemjoin*={{ and }}
  }%
}
%    \end{macrocode}
% \end{environment}
% And now, check if \pkgname{enumitem} is loaded and apply the definitions.
%    \begin{macrocode}
\@ifpackageloaded{enumitem}{\phfea@setup@enumitem}{}
%    \end{macrocode}
% 
%
% \paragraph{Setup specific for theorems}
%
% Create a new theorem style called |extendedabstracthm|.  Note that if
% \pkgname{amsthm} (or similar) wasn't loaded, then |\newtheoremstyle| isn't
% defined.  In that case, we simply won't define the new theorem style right
% now.
%    \begin{macrocode}
\def\phfeaDefineTheoremStyle{%
  \newtheoremstyle{phfextendedabstractthm}%
    {\phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor}{\phfeaListsVerticalSkip}}%
    {\phfea@scaleglue{%
        \phfeaVerticalSpacingCompressionFactor}{\phfeaListsVerticalSkip}}%
    {\itshape}%
    {\z@}%
    {\bfseries\itshape}%
    {:}%
    {0.8em}%
    {\thmname{##1\thmnumber{ ##2}\thmnote{ (##3)}}}%
}
%    \end{macrocode}
% Ensure we create our new theorem style (only if |\newtheoremstyle| is
% available) and load our \pkgname{phfthm} package.  Make sure we don't load
% \pkgname{phfthm} if we were asked not to load theorems in the class options.
%    \begin{macrocode}
\ifdefined\newtheoremstyle
  \phfeaDefineTheoremStyle
\fi
\ifphfeaopt@loadtheorems
  \ifdefined\newtheoremstyle\else
    \ClassError{phfextendedabstract}{%
      %
      Impossible to load theorems (`loadtheorems=true') because there
      is no \string\newtheoremstyle\space command that was defined.
      Consider setting `pkgset=...' so that a theroems-related package
      (e.g., amsthm) is loaded!  (e.g. `pkgset=minimal', `pkgset=rich'
      or `pkgset=extended').  Alternatively, set the class option
      `loadtheorems=false' and you can then manually define any
      theorem environments you'd like using your favorite pacakges.
      %
    }{}
  \fi
  \PassOptionsToPackage{proofref=false,theoremstyle=phfextendedabstractthm}{phfthm}
  \RequirePackage{phfthm}
\fi
%    \end{macrocode}
%
% \iffalse
% \paragraph{References section}
%
% Have a simple section for references.  If you'd like to restore \RevTeX'
% ornament you can simply do |\let\bibsection\rtxapsbibsection|.
%    \begin{XXXmacrocode}
%% \let\rtxapsbibsection\bibsection
%% \def\bibsection{%
%%   \par\section{\refname}\leavevmode\par\addvspace{4pt}\relax
%% %%  \par\noindent\rule{6em}{.4pt}\par\addvspace{6pt}\relax
%% }
%    \end{XXXmacrocode}
% \fi
%
%
%\Finale
\endinput
