%
% \iffalse meta-comment
%
% Copyright 2016--2024 Brian Dunn
%
% This work 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
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{keyfloat}
%<package>    [2024/01/12 v2.09 Key/value interface for floats and subfloats.]
%
%<*driver>
\documentclass{ltxdoc}

\newcommand*{\mypackagename}{keyfloat}
\newcommand{\quicksummary}{Provides a key/value interface for generating floats.}


% \usepackage{lmodern}
\usepackage{erewhon}
\usepackage{roboto}
% \usepackage{sourcesanspro}
\usepackage{inconsolata}
% \usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}	% provides \degree, \textquotesingle, \textmu


\newcommand*{\TakeFourierOrnament}[1]{{%
\fontencoding{U}\fontfamily{futs}\selectfont\char#1}}

\newcommand*{\textwarning}{\TakeFourierOrnament{66}}

% copy/paste special unicode symbols:
\input{glyphtounicode}
\pdfglyphtounicode{prime}{2032}% hex
\pdfglyphtounicode{diameter}{2300}% diameter
\pdfglyphtounicode{warningsign}{26A0}% warning sign
\pdfgentounicode=1

\usepackage{newunicodechar}
\newunicodechar{ﬀ}{ff}
\newunicodechar{ﬁ}{fi}
\newunicodechar{ﬂ}{fl}
\newunicodechar{ﬃ}{ffi}
\newunicodechar{ﬄ}{ffl}
% \newunicodechar{°}{\degree}
\newunicodechar{ρ}{\ensuremath{\rho}}
\newunicodechar{⨯}{\texttimes}
\newunicodechar{⁄}{\textfractionsolidus}
% \newunicodechar{®}{\textregistered}
% \newunicodechar{©}{\textcopyright}
\newunicodechar{—}{---}
\newunicodechar{–}{--}
% \newunicodechar{”}{''}
% \newunicodechar{“}{``}
% \newunicodechar{§}{\S}
% \newunicodechar{¶}{\P}
% \newunicodechar{†}{\dag}
\newunicodechar{‡}{\ddag}
\newunicodechar{⚠}{\textwarning}

\usepackage{etoolbox}

\usepackage{xparse}

\usepackage{metalogox}

\usepackage{microtype}





\usepackage[svgnames]{xcolor}
\definecolor{myurlcolor}{rgb}{0,0,.7}
\definecolor{mylinkcolor}{rgb}{.7,0,0}
\definecolor{codecolor}{rgb}{0,.4,.2}
\definecolor{overviewcolor}{rgb}{0,.2,.4}


\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{enumitem}

\usepackage{needspace}

\usepackage{array}
\usepackage{booktabs}
\usepackage{threeparttable}

\usepackage{fancybox}% must be loaded before fancyvrb
\usepackage{fancyvrb}


\usepackage{caption}
\usepackage{newfloat}

\captionsetup{labelfont={small,bf},textfont={small,bf}}

\captionsetup*[figure]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=2ex,
	labelfont={small,bf},textfont={small,bf}
}

\captionsetup*[table]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=1ex,
	labelfont={small,bf},textfont={small,bf},
    position=top
}

\captionsetup*[subfigure]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=2ex,
	labelfont={small},textfont={small}
}

\captionsetup*[subtable]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=1ex,
	labelfont={small},textfont={small},
    position=top
}

\captionsetup*[wrapfigure]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=2ex,
	labelfont={small,bf},textfont={small,bf}
}

\captionsetup*[wraptable]{
	style=default, justification=centering,
	margin=0pt, parskip=0pt, skip=1ex,
	labelfont={small,bf},textfont={small,bf}
}



\usepackage{blindtext}



\usepackage{tikz}
\usetikzlibrary{positioning,fit,backgrounds,calc,shapes.geometric,shadows}

\usepackage[framemethod=tikz]{mdframed}

\mdfdefinestyle{boxroundshadow}{linewidth=1pt,innerleftmargin=0in,innerrightmargin=0in,%
innertopmargin=0in,innerbottommargin=0in,%
align=center,roundcorner=3pt,shadow=true,shadowcolor=black!50,shadowsize=4pt,%
leftmargin=0pt,rightmargin=0pt,%
frametitlebackgroundcolor=black!15,%
skipabove=0ex,skipbelow=0ex,%
frametitlerulewidth=1pt,frametitleaboveskip=5pt,%
}

\newmdenv[style=boxroundshadow,align=center]{mdtightframe}

\newmdenv[style=boxroundshadow,align=center,%
	innertopmargin=3pt,innerbottommargin=3pt,%
	innerleftmargin=3pt,innerrightmargin=3pt]{mdlooseframe}


\usepackage[normalem]{ulem}


\usepackage{tocdata}[2019/03/21]% v2.02 or later

\usepackage{tocloft}
\setlength{\cftsubsecnumwidth}{3em}
\setlength{\cftsubsubsecindent}{2.8em}
\setlength{\cftsubsubsecnumwidth}{4em}
\setlength{\cftbeforesubsecskip}{1ex}

% \usepackage{titletoc}



\usepackage{titleps}

\newpagestyle{pageheadfoot}{
	\headrule
	\sethead{\pkg{\mypackagename}}{}{\thepage}
% 	\renewcommand{\makefootrule}{\rule[2.5ex]{\linewidth}{.4pt}}
	\setfoot{}{}{}
}

\pagestyle{pageheadfoot}


% Indexing, logos, \Describexxxx, etc:
\usepackage{dtxdescribe}[2023/01/03]



\usepackage{splitidx}

\newindex[Index of Objects]{idx}
\newindex[General Index]{gen}
% \newindex[Troubleshooting Index]{trb}
\newindex[Index of Indexes]{meta}

\makeindex

\newcommand*{\gindex}[1]{\sindex[gen]{#1}\ignorespaces}

% \trouble[watchout phrase]{index entry}
\newcommand*{\trouble}[2][]{%
\ifblank{#1}{}{%
    \watchout[#1]%
}%
% \sindex[trb]{#2}%
\gindex{#2}%
\ignorespaces%
}




\newcommand{\testtable}{%
\begin{tabular}{cc}%
\hline\rule{0pt}{2.7ex}%
A & B \\
C & D \\
\hline
\end{tabular}%
}

\newcommand{\testwidetable}{%
\begin{tabular}{cccc}%
\hline\rule{0pt}{2.7ex}%
A & B & C \\
D & E & F \\
\hline
\end{tabular}%
}


\newcommand{\mainsubarg}{empty or ``\texttt{subgrp}''}
\newcommand{\keyvalsarg}{keys \Slash values}

\setlength{\floatsep}{5ex plus 1ex minus 1ex}
\setlength{\dblfloatsep}{5ex plus 1ex minus 1ex}


\usepackage{\mypackagename}



\AtBeginDocument{
\hypersetup{%
pdfinfo={%
Title={The LaTeX \mypackagename\ package},%
Author={Brian Dunn},%
Subject={A key/value interface for LaTeX floats.},%
Keywords={LaTeX, floats, key/val, subcaption, rows}%
colorlinks,%
linkcolor=mylinkcolor,%
urlcolor=myurlcolor,%
pageanchor=true,
}}

\pdfstringdefDisableCommands{
\def\quad{ }
\def\\{ }
\def\pkg#1{#1}
\def\cs#1{\textbackslash#1}
\def\env#1{#1}
\def\,{ }
\def\prog#1{#1}
\def\LuaLaTeX{LuaLaTeX}
\def\XeLaTeX{XeLaTeX}
\def\TeX{TeX}
\def\LaTeX{LaTeX}
\def\Dash{ --- }
\def\dash{ -- }
\def\element#1{#1}
\def\attribute#1{#1}
}
}% AtBeginDocument

\AddToHook{begindocument/before}{% Before .aux file is loaded.
  \usepackage{cleveref}%                  If needed.
}




\setlength{\marginparsep}{1em}
\setlength{\marginparpush}{.7ex}
\setlength{\IndexMin}{40ex}

\setcounter{IndexColumns}{2}

\DisableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\mypackagename.dtx}
\end{document}
%
%</driver>
% 
% \fi
%
% \iffalse
%<*package>
% \fi
%

% \changes{v0.10}{2016/12/01}{\ 2016/12/01 Initial ver.}
% \changes{v0.11}{2016/12/02}{\ 2016/12/02}
% \changes{v0.12}{2016/12/09}{\ 2016/12/09}
% \changes{v0.12}{2016/12/02}{Docs: Loading keyfloat.}
% \changes{v0.12}{2016/12/05}{Docs: Improved index.}
% \changes{v0.13}{2017/01/18}{\ 2017/01/18}
% \changes{v0.13}{2017/01/12}{Docs: Other Settings.}
% \changes{v0.14}{2017/02/09}{\ 2017/02/09}
% \changes{v0.15}{2017/05/12}{\ 2017/05/12}
% \changes{v1.00}{2019/01/11}{\ 2019/01/11}
% \changes{v1.00}{2019/01/08}{Source formatting improvements.}
% \changes{v1.00}{2019/01/08}{Docs \PDF\ bookmark improvements.}
% \changes{v1.00}{2019/01/08}{Removed spurious spaces.}
% \changes{v2.00}{2019/03/21}{\ 2019/03/21}
% \changes{v2.00}{2019/03/17}{Added custom float types.}
% \changes{v2.00}{2019/03/17}{Added float authors.}
% \changes{v2.01}{2019/09/23}{2019/09/23}
% \changes{v2.02}{2021/05/28}{2021/05/27}
% \changes{v2.03}{2021/05/28}{Fixed \cs{hbadness} w/ \cs{relax}.}
% \changes{v2.03}{2021/05/28}{2021/05/28}
% \changes{v2.04}{2021/06/08}{2021/06/08}
% \changes{v2.05}{2021/06/11}{2021/06/11}
% \changes{v2.06}{2021/06/29}{2021/06/29}
% \changes{v2.07}{2021/08/30}{Docs: Show macro and environment nesting.}
% \changes{v2.07}{2022/01/10}{2022/01/10}
% \changes{v2.08}{2023/01/03}{Docs updated for \pkg{dtxdescribe}.}
% \changes{v2.08}{2023/01/03}{2023/01/03}
% \changes{v2.09}{2024/01/12}{2024/01/12}
% \changes{v2.09}{2024/01/12}{Updated contact info.}



% \GetFileInfo{\mypackagename.sty}
%
% \DoNotIndex{\newcommand,\renewcommand,\addtocounter,\begin,\end,\begingroup,\endgroup}
% \DoNotIndex{\global,\ifbool,\ifthenelse,\isequivalentto,\let}
% \DoNotIndex{\booltrue,\boolfalse}
% \expandafter\DoNotIndex\expandafter{\detokenize{\(,\),\,,\\,\#,\$,\%,\^,\_,\~,\ ,\&,\{,\}}}
%
%
% \thispagestyle{empty}
% \begin{center}
% \vfill
% ^^A \includegraphics[width=.3\linewidth]{\mypackagename_logo.pdf}
% \vfill
% {\Huge The \LaTeX\ \pkg{\mypackagename} Package}
% \bigskip
%
% \fileversion{} --- \filedate
%
% \bigskip
%
% {\small\textcopyright{} 2016--2024} Brian Dunn\\ \small \url{https://github.com/bdtc/keyfloat}
%
% \vspace{.5in}
%
% {\Large \textup{\quicksummary}}
%
%
% \vfill
%
% 
% ^^A % \title{The \pkg{keyfloat} package\thanks{This document
% ^^A %   corresponds to \pkg{keyfloat}~\fileversion,
% ^^A %   dated \filedate.}}
% ^^A % \author{{\small\textcopyright{} 2016} Brian Dunn\\ \small \url{https://github.com/bdtc/keyfloat}
% ^^A % \published{}
% ^^A % \subtitle{\textup{Subtitle}}
% ^^A %
% ^^A % \maketitle
%
% \vfill
%
%
% \begin{abstract}
% \noindent
% The \pkg{keyfloat} package provides a key/value user interface for quickly
% creating figures with a single image each, figures with arbitrary contents,
% tables, subfloats, rows of floats, floats located |[H|]ere,
% floats in the |[M]|argin, and floats with text |[W]|rapped around them.
%
% Key/value combinations may specify a caption and label, a width proportional
% to \cs{linewidth}, a fixed width and/or height, rotation, scaling, a
% tight or loose frame, an \cs{arraystretch}, a continued float,
% additional supplemental text,
% and an artist/author's name with automatic index entry.
% When used with the \pkg{tocdata} package, the name also appears in the
% List of Figures.
%
% Floats may be moved into or rearranged inside a multi-row environment or subfloats,
% and are typeset to fit within the given number of columns,
% continuing to additional rows as necessary.
% Nested sub-rows may be used to generate layouts such as
% two small figures placed vertically next to
% one larger figure.
%
% As an example, a typical command to include a figure with a framed image of half \cs{linewidth}
% could be: \\
% \hspace*{1em}\verb|\keyfig*[hbp]{f,lw=.5,c={A caption},l={fig:label}}{image}|
%
% \pkg{keyfloat} uses the \pkg{caption}, \pkg{subcaption},
% \pkg{newfloat} or \pkg{float}, and \pkg{wrapfig} packages,
% \watchout[incompatible packages]
% and cannot be used with the
% \pkg{subfig}, \pkg{subfigure}, \pkg{subfloat}, \pkg{floatrow},
% or \pkg{floatflt} packages.
%
% See the \nameref{sec:indexgen} for an index of topics and troubleshooting.
% \watchout[Need help?]
%
% For the latest updates, see \nameref{sec:updates}.
% \margintag{What's new?}
%
% \vfill
%
% \footnotesize
% \begin{description}
% \item[License:] \
%
% This work 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.
% \end{description}
%
% \end{abstract}
%
% \vspace*{\fill}
% \vspace*{\fill}
% \vspace*{\fill}
% \end{center}
% \clearpage
%
% \tableofcontents
% \listofdtxexamplefloats
% \listoffigures
% \listoftables
%
%
% \thispagestyle{pageheadfoot}
%
% \clearpage
%
%^^A \part{keyfloat.sty}
%
% \section{Introduction}
%
% The \pkg{keyfloat} package simplifies the creation
% of \LaTeX\ floats, while still allowing a large number of useful features.
%
%
% \subsection{A problem with floats}
%
% When including a figure with a graphics image into a document,
% the user typically enters something such as:
% \begin{sourceverb}
% \begin{figure}
% \centering
% \includegraphics[width=3in]{filename}
% \caption{A Figure}
% \label{fig:somelabel}
% \end{figure}
% \end{sourceverb}
% \unskip
%
% When doing that often enough, it makes sense to factor the common code:
% \begin{sourceverb}
% \onefigure[3in]{filename}{A Figure}{fig:somelabel}
% \end{sourceverb}
% \unskip
% 
% Expanding the capability of \cs{onefigure} via \pkg{xparse} can lead to the general case of:
% \begin{sourceverb}
% \onefigure*[loc](width){filename}(add'l text)[shortcap]{caption}*[label]
% \end{sourceverb}
% \unskip
% Attempting to add additional features such as frames and continued floats
% hits the limit of nine parameters for a \TeX\ macro,
% requiring that new features use some kind of change-state macros instead.
% Attempting to support rows of floats or subfloats only makes things more complicated still.
% 
% A key/value system solves the problem of adding more features,
% does not require much additional typing, is a more self-documenting
% syntax, and allows a shared syntax with subfloats and groups of floats as well.
% Thus, the \pkg{keyfloat} package.
%
% \subsection{The \pkg{keyfloat} package}
% 
% Using \pkg{keyfloat}, the previous example becomes:
% \begin{sourceverb}
% \keyfig{w=3in,c=A figure,l=fig:somelabel}{filename}
% \end{sourceverb}
% \unskip
% 
% The \cs{onefigure} general case becomes:
% \begin{sourceverb}
% \keyfig*[loc]{w=width,t={add'l text},sc=shortcap,cstar=caption,
%     l=label}{filename}
% \end{sourceverb}
%
%
% \subsection{Features}
%
% The macros and environments provided by \pkg{keyfloat} include:
% \begin{description}
% \item[\cs{keyfig}:] A figure with an image.
% \item[\cs{keytab}:] A table.
% \item[\cs{keyflt}:] An arbitrary float type macro.
% \item[\cs{keyfigbox}:] A figure with arbitrary contents.
% \item[\cs{keyparbox}:] A ``figure'' without a caption, useful
%	to place uncaptioned text inside a group,
% \item[\env{keyfigure}:] A figure environment.
% \item[\env{keytable}:] A table environment.
% \item[\env{keyfloat}:] An arbitrary float type environment.
% \item[\env{keyfloats}:] A group of rows and columns of floats.
% \item[\env{keysubfigs}:] A figure containing a group of rows and columns of subfigures.
% \item[\env{keysubtabs}:] A table containing a group of rows and columns of subtables.
% \item[\env{keysubfloats}:] A float of arbitrary type containing a group of rows and columns of subfloats.
% \item[\env{keywrap}:] Wraps a keyfloat around an environment of text.  Usable inside a list.
% \item[\env{marginfigure}:] A figure environment placed into
%	the margin.\footnote{\env{marginfigure} and \env{margintable}: The environments
%	provided by the |tufte-book| class are used if loaded,
%	otherwise \pkg{keyfloat} provides its own versions.}
% \item[\env{margintable}:] A table environment placed in the margin.
% \end{description}
%
% Additional features include:
% \begin{itemize}
% \item Rows and columns of floats may be generated by placing them inside a \env{keyfloats}
% environment.
% \item Subfloats may be generated by placing them inside a \env{keysubfigs}
% or \env{keysubtabs} environment.
% \item Dynamic layout: The number of columns is specified. Extra
% 	floats are placed onto additional rows as needed, with the final row
% 	adjusted to compensate for leftovers.
% \item Floats may be placed \optn{[H]}ere.
% \item Floats may be placed in the \optn{[M]}argin.
% \item Floats may be placed with text \optn{[W]}rapped around them.
% \item Floats may be starred to span two columns.
% \item Continued floats may be used to repeat the previous float number.
% \item A figure may contain an image, with additional sizing, rotation, and a frame.
% \item Tables may be stretched. (\cs{arraystretch})
% \item Boxes of arbitrary contents may be assigned a width and framed.
% \item Floats may be moved into and out of the grouping environments as needed.
% \item An artist/author's name may be added to a figure and the index.
% \item If the \pkg{tocdata} package is loaded (use v0.12+),
%	the name is also added to the \acro{LOF}.
% \item Additional descriptive text may be added as well.
% \item Frames may be customized.
% \end{itemize}
%
% A large number of examples are provided, each showing \LaTeX\ source and
% \margintag{examples}
% the resulting float.
%
% A customized index is included at the back of the documentation,
% \margintag{index}
% including troubleshooting issues.
%
% Blue margin tags are used to help quickly find information, and often
% \margintag{margin tags}
% indicate the destination of index entries.
%
% Several warnings are noted in the text.  Watch out for these special cases.
% \watchout[warnings]
%
% ^^A % See the ``troubleshooting'' section of the index for help
% ^^A % \margintag{problems}
% ^^A % with specific problems which may occur.
%
% \subsection{Updates}
%
% \label{sec:updates}
%
% Recent changes include the following:
% \begin{description}
% \item[v2.06:] Added shared keys for groups of floats or subfloats.
%       Added the \optn{kar} key to keep the aspect ratio of an image.
%       Removed \texttt{:} for an empty caption.
%       Warns if an image is too wide to fit.
% \item[v2.02, v2.04:] Added keys for wrapped floats.
% \end{description}
%
% \subsection{Other float-related packages}
%
% Several other \LaTeX\ packages related to floats include:
% \begin{description}
% \item[\pkg{caption} and \pkg{subcaption}:] Improved control over captions.
% \item[\pkg{floatrow}:] A macro-based package for creating floats; including captions,
%       footnotes, and rows of floats.
% \item[\pkg{hvfloat}:] A key \Slash value system allowing the easy rotation of
%       captions and floats.
% \item[\pkg{nccfloats}:] Macros for minipage floats and side-by-side floats.
% \item[\pkg{newfloat}:] Macros for the creationg of float environments.
% \item[\pkg{rotfloat}:] Environments for rotated floats.
% \item[\pkg{subfig}:] Macros to add subfloats inside a float.
% \end{description}
%
%
% \clearpage
%
% \section{Using the \pkg{keyfloat} package}
%
% \subsection{Loading \pkg{keyfloat} and related packages}
%
% \pkg{keyfloat} is loaded with the usual command:
% \begin{sourcedisplay}
% 	\cs{usepackage}\{keyfloat\}
% \end{sourcedisplay}
%
%
% If you wish to have artists' names appear in the list of figures,
% \DescribePackage{tocdata}%
% \DescribePackage{tocloft}%
% \DescribePackage{titletoc}%
% as provided by the \pkg{tocdata} package,
% load \pkg{tocdata},
% optionally followed by either \pkg{tocloft} or \pkg{titletoc},
% then \pkg{keyfloat}:
% \begin{sourcedisplay}
% 	\cs{usepackage}\{tocdata\} \\
%   \cs{usepackage}\{titletoc\}\% or titletoc, or neither \\
% 	\cs{usepackage}\{keyfloat\}
% \end{sourcedisplay}
%
% To use custom float types with the \pkg{float} package:
% \DescribePackage{float}
% \begin{sourceverb}
% \usepackage{float}
% \newfloat{diagram}{htb}{lod}
% \end{sourceverb}
%
% To use custom float types with the \pkg{newfloat} package:
% \DescribePackage{newfloat}
% \begin{sourceverb}
% \usepackage{newfloat}
% \DeclareFloatingEnvironment[
%     fileext={lod},
%     listname={List of Diagrams},
%     name={Diagram},
% ]{diagram}
% \end{sourceverb}
%
% For the \pkg{caption} package, to have table captions appear above the tables, and
% \DescribePackage{caption}
% to use custom float types:
% \begin{sourceverb}
% \usepackage[tableposition=top]{caption}
% \captionsetup[diagram]{
%     style=default, justification=centering,
%     margin=0pt, parskip=0pt, skip=1ex,
%     labelfont={small,bf},textfont={small,bf}
% }
% \end{sourceverb}
%
% To use custom float and subfloat types with \pkg{cleveref}:
% \DescribePackage{cleveref}
% \begin{sourceverb}
% \usepackage{cleveref}
% \crefname{diagram}{diagram}{diagrams}
% \crefname{subdiagram}{subdiagram}{subdiagrams}
% \end{sourceverb}
%
%
% \needspace{7\baselineskip}
% \subsection{Macros and environments}
%
% \DescribeMacro{\keyfig} * \oarg{loc} \marg{\keyvalsarg} \marg{image filename} \\
% A macro to generate a figure with an image from a file.
%
% \DescribeMacro{\keytab} * \oarg{loc} \marg{\keyvalsarg} \marg{tabular contents} \\
% A macro to generate a table with tabular contents.
% Usually use the \env{keytable} environment instead.
%
% \DescribeMacro{\keyflt} * \oarg{loc} \marg{float type} \marg{keys/values} \marg{contents} \\
% A macro to generate an arbitrary float type with its contents.
%
% \DescribeMacro{\keyfigbox} * \oarg{loc} \marg{\keyvalsarg} \marg{box contents} \\
% A macro to generate a figure with arbitrary paragraph contents.
% See \cref{ex:keyfigbox}.
%
% \DescribeMacro{\keyparbox} * \oarg{loc} \marg{\keyvalsarg} \marg{box contents} \\
% A macro to generate a figure with arbitrary paragraph contents,
% but no number or caption. This is equal to a \cs{keyfigbox} with |cstar={}|.
% Mostly useful to add supplemental information inside a row of floats or subfloats.
% See \cref{ex:keyparbox}.
%
% \DescribeEnv{keyfigure} * \oarg{loc} \marg{\keyvalsarg} \\
% An environment to generate a figure with arbitrary contents.
% Useful for multi-paragraph contents.
% See \cref{ex:keyfigure}.
%
% \DescribeEnv{keytable} * \oarg{loc} \marg{\keyvalsarg} \\
% An environment to generate a table with arbitrary contents.
% Useful for larger tables.
% See \cref{ex:keytable}.
%
% \DescribeEnv{keyfloat} * \oarg{loc} \marg{float type} \marg{\keyvalsarg} \\
% An environment to generate an arbitrary float type with its contents.
% Useful for multi-paragraph contents.
%
% \begin{docsidebar}
% \textbf{The above macros and environments may be used by themselves,
% or inside the following \env{keyfloats}, \env{keysubfigs}, or
% \env{keysubtabs} environments.}
% \end{docsidebar}
%
%
% \DescribeEnv{keyfloats} * \oarg{loc} \marg{num columns} \oarg{shared \keyvalsarg} \\
% A group of figures or tables typeset in rows.  May be nested, [H], [W], or [M].
% The optional shared \keyvalsarg\ are passed to each object within.
% See \cref{ex:keyfloats}.
%
% \DescribeEnv{keysubfigs} * \oarg{loc} \marg{numcols} \marg{keys} \oarg{shared \keyvalsarg} \\
% A group of subfigures typeset in rows.
% May \emph{not} be nested.  May be [H], [W], or [M].
% The optional shared \keyvalsarg\ are passed to each object within.
% See \cref{ex:keysubfigs}.
%
% \needspace{2\baselineskip}
% \DescribeEnv{keysubtabs} * \oarg{loc} \marg{numcols} \marg{keys} \oarg{shared \keyvalsarg} \\
% A group of subtables typeset in rows.
% May \emph{not} be nested.  May be [H], [W], or [M].
% The optional shared \keyvalsarg\ are passed to each object within.
% See \cref{ex:keysubtabs}.
%
% \needspace{2\baselineskip}
% \DescribeEnv{keysubfloats} * \oarg{loc} \marg{float type} \marg{numcols} \marg{keys} \oarg{shared \keyvalsarg} \\
% A group of subfloats typeset in rows.
% May \emph{not} be nested.  May be [H], [W], or [M].
% The optional shared \keyvalsarg\ are passed to each object within.
%
% \DescribeEnv{keywrap} \marg{width of keyfloat} \marg{keyfloat} \\
% Displays a keyfloat next to an environment of text.
% Two minipages are used side-by-side, which allows its use inside a list item
% where [W] will not work, but extra empty vertical space
% \watchout[empty space]
% will appear if the keyfloat and the text are of unequal vertical size.
% \meta{keyfloat} may be any of \cs{keyfig}, \env{keyfigure},
% \env{keyfloats}, \env{keysubfigs}, etc., each with its proper arguments.
% See \cref{ex:keywrapkeyfig}.
%
% \DescribeEnv{marginfigure} \oarg{offset} \\
% A figure placed into the margin, with an optional vertical offset.
% \cs{keyfloat} uses the version provided by the |tufte-book| class if available,
% or provides its own version otherwise.
% See \cref{ex:marginfigure}.
%
% \DescribeEnv{margintable} \oarg{offset} \\
% A table placed into the margin, with an optional vertical offset.
% \cs{keyfloat} uses the version provided by the |tufte-book| class if available,
% or provides its own version otherwise.
% See \cref{ex:margintable}.
%
% \medskip\hrule\medskip
%
% \DescribeArgument{*}
% The star option create floats which span both columns in a two-column
% document.
%
% \DescribeArgument{{[H]}}
% The |[H]| location forces a figure to be ``Here'', in the
% form of a minipage instead of a float.  A caption, label, etc.\ may
% still be assigned.
%
% \DescribeArgument{{[M]}}
% The |[M]| location places the float into the margin.  When the |tufte-book| class
% is used, its \env{marginfigure} and \env{margintable} environments are used,
% otherwise \pkg{keyfloat} provides and uses its own versions of the same environments.
% See \cref{ex:keyfigm,ex:keytablem}.
%
% \DescribeArgument{{[W]}}\DescribePackage{wrapfig}
% The |[W]| location wraps text around the float.  Use this just before the start of
% a paragraph with contents large enough to wrap around the float.  Do not use this
% inside a list environment.  Select placement with the |wp| key; see
% the \pkg{wrapfig} package documentation for more information.
% Use \optn{w} or \optn{lw} to set the width of the item \Slash image contained
% inside the wrap area.  By default the caption will also be contained in this width.
% To use a larger width for the overall container and caption,
% set \optn{w} or \optn{lw} for the size of the image, and also use
% \optn{ww} or \optn{wlw} for a larger size for the caption.
% Watch the log for warnings from \pkg{wrapfig}.\watchout[\pkg{wrapfig} warnings]
%
% \DescribeArgument{{[loc]}}
% The star and [loc] options are ignored for floats inside a \env{keyfloats},
% \env{keysubfigs}, or \env{keysubtabs} environment.  Note that these
% container environments may have their own star and [loc] options.
%
%
% \clearpage
%
%
%
%
% \subsection{Keys and values}
%
% \changes{v2.05}{2021/06/11}{Docs: Fixed braces for multi-word values.}
%
% \newcommand{\largebullet}{{\Large\textbullet}}
%
% \begin{keytable}[bp]{c={Keys and values — part I},l={tab:keyvals},stretch=1.5}
% \centering
% \gindex{keys>and values}
% \begin{threeparttable}
% \small
% \begin{tabular}{>{\ttfamily}cc>{\raggedright}p{2.5in}>{\centering\arraybackslash}>{\ttfamily\arraybackslash}p{1in}}
% \toprule
% \textrm{Key} & Sub\tnote{a} & Description & \textrm{Example} \\
% \midrule
% c & \largebullet &  An unstarred caption.
%	If empty, creates a figure with a number but no caption. & c=\{A caption\} \\
% cstar & \largebullet &  A starred caption.  Creates a float without a number.
% 	If empty, creates a figure with no number or caption. & cstar=\{No Num\} \\
% sc & \largebullet &  The short caption for the \acro{LOF}/\acro{LOT}, even if cstar. & sc=\{Short cap\} \\
% cont & \largebullet &  Continued float?  & cont \\
% l & \largebullet &  The label.  Enclose in braces if a comma is included.
%	Ignored in unnumbered floats. & l=fig:alabel  \\
% ap, aup & \largebullet & Artist/author's prefix, such as ``Mr.''\,\tnote{b} & ap=Mr. \\
% af, auf & \largebullet & Artist/author's first name.\tnote{b} & af=First \\
% al, aul & \largebullet & Artist/author's last name.\tnote{b} & al=Last \\
% as, aus & \largebullet & Artist/author's suffix, such as |~III|.\tnote{b} & |al=~III| \\
% t & \largebullet &  Additional text.  May include paragraphs. \\
% 	Enclose in braces if a comma is included. 
%	May need \cs{protect} before macro calls.
%	Fully-justified alignment.
%	& t=\{Paragraphs\} \\
% tc & \largebullet & Additional text, aligned to the center. & tc=\{Paragraphs\} \\
% tl & \largebullet & Additional text, aligned to the left. & tl=\{Paragraphs\} \\
% tr & \largebullet & Additional text, aligned to the right. & tr=\{Paragraphs\} \\
% \bottomrule
% \end{tabular}
% \begin{tablenotes}
% \item[a:] All the keys in Part I may be used with the main keys of the
%	\env{keysubfigs}, \env{keysubtabs}, and \env{keysubfloats} environments.
% \item[b:] Artist \Slash author keys:
%   |al| is an artist's last name, |aul| is an author's last name, etc.
%   Artists names are printed centered, authors are flush right.
%	A fixed-width non-breakable space is placed between parts of names, except that
%	the optional suffix is connected directly to the last name, allowing
%	``|as={, Title}|'', for example.
% \end{tablenotes}
% \smallskip
% \hrule\medskip\centering
% {\footnotesize \dots\ continued}
% \end{threeparttable}
% \end{keytable}


% \changes{v2.05}{2021/06/11}{Docs: Fixed \optn{r} key.}

% \begin{keytable}{
%	c={Keys and values — part II},cont,stretch=1.5}
% \centering
% \gindex{keys>and values}
% \begin{threeparttable}
% \small
% \begin{tabular}{>{\ttfamily}cc>{\raggedright}p{2.5in}>{\centering\arraybackslash}>{\ttfamily\arraybackslash}p{1in}}
% \toprule
% \textrm{Key} & Sub\tnote{c} & Description & \textrm{Example} \\
% \midrule
% lw & --- & Set the width to a fraction of \cs{linewidth}.  Cancels |w|.
% 	If a non-image float, sets the width of the text box.
%   For wrapped objects, may be used with \optn{wlw} for a smaller item
%       with a larger caption.
%           & lw=.5 \\  
% w &  --- & Set the actual width.  Cancels |lw|.
% 	If a non-image float, sets the width of the text box.
%   For wrapped objects, may be used with \optn{ww} for a smaller item
%       with a larger caption.
%           & w=2in \\
% h & --- & Set the actual height.  Images only.  & w=2in \\
% kar & --- & Keep aspect ratio: Use with \optn{w} or \optn{lw}, along with \optn{h},
%           to fit an image into a given area.  Images only. & kar \\
% s & --- & Set the image scale.  Images only.  & s=3 \\
% r & --- & Set the rotation angle; counter-clockwise degrees. & r=90 \\
% f & --- & Selects a loose frame with the current \cs{fboxsep}.
%	Only rotated with \cs{keyfig}.  & f \\
% ft & --- & Selects a tight frame with no \cs{fboxsep}.  Useful for photographs,
% 	or diagrams which already have some margin built in. & ft \\
% stretch & --- & Sets \cs{arraystretch} inside the float. & stretch=1.5 \\
% mo & --- & Sets the vertical offset for a margin float. & mo=-1.2ex \\
% wn & --- & Sets the number of lines for a wrapped float. & wn=2 \\
% wp & --- & Sets the wrap placement for a wrapped float. The default
%	is |O|, which places the wrapped float at the outside edge of the text.
%	See \cref{tab:wrapplacement}.
%	& wp=I \\
% wo & --- & Sets the wrap overhang for a wrapped float. & wo=8em \\
% wlw & --- & Sets the total width of the wrapped item to a fraction of \cs{linewidth}.
%       May be more than the \optn{w} or \optn{lw} width. & wlw=.6 \\
% ww & --- & Sets the total width of the wrapped item.
%       May be more than the \optn{w} or \optn{lw} width. & ww=2in \\
% va & --- & Sets the vertical alignment of the outermost minipage container for the keyfloat.
%	Defaults to 'c'.  Ignored by \env{subfigure}, \env{subtable}.
%	& va=t \\
% \bottomrule
% \end{tabular}
% \begin{tablenotes}
% \item[c:] None of the keys in Part II are used in the main keys of the
%	\env{keysubfigs}, \env{keysubtabs}, or \env{keysubfloats} environments,
%   but may be used in the optional shared keys to be passed to each object within.
% \end{tablenotes}
% \end{threeparttable}
% \end{keytable}
%
% \Cref{tab:keyvals} shows the key/value combinations which are allowed.
% In most cases these may be used in any order and any combination,
% except for the following:
%
% The keys labeled "Sub"\margintag{subfloat keys}
% \gindex{subfloat>keys}\gindex{keys>subfloats}
% may be used for the \env{keysubfigs} and
% \env{keysubtabs} environments, which group a number of subfloats together under
% one master float.  The master float has its own caption, label, and text, and
% each subfloat inside the group likewise has its own set of keys.
%
% \env{keyfloats} does not accept any keys at all.\margintag{keyfloats keys}
% \gindex{keyfloats>keys}\gindex{keys>keyfloats}
%
% The ``artist'' keys |ap|, |af|, |al|, and |as| are only used by figures.
%
% The |stretch| key increases space between tabular elements.
%
% The rest of the macros
% and environments accept all of the keys, as they each create an individual
% float or subfloat, and each may have its own assigned dimensions and frame.
%
% \Cref{tab:captions} shows the combinations of the caption-related keys
% \margintag{short/long\\caption combinations}
% |c|, |cstar|, and |sc|, and how they control the caption numbering and
% entries in the \acro{LOF}/\acro{LOT}.
% 
%
% \begin{keytable}{c={Caption-related key combinations},l=tab:captions,stretch=1.5}
% \gindex{caption>options}
% \centering
% \begin{threeparttable}
% \small
% \begin{tabular}{ccccc}
% \toprule
% \multicolumn{3}{c}{\bfseries Keys in Use} & \multicolumn{2}{c}{\bfseries Type of} \\
% \cmidrule(r){1-3}\cmidrule(l){4-5}
% |c| & |cstar| & |sc| & \textbf{Caption}\tnote{a} & \textbf{\LOF\Slash\LOT}\tnote{b} \\
% \cmidrule(r){1-3} \cmidrule(l){4-5}
% \largebullet & — & — & Numbered & Caption \\
% \largebullet & — & \largebullet & Numbered & Short Caption \\
% \midrule
% — & \largebullet & — & Unnumbered & None \\
% — & \largebullet & \largebullet & Unnumbered & Short Caption \\
% \midrule
% — & |cstar={}| & Ignored & None & None \\
% \bottomrule
% \end{tabular}
% \begin{tablenotes}
% \item[a:] Caption: Shows whether the float will
% be numbered, unnumbered, or have no caption.
% \item[b:] \LOF\Slash\LOT: Shows whether the regular or short caption
% will appear in the List of Figures or List of Tables, or if there will be no listing.
% \end{tablenotes}
% \end{threeparttable}
% \end{keytable}
%
%
% \Cref{tab:wrapplacement} shows the wrapped-float placement
% \margintag{wrapped float placement}
% options for the |wp| key
% for floats placed |[W]|.
%
% \begin{keytable}{c={Key \optn{wp}: Wrapped float placement options},l=tab:wrapplacement}
% \gindex{float>wrapped placement}\gindex{wrapped float placement}
% \centering
% \begin{tabular}{ccl}
% \toprule
% \multicolumn{2}{c}{Key} & Location \\
% \cmidrule(r){1-2}\cmidrule{3-3}
% r & R & to the right of the text body \\
% l & L & to the left of the text body \\
% i & I & to the inside margin \\
% o & O & to the outside margin \\
% \bottomrule
% \end{tabular}
%
% \raggedright\small
% The un-capitalized key attempts to place the float ``here'', and
% the capitalized key allows \LaTeX\ to try to find the best location.
% The default is |O|.
% \end{keytable}
%
%
% \clearpage
%
% \subsection{Other settings}
%
% \DescribeMacro{\KFLTtightframe} \marg{contents} Frames the contents without separation.
%
% \DescribeMacro{\KFLTlooseframe} \marg{contents} Frames the contents with separation.
%
% These may be used to re-define how contents are framed.  The default
% is a simple \cs{fbox}.
%
% \DescribeLength{\KFLTtightframewidth} Combined width of the frame and separation
%	for each of tight and loose frames.  These settings should be adjusted when
%	changing the frame width and/or separation.  The value should be equivalent
%	to \cs{fboxwidth} plus \cs{fboxsep}.
% \DescribeLength{\KFLTlooseframewidth}
%
% \DescribeLength{\KFLTimageboxwidth} The computed width of the image.
% Useful to enclose an mdframed environment to restrict its width.
% See \cref{ex:customframe}.
%
%
%
%
% \clearpage
%
% \subsection{Examples}
%
%
% \subsubsection{Single floats}
%
%
% \begin{dtxexample}[\Cref{fig:simple}]{Figure with an image from a file}
% \keyfig{c=A \cs{keyfig} with an image,l=fig:simple}{image}
% \end{dtxexample}
%
% This float (\cref{fig:simple}) is shown at its natural size
% \margintag{natural size}
% because no width or height modifiers were specified.  When used alone like this,
% a regular float is created.
% \gindex{image>natural size}
%
%
% \begin{dtxexample}[\Cref{fig:figbox}]{Figure with arbitrary contents\label{ex:keyfigbox}}
% \keyfigbox{f,c={A \cs{keyfigbox}},l=fig:figbox}
% 	{Some text.  More text. \par  Another paragraph.}
% \end{dtxexample}
%
% The \cs{keyfigbox} creates a figure with a box of arbitrary contents, instead of
% an image from a file.  Its default width is the full \cs{linewidth},\margintag{default width}
% \gindex{float>default width}
% unless |w| or |lw| keys are used.
%
%
% \begin{dtxexample}[\Cref{fig:environment}]
% {Figure environment with arbitrary contents\label{ex:keyfigure}}
% \begin{keyfigure}{f,c={A \env{keyfigure} environment},
% 	l=fig:environment}
% Arbitrary contents may go here.
% 
% Including multiple paragraphs.
% \end{keyfigure}
% \end{dtxexample}
%
% The \env{keyfigure} environment is preferred over the \cs{keyfigbox} macro when
% multiple lines of contents are to be included.
%
% \begin{dtxexample}[\Cref{tab:simpletable}]{Table macro}
% \keytab{c=A \cs{keytab} table,l=tab:simpletable}{\testtable}
% \end{dtxexample}
%
% Do not try to use tables which overflow the page.
%
% For anything other than a simple table, use the \env{keytable} environment.
% See \cref{ex:keytable}.
%
% For large tables, use the \pkg{longtable} or \pkg{supertabular} packages.
% \margintag{large tables}
% \trouble{table>large}
%
%
% \begin{dtxexample}[\Cref{tab:environment}]
% {Table environment with arbitrary contents\label{ex:keytable}}
% \begin{keytable}{f,c={A \env{keytable} environment},
% 	l=tab:environment}
% Arbitrary contents may go here.\footnote{A footnote.}
%
% \testtable
% \end{keytable}
% \end{dtxexample}
%
% The \env{keytable} environment is preferred over the \cs{keytab} macro
% since most tables are multi-line creations.
%
% \cs{keytab} centers the table, but \env{keytable} does not.
% Add \cs{centering} if desired.
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:options}]{Figure with many options selected}
% \keyfig{
% 	w=2in,ft,r=15,
% 	c=A figure with many options,
% 	sc=A figure with options,
% 	t={Additional text.  Multiple paragraphs may be used.
% 	The entire text is enclosed in braces because a comma
% 	is included. Alignment may be set by using
% 	tags \optn{tc}, \optn{tl}, or \optn{tr}
% 	instead of \optn{t}},
% 	l=fig:options
% }{image}
% \end{dtxexample}
%
% \gindex{text>added}
% \gindex{float>text added}
%
% Width is fixed at 2\,in, a tight frame is specified (\cs{fboxsep} of 0\,pt),
% a short caption appears in the List of Figures, and the additional text
% is using the default fully-justified alignment.
%
% Since \cref{fig:options} is a float, it may appear on the following page.
%
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:linewidth}]{Using \cs{linewidth}}
% \keyfig{lw=.5,c=Half of \cs{linewidth},l=fig:linewidth}{image}
% \end{dtxexample}
%
% \Cref{fig:linewidth} is half of \cs{linewidth} in size.
% \margintag{\cs{linewidth}}
% \gindex{image>linewidth=\cs{linewidth}}\gindex{linewidth=\cs{linewidth}}
% \gindex{subfloat>\cs{linewidth}}\gindex{keyfloats>\cs{linewidth}}
% When the |lw| key is used inside a \env{keyfloats} or \env{keysubfigs} environment,
% the \cs{linewidth} will be proportional to the sub-box for each element.
% When used alone, such as here, the \cs{linewidth} is the full width of the text on
% this page.
%
% |lw| and |w| are not used at the same time.
% If both |lw| and |w| are specified, the last one cancels any previous ones.
%
%
% \clearpage
%
% \begin{dtxexample}[\Cref%
%     {fig:looseframe,fig:tightframe,tab:looseframe,tab:tightframe}%
% ]{Using frames}
% \begin{keyfloats}[hbp]{4}
% \keyfig{f,c=Loosely-framed figure,l=fig:looseframe}{image}
% \keyfig{ft,c=Tightly-framed figure,l=fig:tightframe}{image}
% \keytab{f,c=Loosely-framed table,l=tab:looseframe}{\testtable}
% \keytab{ft,c=Tightly-framed table,l=tab:tightframe}{\testtable}
% \end{keyfloats}
% \end{dtxexample}
%
% The |f| key adds a loose frame with the current \cs{fboxsep}.
% This is desirable in most cases.
%
% The |tf| key adds a tight frame with no separation.
% This is useful for framing a photograph, or a diagram which already has a margin.
%
% Framing tables is seldom recommended.  In the case of the tight frame, \cref{tab:tightframe},
% note that the external frame almost overwrites the table's natural horizontal rules.
%
% Also see \cref{sec:customframes} for customizing frames.
% \margintag{custom frames}
%
%
% \clearpage
%
% \begin{dtxexample}[\Cref{tab:rotated}]{Using rotation with boxes}
% \keytab{f,w=.8in,c={Table, rotated},
% 	r=70,l=tab:rotated,
% 	tc=(Framed to show box width.)}
% 	{\testwidetable}
% \end{dtxexample}
%
% Unless a width is given, a box is the full \cs{linewidth}.
% \margintag{rotated whitespace}
% When rotated, this extra horizontal space is rotated into extra vertical space.
% \gindex{rotate>box width and vertical space}\gindex{linewidth=\cs{linewidth}>with rotation}
% \trouble{rotate>extra space}
% To avoid this extra space, set a |w| or |lw| to be wide enough
% \watchout[box width]
% for the table or other contents,
% but not much wider.  When this box is rotated, it will not take much more
% vertical space than necessary.
%
% Unlike an image, the frame of a box does not rotate with its contents.
% \margintag{frame rotation}\gindex{frame>rotation}
% \trouble{rotate>frame}
%
% \clearpage
%
% \begin{dtxexample}[\Cref{tab:here}, \Cref{fig:here}]{Located [H]ere}
% \keytab[H]{c={A table [H]},l=tab:here}{\testtable}
% \keyfig[H]{f,w=1in,c={A keyfig [H]},l=fig:here}{image}
% \end{dtxexample}
%
% \gindex{h=[H]ere placement}
% \gindex{float>h=[H]ere placement}
% \gindex{float>inline}
% \Cref{tab:here} and \Cref{fig:here} are to be placed ``[H]ere'', and therefore may appear
% \watchout[Out of sequence]
% out-of-sequence with surrounding figures.
% \trouble{float>out of sequence}
% Place a \cs{clearpage} before or after to re-sync, if necessary.
%
%
% \clearpage
%
% \begin{dtxexample}[See fig: ``A starred caption''.]{Unnumbered float}
% \keyfig[H]{f,cstar={A starred caption}}{image}
% \end{dtxexample}
%
% \gindex{float>unnumbered}
%
% A starred caption creates a float without a number, and without
% an entry in the List of Figures unless there is a non-empty short caption.
% (See the next example.)
%
% Labels cannot be used when there is no number for a float.
% \trouble[No label]{label>missing}
% \trouble{label>unnumbered float}
% \trouble{float>unnumbered>no label}
%
% \begin{dtxexample}
% 	[See fig: ``Starred caption with a short caption''.]
% 	{Unnumbered float with a \acro{LOF} entry}
% \keyfig{
% 	f,cstar={Starred caption with a short caption.},
% 	sc={Starred short caption}
% }{image}
% \end{dtxexample}
%
% A starred caption with a non-empty short caption creates an
% unnumbered entry in the List of Figures.
%
%
% \clearpage
%
% \begin{dtxexample}
% 	[See fig: ``Optional text which is not a caption.'']
% 	{An unnumbered in-text image}
% \keyfig[H]{f,cstar={},
% 	tc={Optional text which is not a caption.}
% }{image2}
% \end{dtxexample}
%
% \gindex{float>inline without caption}
%
% By using [H] and |cstar={}|, the image is placed inline
% without a number or \acro{LOF} entry.
%
% Also see \cref{ex:keyparbox}.
%
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:nexttoparbox}, and the box to its left.]
% 	{A box without a caption.\label{ex:keyparbox}}
% \begin{keyfloats}{2}
% \keyparbox{
% 	f,lw=.5,
% 	tc={A \cs{keyparbox} with no number or label.}
% }{Some contents.}
% \keyfig{c=Next to a \cs{keyparbox},l=fig:nexttoparbox}{image}
% \end{keyfloats}
% \keyparbox[H]{f,lw=.5}{A \cs{keyparbox} [H], outside the keyfloats.}
% \end{dtxexample}
%
% \gindex{float>without caption}
%
% A \cs{keyparbox} is a \cs{keyfigbox} with |cstar={}|,
% and is mostly useful as an information box inside a row or a set of subfloats.
%
%
%
%
% \clearpage
%
% \subsubsection{Groups of floats, shared keys, keep aspect ratio}
%
% \begin{dtxexample}[\Cref{fig:firstinrow} to \Cref{tab:seventhinrow}]{Groups of figures — \env{keyfloats} environment\label{ex:keyfloats}}
% \begin{keyfloats}{2}
% \keyfig{lw=1,c={First in a group},
% 	l=fig:firstinrow,tl={\cs{raggedright} text}
% 	}{image}
% \keyparbox{}{\centering A \cs{keyparbox} describing something.
% 	\par With several paragraphs.}
% \begin{keyfloats}{2}[f,lw=1,h=3em,kar,va=t]
%       \keyfig{lw=1,c={Third in a group},
%           l=fig:thirdinarow}{image}
%       \keyfig{lw=1,c={Fourth in a group, with a longer caption}}{image2}
%       \keyfig{lw=1,c={Fifth in a group}}{image}
%       \keyfig{lw=1,c={Sixth in a group},
%           l=fig:sixthinarow}{image2}
% \end{keyfloats}
% \keytab{c={Seventh in a group},l=tab:seventhinrow}{\testwidetable}
% \end{keyfloats}
% \end{dtxexample}
%
% 
% The \env{keyfloats} environment takes an argument for the number of columns.
% Additional floats
% \margintag{automatic layout}
% are automatically placed on following rows.
% Changing the number of columns will cause the floats to automatically readjust as
% necessary.  Leftovers will be centered on the last row.
% An optional argument
% \margintag{shared keys}
% \gindex{group>shared keys}
% \gindex{float>shared keys}
% \gindex{keys>shared in a group}
% may contain keys and values which are passed to each object
% inside the group.
%
% \Cref{fig:firstinrow} to \cref{tab:seventhinrow} are in a \env{keyfloats} environment.
% Furthermore,
% \margintag{nested groups}
% \Crefrange{fig:thirdinarow}{fig:sixthinarow} are in an
% additional nested \env{keyfloats} environment, forming a small box of floats inside
% the larger group.
% In this subgroup, shared keys are set so that each image is framed
% and keeps its aspect ratio while being resized to fit a fixed width and height.
%
% Note that \cs{linewidth} is adjusted for each row and nested row,
% \watchout[\cs{linewidth}]
% so the |lw| key may need to be changed if a float is moved to a different nesting level.
% \trouble{linewidth=\cs{linewidth}}\gindex{linewidth=\cs{linewidth}>subfloats}
% \gindex{subfloat>\cs{linewidth}}
%
% Fixed-width or fixed-height floats may be too large to fit
% \watchout[image too large]
% if they are moved into a group.  A warning is issued if so.
% It is the user's responsibility to adjust |w|, |h|, or |lw| as necessary.
% \trouble{image>too large}
% To allow images to automatically adjust, use |lw=1| or less, which adjusts
% to the \cs{linewidth}.
%
% Keyfloats may be located
% \margintag{location}
% [H], [M], or located [W] set with half the line width:\\
% \hspace*{2em}|\begin{keyfloats}[H]{2}| \dots
%
% Keyfloats may be starred
% \margintag{two columns}
% to span both columns in a two-column format: \\
% \hspace*{2em}|\begin{keyfloats}*{2}| \dots
%
% As shown in the sub group above,
% \margintag{grid of images}
% \gindex{group>nested}
% \gindex{float>nested group}
% \gindex{image>grid of}
% \gindex{image>keep aspect ratio}
% \gindex{aspect ratio}
% \gindex{keep aspect ratio}
% to display a group of images of varying shape inside a grid, use the shared option to
% select a maximum size, keep aspect ratio, and align at the top so that captions
% of varying length may wrap below each image:
% \begin{sourceverb}
% \begin{keyfloats}{2}[lw=1,h=3em,kar,va=t]
% ...
% \end{keyfloats}
% \end{sourceverb}
%
%
% \clearpage
%
% \subsubsection{Subfloats}
%
% \begin{dtxexample}[\Cref{fig:subfigs}]{Subfigures — \env{keysubfigs} environment\label{ex:keysubfigs}}
% \begin{keysubfigs}{3}{c=Subfigures,l=fig:subfigs}
% \keyfig{lw=1,f,c={First subfigure},
% 	l=fig:firstsubfig,t=Some text}{image}
% \keyfig{lw=1,f,r=90,c={Second subfigure},
% 	l=fig:secondsubfig,
% 	t=Lots of lots of lots of lots of text.}
% 	{image2}
% \begin{keyfloats}{1}
%       \keyfig{lw=1,f,c={Third subfigure},l=fig:thirdsubfig}{image}
%       \keytab{c={Fourth subfigure},l=fig:fourthsubfig}{\testtable}
%       \keyfig{lw=.5,f,c={Fifth subfigure},l=fig:fifthsubfig}{image}
% \end{keyfloats}
% \end{keysubfigs}
% \end{dtxexample}
% 
% \Crefrange{fig:firstsubfig}{fig:fifthsubfig} are in
% the \cref{fig:subfigs} \env{keysubfigs} environment.
% The \env{keysubtabs} environment is similar.
% Mixed types have the type of their container, as shown with \cref{fig:fourthsubfig}.
%
% Subfloats are associated floats (a, b, \dots) collected together into one common float
% (the enclosing \env{keysubfigs} or \env{keysubtabs} environment).
% The enclosing float can have its own caption (call ``Sub-Figures'' in the example),
% which appears in the \acro{LOF}/\acro{LOT}, and also a label.
% Each subfloat can have its own caption and label as well, but the
% subcaption does not appear in the \acro{LOF}/\acro{LOT}.
%
% All subfloats are forced to have the same type as
% its containing float.\trouble{mixed subfloats}
% \watchout[mixed subfloats]
% A table inside a figure will be labeled as a figure, for example.
% This avoids miss-labeling as each subfloat must clearly be identified
% as a child of its containing float.
%
% \env{keysubfigs} and \env{keysubtabs} may not be used inside\watchout[nested subfloats]
% \trouble{nested subfloats}\gindex{subfloat>nested}
% the \env{keyfloats} environment,
% and cannot be nested inside each other.  (No subfloat |12aa|, |12ab|, |12ba|, etc.)
%
% The \env{keyfloats} environment may be used inside \env{keysubfigs} or
% \margintag{nested keyfloats}\gindex{keyfloats>nested}
% \env{keysubtabs} to gather subfloats together, such as the
% three right-most figures in \cref{fig:subfigs}.
%
% Subfloats may be located
% \margintag{location}
% [H], [M], or located [W] set with half the line width: \\
% \hspace*{2em}|\begin{keysubfigs}[H]{3}{|key/vals \dots|}|
% 
% Subfloats may be starred
% \margintag{two columns}
% to span both columns in a two-column format: \\
% \hspace*{2em}|\begin{keysubfigs}*{2}{|key/vals \dots|}|
%
% A group of subfloats
% \margintag{shared keys}
% \gindex{group>shared keys}
% \gindex{subfloat>shared keys}
% \gindex{keys>shared in a group}
% may have an optional argument for shared keys and values,
% which are then passed to each subfloat within.
%
% The vertical alignment
% \watchout[va]
% option |va| does not work with subfloats.
%
% \begin{dtxexample}[\Cref{tab:subtabs}]{Subtables [H] — \env{keysubtabs} environment\label{ex:keysubtabs}}
% \begin{keysubtabs}[H]{2}{c=Subtables [H],l=tab:subtabs}
% \keytab{c={First subtable},l=fig:firstsubtab}{\testtable}
% \keytab{c={Second subtable},l=fig:secondsubtab}{\testwidetable}
% \end{keysubtabs}
% \end{dtxexample}
% 
%
%
% \clearpage
%
% \subsubsection{Continued floats}
%
% \gindex{float>continued}
% \gindex{continued float}
%
% The |cont| key may be used to generate a ``continued'' float.
% The continued float receives the same number as the previous float,
% and it is assumed that they are the same float, except that
% they are separated for some reason such as size on the page.
%
% The label may be placed in a continued float, and will still
% receive the same float number as the prior non-continued float.
%
% \begin{dtxexample}[\Cref{fig:firstcontinued}]{Continued figure}
% \begin{keyfloats}{2}
% \keyfig{,c=Figure to be continued}{image}
% \keyfig{c={\dots continued},cont,l=fig:firstcontinued}{image2}
% \end{keyfloats}
% \end{dtxexample}
%
%
% \clearpage
% \subsubsection{Continued subfloats}
%
% \gindex{float>subfloat continued}
% \gindex{subfloat>continued}
% \gindex{continued subfloat}
%
% The \env{keysubfigs} and \env{keysubtabs} environments may also
% be given the |cont| key.
% The containing environment's float receives the same number as the previous float
% (presumably another subfloat container).
%
% \begin{dtxexample}[\Cref{fig:continuedfigures}]{Continued subfloats}
% \begin{keysubfigs}{2}{c={A set of figures},l=fig:continuedfigures}
% \keyfig{c={First of a set},l=fig:contfirst}{image}
% \keyfig{c={Second of a set},l=fig:contsecond}{image}
% \end{keysubfigs}
% \begin{keysubfigs}{2}{c={\dots continued},cont}
% \keyfig{c={Third of a set},l=fig:contthird}{image2}
% \keyfig{c={Fourth of a set},l=fig:contfourth}{image2}
% \end{keysubfigs}
% \end{dtxexample}
%
%
% \clearpage
% \subsubsection{Margin floats}
% \changes{v0.12}{2016/12/02}{Docs: Margin float examples.}
%
% \gindex{float>margin placement}
% \gindex{margin placement}
%
% When a keyfloat is located [M], it will be placed in the margin.
%
% \DescribeClass{tufte-book}
% When the |tufte-book| class is used, its \env{marginfigure} or \env{margintable}
% environments will be used, otherwise \pkg{keyfloat} provides environments
% of the same name and uses those instead.
%
% \begin{dtxexample}[\Cref{fig:marginfigure}]{The \env{marginfigure} environment\label{ex:marginfigure}}
% \begin{marginfigure}
% \centering
% \includegraphics[width=.75\linewidth]{image}
%
% Some text added by hand.
% \caption{A \env{marginfigure}}
% \label{fig:marginfigure}
% \end{marginfigure}
% \end{dtxexample}
%
%
% \begin{dtxexample}[\Cref{fig:margintable}]{The \env{margintable} environment\label{ex:margintable}}
% \begin{margintable}
% \centering
% \testwidetable
% \caption{A \env{margintable}}
% \label{fig:margintable}
% \end{margintable}
% \end{dtxexample}
%
%
% \begin{dtxexample}[\Cref{fig:keyfigm}]{Using \cs{keyfig}\optn{[M]}\label{ex:keyfigm}}
% \keyfig[M]{c={A \cs{keyfig}\optn{[M]}},l=fig:keyfigm,ft,
% 	t=Additional text.
% 	Text text text text text text.
% 
% 	More paragraphs.
% }{image2}
% \end{dtxexample}
%
%
% \begin{dtxexample}[\Cref{tab:keytablem}]
%	{Using \env{keytable}\optn{[M]} and an offset\label{ex:keytablem}}
% \begin{keytable}[M]{c={A \env{keytable}\optn{[M]}},
% 	l=tab:keytablem,mo=-.9in}
% \centering
% \testwidetable
% \end{keytable}
% \end{dtxexample}
%
% A negative offset was used to shift the table upwards
% \margintag{margin float offset}
% to the top of the example.
%
% To set the minimum-allowed distance between \cs{marginpar}s and margin floats:
% \margintag{distance between floats}
% \gindex{distance between floats}\gindex{float>distance between}
% \begin{sourceverb}
% \setlength{\marginparpush}{3ex}
% \end{sourceverb}
%
%
%
% \clearpage
%
% \subsubsection{Wrapped floats}
% \changes{v0.12}{2016/12/03}{Docs: Wrapped float examples.}
%
% Note: If you see the warning:
% \watchout[\pkg{wrapfig} warning]\gindex{wrapfig=\pkg{wrapfig} collision warning}
% \begin{center}
% |Package wrapfig Warning: Collision between wrapping environments|
% \end{center}
% then \pkg{wrapfig} was not able to wrap the paragraph correctly.
% Try adding \cs{clearpage} or \cs{newpage} before the wrapped object,
% or see the \pkg{needspace} package to automatically insert
% a \cs{newpage} if necessary.
%
% \begin{dtxexample}[\Cref{fig:keyfigw,tab:keytabw}]
%	{Using \cs{keyfig}\optn{[W]} and \cs{keytab}\optn{[W]}\label{ex:keyfigw}}
% \keyfig[W]{c={A \cs{keyfig}\optn{[W]}},
% 	l=fig:keyfigw,ft,lw=.4,wp=I, wo=8em, wn=12,
% 	t={.4\cs{linewidth} wide, placed \optn{I}.}
% }{image2}
% \blindtext

% \keytab[W]{c={A \cs{keytab}\optn{[W]}},l=tab:keytabw,w=.75in,
% }{\testtable}
% \blindtext
% \end{dtxexample}
%
% \begin{dtxexample}[\Cref{fig:keyfigboxw} and the \cs{keyparbox}.]
%	{Using \cs{keyfigbox}\optn{[W]} and \cs{keyparbox}\optn{[W]}\label{ex:keyfigboxw}}
% \keyfigbox[W]{
%   c={A \cs{keyfigbox}\optn{[W]}},
% 	l=fig:keyfigboxw,f,lw=.25,wp=I, wn=7,
% 	t=Text text text text text text text text text
% }{The contents.}
% \blindtext

% \keyparbox[W]{w=1in}{
%   A \cs{keyparbox}[W] and some text.
%   No caption or numbering.
% }
% \blindtext
% \end{dtxexample}
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:keyfigurew,tab:keytablew}]
%	{Using \cs{keyfigure}\optn{[W]} and \cs{keytable}\optn{[W]}\label{ex:keyfiguretablew}}
% \begin{keyfigure}[W]{c={A \cs{keyfigure}\optn{[W]}},
% 	l=fig:keyfigurew,f,w=1.5in, wo=4em,wn=5}
% This is a keyfigure.
% \end{keyfigure}
% \blindtext
%
% \begin{keytable}[W]{c={A \env{keytable}\optn{[W]}},
% 	l=tab:keytablew,w=2in,wp=L,
%   tc=Placed \optn{L} and 2in wide.}
% \centering
% \testwidetable
% \end{keytable}
% \blindtext
% \end{dtxexample}
%
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:keywrapfig}]
%	{Using \env{keywrap} with a \cs{keyfig}\label{ex:keywrapkeyfig}}
% \begin{itemize}
% \item First item.
%     Several lines of text text text text text
%     text text text text text text text text.
% \item \begin{keywrap}{.3\linewidth}{\keyfig{%
%       lw=1,c={Keywrap with \cs{keyfig}},l=fig:keywrapfig%
%     }{image}}
%         Second item.
%
%         These paragraphs are inside the \texttt{keywrap}.
%         A vertical gap appears below if the text is not enough to
%         fill the space next to the \cs{keyfig}.
%     \end{keywrap}
%     Now outside the \env{keywrap},\margintag{notes}\
%     but still in the second item.
%     There is no elegant way to place only part of a paragraph
%     inside a \env{keywrap}.
% \item Third item.
% \end{itemize}
% \end{dtxexample}
%
% \clearpage
%
% \begin{dtxexample}[\Cref{fig:keyfigwlw,fig:keyfigww}]
%   {Using wrap width \optn{ww} and \optn{wlw}\label{ex:keyfigwlw}}
% \keyfig[W]{c={A \cs{keyfig}\optn{[W] with \optn{wlw}}},
%   l=fig:keyfigwlw,ft,lw=.15,wlw=.4,wp=I,
%   t={.15\cs{linewidth} wide, in a .4\cs{linewidth} box.}
% }{image2}
% \blindtext[1]
%
% \keyfig[W]{c={A \cs{keyfig}\optn{[W] with \optn{ww}}},
%   l=fig:keyfigww,ft,w=1cm,ww=3cm,wp=I,
%   t={1cm wide, in a 3cm box.}
% }{image2}
% \blindtext[1]
% \end{dtxexample}
%
%
% \clearpage
% \subsubsection{Custom frames}
%
% \begin{dtxexample}[\Cref{fig:customframe,fig:customlooseframe}]
%	{Custom frames with \pkg{mdframed}\label{ex:customframe}}
% \renewcommand{\KFLTtightframe}[1]{%
% \begin{minipage}{\KFLTimageboxwidth}
% \begin{mdtightframe}%
% #1
% \end{mdtightframe}%
% \end{minipage}
% }
% \setlength{\KFLTtightframewidth}{1pt}
%
% \renewcommand{\KFLTlooseframe}[1]{%
% \begin{mdlooseframe}[leftmargin=.5in,rightmargin=.5in]%
% #1
% \end{mdlooseframe}%
% }
% \setlength{\KFLTlooseframewidth}{4pt}
%
% \keyfig{ft,c=Custom-framed image,l=fig:customframe,r=90}{image}
% \keyfigbox{f,c=Custom loosely-framed box,
%   l=fig:customlooseframe}{A loosely-framed box.}
% \end{dtxexample}
%
% \gindex{frame>mdframed}
% \gindex{mdframed}
%
% \DescribePackage{mdframed}
% \Cref{ex:customframe} shows custom frames
% created with the \pkg{mdframed} package along with \pkg{tikz}.
% Note that \pkg{mdframed} uses the full \cs{linewidth}
% \watchout[\pkg{mdframed} width]
% even if the left/right margins are explicitly set, which
% causes extra vertical space when rotated.
% Because of this, the framed object is enclosed inside a minipage
% whose width is precomputed based on the object itself, then
% set in \cs{KFLTimageboxwidth}.  Any shadow may fall outside this
% box.
% \trouble{rotate>extra space}
% \trouble{mdframed}
%
% See \cref{sec:customframes} for more details.
%
% \begin{dtxexample}[\Cref{fig:customshadow,fig:customlooseshadow}]
%	{Custom shadows with \pkg{fancybox}\label{ex:customshadow}}
% \renewcommand{\KFLTtightframe}[1]{%
% \setlength{\fboxrule}{.4pt}
% \setlength{\fboxsep}{0pt}
% \setlength{\shadowsize}{2pt}
% \shadowbox{#1}%
% }
% \setlength{\KFLTtightframewidth}{0.4pt}
%
% \renewcommand{\KFLTlooseframe}[1]{%
% \setlength{\fboxrule}{.4pt}
% \setlength{\fboxsep}{3pt}
% \setlength{\shadowsize}{2pt}
% \shadowbox{#1}%
% }
% \setlength{\KFLTlooseframewidth}{3.4pt}
%
% \keyfig{ft,c=Custom shadow,l=fig:customshadow}{image}
% \keyfigbox{f,c=Custom loosely-framed shadow,lw=.5,
% 	l=fig:customlooseshadow}{A loosely-framed shadow box.}
% \end{dtxexample}
%
% \gindex{fancybox}
% \gindex{frame>fancybox}
%
% \DescribePackage{fancybox}
% \Cref{ex:customshadow} shows custom shadow frames
% created with the \pkg{fancybox} package.
% This combination respects |lw| and |w|.
%
% See \cref{sec:customframes} for more details.
%
%
%
%
%
% \renewcommand{\KFLTtightframe}[1]{%
% \setlength{\fboxsep}{0pt}%
% \setlength{\fboxrule}{.4pt}%
% \fbox{#1}%
% }
% \setlength{\KFLTtightframewidth}{.4pt}
% 
% \renewcommand{\KFLTlooseframe}[1]{%
% \setlength{\fboxsep}{3pt}%
% \setlength{\fboxrule}{.4pt}%
% \fbox{#1}%
% }
% \setlength{\KFLTlooseframewidth}{3.4pt}
%
%
%
%
%
% \clearpage
% \subsubsection{Artist's name}
%
% \gindex{author's or artist's name}
% \gindex{name>author or artist}
%
% \begin{dtxexample}[\Cref{fig:artist}]{Artist's name — image}
% \keyfig{ft,ap=Mr.,af=First,al=Last,as={~III},
%	tc={\textit{About the illustration.}},
%	c=Artist's name — image,l=fig:artist}{image}
% \end{dtxexample}
%
%
% \begin{dtxexample}[\Cref{fig:artistpar}]{Artist's name — arbitrary contents}
% \tdartistright
% \begin{keyfigure}{f,ap=Mr.,al=Last,
%	c=Artist's name — arbitrary contents,l=fig:artistpar}
% \centering Some text, a quotation, a TikZ\ diagram —
% anything not an image file.
% \end{keyfigure}
% \tdartistcenter
% \end{dtxexample}
%
% The artist's name and optional prefix/suffix are printed below the figure,
% and an index entry is made for the name in (Last, First) format,
% or (Last) if there is no first name.
% If the \pkg{tocdata} package is loaded, the artist's name is also added to
% the List of Figures, and the \pkg{tocdata} \cs{tdname}\dots\ macros
% may be used to align the name.
%
%
%
% \begin{dtxexample}[\Cref{fig:artistcollection}]{Subfloats with an artist}
% \begin{keysubfigs}{2}{
% 	c=Artist's collection, l=fig:artistcollection,
% 	t={Some fully-justified text just for illustrative purposes,
% 	in case you have use for long explanations.
% 	This text may be the full \cs{linewidth} in size. \par
% 	Multiple paragraphs of text are allowed.},
% 	ap=Prefix,af=First,al=Last,as={, Suffix}
% }
% 	\keyfig{c=Artist's First Work}{image}
% 	\keyfig{c=Artist's Second Work,
% 		tc={Commentary about the work.}}{image2}
% \end{keysubfigs}
% \end{dtxexample}
%
% A group of figures may be placed into a subfloat container,
% which may have its own artist keys and additional text.
% Furthermore, each subfloat inside the collection may also have its
% own artist tags and additional text.
%
%
% \clearpage
%
% \subsection{Customization}
%
% \subsubsection{Custom frames}
% \label{sec:customframes}
%
% \gindex{frame>custom}
%
% There are two user-redefinable framing macros: \\
% \hspace*{2em}\cs{KFLTtightframe} and \cs{KFLTlooseframe}
%
% A float's contents are placed into a box,
% which is passed to either of these two macros
% depending on the key |f| or |tf|.
%
% Each macro takes one argument and frames it.
%
% Each macro has a associated \LaTeX\ lengths: \\
% \hspace*{2em}\cs{KFLTtightframewidth} and \cs{KFLTlooseframewidth}
%
% These lengths must be redefined to the expected
% total frame width, equal to the frame thickness plus
% separation.
%
% The default definitions are:
% \begin{sourceverb}
% \newcommand{\KFLTtightframe}[1]{%
%   \setlength{\fboxsep}{0pt}%
%   \setlength{\fboxrule}{.4pt}%
%   \fbox{#1}%
% }
% \setlength{\KFLTtightframewidth}{.4pt}
% 
% \newcommand{\KFLTlooseframe}[1]{%
%   \setlength{\fboxsep}{3pt}%
%   \setlength{\fboxrule}{.4pt}%
%   \fbox{#1}%
% }
% \setlength{\KFLTlooseframewidth}{3.4pt}
% \end{sourceverb}
%
% See \cref{ex:customframe} for an example
% created with the \pkg{mdframed} package,
% and \cref{ex:customshadow} for an example
% created with the \pkg{fancybox} package.
%
%
%
% \subsubsection{Distance between floats and rows}
% \gindex{distance between floats}
% \gindex{subfloat>distance between}
% \gindex{float>distance between}
% \trouble{table>rows too close or far}
% To spread out the distance between floats and/or rows of floats
% \margintag{rows too close/far}
% on a busy page, the following settings may be changed.
% The settings used in this documentation are:
% \begin{sourceverb}
% \setlength{\floatsep}{5ex plus 1ex minus 1ex}
% \setlength{\dblfloatsep}{5ex plus 1ex minus 1ex}
% \end{sourceverb}
%
%
% \subsubsection{Formatting the captions}
%
% ^^A \trouble{caption format}
% To modify the typesetting of the captions, see the \pkg{caption} package.
% \gindex{caption>formatting}
% The settings used in this documentation are:
% \begin{sourceverb}
% % default applied to margin floats:
% \captionsetup{labelfont={small,bf},textfont={small,bf}}
% 
% \captionsetup[figure]{
% 	style=default, justification=centering,
% 	margin=0pt, parskip=0pt, skip=2ex,
% 	labelfont={small,bf},textfont={small,bf}
% }
% 
% \captionsetup[table]{
% 	style=default, justification=centering,
% 	margin=0pt, parskip=0pt, skip=1ex,
% 	labelfont={small,bf},textfont={small,bf}
% }
% 
% \captionsetup[subfigure]{
% 	style=default, justification=centering,
% 	margin=0pt, parskip=0pt, skip=2ex,
% 	labelfont={small},textfont={small}
% }
% 
% \captionsetup[subtable]{
% 	style=default, justification=centering,
% 	margin=0pt, parskip=0pt, skip=1ex,
% 	labelfont={small},textfont={small}
% }
% \end{sourceverb}



% \clearpage
%
% ^^A \StopEventually{\PrintChanges\PrintIndex}
%
% \makeatletter
%
% \StopEventually{
% ^^A \part{Change History and Index}
% ^^A  \part{Change History}
%
%
% \pagestyle{plain}
%
% ^^A Each index has a prologue which creates its own \part, label,
% ^^A and meta index entry.
%   \GlossaryPrologue{
%       \part{Change History}
% ^^A     \section{Chg Hist}
%       \label{sec:changehistory}
%       \sindex[meta]{Change History}
%       \markboth{{Change History}}{{Change History}}
%
%       For the most recent changes, see page \pageref{sec:changesend}.
%
%   }
%   \PrintChanges
%   \phantomsection
%   \label{sec:changesend}
%
%
% ^^A The instructions for the Index of Objects:
%   \IndexPrologue{
%       \clearpage
%       \expandafter\part\expandafter{\indexname}
%       \label{sec:index\indexshortcut}
%       \sindex[meta]{\indexname}
%         \markboth{Index of Objects}{Index of Objects}%
%
%       This is an index of macros, environments, booleans, counters, lengths,
%       packages, classes, options, keys, files, and various other programming objects.
%       Each is listed by itself, and also by category.
%       In some cases, they are further subdivided by [class].
%
%       Numbers written in italic refer to the page
%       where the corresponding entry is described;
%       numbers underlined refer to the
%       \ifcodeline@index
%       code line of the
%       \fi
%       definition.
% ^^A        ; numbers in roman refer to the
% ^^A         \ifcodeline@index
% ^^A         code lines
% ^^A         \else
% ^^A         pages
% ^^A         \fi
% ^^A         where the entry is used.
%   }
%
%   \printindex[idx][Index of Objects]
%
%
% ^^A The instructions for the General Index:
%   \IndexPrologue{
%       \clearpage
%       \expandafter\part\expandafter{\indexname}
%       \label{sec:index\indexshortcut}
%       \sindex[meta]{\indexname}
%
% ^^A      This is an index of instructions and concepts.
% ^^A      Look here when wondering how to do something, and
% ^^A      check the Troubleshooting Index when something goes wrong.
%       This is a general index, including how-to and troubleshooting.
%   }
%
%   \printindex[gen][General Index]
%
%
% ^^A% The instructions for the Troubleshooting Index:
% ^^A%   \IndexPrologue{
% ^^A%       \clearpage
% ^^A%       \expandafter\part\expandafter{\indexname}
% ^^A%       \label{sec:index\indexshortcut}
% ^^A%       \sindex[meta]{\indexname}
% ^^A%
% ^^A%       This index is a sorted reference of problems and solutions.
% ^^A%       In order to make it easier to locate a solution,
% ^^A%       the same issue may be addressed by more than one entry.
% ^^A%
% ^^A%       Entries with higher page numbers are often duplicates of entries with
% ^^A%       lower page numbers, as the same warning may occur within the user manual
% ^^A%       and again within the source code for a given package.
% ^^A%   }
% ^^A%
% ^^A%   \printindex[trb][Troubleshooting Index]
%
%
% ^^A The meta index does not get a meta index entry pointing  to itself:
%   \IndexPrologue{

%       \clearpage
%       \expandafter\part\expandafter{\indexname}
%       \label{sec:index\indexshortcut}
%   }
%
%   \printindex[meta][Index of Indexes]
% }
%
% \makeatother
%
%
%
%
% \section{Code}
% ^^A *source
%
%
%
%
% \subsection{Older packages}
%
% Ensure that \pkg{tocdata}, if loaded, is new enough:
%    \begin{macrocode}
\@ifpackageloaded{tocdata}{
    \@ifpackagelater{tocdata}{2019/03/21}{}{
        \PackageError{keyfloat}
        {%
            The tocdata package is out of date.\MessageBreak
            Update to tocdata v2.02 2019/03/21 or later\MessageBreak
            to use use this version of keyfloat%
        }
        {%
            Please update the tocdata package.  It's worth it!%
        }
    }
}{}
%    \end{macrocode}
%
% \subsection{Prohibited packages}
%
% Prohibits the use of a certain other packages.
%
% \begin{macro}{\KFLT@@prohibitpackage} \marg{packagename}
%    \begin{macrocode}
\newcommand*{\KFLT@@prohibitpackage}[2]{%
\@ifpackageloaded{#1}
{
    \PackageError{keyfloat}
    {%
        The keyfloat package conflicts with the #1\MessageBreak
        package. Remove #1 to use keyfloat.\MessageBreak
        Alternative(s):\MessageBreak
        \space\space#2%
    }
    {%
        Keyfloat uses the caption, subcaption, newfloat, and wrapfig packages.%
    }
}{}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\KFLT@prohibitpackage} \marg{packagename}
%
% Prohibits the use of another package, both now and also \cs{AtBeginDocument}.
%
% \changes{v2.00}{2019/03/11}{Improved package conflict detection.}
%    \begin{macrocode}
\newcommand*{\KFLT@prohibitpackage}[2]{
    \KFLT@@prohibitpackage{#1}{#2}
    \AtBeginDocument{\KFLT@@prohibitpackage{#1}{#2}}
}
%    \end{macrocode}
% \end{macro}
%
%
% The list of prohibited packages:
% \changes{v2.02}{2021/05/18}{Work with \pkg{float}.}
%    \begin{macrocode}
\KFLT@prohibitpackage{floatrow}{caption and subcaption}
\KFLT@prohibitpackage{subfig}{subcaption}
\KFLT@prohibitpackage{subfigure}{subcaption}
\KFLT@prohibitpackage{subfloat}{subcaption}
\KFLT@prohibitpackage{floatflt}{wrapfig}
%    \end{macrocode}
%
%
%
% \subsection{Required packages}
% \changes{v1.00}{2019/01/08}{Removed \pkg{xifthen} dependency.}
%
% \DescribePackage{etoolbox} v2.6 or later
%	for \cs{BeforeBeginEnvironment}, \cs{AfterEndEnvironment}
%    \begin{macrocode}
\RequirePackage{etoolbox}[2011/01/03]%
%    \end{macrocode}
% \DescribePackage{xparse} Argument processing:
%    \begin{macrocode}
\RequirePackage{xparse}
%    \end{macrocode}
% \DescribePackage{keyval} Key processing:
%    \begin{macrocode}
\RequirePackage{xkeyval}
%    \end{macrocode}
% \DescribePackage{graphicx} For \cs{includegraphics} and \pkg{rotating}:
%    \begin{macrocode}
\RequirePackage{graphicx}
%    \end{macrocode}
% \DescribePackage{caption} Handles all caption-related functions:
%    \begin{macrocode}
\RequirePackage{caption}[2010/10/31]% v3.2 to support \phantomcaption
%    \end{macrocode}
% \DescribePackage{subcaption} Derived from \pkg{caption}, used to handle subfloats:
%    \begin{macrocode}
\RequirePackage{subcaption}
%    \end{macrocode}
% \DescribePackage{calc} Used to compute box width minus frame sep and width.
%    \begin{macrocode}
\RequirePackage{calc}
%    \end{macrocode}
% \DescribePackage{rotating} Provides rotation via the \env{turn} environment:
%    \begin{macrocode}
\RequirePackage{rotating}
%    \end{macrocode}
% \DescribePackage{placeins} Provides \FloatBarrier to process existing floats before adding new ones.
%    \begin{macrocode}
\RequirePackage{placeins}
%    \end{macrocode}
% \DescribePackage{wrapfig} Provides figure wrapping code.
%    \begin{macrocode}
\RequirePackage{wrapfig}
%    \end{macrocode}
%


% \DescribePackage{gettitlestring} Used by \pkg{hyperref} and \pkg{nameref}.
%
% \changes{v0.13}{2017/01/14}{Fix: Expands names in references.}
%
% Expand names used in titles:
%    \begin{macrocode}
\PassOptionsToPackage{expand}{gettitlestring}
%    \end{macrocode}


% Rows of floats are created by a simple \env{minipage} environment,
% instead of relying on a preexisting package.  This proved to be
% advantageous when support was added for multiple rows in one
% environment.
%

% \subsection{In-line figures and tables}

% These macros are commonly used by others.

% \begin{environment}{tablehere} Place a table exactly [H].
%
% \shownesting{\env{tablehere}}
%   {\shownesting{\env{minipage}}{Contents}}
%
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
\ProvideDocumentEnvironment{tablehere}{}
{%
    \vskip\intextsep\noindent%
    \minipage{\linewidth}%
    \def\@captype{table}%
    \normalcolor\reset@font\normalsize%
}%
{\endminipage\vskip\intextsep}%
%    \end{macrocode}
% \end{environment}

% \begin{environment}{figurehere} Place a figure exactly [H].
%
% \shownesting{\env{figurehere}}
%   {\shownesting{\env{minipage}}{Contents}}
%
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
\ProvideDocumentEnvironment{figurehere}{}
{%
    \vskip\intextsep\noindent%
    \minipage{\linewidth}%
    \def\@captype{figure}%
    \normalcolor\reset@font\normalsize%
}%
{\endminipage\vskip\intextsep}%
%    \end{macrocode}
% \end{environment}



% \subsection{Row counting and control}

% Used to count position and wrap at end of each row.


% \DescribeCounter{KFLT@numcols} Columns per row.
%    \begin{macrocode}
\newcounter{KFLT@numcols}
%    \end{macrocode}

% \DescribeCounter{KFLT@thiscol} Column currently processing.
% |0| if not yet in a keyfloats or subfloat.
%
%    \begin{macrocode}
\newcounter{KFLT@thiscol}
%    \end{macrocode}

% \DescribeLength{\KFLT@rowboxwidth} How wide is each box in the row.
%    \begin{macrocode}
\newlength{\KFLT@rowboxwidth}
%    \end{macrocode}





% \subsection{Float key handling}

% \DescribeBoolean{KFLT@cont} Continued float?
%    \begin{macrocode}
\newboolean{KFLT@cont}
%    \end{macrocode}
%
% \DescribeKey[main]{cont} Continued float?
%
%    \begin{macrocode}
\define@key{KFLT@keys}{cont}[true]{\setboolean{KFLT@cont}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@c} Caption storage
%    \begin{macrocode}
\newcommand{\KFLT@c}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeBoolean{KFLT@cstar} Starred caption?
%    \begin{macrocode}
\newboolean{KFLT@cstar}
%    \end{macrocode}
%
% \DescribeKey[main]{c} Caption
%
%    \begin{macrocode}
\define@key{KFLT@keys}{c}{%
    \renewcommand{\KFLT@c}{#1}\setboolean{KFLT@cstar}{false}%
}
%    \end{macrocode}
%
% \DescribeKey[main]{cstar} Caption starred?
%
%    \begin{macrocode}
\define@key{KFLT@keys}{cstar}{%
    \renewcommand{\KFLT@c}{#1}\setboolean{KFLT@cstar}{true}%
}
%    \end{macrocode}
%
% \DescribeKey[main]{sc} Short caption
%
%    \begin{macrocode}
\define@key{KFLT@keys}{sc}{%
    \renewcommand{\KFLT@sc}{#1}%
    \setboolean{KFLT@scgiven}{true}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@sc} Short caption storage
%    \begin{macrocode}
\newcommand{\KFLT@sc}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeBoolean{KFLT@scgiven} Was a short caption given?
%    \begin{macrocode}
\newboolean{KFLT@scgiven}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@type} Float type: ``|figure|'', ``|table|''
%    \begin{macrocode}
\newcommand*{\KFLT@type}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{l} Label
%    \begin{macrocode}
\define@key{KFLT@keys}{l}{\renewcommand{\KFLT@l}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@l} Label storage
%    \begin{macrocode}
\newcommand*{\KFLT@l}{}
%    \end{macrocode}
% \end{macro}
%
%
% For the artist/author keys:
%
% \DescribeKey[main]{ap} Artist prefix
%    \begin{macrocode}
\define@key{KFLT@keys}{ap}{\renewcommand{\KFLT@ap}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@ap} Storage for artist prefix
%    \begin{macrocode}
\newcommand*{\KFLT@ap}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{af} Artist first name
%    \begin{macrocode}
\define@key{KFLT@keys}{af}{\renewcommand{\KFLT@af}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@af} Storage for artist first name
%    \begin{macrocode}
\newcommand*{\KFLT@af}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{al} Artist last name
%    \begin{macrocode}
\define@key{KFLT@keys}{al}{\renewcommand{\KFLT@al}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@al} Storage for artist last name
%    \begin{macrocode}
\newcommand*{\KFLT@al}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{as} Artist suffix
%    \begin{macrocode}
\define@key{KFLT@keys}{as}{\renewcommand{\KFLT@as}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@as} Storage for artist suffix
%    \begin{macrocode}
\newcommand*{\KFLT@as}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{aup} Author prefix
%    \begin{macrocode}
\define@key{KFLT@keys}{aup}{\renewcommand{\KFLT@aup}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@aup} Storage for author prefix
%    \begin{macrocode}
\newcommand*{\KFLT@aup}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{auf} Author first name
%    \begin{macrocode}
\define@key{KFLT@keys}{auf}{\renewcommand{\KFLT@auf}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@auf} Storage for author first name
%    \begin{macrocode}
\newcommand*{\KFLT@auf}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{aul} Author last name
%    \begin{macrocode}
\define@key{KFLT@keys}{aul}{\renewcommand{\KFLT@aul}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@al} Storage for author last name
%    \begin{macrocode}
\newcommand*{\KFLT@aul}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[main]{aus} Author suffix
%    \begin{macrocode}
\define@key{KFLT@keys}{aus}{\renewcommand{\KFLT@aus}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@aus} Storage for author suffix
%    \begin{macrocode}
\newcommand*{\KFLT@aus}{}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \begin{macro}{\KFLT@textalign} Storage for text alignment.
%
% Used for the additional text in the float.
%    \begin{macrocode}
\newcommand*{\KFLT@textalign}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KFLT@t} Additional text storage
%
% Used for the additional text in the float.
%    \begin{macrocode}
\newcommand{\KFLT@t}{}
%    \end{macrocode}
% \end{macro}
%
%
% Create replacement macros in case \pkg{tocdata} is not loaded:
% \changes{v0.12}{2016/12/02}{Adapts to older version of tocdata.}
% \changes{v2.00}{2019/03/20}{Adjustments for \pkg{tocdata} v2.00.}
%    \begin{macrocode}
\providecommand{\tdartisttextjustify}{}
\providecommand{\tdartisttextcenter}{}
\providecommand{\tdartisttextleft}{}
\providecommand{\tdartisttextright}{}
\providecommand{\tdauthortextjustify}{}
\providecommand{\tdauthortextcenter}{}
\providecommand{\tdauthortextleft}{}
\providecommand{\tdauthortextright}{}
\providecommand{\tdartistjustify}{}
\providecommand{\tdartistcenter}{}
\providecommand{\tdartistleft}{}
\providecommand{\tdartistright}{}
\providecommand{\tdauthorjustify}{}
\providecommand{\tdauthorcenter}{}
\providecommand{\tdauthorleft}{}
\providecommand{\tdauthorright}{}
%    \end{macrocode}
%
%
% \DescribeKey[main]{t} Additional text, justified alignment.
%    \begin{macrocode}
\define@key{KFLT@keys}{t}{%
    \renewcommand{\KFLT@t}{#1}%
    \renewcommand{\KFLT@textalign}{}%
}
%    \end{macrocode}
%
%
% \DescribeKey[main]{tc} Additional text, centered alignment.
%    \begin{macrocode}
\define@key{KFLT@keys}{tc}{%
    \renewcommand{\KFLT@t}{#1}%
    \renewcommand{\KFLT@textalign}{\centering}%
}
%    \end{macrocode}
%
%
% \DescribeKey[main]{tr} Additional text, aligned to the right.
%    \begin{macrocode}
\define@key{KFLT@keys}{tr}{%
    \renewcommand{\KFLT@t}{#1}%
    \renewcommand{\KFLT@textalign}{\raggedleft}%
}
%    \end{macrocode}
%
%
% \DescribeKey[main]{tl} Additional text, aligned to the left.
%    \begin{macrocode}
\define@key{KFLT@keys}{tl}{%
    \renewcommand{\KFLT@t}{#1}%
    \renewcommand{\KFLT@textalign}{\raggedright}%
}
%    \end{macrocode}
%
%
% \DescribeKey[main]{lw} Fraction of \cs{linewidth}
%    \begin{macrocode}
\define@key{KFLT@keys}{lw}{%
    \renewcommand{\KFLT@lw}{#1}%
    \setlength{\KFLT@w}{0pt}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@lw} Fraction of linewidth storage: ``|.5|''
%    \begin{macrocode}
\newcommand*{\KFLT@lw}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{w} Fixed width
%    \begin{macrocode}
\define@key{KFLT@keys}{w}{%
    \setlength{\KFLT@w}{#1}%
    \renewcommand{\KFLT@lw}{}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@w} Width storage: ``3cm''
%    \begin{macrocode}
\newlength{\KFLT@w}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{h} Fixed height
%    \begin{macrocode}
\define@key{KFLT@keys}{h}{\setlength{\KFLT@h}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@h} Height storage: ``2in''
%    \begin{macrocode}
\newlength{\KFLT@h}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{kar} Keep aspect ratio
% \changes{v2.06}{2021/06/25}{Added \optn{kar}.}
%    \begin{macrocode}
\define@key{KFLT@keys}{kar}[false]{%
    \renewcommand{\KFLT@keepaspectratio}{keepaspectratio}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@keepaspectratio} Stores ``\optn{keepaspectratio}'' if set.
% \changes{v2.06}{2021/06/25}{Added \optn{kar}.}
%    \begin{macrocode}
\newcommand{\KFLT@keepaspectratio}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{s} Scale
%    \begin{macrocode}
\define@key{KFLT@keys}{s}{\renewcommand{\KFLT@s}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@s} Scale storage: ``3''
%    \begin{macrocode}
\newcommand*{\KFLT@s}{1}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{r} Angle.  90 is counter-clockwise 90 degrees.
%    \begin{macrocode}
\define@key{KFLT@keys}{r}{\renewcommand{\KFLT@r}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@r} Angle storage: ``90''
%    \begin{macrocode}
\newcommand*{\KFLT@r}{0}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{f} Frame the image with \cs{KFLTlooseframe}.
%    \begin{macrocode}
\define@key{KFLT@keys}{f}[true]{\setboolean{KFLT@f}{#1}}
%    \end{macrocode}
%
% \DescribeBoolean{KFLT@f} Frame the image?
%    \begin{macrocode}
\newboolean{KFLT@f}
%    \end{macrocode}
%
%
% \DescribeKey[main]{ft} Tightly frame the image using \cs{KFLTtightframe}.
%	This is useful for photographs, or diagrams which
%	already have built-in margins.
%    \begin{macrocode}
\define@key{KFLT@keys}{ft}[true]{\setboolean{KFLT@ft}{#1}}
%    \end{macrocode}
%
% \DescribeBoolean{KFLT@ft} Tightly frame the image?
%    \begin{macrocode}
\newboolean{KFLT@ft}
%    \end{macrocode}


% \DescribeKey[main]{stretch} Set \cs{arraystretch} inside the table environment.
%    \begin{macrocode}
\define@key{KFLT@keys}{stretch}{\renewcommand{\KFLT@stretch}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@stretch} Storage for \cs{arraystretch}.
%    \begin{macrocode}
\newcommand*{\KFLT@stretch}{1}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{mo} Set vertical offset for a margin float.
% \changes{v0.12}{2016/12/03}{Added \optn{mo} key.}
%    \begin{macrocode}
\define@key{KFLT@keys}{mo}{\setlength{\KFLT@mo}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@mo} Storage for the vertical margin offset.
%    \begin{macrocode}
\newlength{\KFLT@mo}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{wn} Set wrap number of narrow lines for a wrapped float.
%
% \changes{v2.04}{2021/06/08}{Added \optn{wn} key.}
%    \begin{macrocode}
\define@key{KFLT@keys}{wn}{\renewcommand{\KFLT@wn}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@wn} Storage for the wrap placement.
%    \begin{macrocode}
\newcommand{\KFLT@wn}{}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{wp} Set wrap placement for a wrapped float.
%
% See \cref{tab:wrapplacement} on \cpageref{tab:wrapplacement}.
% 
% \changes{v0.12}{2016/12/03}{Added \optn{wp} key.}
%    \begin{macrocode}
\define@key{KFLT@keys}{wp}{\renewcommand{\KFLT@wp}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@wp} Storage for the wrap placement.
%    \begin{macrocode}
\newcommand{\KFLT@wp}{O}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{wo} Set wrap overhang for a wrapped float.
%
% \changes{v2.04}{2021/06/08}{Added \optn{wo} key.}
%    \begin{macrocode}
\define@key{KFLT@keys}{wo}{\renewcommand{\KFLT@wo}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@wo} Storage for the wrap placement.
%    \begin{macrocode}
\newcommand{\KFLT@wo}{\wrapoverhang}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{wlw} Wrapped figure, fraction of \cs{linewidth}
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
%    \begin{macrocode}
\define@key{KFLT@keys}{wlw}{%
    \renewcommand{\KFLT@wlw}{#1}%
    \setlength{\KFLT@ww}{0pt}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@wlw} Wrapped figure, fraction of linewidth storage: ``|.5|''
%    \begin{macrocode}
\newcommand*{\KFLT@wlw}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[main]{ww} Wrapped figure, fixed width
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
%    \begin{macrocode}
\define@key{KFLT@keys}{ww}{%
    \setlength{\KFLT@ww}{#1}%
    \renewcommand{\KFLT@wlw}{}%
}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@ww} Wrapped figure, width storage: ``3cm''
%    \begin{macrocode}
\newlength{\KFLT@ww}
%    \end{macrocode}
% \end{macro}


% \DescribeKey[main]{va} Set vertical alignment of the outermost minipage container.
%
% \changes{v0.15}{2017/05/09}{Added vertical alignment key \optn{va}.}
%    \begin{macrocode}
\define@key{KFLT@keys}{va}{\renewcommand{\KFLT@va}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@va} Storage for the vertical alignment.
%    \begin{macrocode}
\newcommand{\KFLT@va}{c}
%    \end{macrocode}
% \end{macro}





% \subsection{Nesting control}

% \DescribeCounter{KFLT@keyfloatdepth} Depth inside a keyfigs environment
%    \begin{macrocode}
\newcounter{KFLT@keyfloatdepth}
\setcounter{KFLT@keyfloatdepth}{0}
%    \end{macrocode}

% \DescribeBoolean{KFLT@inkeysubfloats} Inside a \env{keysubfigs} environment?
%    \begin{macrocode}
\newboolean{KFLT@inkeysubfloats}
\setboolean{KFLT@inkeysubfloats}{false}
%    \end{macrocode}



% \subsection{Subfloat key handling}
%
% These keys are for the container holding a collection of subfigures.

% \DescribeBoolean{KFLT@subgrpcont} Continued float?
%    \begin{macrocode}
\newboolean{KFLT@subgrpcont}{}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{cont} Continued float
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{cont}[true]{%
    \setboolean{KFLT@subgrpcont}{#1}%
}
%    \end{macrocode}

% \begin{macro}{\KFLT@subgrpc} Sub-caption storage
%    \begin{macrocode}
\newcommand{\KFLT@subgrpc}{}
%    \end{macrocode}
% \end{macro}

% \DescribeBoolean{KFLT@subgrpcstart} Sub-caption starred?
%    \begin{macrocode}
\newboolean{KFLT@subgrpcstar}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{c} Caption
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{c}{%
    \renewcommand{\KFLT@subgrpc}{#1}\setboolean{KFLT@subgrpcstar}{false}%
}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{cstar} Starred caption?
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{cstar}{%
    \renewcommand{\KFLT@subgrpc}{#1}\setboolean{KFLT@subgrpcstar}{true}%
}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{sc} Short caption
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{sc}{%
    \renewcommand{\KFLT@subgrpsc}{#1}%
    \setboolean{KFLT@subgrpscgiven}{true}%
}
%    \end{macrocode}

% \begin{macro}{\KFLT@subgrpsc} Sub-shortcaption storage
%    \begin{macrocode}
\newcommand{\KFLT@subgrpsc}{}
%    \end{macrocode}
% \end{macro}

% \DescribeBoolean{KFLT@subgrpscgiven} Sub-shortcaption was given?
%    \begin{macrocode}
\newboolean{KFLT@subgrpscgiven}
%    \end{macrocode}

% \begin{macro}{\KFLT@subgrptype} Subfloats collection type storage:
%	``|figure|'', ``|table|''
%    \begin{macrocode}
\newcommand*{\KFLT@subgrptype}{}
%    \end{macrocode}
% \end{macro}


%
% \DescribeKey[subfloat container]{l} Label
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{l}{\renewcommand{\KFLT@subgrpl}{#1}}
\newcommand*{\KFLT@subgrpl}{}
%    \end{macrocode}
%
%
%
% \begin{macro}{\KFLT@subgrptextalign} Storage for text alignment.
%
% Used for the additional text in the float.
%    \begin{macrocode}
\newcommand*{\KFLT@subgrptextalign}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KFLT@subgrpt} Additional text storage
%
% Used for the additional text in the float.
%    \begin{macrocode}
\newcommand{\KFLT@subgrpt}{}
%    \end{macrocode}
% \end{macro}
%
%
% \DescribeKey[subfloat container]{t} Additional text — full justification
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{t}{%
    \renewcommand{\KFLT@subgrpt}{#1}%
    \renewcommand{\KFLT@subgrptextalign}{}%
}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{t} Additional text — center justification
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{tc}{%
    \renewcommand{\KFLT@subgrpt}{#1}%
    \renewcommand{\KFLT@subgrptextalign}{\centering}%
}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{t} Additional text — aligned left
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{tl}{%
    \renewcommand{\KFLT@subgrpt}{#1}%
    \renewcommand{\KFLT@subgrptextalign}{\raggedright}%
}
%    \end{macrocode}
%
% \DescribeKey[subfloat container]{t} Additional text — aligned right
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{tr}{%
    \renewcommand{\KFLT@subgrpt}{#1}%
    \renewcommand{\KFLT@subgrptextalign}{\raggedleft}%
}
%    \end{macrocode}
%
%
%
% For the \pkg{tocdata} package:
%
% \DescribeKey[subfloat container]{ap} Artist prefix
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{ap}{\renewcommand{\KFLT@subgrpap}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpap} Storage for artist prefix
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpap}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{af} Artist first name
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{af}{\renewcommand{\KFLT@subgrpaf}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpaf} Storage for artist first name
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpaf}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{al} Artist last name
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{al}{\renewcommand{\KFLT@subgrpal}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpal} Storage for artist last name
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpal}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{as} Artist suffix
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{as}{\renewcommand{\KFLT@subgrpas}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpas} Storage for artist suffix
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpas}{}
%    \end{macrocode}
% \end{macro}

% \DescribeKey[subfloat container]{aup} Author prefix
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{aup}{\renewcommand{\KFLT@subgrpaup}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpaup} Storage for author prefix
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpaup}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{auf} Author first name
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{auf}{\renewcommand{\KFLT@subgrpauf}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpauf} Storage for author first name
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpauf}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{aul} Author last name
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{aul}{\renewcommand{\KFLT@subgrpaul}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpaul} Storage for author last name
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpaul}{}
%    \end{macrocode}
% \end{macro}
%
% \DescribeKey[subfloat container]{aus} Author suffix
%    \begin{macrocode}
\define@key{KFLT@subgrpkeys}{aus}{\renewcommand{\KFLT@subgrpaus}{#1}}
%    \end{macrocode}
%
% \begin{macro}{\KFLT@subgrpaus} Storage for author suffix
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpaus}{}
%    \end{macrocode}
% \end{macro}


% \subsection{Computing image width}

% \DescribeLength{\KFLT@imagewidth} Computed width of the image
%    \begin{macrocode}
\newlength{\KFLT@imagewidth}
%    \end{macrocode}

% \DescribeLength{\KFLT@boxwidth} Computed width of the container box
%    \begin{macrocode}
\newlength{\KFLT@boxwidth}
%    \end{macrocode}
%
% \DescribeLength{\KFLT@wrapwidth} Computed width of the wrapped figure
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
%    \begin{macrocode}
\newlength{\KFLT@wrapwidth}
%    \end{macrocode}

%
% \begin{macro}{\KFLT@findwidths} Figure out how wide to make an image and its container
%    \begin{macrocode}
\newcommand*{\KFLT@findwidths}{%
%    \end{macrocode}
%
% Default to a box of full \cs{linewidth} minus the potential frame:
%    \begin{macrocode}
    \ifbool{KFLT@ft}% tight frame?
        {\setlength{\KFLT@boxwidth}{\linewidth - 2\KFLTtightframewidth}}%
        {% not tight frame
            \ifbool{KFLT@f}% loose frame?
                {\setlength{\KFLT@boxwidth}{\linewidth - 2\KFLTlooseframewidth}}%
                {\setlength{\KFLT@boxwidth}{\linewidth}}% no frame
        }% not tight frame
%    \end{macrocode}
%
% Several width options exist.  First see if width was given:
%    \begin{macrocode}
    \ifdimgreater{\KFLT@w}{0pt}%
%    \end{macrocode}
%
%  Width was given:
%    \begin{macrocode}
        {\setlength{\KFLT@imagewidth}{\KFLT@w}}%
        {% width not given
%    \end{macrocode}
%
% Use full \cs{linewidth} or only a fraction:
%    \begin{macrocode}
            \ifcsempty{KFLT@lw}%
                {\setlength{\KFLT@imagewidth}{\KFLT@boxwidth}}%
                {\setlength{\KFLT@imagewidth}{\KFLT@lw\KFLT@boxwidth}}%
        }% width not given
%    \end{macrocode}
%
% The wrap width is the same as the image width, unless specified:
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
%    \begin{macrocode}
    \ifdimgreater{\KFLT@ww}{0pt}%
%    \end{macrocode}
%
%  Width was given:
%    \begin{macrocode}
        {%
            \setlength{\KFLT@wrapwidth}{\KFLT@ww}}%
        {% width not given
%    \end{macrocode}
%
% If \optn{wlw}, use a fraction of line width,
% else if none given use the same as the image width.
%    \begin{macrocode}
            \ifcsempty{KFLT@wlw}%
                {%
                    \setlength{\KFLT@wrapwidth}{\KFLT@imagewidth}}%
                {%
                    \setlength{\KFLT@wrapwidth}{\KFLT@wlw\KFLT@boxwidth}}%
        }% width not given
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Framing and rotation}
%
%
% A user-redefinable macro and length to tightly frame the contents.
%
% \begin{description}
% \item [\cs{KFLTtightframe}:] Redefine to a macro which frames its contents.
% \item [\cs{KFLTtightframewidth}:] Redefine to the total width of the new.
%   frame and its separation.
% \item[\cs{KFLTlooseframe}:] Redefine to a macro which frames its contents.
% \item[\cs{KFLTlooseframewidth}:] Redefine to the total width of the new
%   frame and its separation.
% \end{description}
%
% \begin{macro}{\KFLTtightframe} \marg{contents}
%    \begin{macrocode}
\newcommand{\KFLTtightframe}[1]{%
    \setlength{\fboxsep}{0pt}%
    \setlength{\fboxrule}{.4pt}%
    \fbox{#1}%
}

%    \end{macrocode}
% \end{macro}
%
% \DescribeLength{\KFLTtightframewidth} Must be set to the combined width of
%   the tight frame and separation used by \cs{KFLTtightframe}.
%    \begin{macrocode}
\newlength{\KFLTtightframewidth}
\setlength{\KFLTtightframewidth}{.4pt}
%    \end{macrocode}
%
%
% \begin{macro}{\KFLTlooseframe} \marg{contents}
%
% A user-redefinable macro and length to loosely frame the contents.
%
%    \begin{macrocode}
\newcommand{\KFLTlooseframe}[1]{%
    \setlength{\fboxsep}{3pt}%
    \setlength{\fboxrule}{.4pt}%
    \fbox{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \DescribeLength{\KFLTlooseframewidth} Must be set to the combined width of
% the loose frame and separation used by \cs{KFLTlooseframe}.
%    \begin{macrocode}
\newlength{\KFLTlooseframewidth}
\setlength{\KFLTlooseframewidth}{3.4pt}
%    \end{macrocode}
%
%
% \begin{macro}{\KFLT@frame} \marg{contents}
%
% Frames the contents according to the |f| key.  To be nested for further processing.
% \changes{v2.07}{2022/01/08}{Reduced hbox warnings.}
%    \begin{macrocode}
\newcommand{\KFLT@frame}[1]
{%
    \ifbool{KFLT@ft}%
        {%
            {%
                \hfuzz=\linewidth%
                \KFLTtightframe{#1}%
            }%
        }%
        {% not tightframe
            \ifbool{KFLT@f}%
                {%
                    {%
                        \hfuzz=\linewidth%
                        \KFLTlooseframe{#1}%
                    }%
                }%
                {#1}% no frame
        }% not looseframe
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{KFLT@findenvboxwidth}
% Figures the width of the contents of \cs{KFLT@envbox} plus the frame:
%    \begin{macrocode}
\newcommand{\KFLT@findenvboxwidth}{%
    \settowidth{\KFLTimageboxwidth}{\usebox{\KFLT@envbox}}%
    \ifbool{KFLT@ft}%
        {\addtolength{\KFLTimageboxwidth}{2\KFLTtightframewidth}}%
        {% not tightframe
            \ifbool{KFLT@f}%
                {\addtolength{\KFLTimageboxwidth}{2\KFLTlooseframewidth}}%
                {}% no frame
        }% not looseframe
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \subsection{A graphics image from a file}
%
% \DescribeLength{\KFLT@testwidth} Used to find the width of a graphics image.
%    \begin{macrocode}
\newlength{\KFLT@testwidth}
%    \end{macrocode}
%
%
% \begin{macro}{\KFLT@includegraphics} \oarg{keys} \marg{file name}
%
% Issue a warning if the image will be too wide, then display the image.
%    \begin{macrocode}
\newcommand*{\KFLT@includegraphics}[2][]{%
%    \end{macrocode}
%
% Find the width of the image:
%    \begin{macrocode}
    \settowidth{\KFLT@testwidth}{\includegraphics[#1]{#2}}%
%    \end{macrocode}
%
% Avoid rounding errors when using the \optn{lw} option,
% and also avoid the exact line width in case images are side-by-side.
%
% If close to \cs{linewidth}, use slightly less than the \cs{linewidth}:
% \changes{v2.06}{2021/06/25}{Clip if close to \cs{linewidth}.}
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifdimgreater{\KFLT@testwidth}{\linewidth-.01pt}} and
        test {\ifdimless{\KFLT@testwidth}{\linewidth+1pt}}
    }%
        {\setlength{\KFLT@testwidth}{\linewidth-.01pt}}%
        {}%
%    \end{macrocode}
%
%
% Issue a warning if wider than the \cs{linewidth}:
% \changes{v2.06}{2021/06/25}{Warn if image too wide.}
%    \begin{macrocode}
    \ifdimgreater{\KFLT@testwidth}{\linewidth}{%
        \PackageWarning{keyfloat}{The image is wider than the line width}%
    }{}%
%    \end{macrocode}
%
% Display the image:
%    \begin{macrocode}
    \includegraphics[#1]{#2}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\KFLT@onefigureimage} \marg{filename}
%
% Create an image with size, frame, and turn.
%
% \shownesting{\cs{KFLT@onefigureimage}}
% {
%   \shownesting{\env{turn}}
%   {
%       \shownesting{\cs{KFLT@frame} $\to$ \cs{fbox}}
%           {\cs{KFLT@includegraphics}}
%   }
% }
%
% \changes{v2.00}{2019/03/12}{Filename in arg instead of \cs{KFLT@i}.}
% \changes{v2.06}{2021/06/25}{Added \optn{kar}.}
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@onefigureimage}{m}%
{%
%    \end{macrocode}
% Several possible combinations of linewidth, width, and height are available,
% and each is treated separately.
% Scaling and width/height are done first, then framing, then rotation.
%    \begin{macrocode}
    \begin{lrbox}{\KFLT@envbox}%
%    \end{macrocode}
% Handle the |lw| key.  If |lw| is used, width and height are ignored.
%    \begin{macrocode}
    \ifdefempty{\KFLT@lw}%
    {% not linewidth
%    \end{macrocode}
% Handle the |w| key, which may be used along with the |h| key:
%    \begin{macrocode}
        \ifdimgreater{\KFLT@w}{0pt}%
        {% width is given
            \ifdimgreater{\KFLT@h}{0pt}%
%    \end{macrocode}
% Width and height are both given:
%    \begin{macrocode}
            {% w and h
                \KFLT@includegraphics[%
                    scale=\KFLT@s,%
                    width=\KFLT@imagewidth,%
                    height=\KFLT@h,%
                    \KFLT@keepaspectratio,%
                ]{#1}%
            }% w and h
%    \end{macrocode}
% Only width:
%    \begin{macrocode}
            {% only w
                \KFLT@includegraphics[%
                    scale=\KFLT@s,%
                    width=\KFLT@imagewidth,%
                    \KFLT@keepaspectratio,%
                ]{#1}%
            }% only w
        }% width is given
%    \end{macrocode}
% Width was not given, so maybe handle |h| alone:
%    \begin{macrocode}
        {% width is not given
            \ifdimgreater{\KFLT@h}{0pt}%
%    \end{macrocode}
% |h| was given:
%    \begin{macrocode}
                {%
                    \KFLT@includegraphics[%
                        scale=\KFLT@s,%
                        height=\KFLT@h,%
                        \KFLT@keepaspectratio,%
                    ]{#1}%
                }%
%    \end{macrocode}
% If none were given, use the image's natural size:
%    \begin{macrocode}
                {%
                    \KFLT@includegraphics[%
                        scale=\KFLT@s,%
                        \KFLT@keepaspectratio,%
                    ]{#1}%
                }%
        }% width is not given
    }% not linewidth
    {% linewidth given
%    \end{macrocode}
% \changes{v2.06}{2021/06/25}{Fix: \optn{lw} with \optn{h}.}
%    \begin{macrocode}
        \ifdimgreater{\KFLT@h}{0pt}%
        {% lw and h given
            \KFLT@includegraphics[%
                scale=\KFLT@s,%
                width=\KFLT@imagewidth,%
                height=\KFLT@h,%
                \KFLT@keepaspectratio,%
            ]{#1}%
        }%
        {% lw w/o h
            \KFLT@includegraphics[%
                scale=\KFLT@s,%
                width=\KFLT@imagewidth,%
                \KFLT@keepaspectratio,%
            ]{#1}%
        }%
    }%
    \end{lrbox}%
    \unskip%
    \KFLT@findenvboxwidth%
    \begin{turn}{\KFLT@r}%
    \KFLT@frame{\usebox{\KFLT@envbox}}%
    \unskip%
    \end{turn}%
}
%    \end{macrocode}
% \end{macro}




% \subsection{Printing the caption}
%
%
% \begin{macro}{\KFLT@dosimplecaption} \marg{star?} \marg{short cap or |-NO VALUE-|} \marg{caption}
%
% Calls \cs{caption} depending on several combinations of star and short captions
% being given.
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@dosimplecaption}{m m m}
{%
    \unskip%
    \IfBooleanTF{#1}% star?
        {\IfValueTF{#2}{\caption*[#2]{#3}}{\caption*{#3}}}%
        {\IfValueTF{#2}{\caption[#2]{#3}}{\caption{#3}}}%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% There are two versions of \cs{KFLT@docaption},
% depending on whether \pkg{tocdata} is loaded.
%
%    \begin{macrocode}
\@ifpackageloaded{tocdata}
{% tocdata loaded
%    \end{macrocode}
%
%
% \begin{macro}{\KFLT@@docaption} {1: artist/author} \marg{2: empty or ''u''}
%       \marg{3: star?}
%       \marg{4: short caption} \marg{5: caption}
%       \marg{6: \mainsubarg}
% \changes{v2.00}{2019/03/19}{Factored.}
%    \begin{macrocode}
\newcommand*{\KFLT@@docaption}[6]{%
%    \end{macrocode}
% (\pkg{tocdata} does not expand its text argument before checking for empty.)
%    \begin{macrocode}
\addvspace{\smallskipamount}%
\ifcsempty{KFLT@#6t}{%
    \IfBooleanTF{#3}%
    {%
        \csuse{caption#1}*[#4]{#5}%
            []%
            [\csuse{KFLT@#6a#2p}]%
            {\csuse{KFLT@#6a#2f}}%
            {\csuse{KFLT@#6a#2l}}%
            [\csuse{KFLT@#6a#2s}]%
    }{%
        \csuse{caption#1}[#4]{#5}%
            []%
            [\csuse{KFLT@#6a#2p}]%
            {\csuse{KFLT@#6a#2f}}%
            {\csuse{KFLT@#6a#2l}}%
            [\csuse{KFLT@#6a#2s}]%
    }%
}{%
    \ifcsstring{KFLT@#6textalign}{}{\csuse{td#1textjustify}}{}%
    \ifcsstring{KFLT@#6textalign}{\centering}{\csuse{td#1textcenter}}{}%
    \ifcsstring{KFLT@#6textalign}{\raggedleft}{\csuse{td#1textright}}{}%
    \ifcsstring{KFLT@#6textalign}{\raggedright}{\csuse{td#1textleft}}{}%
    \IfBooleanTF{#3}%
    {%
        \csuse{caption#1}*[#4]{#5}%
            [\csuse{KFLT@#6t}]%
            [\csuse{KFLT@#6a#2p}]%
            {\csuse{KFLT@#6a#2f}}%
            {\csuse{KFLT@#6a#2l}}%
            [\csuse{KFLT@#6a#2s}]%
    }{%
        \csuse{caption#1}[#4]{#5}%
            [\csuse{KFLT@#6t}]%
            [\csuse{KFLT@#6a#2p}]%
            {\csuse{KFLT@#6a#2f}}%
            {\csuse{KFLT@#6a#2l}}%
            [\csuse{KFLT@#6a#2s}]%
    }%
}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KFLT@docaption} * \oarg{2:short caption} \marg{3:caption} \marg{4: \mainsubarg}
%
% Depending on whether the \pkg{tocdata} package is present,
% and an artist is specified,
% use either \cs{caption} or \cs{captionartist}.
%
% The fourth argument is |{}| if a regular float, or
% |subgrp| if \env{keysubfigs} or \env{keysubtabs}.
%
% See Table \ref{tab:captions} for the possible combinations of
% the caption-related keys: |c|, |cstar|, and |sc|.
%
% \changes{v0.14}{2017/02/09}{Fix: No index entry if no artist given.}
%
% With \pkg{tocdata}:
%
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@docaption}{s o m m}
{%
%    \end{macrocode}
% Is the last name empty?  Assume no artist if so.
%    \begin{macrocode}
    \ifcsempty{KFLT@#4al}%
    {% figure w/o artist
        \ifcsempty{KFLT@#4aul}%
        {% figure w/o artist or author
%    \end{macrocode}
% A figure without an artist or author uses the simple caption.
%    \begin{macrocode}
            \KFLT@dosimplecaption{#1}{#2}{#3}%
        }% figure w/o artist or author
%    \end{macrocode}
% A figure with an author uses the \pkg{tocdata} \cs{captionauthor} macro,
% which also creates an index entry.
%    \begin{macrocode}
        {% figure w/ author
            \KFLT@@docaption{author}{u}{#1}{#2}{#3}{#4}%
        }% figure w/ author
    }% figure w/o artist
    {% figure with an artist
%    \end{macrocode}
% A figure with an artist uses the \pkg{tocdata} \cs{captionartist} macro,
% which also creates an index entry.
%    \begin{macrocode}
        \KFLT@@docaption{artist}{}{#1}{#2}{#3}{#4}%
    }% figure with an artist
}% KFLT@tocdata
}% tocdata loaded
{% no tocdata
%    \end{macrocode}
% \end{macro}
%
% Without \pkg{tocdata}:
%
% \begin{macro}{\KFLT@docaption} * \oarg{2:short caption} \marg{3:caption} \marg{4: \mainsubarg}
% \changes{v2.00}{2019/03/19}{Added support for authors.}
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@docaption}{s o m m}
{%
%    \end{macrocode}
% If \pkg{tocdata} is not loaded, use a simple caption.
%    \begin{macrocode}
    \KFLT@dosimplecaption{#1}{#2}{#3}%
%    \end{macrocode}
% Create an index entry depending on whether there is a last, first name:
%    \begin{macrocode}
    \ifcsempty{KFLT@#4al}%
    {%
        \ifcsempty{KFLT@#4aul}%
        {}%
        {% yes author
            \ifcsempty{KFLT@#4auf}%
                {\index{\csuse{KFLT@#4aul}}}%
                {\index{\csuse{KFLT@#4aul}, \csuse{KFLT@#4auf}}}%
        }% yes author
    }% no artist
    {% yes artist
        \ifcsempty{KFLT@#4af}%
            {\index{\csuse{KFLT@#4al}}}%
            {\index{\csuse{KFLT@#4al}, \csuse{KFLT@#4af}}}%
    }% yes artist
}% KFLT@docaption
}% no tocdata
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@caption} \marg{\mainsubarg}
%
% Caption-creation logic.
%
% The argument is |{}| if a regular float, or
% |subgrp| if \env{keysubfigs} or \env{keysubtabs}.
%
% See Table \ref{tab:captions} for the possible combinations of
% the caption-related keys: |c|, |cstar|, and |sc|.
%    \begin{macrocode}
\newcommand{\KFLT@caption}[1]{%
%    \end{macrocode}
% A starred caption is printed but not numbered.
%    \begin{macrocode}
    \ifbool{KFLT@#1cstar}% starred caption?
%    \end{macrocode}
% This is a starred caption:
%    \begin{macrocode}
    {%starred caption
%    \end{macrocode}
% A key given as |cstar={}| yields a float with no caption at all.
%    \begin{macrocode}
        \ifcsempty{KFLT@#1c}% cstar={}?
        {}%
%    \end{macrocode}
% Non-empty starred caption might have a \acro{LOF} entry
% if it has a short caption |sc| key:
%    \begin{macrocode}
        {% non-empty starred caption
            \ifcsempty{KFLT@#1sc}%
%    \end{macrocode}
% No |sc| short caption, but there is a |cstar|, so no \acro{LOF} entry:
%    \begin{macrocode}
            {}%
%    \end{macrocode}
% Both |cstar| and |sc| were given, so add a \acro{LOF} entry:
% \changes{v2.00}{2019/01/22}{Generalized for float type.}
%    \begin{macrocode}
            {% non-empty cstar and sc:
                \edef\KFLT@listtype{\csuse{KFLT@#1type}}%
                \addcontentsline{\csuse{ext@\KFLT@listtype}}%
                    {\csuse{KFLT@#1type}}{\KFLT@sc}%
            }% non-empty cstar and sc
%    \end{macrocode}
%
% In the following,
% the test for an empty caption is because the \pkg{caption} package does not
% detect an empty caption if it is given as a macro.
%
% |cstar| was given, so create an unnumbered caption:
% \changes{v2.06}{2019/06/29}{Fix for empty caption.}
%    \begin{macrocode}
            \ifcsempty{KFLT@#1c}%
                {\KFLT@docaption*{}{#1}}%
                {\KFLT@docaption*{\csuse{KFLT@#1c}}{#1}}%
        }%
    }% starred caption
%    \end{macrocode}
% Unstarred caption |c| was given, so number this float:
% \changes{v2.06}{2019/06/29}{Fix for empty caption.}
%    \begin{macrocode}
    {% unstarred caption
        \ifcsempty{KFLT@#1sc}%
        {% no short cap
            \ifcsempty{KFLT@#1c}%
                {\KFLT@docaption{}{#1}}%
                {\KFLT@docaption{\csuse{KFLT@#1c}}{#1}}%
        }% no short cap
        {% short cap
            \ifcsempty{KFLT@#1c}%
                {\KFLT@docaption[\csuse{KFLT@#1sc}]{}{#1}}%
                {\KFLT@docaption[\csuse{KFLT@#1sc}]{\csuse{KFLT@#1c}}{#1}}%
        }% short cap
%    \end{macrocode}
% Optional label:
%    \begin{macrocode}
        \ifcsempty{KFLT@#1l}%
        {}%
        {\label{\csuse{KFLT@#1l}}}%
    }% unstarred caption
}
%    \end{macrocode}
% \end{macro}


% \subsection{Defaults for a new float}

% \begin{macro}{\KFLT@defaults} Defaults all settings before reading the keys.
% \changes{v2.06}{2021/06/25}{Added \optn{kar}.}
%    \begin{macrocode}
\newcommand*{\KFLT@defaults}{%
    \setboolean{KFLT@cont}{false}%
    \renewcommand{\KFLT@c}{}%
    \setboolean{KFLT@cstar}{false}%
    \renewcommand{\KFLT@sc}{}%
    \setboolean{KFLT@scgiven}{false}%
    \renewcommand{\KFLT@type}{figure}%
    \renewcommand{\KFLT@l}{}%
    \renewcommand{\KFLT@ap}{}%
    \renewcommand{\KFLT@af}{}%
    \renewcommand{\KFLT@al}{}%
    \renewcommand{\KFLT@as}{}%
    \renewcommand{\KFLT@aup}{}%
    \renewcommand{\KFLT@auf}{}%
    \renewcommand{\KFLT@aul}{}%
    \renewcommand{\KFLT@aus}{}%
    \renewcommand{\KFLT@t}{}%
    \renewcommand{\KFLT@textalign}{}%
    \renewcommand{\KFLT@lw}{}%
    \setlength{\KFLT@w}{0pt}%
    \setlength{\KFLT@h}{0pt}%
    \renewcommand{\KFLT@keepaspectratio}{}%
    \renewcommand{\KFLT@s}{1}%
    \renewcommand{\KFLT@r}{0}%
    \setboolean{KFLT@f}{false}%
    \setboolean{KFLT@ft}{false}%
    \renewcommand{\KFLT@stretch}{1}%
    \setlength{\KFLT@mo}{-1.2ex}%
    \renewcommand{\KFLT@wn}{}%
    \renewcommand{\KFLT@wp}{O}%
    \renewcommand{\KFLT@wo}{\wrapoverhang}%
    \renewcommand{\KFLT@wlw}{}%
    \setlength{\KFLT@ww}{0pt}%
    \renewcommand{\KFLT@va}{c}%
}
%    \end{macrocode}
% \end{macro}

% \subsection{Row start/end processing}

% \begin{macro}{\KFLT@maybestartfloatrow} Counts rows
%
% After ending a preexisting row, move to the next row.
% The use of \cs{defcounter} makes this counter change local.
%    \begin{macrocode}
\newcommand*{\KFLT@maybestartfloatrow}{%
    \KFLT@maybeendfloatrow%
    \defcounter{KFLT@thiscol}{\value{KFLT@thiscol}+1}%
}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@maybeendfloatrow} Counts rows
%
% Adds vertical space then resets to allow the start of a new row.
% The use of \cs{defcounter} makes this counter change local.
%    \begin{macrocode}
\newcommand*{\KFLT@maybeendfloatrow}{%
    \ifnumless{\value{KFLT@thiscol}}{\value{KFLT@numcols}}%
    {}% thiscol < numcols
    {% >=
        \par%
        \addvspace{.75\floatsep}%
        \defcounter{KFLT@thiscol}{0}%
    }%
}%
%    \end{macrocode}
% \end{macro}






% \subsection{Key environment helper macros}


% \begin{macro}{\KFLT@trackrows} Tracks and spaces rows and columns.
%    \begin{macrocode}
\newcommand{\KFLT@trackrows}%
{%
%    \end{macrocode}
% If are nested inside a keyfloats or a subfloat:
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{0}} or%
        bool{KFLT@inkeysubfloats}%
    }%
    {% nested
%    \end{macrocode}
% Tracks row start and end:
%    \begin{macrocode}
        \KFLT@maybestartfloatrow%
%    \end{macrocode}
% Possibly fill space between columns:
%    \begin{macrocode}
        \ifnumgreater{\value{KFLT@thiscol}}{1}%
            {\hfill}%
            {}%
    }% nested
    {}% not nested
}
%    \end{macrocode}
% \end{macro}



% \begin{macro}{\KFLT@addtext} \marg{\mainsubarg}
%
% Adds optional additional text.
%
% The argument is |{}| if a regular float, or
% |subgrp| if \env{keysubfigs} or \env{keysubtabs}.
%
% \changes{v0.11}{2016/12/02}{Improved paragraph handling.}
%
%    \begin{macrocode}
\newcommand{\KFLT@addtext}[1]
{%
%    \end{macrocode}
% Is there text to add?
%    \begin{macrocode}
    \ifcsempty{KFLT@#1t}%
    {}% no text
    {% text to add
        {% local
%    \end{macrocode}
% Add some space, then create a full-width minipage to contain the text:
%    \begin{macrocode}
        \addvspace{\smallskipamount}%
        \begin{minipage}{\linewidth}%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
        \hbadness=10000\relax%
%    \end{macrocode}
% Set the alignment and some text parameters:
%    \begin{macrocode}
        \csuse{KFLT@#1textalign}%
        \footnotesize%
        \setlength{\parskip}{1.5ex}%
        \setlength{\parindent}{0em}%
%    \end{macrocode}
% Typeset the actual text:
%    \begin{macrocode}
        \csuse{KFLT@#1t}%
%    \end{macrocode}
% Close it all out with a little more space:
%    \begin{macrocode}
        \end{minipage}%
        \par\addvspace{2ex}%
        }% local
    }% text to add
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\KFLT@optionalname} \marg{name}
%
% Adds optional artist's name and the following space.
%
%    \begin{macrocode}
\newcommand{\KFLT@optionalname}[1]
{%
    \ifblank{#1}%
        {}%
        {#1~}%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\KFLT@addartisttext} \marg{\mainsubarg}
%
% Adds optional additional text.
%
% The argument is |{}| if a regular float, or
% |subgrp| if \env{keysubfigs} or \env{keysubtabs}.
%
% One of two versions is used, depending on whether the \pkg{tocdata}
% package is available.
%
% If \pkg{tocdata} is loaded and this float has an artist or author,
% then the float's artist's information and optional text will be printed
% elsewhere by \cs{KFLT@caption}.  Otherwise, the text is printed here.
%
% Two versions, depending on whether \pkg{tocdata} is loaded:
%    \begin{macrocode}
\@ifpackageloaded{tocdata}
{% tocdata loaded
%    \end{macrocode}
% If \pkg{tocdata} is loaded:
%    \begin{macrocode}
\newcommand{\KFLT@addartisttext}[1]
{%
%    \end{macrocode}
% Only add text if is a figure without an artist or author name.
% If an artist or author is given, the name and text will be added
% by \pkg{tocdata}.
%    \begin{macrocode}
    \ifcsempty{KFLT@#1al}% artist last name
        {%
            \ifcsempty{KFLT@#1aul}% author last name
                {\KFLT@addtext{#1}}
                {}%
        }%
        {}% fig w/ artist: text will be added by \captionartist in \KFLT@caption
}% KFLT@addartisttext
}% tocdata loaded
%    \end{macrocode}
% If \pkg{tocdata} is not loaded, the name and text are added here:
%    \begin{macrocode}
{% tocdata not loaded
%    \end{macrocode}

% Factored from \cs{KFLT@addartisttext}
%    \begin{macrocode}
\newcommand*{\KFLT@@addartisttext}[3]{%
%    \end{macrocode}
% Add space and create the name inside a full-width minipage:
%    \begin{macrocode}
        \addvspace{\medskipamount}%
    \begin{minipage}{\linewidth}%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
    \hbadness=10000\relax%
%    \end{macrocode}
%
% Text alignment is |#3|, and depends on artist or author:
%    \begin{macrocode}
    #3%
%    \end{macrocode}
%
% |#1| is empty or '|subgrp'| \\
% |#2| is empty for artist, `|u|' for author:
%    \begin{macrocode}
    \footnotesize\textsc{%
        \KFLT@optionalname{\csuse{KFLT@#1a#2p}}%
        \KFLT@optionalname{\csuse{KFLT@#1a#2f}}%
        \csuse{KFLT@#1a#2l}%
        \csuse{KFLT@#1a#2s}%
    }%
    \end{minipage}%
    \par\addvspace{2ex}%
}

\newcommand{\KFLT@addartisttext}[1]
{%
%    \end{macrocode}
% Only use the artist information if a last name is given:
%    \begin{macrocode}
    \ifcsempty{KFLT@#1al}%
    {% artist last name not given
        \ifcsempty{KFLT@#1aul}%
        {}% author last name not given
        {% author last name given
            \KFLT@@addartisttext{#1}{u}{\raggedleft}%
        }% author last name given
    }% artist last name not given
    {% artist last name given
        \KFLT@@addartisttext{#1}{}{\centering}%
    }%
%    \end{macrocode}
% Any additional text follows the artist's name:
%    \begin{macrocode}
    \KFLT@addtext{#1}%
}% KFLT@addartisttext
}% tocdata not loaded
%    \end{macrocode}
% \end{macro}


% \DescribeLength{\KFLTimageboxwidth} The computed width of the object.
%
% \changes{v0.13}{2017/01/12}{\cs{KFLTimageboxwidth}: Added.}
%
% This may be used as the width parameter of a minipage to encase the object.
%
%    \begin{macrocode}
\newlength{\KFLTimageboxwidth}
%    \end{macrocode}


% \newcommand*{\showKFLTboxinner}[1]{%
% \shownesting{\env{KFLT@boxinner}}{
%   \shownesting{\cs{KFLT@frame} $\to$ \cs{fbox}}
%   {
%       \shownesting{\env{turn}}
%           {\shownesting{\env{minipage}}{#1}}
%   }
% }
% }
%
% \begin{environment}{KFLT@boxinner}
%
% Typeset the contents in a width which depends on the keys.
%
% \showKFLTboxinner{Contents}
%
%    \begin{macrocode}
\newsavebox{\KFLT@envbox}

\NewDocumentEnvironment{KFLT@boxinner}{}
{% keyboxinner
%    \end{macrocode}
% (Possibly) frame the contents of an \env{lrbox}:
%    \begin{macrocode}
    \begin{lrbox}{\KFLT@envbox}%
%    \end{macrocode}
% Rotate the contents:
%    \begin{macrocode}
    \turn{\KFLT@r}%
%    \end{macrocode}
% Box the contents in the width computed by \cs{KFLT@findwidths}:
%    \begin{macrocode}
    \minipage{\KFLT@imagewidth}%
%    \end{macrocode}
% Spacing inside the box.
% Also default to regular justified text alignment.
%    \begin{macrocode}
    \setlength{\parskip}{2ex}%
    \renewcommand{\arraystretch}{\KFLT@stretch}%
}% keyboxinner
%    \end{macrocode}
% End of the environment:
%    \begin{macrocode}
{% endkeyboxinner
    \endminipage%
%    \end{macrocode}
% End the rotated box:
%    \begin{macrocode}
    \endturn%
%    \end{macrocode}
% Possibly frame:
%    \begin{macrocode}
    \end{lrbox}%
    \KFLT@frame{\usebox{\KFLT@envbox}}%
    \par%
}% endkeyboxinner
%    \end{macrocode}
% \end{environment}


% \begin{macro}{\KFLT@sharedkeys}
% Key/values to apply to each object in this group,
% such as a \env{keyfloats} or \env{keysubfigs}.
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
\newcommand*{\KFLT@sharedkeys}{}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\KFLT@boxkeys} \marg{keys} \marg{float type}
%
% Default the options, adjust for a table, then parse the keys:
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@boxkeys}{+m m}
{%
%    \end{macrocode}
% Set the key defaults:
%    \begin{macrocode}
    \KFLT@defaults%
%    \end{macrocode}
% Remember the float type:
% \changes{v2.07}{2022/01/06}{Fixed: Nested types.}
%    \begin{macrocode}
    \ifbool{KFLT@inkeysubfloats}%
        {\renewcommand{\KFLT@type}{\@captype}}%
        {\renewcommand{\KFLT@type}{#2}}%
%    \end{macrocode}
% Set the shared keys.  Expansion seems to be required for \pkg{xkeyval}.
%    \begin{macrocode}
    \edef\next{\noexpand\setkeys{KFLT@keys}{\KFLT@sharedkeys}}%
    \next%
%    \end{macrocode}
% Set the float-specific keys, which might overright the group's keys:
%    \begin{macrocode}
    \setkeys{KFLT@keys}{#1}%
}
%    \end{macrocode}
% \end{macro}


% \DescribeBoolean{KFLT@captionistop} Saves the value of \cs{caption@position},
% which may become unreliable if using Komascript and
% \begin{sourceverb}
% \captionsetup[table]{position=above}
% \end{sourceverb}
%
%    \begin{macrocode}
\newbool{KFLT@captionistop}
%    \end{macrocode}


% \begin{macro}{\KFLT@LWR@hook@boxouter} Used by \pkg{lwarp}.
%    \begin{macrocode}
\newcommand*{\KFLT@LWR@hook@boxouter}{}%
%    \end{macrocode}
% \end{macro}


% \begin{environment}{KFLT@boxouter} \marg{star?} \marg{loc}
%
% Boxes the contents of figures and floats.
%
% Not used by subfigures.
%
% \changes{v0.12}{2016/12/03}{[M] and [W] floats.}
% \changes{v0.15}{2017/05/09}{Handle vertical alignment key \optn{va}.}
% \changes{v0.15}{2017/05/12}{Adjustments for \protect\env{keywrap}.}
%    \begin{macrocode}
\NewDocumentEnvironment{KFLT@boxouter}{m m}
{% boxouter
%    \end{macrocode}
% The \env{keyfigure} and \env{keytable} environments handle the contents in one of
% three possible ways, depending on whether it is
% called alone, inside a \env{keyfloats} environment, or
% inside a \env{keysubfigs} or \env{keysubtabs} environment.
%
% Start the new subfigure or subtable, of the given width:
%    \begin{macrocode}
    \ifbool{KFLT@inkeysubfloats}%
    {\csuse{sub\KFLT@type}{\KFLT@rowboxwidth}}% subfloat
%    \end{macrocode}
% If \env{keyfloats}, place the contents inside a \env{minipage}:
%    \begin{macrocode}
    {% not subfloat:
        \ifnumgreater{\value{KFLT@keyfloatdepth}}{0}%
        {% keyfloats
            \ifbool{KFLT@keywrap}%
                {\minipage[t]{\KFLT@rowboxwidth}}%
                {\minipage[\KFLT@va]{\KFLT@rowboxwidth}}%
            \captionsetup*{type=\KFLT@type}%
        }% keyfloats
        {% not keyfloats
%    \end{macrocode}
% A hook for \pkg{lwarp} to set \cs{linewidth}, etc.
%    \begin{macrocode}
            \KFLT@LWR@hook@boxouter%
%    \end{macrocode}
%
% Not a subfloat or \env{keyfloats}, so create a single float.
%
% See if inside a \env{keywrap}.
% If so, force [H] and vertical align top.
%    \begin{macrocode}
            \ifbool{KFLT@keywrap}%
            {%
                \par\addvspace{\baselineskip}%
                \noindent%
                \minipage[t]{\linewidth}%
                \captionsetup{type=\KFLT@type}%
            }%
            {% not a keywrap
%    \end{macrocode}
%
% See if the float should [W]rap:
%
%    \begin{macrocode}
                \ifstrequal{#2}{W}%
%    \end{macrocode}
% Place [W], so create a wrapfloat using the \pkg{wrapfig} package:
%    \begin{macrocode}
                {% [W]
%    \end{macrocode}
%
% Temporarily figure out \cs{KFLT@imagewidth},
% and make the wrapped figure environment as wide as the
% desired image size plus frame:
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
% \changes{v2.04}{2021/06/08}{Added \optn{wn} and \optn{wo}.}
%    \begin{macrocode}
                    \KFLT@findwidths%
%    \end{macrocode}
%
% Expand the arguments for \pkg{wrapfig}:
% \changes{v2.05}{2021/06/11}{No longer patch \pkg{wrapfig} for expansion.}
%    \begin{macrocode}
                    \edef\next{%
                        \noexpand\wrapfloat%
                            {\KFLT@type}[\KFLT@wn]{\KFLT@wp}[\KFLT@wo]%
                            {\KFLT@wrapwidth+2\KFLTlooseframewidth}%
                    }%
                    \next%
%    \end{macrocode}
%    \begin{macrocode}
                    \minipage{\KFLT@wrapwidth+2\KFLTlooseframewidth}%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
                    \hbadness=10000\relax%
%    \end{macrocode}
%    \begin{macrocode}
                    \normalcolor\reset@font\normalsize%
%    \end{macrocode}
%
% Change the interior image to the discovered fixed width.
% \changes{v2.02}{2021/05/27}{Added \optn{ww} and \optn{wlw}.}
%    \begin{macrocode}
                    \renewcommand{\KFLT@lw}{}%
                    \renewcommand{\KFLT@w}{\KFLT@imagewidth}%
                    \renewcommand{\KFLT@wlw}{}%
                    \renewcommand{\KFLT@ww}{0pt}%
                }% [W]
                {% not [W]
%    \end{macrocode}
%
% See if the float should be positioned in the [M]argin:
%    \begin{macrocode}
                    \ifstrequal{#2}{M}%
%    \end{macrocode}
% Place [M], so create a marginfloat:
% \changes{v2.00}{2019/03/18}{Added custom float types.}
%    \begin{macrocode}
                    {% [M]
                        \KFLT@marginfloat[\KFLT@mo]{\KFLT@type}%
                    }% [M]
                    {% not [M]
%    \end{macrocode}
%
% See if the float should be positioned [H]ere:
%    \begin{macrocode}
                        \ifstrequal{#2}{H}%
%    \end{macrocode}
% Place [H], so create an inline minipage:
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
                        {% [H]
                            \vskip\intextsep%
                            \noindent\minipage[\KFLT@va]{\linewidth}%
                            \normalcolor\reset@font\normalsize%
                            \captionsetup{type=\KFLT@type}%
                        }% [H]
%    \end{macrocode}
% Not [H], so create a float:
% For a starred float, make a two-column table in a two-col format.
%    \begin{macrocode}
                        {% not [H]
                            \IfBooleanTF{#1}%
                                {\csuse{\KFLT@type*}[#2]}%
                                {\csuse{\KFLT@type}[#2]}%
                        }% not [H]
                    }% not [M]
                }% not [W]
            }% not keywrap
        }% not keyfloats
    }% not subfloat
%    \end{macrocode}
% Handle a continued float.  Ignored if in a subfloat.
%    \begin{macrocode}
    \ifbool{KFLT@cont}{\ContinuedFloat}{}%
%    \end{macrocode}
% Figure out image and parbox widths for the contents:
%    \begin{macrocode}
    \KFLT@findwidths%
%    \end{macrocode}
% Place the caption above the contents depending on \pkg{caption} \optn{position} option:
% \changes{v2.01}{2019/09/11}{Fix: Positions with \brand{Komascript}.}
%    \begin{macrocode}
    \caption@iftop%
        {\booltrue{KFLT@captionistop}}%
        {\boolfalse{KFLT@captionistop}}%
    \ifbool{KFLT@captionistop}{\KFLT@caption{}}{}%
%    \end{macrocode}
% Typeset the contents:
%    \begin{macrocode}
    \center\unskip%
}% boxouter
%    \end{macrocode}
%
% End of the KFLT@boxouter environment:
%
%    \begin{macrocode}
{% endboxouter
    \endcenter\unskip%
    \addvspace{\smallskipamount}%
%    \end{macrocode}
% Optionally print artist's name and additional text:
%    \begin{macrocode}
    \KFLT@addartisttext{}%
%    \end{macrocode}
% Place the caption below the contents depending on \pkg{caption} \optn{position} option:
% \changes{v2.01}{2019/09/11}{Fix: Positions with \brand{Komascript}.}
%    \begin{macrocode}
    \ifbool{KFLT@captionistop}{}{\KFLT@caption{}}%
%    \end{macrocode}
% If are inside \env{keysubtabs}, end the subtable:
%    \begin{macrocode}
    \ifbool{KFLT@inkeysubfloats}%
    {%
        \csuse{endsub\KFLT@type}%
    }% subfloat
    {% not subfloat
        \ifnumgreater{\value{KFLT@keyfloatdepth}}{0}% keyfloats?
        {%
%    \end{macrocode}
%    \begin{macrocode}
            \endminipage%
        }% keyfloats
        {% not keyfloats
%    \end{macrocode}
%
% Not subfloat or \env{keyfloats}, so is an individual float.
%
% Close the minipage or float:
%
% See if in a \env{keywrap}:
%    \begin{macrocode}
            \ifbool{KFLT@keywrap}{%
                \endminipage%
                \par\addvspace{\baselineskip}%
            }%
            {% not keywrap
%    \end{macrocode}
%
% See if the float should [W]rap:
%    \begin{macrocode}
                \ifstrequal{#2}{W}%
%    \end{macrocode}
% Place [W], so close the wrap float:
%    \begin{macrocode}
                {% [W]
                    \endminipage%
                    \endwrapfloat%
                }% [W]
                {% not[W]
%    \end{macrocode}
%
% See if the float should be positioned in the [M]argin:
%    \begin{macrocode}
                    \ifstrequal{#2}{M}%
%    \end{macrocode}
% [M], so close the marginfloat:
% \changes{v2.00}{2019/03/18}{Added custom float types.}
%    \begin{macrocode}
                    {% [M]
                        \endKFLT@marginfloat%
                    }% [M]
%    \end{macrocode}
% [H] or float:
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
                    {% not [M]
                        \ifstrequal{#2}{H}%
                        {%
                            \endminipage% [H]
                            \vskip\intextsep%
                        }%
                        {% not [H]
                            \IfBooleanTF{#1}% starred float?
                                {\csuse{end\KFLT@type*}}%
                                {\csuse{end\KFLT@type}}%
                        }% not [H]
                    }% not [M]
                }% not [W]
            }% not keywrap
        }% not keyfloats
    }% not subfloat
}% endkeyboxouter
%    \end{macrocode}
% \end{environment}


% \begin{macro}{\KFLT@@ignorespaces} \marg{commandname}
% Only do command if not nested inside something.
% \changes{v2.00}{2019/01/22}{Added.}
%    \begin{macrocode}
\newcommand*{\KFLT@@ignorespaces}[1]{%
    \ifboolexpr{%
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{0}} or%
        bool{KFLT@inkeysubfloats}%
    }{}{\csuse{#1}}%
}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@ignorespaces}
% Only \cs{ignorespaces} if not nested inside something.
% \changes{v2.00}{2019/01/22}{Added.}
%    \begin{macrocode}
\newcommand*{\KFLT@ignorespaces}{%
    \KFLT@@ignorespaces{ignorespaces}%
}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@envignorespaces}
% Only \cs{ignorespaces} if not nested inside something.
% \changes{v2.00}{2019/01/22}{Added.}
%    \begin{macrocode}
\newcommand*{\KFLT@envignorespaces}{%
    \KFLT@@ignorespaces{ignorespacesafterend}%
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \cs{KFLT@keyflt} macro}
%
% \begin{macro}{\KFLT@keyflt}
%   \marg{1:star} \marg{2:loc} \marg{3:type} \marg{4:\keyvalsarg} \marg{5:contents}
%
% A lower-level macro to generate a float with its contents.
% This is used by \cs{keyfig} and \cs{keyflt}.
%
% \changes{v2.00}{2019/03/17}{Added.}
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@keyflt}{m m m +m +m}
{%
%    \end{macrocode}
%
% \changes{v2.02}{2021/05/18}{Work with \pkg{float}.}
%    \begin{macrocode}
    \ifcsdef{ftype@#3}{}{%
        \PackageError{keyfloat}%
        {%
            \protect\keyflt: Invalid float type.\MessageBreak%
            \protect\keyflt*[loc]{type}{keys/values}{contents}\MessageBreak%
            Also, \protect\keyflt\space is not an environment
        }%
        {%
            Check argument order and float type.
        }%
    }%
%    \end{macrocode}
%
%    \begin{macrocode}
    \KFLT@ignorespaces%
    \KFLT@trackrows%
    \KFLT@boxkeys{#4}{#3}%
    \begingroup%
    \KFLT@boxouter{#1}{#2}%
    #5%
    \endKFLT@boxouter%
    \endgroup%
    \KFLT@ignorespaces%
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \cs{keyflt} macro}

% \begin{macro}{\keyflt} * \oarg{loc} \marg{type} \marg{\keyvalsarg} \marg{contents}
%
% A user-level macro to generate a float with its contents
% centered inside an inner box.
% This may be used by itself, or inside a \env{keyfloats} or
% \env{keysubtabs} environment.
%
% \shownesting{\cs{keyflt}}{
%   \shownesting{\cs{KFLT@keyflt}}{
%       \shownesting{\env{KFLT@boxouter}}{
%           \showKFLTboxinner{Contents}
%       }
%   }
% }
%
% \changes{v0.12}{2016/12/03}{Group around contents.}
% \changes{v2.00}{2019/03/17}{Added.}
%    \begin{macrocode}
\NewDocumentCommand{\keyflt}{s O{tbp} m +m +m}
{%
    \KFLT@keyflt{#1}{#2}{#3}{#4}{%
        \KFLT@boxinner%
        \centering%
        #5%
        \endKFLT@boxinner%
    }%
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\endkeyflt}
%
% Generates an error in case the user tried to use \cs{keyflt} as an environment.
% \changes{v2.00}{2019/03/17}{Added.}
%    \begin{macrocode}
\def\endkeyflt{%
    \PackageError{keyfloat}
    {%
        \protect\end{keyflt}:\MessageBreak
        \protect\keyflt\space is a macro, not an environment.\MessageBreak
        Perhaps you want the keyfloat environment instead%
    }
    {%
        Use \protect\begin{keyfloat} ... \protect\end{keyfloat}.
    }
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \env{keyfloat} environment}

% \begin{macro}{\KFLT@keyfloatstart} \marg{star?} \marg{loc} \marg{float type} \marg{\keyvalsarg}
%
% \changes{v2.00}{2019/03/18}{Factored.}
%    \begin{macrocode}
\newcommand{\KFLT@keyfloatstart}[4]{%
    \KFLT@envignorespaces%
    \KFLT@boxkeys{#4}{#3}%
    \KFLT@boxouter{#1}{#2}%
    \KFLT@boxinner%
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\KFLT@keyfloatend}
% \changes{v2.00}{2019/03/18}{Factored.}
%    \begin{macrocode}
\newcommand{\KFLT@keyfloatend}{%
    \endKFLT@boxinner%
    \endKFLT@boxouter%
    \KFLT@envignorespaces%
}
%    \end{macrocode}
% \end{macro}

% \begin{environment}{keyfloat} * \oarg{loc} \marg{float type} \marg{\keyvalsarg}
%
% \shownesting{\env{keyfloat}}{
%   \shownesting{\cs{KFLT@keyfloatstart}, \cs{KFLT@keyfloatend}}
%   {
%       \shownesting{\env{KFLT@boxouter}}{
%           \showKFLTboxinner{Contents}
%       }
%   }
% }
%
% \changes{v2.00}{2019/03/18}{Added.}
%    \begin{macrocode}
\NewDocumentEnvironment{keyfloat}{s O{tbp} m +m}
{%
    \KFLT@keyfloatstart{#1}{#2}{#3}{#4}%
}%
{%
    \KFLT@keyfloatend%
}
%    \end{macrocode}
% \end{environment}

% Extra code to track rows outside of the \env{keyfloat} environment,
% \DescribeObject{Before \env{keyfloat}}
% before it starts.  This is done to allow nesting without losing track
% of the prior level.
%
%    \begin{macrocode}
\BeforeBeginEnvironment{keyfloat}{%
    \KFLT@trackrows%
}
%    \end{macrocode}


% \subsection{The \env{keyfigure} environment}

% \begin{environment}{keyfigure} * \oarg{loc} \marg{\keyvalsarg}
%
% \shownesting{\env{keyfigure}}{
%   \shownesting{\cs{KFLT@keyfloatstart}, \cs{KFLT@keyfloatend}}
%   {
%       \shownesting{\env{KFLT@boxouter}}{
%           \showKFLTboxinner{Contents}
%       }
%   }
% }
%
%    \begin{macrocode}
\NewDocumentEnvironment{keyfigure}{s O{tbp} +m}
{%
    \KFLT@keyfloatstart{#1}{#2}{figure}{#3}%
}%
{%
    \KFLT@keyfloatend%
}
%    \end{macrocode}
% \end{environment}

% Extra code to track rows outside of the \env{keyfigure} environment,
% \DescribeObject{Before \env{keyfigure}}
% before it starts.  This is done to allow nesting without losing track
% of the prior level.
%
%    \begin{macrocode}
\BeforeBeginEnvironment{keyfigure}{%
    \KFLT@trackrows%
}
%    \end{macrocode}


% \subsection{The \cs{keyfig} macro}

% \begin{macro}{\keyfig} * \oarg{2:loc} \marg{3:\keyvalsarg} \marg{4:image filename}
%
% A user-level macro to generate a figure with an image.
% This may be used by itself, or inside a \env{keyfloats} or
% \env{keysubfigs} environment.
%
% \shownesting{\cs{keyfig}}{
%   \shownesting{\cs{KFLT@keyflt}}{
%         \shownesting{\env{KFLT@boxouter}}{
%             \shownesting{
%                 \begin{description}
%                 \item[If \env{keysubfloats}:]
%                     Uses a \env{subfigure}.
%                 \item[If {[}H{]}, \env{keyfloats}, or inside a \env{keywrap}:]
%                     Uses a \env{minipage}.
%                 \item[If {[}W{]}:]
%                     Uses a \env{wrapfloat} from the \pkg{wrapfig} package.
%                 \item[If {[}M{]}:]
%                     Uses a \env{KFLT@marginfloat}.
%                 \item[Otherwise:]
%                     Uses a \env{figure}.
%                 \end{description}
%             }
%             {
%                 \shownesting{\cs{KFLT@onefigureimage}}{
%                     Rotate, frame, \cs{includegraphics}.
%                 }
%             }
%         }
%   }
% }
%
% \changes{v2.00}{2019/03/17}{Factored.}
%    \begin{macrocode}
\NewDocumentCommand{\keyfig}{s O{tbp} +m m}
{%
    \KFLT@keyflt{#1}{#2}{figure}{#3}{%
        \KFLT@onefigureimage{#4}%
    }%
}
%    \end{macrocode}
% \end{macro}



% \subsection{The \cs{keyfigbox} macro}

% \begin{macro}{\keyfigbox} * \oarg{loc} \marg{\keyvalsarg} \marg{box contents}
%
% A user-level macro to generate a figure with arbitrary paragraph contents.
% This may be used by itself, or inside a \env{keyfloats} or
% \env{keysubtabs} environment.
%
% \shownesting{\cs{keyfigbox}}{
%   \shownesting{\env{KFLT@boxouter}}{
%       \showKFLTboxinner{Contents}
%   }
% }
%
% \changes{v0.12}{2016/12/03}{Group around contents.}
%    \begin{macrocode}
\NewDocumentCommand{\keyfigbox}{s O{tbp} +m +m}
{%
    \KFLT@ignorespaces%
    \KFLT@trackrows%
    \KFLT@boxkeys{#3}{figure}%
    \begingroup%
    \KFLT@boxouter{#1}{#2}%
    \KFLT@boxinner%
    #4%
    \endKFLT@boxinner%
    \endKFLT@boxouter%
    \endgroup%
    \KFLT@ignorespaces%
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \cs{keyparbox} macro}

% \begin{macro}{\keyparbox} * \oarg{loc} \marg{\keyvalsarg} \marg{box contents}
%
% A user-level macro to generate a figure with arbitrary paragraph contents,
% but no number or caption.
% This is equal to a \cs{keyfigbox} with |cstar={}|.
% This may be used by itself, or inside a \env{keyfloats} or
% \env{keysubtabs} environment.
%
% \changes{v0.12}{2016/12/03}{Group around contents.}
%    \begin{macrocode}
\NewDocumentCommand{\keyparbox}{s O{tbp} +m +m}
{%
    \KFLT@ignorespaces%
    \KFLT@trackrows%
    \KFLT@boxkeys{#3}{figure}%
%    \end{macrocode}
% Force |cstar={}|:
%    \begin{macrocode}
    \renewcommand{\KFLT@c}{}%
    \setboolean{KFLT@cstar}{true}%
%    \end{macrocode}
% Continue like \cs{figbox}:
%    \begin{macrocode}
    \begingroup%
    \KFLT@boxouter{#1}{#2}%
    \KFLT@boxinner%
    #4%
    \endKFLT@boxinner%
    \endKFLT@boxouter%
    \endgroup%
    \KFLT@ignorespaces%
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \cs{keytab} macro}

% \begin{macro}{\keytab} * \oarg{loc} \marg{\keyvalsarg} \marg{tabular contents}
%
% A user-level macro to generate a table with tabular contents.
% This may be used by itself, or inside a \env{keyfloats} or
% \env{keysubtabs} environment.
%
% \shownesting{\cs{keytab}}{
%   \shownesting{\cs{keyflt}}{
%       \shownesting{\cs{KFLT@keyflt}}{
%           \shownesting{\env{KFLT@boxouter}}{
%               \showKFLTboxinner{Contents}
%           }
%       }
%   }
% }
%
% \changes{v2.00}{2019/03/17}{Factored.}
%    \begin{macrocode}
\NewDocumentCommand{\keytab}{s O{tbp} +m +m}
{%
    \IfBooleanTF{#1}{%
        \keyflt*[#2]{table}{#3}{#4}%
    }{%
        \keyflt[#2]{table}{#3}{#4}%
    }%
}
%    \end{macrocode}
% \end{macro}


% \subsection{The \env{keytable} environment}

% \begin{environment}{keytable} * \oarg{loc} \marg{\keyvalsarg}
%
% \shownesting{\env{keytable}}{
%   \shownesting{\cs{KFLT@keyfloatstart}, \cs{KFLT@keyfloatend}}{
%       \shownesting{\env{KFLT@boxouter}}{
%           \showKFLTboxinner{Contents}
%       }
%   }
% }
%
%    \begin{macrocode}
\NewDocumentEnvironment{keytable}{s O{tbp} +m}
{%
    \KFLT@keyfloatstart{#1}{#2}{table}{#3}%
}%
{%
    \KFLT@keyfloatend%
}
%    \end{macrocode}
% \end{environment}

% Extra code to track rows outside of the \env{keytable} environment,
% \DescribeObject{Before \env{keytable}}
% before it starts.  This is done to allow nesting without losing track
% of the prior level.
%
%    \begin{macrocode}
\BeforeBeginEnvironment{keytable}{%
    \KFLT@trackrows%
}
%    \end{macrocode}



% \subsection{A row of floats}

% \begin{macro}{\KFLT@nonest} Error message if tried to nest subfloats.
%    \begin{macrocode}
\newcommand*{\KFLT@nonest}{%
    \ifboolexpr{%
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{0}} or
        bool {KFLT@inkeysubfloats}%
    }%
    {%
        \PackageError{keyfloat}%
        {%
            Cannot nest keysubfigs or keysubtabs.\MessageBreak%
            (Not in outer par mode.)%
        }%
        {%
            The subcaption package do not support nested environments,%
                \MessageBreak
            so the keyfloat package cannot place a\MessageBreak
            keysubfigs or keysubtabs environment inside another,%
                \MessageBreak
            or inside a keyfloats.%
        }%
    }%
    {}%
}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@LWR@hook@keyfloats} Used by \pkg{lwarp}.
%    \begin{macrocode}
\newcommand*{\KFLT@LWR@hook@keyfloats}{}%
%    \end{macrocode}
% \end{macro}


% \begin{environment}{KFLT@LWR@hook@keyfloatsminipage} \marg{contents}
%
% Modified by \pkg{lwarp}.
% \changes{v2.06}{2021/06/25}{Added vertical alignment.}
%    \begin{macrocode}
\newenvironment*{KFLT@LWR@hook@keyfloatsminipage}[1]
    {\noindent\minipage[\KFLT@va]{#1}}
    {\endminipage}
%    \end{macrocode}
% \end{environment}

% \begin{environment}{keyfloats} * \oarg{loc} \marg{num columns} \oarg{shared keys/values}
%
% User-level macro to create rows of figures/tables.
% Wrapping occurs after the number of specified columns.
% \env{keyfloats} environments may be nested to create
% a vertical set of figures next to a single larger figure,
% for example.
%
% Place \cs{keyfig}, \cs{keyfigbox}, and \cs{keytab} commands
% inside the \env{keyfloats} environment.
%
% Note that |lw| linewidth keys may need to be adjusted inside
% a \env{keyfloats}, \env{keysubfigs}, or \env{keysubtabs}, since
% \cs{linewidth} changes depending on the number of columns.
% Likewise, manually-selected |w| width and |h| tags may need to be
% adjusted to prevent overflow.
%
% \shownesting{\env{keyfloats}}
%   {
%       \shownesting{
%           \begin{description}
%           \item[If {[}H{]}, nested, subfloats, or \env{keywrap}:]
%               Uses a \env{minipage}.
%           \item[If {[}W{]}:] Uses a \env{wrapfloat}.
%           \item[If {[}M{]}:] Uses \cs{KFLT@marginfloat}.
%           \item[Otherwise:] Uses a \env{figure}.
%           \end{description}
%       }{Contents}
%   }
%
% \changes{v0.15}{2017/05/12}{Adjustments for \protect\env{keywrap}.}
%
%    \begin{macrocode}
\NewDocumentEnvironment{keyfloats}{s O{tbp} m O{}}
{%
    \KFLT@envignorespaces%
%    \end{macrocode}
% A hook for \pkg{lwarp} to set \cs{linewidth}, etc.
%    \begin{macrocode}
    \KFLT@LWR@hook@keyfloats%
%    \end{macrocode}
% Track the depth:
%    \begin{macrocode}
    \addtocounter{KFLT@keyfloatdepth}{1}%
%    \end{macrocode}
% Nest the group's keys.
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
    \edef\KFLT@outersharedkeys{\KFLT@sharedkeys}%
    \edef\KFLT@sharedkeys{\KFLT@sharedkeys,#4}%
%    \end{macrocode}
% If [H], nested, subfloats, or keywrap, use a minipage instead of a float:
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifstrequal{#2}{H}} or
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{1}} or
        bool {KFLT@inkeysubfloats} or
        bool {KFLT@keywrap}%
    }%
%    \end{macrocode}
% Create an inline minipage:
%    \begin{macrocode}
    {% [H] or nested
%    \end{macrocode}
% If nested, use different spacing as was computed in the outer nesting level:
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
        \ifboolexpr{%
            test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{1}} or
            bool {KFLT@inkeysubfloats}
        }%
        {%
%    \end{macrocode}
% Use the keys from the outer container.
% Expansion required for \pkg{xkeyval}.
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
            \edef\next{\noexpand\setkeys{KFLT@keys}{\KFLT@outersharedkeys}}%
            \next%
%    \end{macrocode}
% Create the containing minipage:
%    \begin{macrocode}
            \KFLT@LWR@hook@keyfloatsminipage{\KFLT@rowboxwidth}%
        }%
        {%
            \vskip\intextsep%
            \KFLT@LWR@hook@keyfloatsminipage{\linewidth}%
        }%
%    \end{macrocode}
% Reset font and color:
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
%    \begin{macrocode}
        \normalcolor\reset@font\normalsize%
%    \end{macrocode}
% If inside subfloats, generate subfigures by default:
%    \begin{macrocode}
        \ifbool{KFLT@inkeysubfloats}%
            {}%
            {\captionsetup*{type=figure}}%
    }% [H] or nested
%    \end{macrocode}
% Isn't [H] or nested
%    \begin{macrocode}
    {% See if [W]:
        \ifstrequal{#2}{W}
        {% [W]:
%    \end{macrocode}
% [W]:
% \changes{v2.01}{2019/09/16}{Added \env{keyfloats} [W].}
%    \begin{macrocode}
            \wrapfloat{figure}{O}{.5\linewidth}%
            \minipage{\linewidth}%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
            \hbadness=10000\relax%
%    \end{macrocode}
%    \begin{macrocode}
            \normalcolor\reset@font\normalsize%
        }%
        {% not [H]:
            \ifstrequal{#2}{M}%
            {% [M]:
%    \end{macrocode}
% [M]:
% \changes{v2.01}{2019/09/16}{Added \env{keyfloats} [M].}
%    \begin{macrocode}
                \KFLT@marginfloat{figure}%
            }%
%    \end{macrocode}
% A normal figure:
%    \begin{macrocode}
            {% figure
                \IfBooleanTF{#1}% starred figure, two-col figure in a two-col format
                    {\begin{figure*}[#2]}%
                    {\begin{figure}[#2]}%
            }% figure
        }% not [H]
    }%
%    \end{macrocode}
% Compute the width of each entry:
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{1}} or
        bool {KFLT@inkeysubfloats}
    }%
%    \end{macrocode}
% Nested or subfloats:
%    \begin{macrocode}
        {\setlength{\KFLT@rowboxwidth}{.9\KFLT@rowboxwidth/\real{#3}}}%
%    \end{macrocode}
% Keyfloats:
%    \begin{macrocode}
        {\setlength{\KFLT@rowboxwidth}{.9\linewidth/\real{#3}}}%
%    \end{macrocode}
% Center the contents:
%    \begin{macrocode}
    \centering%
%    \end{macrocode}
% Count columns using \cs{defcounter} for a local effect:
%    \begin{macrocode}
    \defcounter{KFLT@numcols}{#3}%
    \defcounter{KFLT@thiscol}{0}%
}% starting keyfloats environment
%    \end{macrocode}
%
% When ending a \env{keyfloats} environment:
%    \begin{macrocode}
{% ending keyfloats environment
%    \end{macrocode}
% [H] or rows/subfigs? Close a minipage:
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifstrequal{#2}{H}} or
        test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{1}} or
        bool {KFLT@inkeysubfloats} or
        bool {KFLT@keywrap}
    }%
    {% was [H], etc.
        \endKFLT@LWR@hook@keyfloatsminipage%
%         \end{minipage}%
%    \end{macrocode}
% Spacing if nested or not:
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
        \ifboolexpr{
            test {\ifnumgreater{\value{KFLT@keyfloatdepth}}{0}} or
            bool {KFLT@keywrap}
        }%
        {}{% not nested
            \vskip\intextsep%
        }%
    }% was [H], etc.
%    \end{macrocode}
% Not [H]:
%    \begin{macrocode}
    {% not [H], etc.
        \ifstrequal{#2}{W}%
        {% [W]:
%    \end{macrocode}
% [W]:
% \changes{v2.01}{2019/09/16}{Added \env{keyfloats} [W].}
%    \begin{macrocode}
            \endminipage%
            \endwrapfloat%
        }%
        {%
            \ifstrequal{#2}{M}%
            {% [M]:
%    \end{macrocode}
% [M]:
% \changes{v2.01}{2019/09/16}{Added \env{keyfloats} [M].}
%    \begin{macrocode}
                \endKFLT@marginfloat%
            }%
            {% figure
%    \end{macrocode}
% A figure:
%    \begin{macrocode}
                \IfBooleanTF{#1}% starred figure?
                    {\end{figure*}}{\end{figure}}%
            }%
        }%
    }% not [H], etc.
%    \end{macrocode}
% Unnest the environment:
%    \begin{macrocode}
    \addtocounter{KFLT@keyfloatdepth}{-1}%
    \KFLT@envignorespaces%
}
%    \end{macrocode}
% \end{environment}



% Extra code to track rows outside of the \env{keyfloats} environment,
% \DescribeObject{Before \env{keyfloats}}
% before it starts.  This is done to allow nesting without losing track
% of the prior level.
%
%    \begin{macrocode}
\BeforeBeginEnvironment{keyfloats}{%
    \KFLT@trackrows%
}
%    \end{macrocode}


% \subsection{Subfloats}

% \begin{macro}{\KFLT@subgrpdefaults} Sets defaults before reading the keys.
%    \begin{macrocode}
\newcommand*{\KFLT@subgrpdefaults}{%
    \setboolean{KFLT@subgrpcont}{false}%
    \renewcommand{\KFLT@subgrpc}{}%
    \setboolean{KFLT@subgrpcstar}{false}%
    \renewcommand{\KFLT@subgrpsc}{}%
    \setboolean{KFLT@subgrpscgiven}{false}%
    \renewcommand{\KFLT@subgrptype}{figure}%
    \renewcommand{\KFLT@subgrpl}{}%
    \renewcommand{\KFLT@subgrpap}{}%
    \renewcommand{\KFLT@subgrpaf}{}%
    \renewcommand{\KFLT@subgrpal}{}%
    \renewcommand{\KFLT@subgrpas}{}%
    \renewcommand{\KFLT@subgrpaup}{}%
    \renewcommand{\KFLT@subgrpauf}{}%
    \renewcommand{\KFLT@subgrpaul}{}%
    \renewcommand{\KFLT@subgrpaus}{}%
    \renewcommand{\KFLT@subgrpt}{}%
    \renewcommand{\KFLT@subgrptextalign}{}%
}
%    \end{macrocode}
% \end{macro}


% \DescribeBoolean{KFLT@subcaptionistop} Saves the value of \cs{caption@position},
% which may become unreliable if using Komascript and
% \begin{sourceverb}
% \captionsetup[table]{position=above}
% \end{sourceverb}
%
%    \begin{macrocode}
\newbool{KFLT@subcaptionistop}
%    \end{macrocode}



% \begin{macro}{\KFLT@subfloats} \marg{starred?} \marg{loc} \marg{cols} \marg{\keyvalsarg}
%
% \shownesting{\cs{KFLT@subfloats}, \cs{KTLT@endsubfloats}}
%   {
%       \shownesting{
%           \begin{description}
%           \item[If {[}H{]} or \env{keywrap}:] Uses a \env{minipage}.
%           \item[If {[}W{]}:] Uses a \env{wrapfloat} and a \env{minipage}.
%           \item[If {[}M{]}:] Uses \cs{KFLT@marginfloat}.
%           \item[Otherwise:] Uses a \env{subfigure}, etc.
%           \end{description}
%       }
%       {Contents}
%   }
%
% \changes{v0.13}{2017/01/16}{Fix: Subfloat type selection.}
% \changes{v0.15}{2017/05/12}{Adjustments for \protect\env{keywrap}.}
%
% Start a subfloat environment
%    \begin{macrocode}
\NewDocumentCommand{\KFLT@subfloats}{m m m +m}
{%
    \KFLT@envignorespaces%
%    \end{macrocode}
% Parse the key-value combinations:
%    \begin{macrocode}
    \setkeys{KFLT@subgrpkeys}{#4}%
%    \end{macrocode}
% Nest the environment:
%    \begin{macrocode}
    \setboolean{KFLT@inkeysubfloats}{true}%
%    \end{macrocode}
% Figure out the width of each subfloat.
% If starred, use the full-page \cs{textwidth}, else use \cs{linewidth}.
% .9 is used to leave a little room between columns.
%    \begin{macrocode}
    \IfBooleanTF{#1}%
        {\setlength{\KFLT@rowboxwidth}{.9\textwidth/\real{#3}}}%
        {\setlength{\KFLT@rowboxwidth}{.9\linewidth/\real{#3}}}%
%    \end{macrocode}
% If [H], or in a \env{keywrap}, create an inline minipage:
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifstrequal{#2}{H}} or
        bool {KFLT@keywrap}
    }%
    {%
        \vskip\intextsep\noindent\begin{minipage}{\linewidth}%
        \normalcolor\reset@font\normalsize%
    }%
%    \end{macrocode}
% Not [H]:
%    \begin{macrocode}
    {%
        \ifstrequal{#2}{W}%
        {% [W]
%    \end{macrocode}
% [W]:
% \changes{v2.01}{2019/09/16}{Added \env{keysubfloats} [W].}
%    \begin{macrocode}
            \wrapfloat{\KFLT@subgrptype}{O}{.5\linewidth}%
            \setlength{\KFLT@rowboxwidth}{.5\KFLT@rowboxwidth}%
            \minipage{\linewidth}%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
            \hbadness=10000\relax%
%    \end{macrocode}
%    \begin{macrocode}
            \normalcolor\reset@font\normalsize%
        }%
        {% not [H]:
            \ifstrequal{#2}{M}%
            {% [M]:
%    \end{macrocode}
% [M]:
% \changes{v2.01}{2019/09/16}{Added \env{keysubfloats} [M].}
%    \begin{macrocode}
                \KFLT@marginfloat{\KFLT@subgrptype}%
                \setlength{\KFLT@rowboxwidth}{.9\marginparwidth/\real{#3}}%
            }% [M]
            {% subfloat
%    \end{macrocode}
% A subfloat:
%    \begin{macrocode}
                \IfBooleanTF{#1}%
                    {\begin{\KFLT@subgrptype*}[#2]}%
                    {\begin{\KFLT@subgrptype}[#2]}%
            }%
        }% not [H]
    }%
%    \end{macrocode}
% Set the caption type:
%    \begin{macrocode}
    \captionsetup*{type=\KFLT@subgrptype}%
%    \end{macrocode}
% Process continued floats:
%    \begin{macrocode}
    \ifbool{KFLT@subgrpcont}%
        {\ContinuedFloat}%
        {}%
%    \end{macrocode}
% Center the contents:
%    \begin{macrocode}
    \center\unskip%
%    \end{macrocode}
% Place the caption above the contents depending on \pkg{caption} \optn{position} option:
% \changes{v2.01}{2019/09/11}{Fix: Positions with \brand{Komascript}.}
%    \begin{macrocode}
    \caption@iftop%
        {\booltrue{KFLT@subcaptionistop}}%
        {\boolfalse{KFLT@subcaptionistop}}%
    \ifbool{KFLT@subcaptionistop}{\KFLT@caption{subgrp}}{}%
%    \end{macrocode}
% Not yet started a row of subfloats.
% The use of \cs{defcounter} makes these changes local.
%    \begin{macrocode}
    \defcounter{KFLT@numcols}{#3}%
    \defcounter{KFLT@thiscol}{0}%
%    \end{macrocode}
% Creat a group for the subfloats.
% Necessary in case they change \cs{tdartisttextcenter}, etc.
%    \begin{macrocode}
    \begingroup%
}
%    \end{macrocode}
% \end{macro}



% \begin{macro}{\KFLT@endsubfloats} \marg{starred?} \marg{loc}
%
% Ends a subfloat environment.
%    \begin{macrocode}
\newcommand*{\KFLT@endsubfloats}[2]{%
%    \end{macrocode}
% End the group containing the subfloats:
%    \begin{macrocode}
    \endgroup%
    \unskip%
    \endcenter%
%    \end{macrocode}
% A little extra space at the bottom:
%    \begin{macrocode}
    \par\addvspace{\bigskipamount}%
%    \end{macrocode}
% Optionally print artist's name and additional text:
%    \begin{macrocode}
    \KFLT@addartisttext{subgrp}%
%    \end{macrocode}
% Place the caption below the contents depending on \pkg{caption} \optn{position} option:
% \changes{v2.01}{2019/09/11}{Fix: Positions with \brand{Komascript}.}
%    \begin{macrocode}
    \ifbool{KFLT@subcaptionistop}{}{\KFLT@caption{subgrp}}%
%    \end{macrocode}
% End the float or minipage:
% \changes{v2.01}{2019/09/14}{Improved vertical space.}
%    \begin{macrocode}
    \ifboolexpr{%
        test {\ifstrequal{#2}{H}} or
        bool{KFLT@keywrap}
    }%
        {\end{minipage}\vskip\intextsep}% was [H]
        {% not [H]:
            \ifstrequal{#2}{W}%
            {% [W]
%    \end{macrocode}
% \changes{v2.01}{2019/09/16}{Added \env{keysubfloats} [W].}
%    \begin{macrocode}
                \endminipage%
                \endwrapfloat%
            }%
            {% not [W]:
                \ifstrequal{#2}{M}%
                {% [M]:
%    \end{macrocode}
% \changes{v2.01}{2019/09/16}{Added \env{keysubfloats} [M].}
%    \begin{macrocode}
                    \endKFLT@marginfloat%
                }% [M]
                {% subfloat
                    \IfBooleanTF{#1}% starred?
                        {\end{\KFLT@subgrptype*}}%
                        {\end{\KFLT@subgrptype}}%
                }%
            }% not [W]
        }% not [H]
%    \end{macrocode}
% Unnest the environment:
%    \begin{macrocode}
    \setboolean{KFLT@inkeysubfloats}{false}%
    \KFLT@envignorespaces%
}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\KFLT@LWR@hook@keysubfloats} Used by \pkg{lwarp}.
%    \begin{macrocode}
\newcommand*{\KFLT@LWR@hook@keysubfloats}{}
%    \end{macrocode}
% \end{macro}

% \begin{environment}{KFLT@keysubfloats} \marg{1: star?}
%       \marg{2: loc} \marg{3: float type} \marg{4: numcols}
%       \marg{5: \keyvalsarg} \marg{6: shared keys/values}
%
% A group of subfigures typeset in rows.
%
% \shownesting{\env{KFLT@keysubfloats}}
%   {
%       \shownesting{\cs{KFLT@subfloats}, \cs{KFLT@endsubfloats}}
%       {
%           \shownesting{
%               \begin{description}
%               \item[If {[}H{]} or \env{keywrap}:] Uses a \env{minipage}.
%               \item[If {[}W{]}:] Uses a \env{wrapfloat} and a \env{minipage}.
%               \item[If {[}M{]}:] Uses \cs{KFLT@marginfloat}.
%               \item[Otherwise:] Uses a \env{subfigure}, etc.
%               \end{description}
%           }
%           {Contents}
%       }
%   }
%
%    \begin{macrocode}
\NewDocumentEnvironment{KFLT@keysubfloats}{m m m m +m m}
{%
%    \end{macrocode}
% Error if trying to nest environments:
%    \begin{macrocode}
    \KFLT@nonest%
%    \end{macrocode}
% A hook for \pkg{lwarp} to set \cs{linewidth}, etc.
%    \begin{macrocode}
    \KFLT@LWR@hook@keysubfloats%
%    \end{macrocode}
% Default the options:
%    \begin{macrocode}
    \KFLT@subgrpdefaults%
%    \end{macrocode}
% Nest the group's keys:
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
    \edef\KFLT@sharedkeys{\KFLT@sharedkeys,#6}%
%    \end{macrocode}
% Default to figure float type:
%    \begin{macrocode}
    \renewcommand{\KFLT@subgrptype}{#3}%
%    \end{macrocode}
% Start of the environment:
%    \begin{macrocode}
    \KFLT@subfloats{#1}{#2}{#4}{#5}%
}% the start of the environment
%    \end{macrocode}
% end of the environment:
%    \begin{macrocode}
{%
    \KFLT@endsubfloats{#1}{#2}%
}
%    \end{macrocode}
% \end{environment}
%
%
%
% \begin{environment}{keysubfloats} * \oarg{2: loc} \marg{3: float type}
%       \marg{4: numcols} \marg{5: \keyvalsarg} \oarg{6: shared \keyvalsarg}
%
% A group of subfloats typeset in rows.
%
% \shownesting{\env{keysubfloats}, \env{keysubfigs}, or \env{keysubtabs}}
%   {
%       \shownesting{\env{KFLT@keysubfloats}}
%       {
%           \shownesting{\cs{KFLT@subfloats}, \cs{KFLT@endsubfloats}}
%           {
%               \shownesting{
%                   \begin{description}
%                   \item[If {[}H{]} or \env{keywrap}:] Uses a \env{minipage}.
%                   \item[If {[}W{]}:] Uses a \env{wrapfloat} and a \env{minipage}.
%                   \item[If {[}M{]}:] Uses \cs{KFLT@marginfloat}.
%                   \item[Otherwise:] Uses a \env{subfigure}, etc.
%                   \end{description}
%               }
%               {Contents}
%           }
%       }
%   }
%
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
\NewDocumentEnvironment{keysubfloats}{s O{tbp} m m +m O{}}
    {\KFLT@keysubfloats{#1}{#2}{#3}{#4}{#5}{#6}}
    {\endKFLT@keysubfloats}
%    \end{macrocode}
% \end{environment}


% \begin{environment}{keysubfigs} * \oarg{2: loc} \marg{3: numcols}
%       \marg{4: \keyvalsarg} \oarg{5: shared \keyvalsarg}
%
% A group of subfigures typeset in rows.
%
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
\NewDocumentEnvironment{keysubfigs}{s O{tbp} m +m O{}}
    {\KFLT@keysubfloats{#1}{#2}{figure}{#3}{#4}{#5}}
    {\endKFLT@keysubfloats}
%    \end{macrocode}
% \end{environment}


% \begin{environment}{keysubtabs} * \oarg{2: loc} \marg{3: numcols}
%       \marg{4: \keyvalsarg} \oarg{5: shared \keyvalsarg}
%
% A group of subtables typeset in rows.
% \changes{v2.06}{2021/06/25}{Added shared keys.}
%    \begin{macrocode}
\NewDocumentEnvironment{keysubtabs}{s O{tbp} m +m O{}}
    {\KFLT@keysubfloats{#1}{#2}{table}{#3}{#4}{#5}}
    {\endKFLT@keysubfloats}
%    \end{macrocode}
% \end{environment}
%
%
%
%
% \subsection{Margin floats}
%
% \begin{environment}{KFLT@marginfloat} \oarg{offset} \marg{type}
%
% \shownesting{\env{KFLT@marginfloat}}
%   {
%       \shownesting{\cs{marginpar}}
%           {\shownesting{\env{minipage}}{Contents}}
%   }
%
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
%    \begin{macrocode}
\newsavebox{\KFLT@marginfloatbox}

\NewDocumentEnvironment{KFLT@marginfloat}{O{-1.2ex} m}
{% start
    \FloatBarrier% keep floats in order
    \KFLT@envignorespaces%
    \begin{lrbox}{\KFLT@marginfloatbox}%
    \begin{minipage}{\marginparwidth}%
    \captionsetup{type=#2}%
    \hbox{}\vspace*{#1}%
    \noindent%
    \normalcolor\reset@font\normalsize%
}% start
{% end
    \end{minipage}%
    \end{lrbox}%
    \marginpar{\usebox{\KFLT@marginfloatbox}}%
    \KFLT@envignorespaces%
}% end
%    \end{macrocode}
% \end{environment}
%
%
% Provided in case \pkg{tufte-book} is not loaded:
%
% \begin{environment}{marginfigure} \oarg{offset}
%
% \shownesting{\env{marginfigure}}
%   {
%       \shownesting{\env{KFLT@marginfloat}}
%           {
%               \shownesting{\cs{marginpar}}
%                   {\shownesting{\env{minipage}}{Contents}}
%           }
%   }
%
%
% \changes{v0.12}{2016/12/03}{Added.}
%    \begin{macrocode}
\ProvideDocumentEnvironment{marginfigure}{O{-1.2ex}}
  {\begin{KFLT@marginfloat}[#1]{figure}}
  {\end{KFLT@marginfloat}}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{environment}{margintable} \oarg{offset}
% \changes{v0.12}{2016/12/03}{Added.}
%    \begin{macrocode}
\ProvideDocumentEnvironment{margintable}{O{-1.2ex}}
  {\begin{KFLT@marginfloat}[#1]{table}}
  {\end{KFLT@marginfloat}}
%    \end{macrocode}
% \end{environment}
%
%
%
%
% \subsection{Wrapped floats}
%
% \DescribeBoolean{KFL@keywrap} Tells the next keyfloat to wrap around some text.
%    \begin{macrocode}
\newboolean{KFLT@keywrap}
\boolfalse{KFLT@keywrap}
%    \end{macrocode}
%
%
% \DescribeLength{\KFLT@keywrapwidth} The width of the object to be wrapped beside the text.
%    \begin{macrocode}
\newlength{\KFLT@keywrapwidth}
%    \end{macrocode}
%
% \DescribeLength{\KFLT@keywrapparskip} The \cs{parskip} outside of the keywrap.
%    \begin{macrocode}
\newlength{\KFLT@keywrapparskip}
%    \end{macrocode}
%
% \DescribeLength{\KFLT@keywrapparindent} The \cs{parindent} outside of the keywrap.
%    \begin{macrocode}
\newlength{\KFLT@keywrapparindent}
%    \end{macrocode}
%
%
% \begin{environment}{keywrap} \marg{width} \marg{wrapped content}
%
% The main text is placed in a minipage to the left,
% and the wrapped content is later placed in another minipage to the right.
%
% \shownesting{\env{keywrap}}
% {
%   \shownesting[.4]{\env{minipage}}
%       {Main text.\newline Multiple paragraphs.}
%   \hfill
%   \cs{hfill}
%   \hfill
%   \shownesting*[.35]{\env{minipage}}
%       {Wrapped content.}
% }
%
% \changes{v0.15}{2017/05/11}{Added.}
% \changes{v2.01}{2019/09/11}{Fix: Font and color.}
% \changes{v2.01}{2019/09/16}{Fix: \cs{noindent}.}
%    \begin{macrocode}
\DeclareDocumentEnvironment{keywrap}{m +m}%
{%
    \par\noindent%
    \setlength{\KFLT@keywrapwidth}{\linewidth}%
    \addtolength{\KFLT@keywrapwidth}{-#1}%
    \addtolength{\KFLT@keywrapwidth}{-2em}%
    \minipage[t]{\KFLT@keywrapwidth}%
%
    \setlength{\parskip}{\KFLT@keywrapparskip}%
    \setlength{\parindent}{\KFLT@keywrapparindent}%
    \booltrue{KFLT@keywrap}%
}
{%
    \par%
    \endminipage%
    \hfill%
    \begin{minipage}[t]{#1}%
    \booltrue{KFLT@keywrap}%
    \normalcolor\reset@font\normalsize%
%    \end{macrocode}
%
% Inside this minipage, temporarily prevent underfull \cs{hbox} warnings:
% \changes{v2.02}{2021/05/28}{Avoid underfull \cs{hbox} warning.}
%    \begin{macrocode}
    \hbadness=10000\relax%
%    \end{macrocode}
%    \begin{macrocode}
    #2%
    \par%
    \unskip\vspace{\smallskipamount}%
    \end{minipage}%
    \par%
}

\BeforeBeginEnvironment{keywrap}{%
    \setlength{\KFLT@keywrapparskip}{\parskip}%
    \setlength{\KFLT@keywrapparindent}{\parindent}%
}
%    \end{macrocode}
%
% \end{environment}
%
%
% \clearpage
%
% \section{\pkg{keyfloat} package maintenance}
%
% To compile \filenm{keyfloat.sty} and \cs{keyfloat.pdf}
% from \filenm{keyfloat.dtx} and \filenm{keyfloat.ins}:
%
% \begin{sourceverb}
% pdflatex keyfloat.ins
% pdflatex keyfloat.dtx
% pdflatex keyfloat.dtx
% pdflatex keyfloat.dtx
% makeindex -s gglo.ist -o keyfloat.gls keyfloat.glo
% splitindex keyfloat.idx -- -s gind.ist
% pdflatex keyfloat.dtx
% pdflatex keyfloat.dtx
% \end{sourceverb}
%
%
% \iffalse
%</package>
% \fi
%
%
%
%
% \clearpage
% \pagestyle{plain}
%
% \renewcommand{\partname}{}
% \renewcommand{\thepart}{}
% ^^A \part{Change History and Index}
%
%
% \Finale
%
\endinput
