% \iffalse meta-comment
%
% mempatch.dtx
% Author: Peter Wilson (Herries Press) herries dot press at earthlink dot net
% Maintainer: Lars Madsen (daleif at math dot au dot dk)
% Copyright 2001 -- 2010 Peter R. Wilson
% Copyright 2011 -- 2013 Peter R. Wilson
% Copyright 2013--       Lars Madsen
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any 
% later version.
% The latest version of the license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of
% LaTeX version 2008/05/04 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This work consists of the files listed in the README file.
%
% 
% \fi
% \CheckSum{559}
%
% \def\dtxfile{\texttt{mempatch.dtx}}
% \def\fileversion{v1.0} \def\filedate{2003/10/04}
% \def\fileversion{v1.1} \def\filedate{2003/10/07}
% \def\fileversion{v1.2} \def\filedate{2003/11/16}
% \def\fileversion{v2.0a} \def\filedate{2004/02/19}
% \def\fileversion{v2.1} \def\filedate{2004/03/01}
% \def\fileversion{v2.3} \def\filedate{2004/03/28}
% \def\fileversion{v2.4} \def\filedate{2004/04/26}
% \def\fileversion{v2.5} \def\filedate{2004/04/27}
% \def\fileversion{v2.6} \def\filedate{2004/04/30}
% \def\fileversion{v2.7} \def\filedate{2004/05/10}
% \def\fileversion{v2.8} \def\filedate{2004/05/13}
% \def\fileversion{v3.0} \def\filedate{2004/12/14}
% \def\fileversion{v3.1} \def\filedate{2004/12/19}
% \def\fileversion{v3.2} \def\filedate{2005/01/01}
% \def\fileversion{v3.3} \def\filedate{2005/01/17}
% \def\fileversion{v3.4} \def\filedate{2005/01/18}
% \def\fileversion{v3.5} \def\filedate{2005/02/01}
% \def\fileversion{v3.6} \def\filedate{2005/02/07}
% \def\fileversion{v3.7} \def\filedate{2005/02/26}
% \def\fileversion{v3.8} \def\filedate{2005/03/06}
% \def\fileversion{v3.9} \def\filedate{2005/03/23}
% \def\fileversion{v3.10} \def\filedate{2005/05/16}
% \def\fileversion{v3.11} \def\filedate{2005/05/23}
% \def\fileversion{v3.12} \def\filedate{2005/06/06}
% \def\fileversion{v4.1} \def\filedate{2005/10/06}
% \def\fileversion{v4.1h} \def\filedate{2005/11/15}
% \def\fileversion{v4.2} \def\filedate{2005/11/21}
% \def\fileversion{v4.3} \def\filedate{2005/12/13}
% \def\fileversion{v4.4} \def\filedate{2006/01/21}
% \def\fileversion{v4.4a} \def\filedate{2006/01/23}
% \def\fileversion{v4.5} \def\filedate{2006/08/08}
% \def\fileversion{v4.6} \def\filedate{2006/12/11}
% \def\fileversion{v4.7} \def\filedate{2006/12/23}
% \def\fileversion{v4.8} \def\filedate{2007/01/22}
% \def\fileversion{v4.9} \def\filedate{2007/12/14}
% \def\fileversion{v4.9a} \def\filedate{2007/12/24}
% \def\fileversion{v4.9a+} \def\filedate{2007/12/31}
% \def\fileversion{v5.0} \def\filedate{2008/05/26}
% \def\fileversion{v5.0} \def\filedate{2008/06/02}
% \def\fileversion{v5.1} \def\filedate{2008/07/11}
% \def\fileversion{v6.0} \def\filedate{2008/07/23}
% \def\fileversion{v6.0a} \def\filedate{2008/08/23}
% \def\fileversion{v6.0b} \def\filedate{2009/01/18}
% \def\fileversion{v6.0c} \def\filedate{2009/02/06}
% \def\fileversion{v6.0d} \def\filedate{2009/07/12}
% \def\fileversion{v6.0e} \def\filedate{2009/07/21}
% \def\fileversion{v6.0f} \def\filedate{2009/07/24}
% \def\fileversion{v6.0g} \def\filedate{2010/04/19}
%
% \title{The LaTeX \Lpack{memoir} class for configurable book 
%        typesetting: Code patches\thanks{This
%        file (\dtxfile) has version number \fileversion, last revised
%        \filedate.}}
%
% \author{%
% Peter Wilson
% ^^A\thanks{\texttt{herries dot press at earthlink dot net}}\\
% \\ Maintained by Lars Madsen\thanks{daleif at math dot au dot dk} \\
% The Herries Press
% }
% \date{\filedate}
% \maketitle
%
%  ^^A \MakeShortVerb{\=}
%
% \begin{abstract}
% The \Lpack{memoir} class is designed for typesetting
% general books such as novels, biographies, histories, 
% and so on, although as it supports all the functionality of the 
% standard \Lpack{book} class it can also be used for technical writing.
% It provides more functions than the standard class as well as 
% presenting a more friendly interface for the book designer.
% It can also simulate the typesetting style of the standard \Lpack{article}
% class.
%
%    Because of its newness not all packages work well with \Lpack{memoir}.
% Also, as more users beat on it, subtle flaws are discovered in \Lpack{memoir}
% itself. Patching code is supplied to resolve known problems.
%
%    Code is also provided for new functionality that will later be 
% folded into the class code.
% \end{abstract}
%
% \tableofcontents
% \listoftables
%
% \StopEventually{}
%
% 
%
% \section{Introduction}
%
% This document provides the commented source for packages that patch
% the LaTeX \Lpack{memoir} class~\cite{MEMOIR}. 
% This class is designed for typesetting
% general books such as novels, biographies, histories, 
% and so on. It has all the functionality of the standard \Lpack{book}
% class and, as well as providing some extra functions, also provides
% a more friendly interface for the document designer. As it can encompass
% everything that the \Lpack{book} class provides it may also be used
% for technical writing.
%
%
%    Section~\ref{sec:docstrip} describes some
% administrative elements and code for general use later in the 
% specification.
% The macros forming the package files are defined in section~\ref{sec:hyper}
% and in section~\ref{sec:class} onwards.
% 
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%
% \section{A driver for this document} \label{sec:docstrip}
%
% The next series of code contains the documentation driver file for
% \LaTeX, i.e., the file that will produce the documentation you are
% currently reading. This will be extracted from this file by the 
% \textsc{docstrip} program.
%
%    \begin{macrocode}
%<*driver>
\documentclass[twoside]{ltxdoc}
\usepackage{url}
%    \end{macrocode}
%
%    We do want an index, using linenumbers, but not update information.
%    \begin{macrocode}
\makeatletter
  \@mparswitchfalse
\makeatother
\EnableCrossrefs
\CodelineIndex
%% \RecordChanges
%    \end{macrocode}
% Don't use the default Short Verb.
%    \begin{macrocode}
\AtBeginDocument{\DeleteShortVerb{\|}}
%    \end{macrocode}
% We had better have page headings to aid navigation, but I don't
% like Uppercased titles.
%    \begin{macrocode}
\renewcommand{\MakeUppercase}[1]{#1}
\pagestyle{headings}
%    \end{macrocode}
% Need more space for ToC subsection numbers
%    \begin{macrocode}
\makeatletter
\renewcommand*{\l@subsection}{\@dottedtocline{2}{1.5em}{3.2em}}

%    \end{macrocode}
%    We may use many \file{docstrip} modules so we set the
%    \texttt{StandardModuleDepth} counter to 1.
%    \begin{macrocode}
\setcounter{StandardModuleDepth}{1}
%    \end{macrocode}
%    Some commonly used abbreviations
%    \begin{macrocode}
\newcommand*{\Lopt}[1]{\textsf {#1}}            % typeset an option
\newcommand*{\file}[1]{\texttt {#1}}            % typeset a file
\newcommand*{\Lcount}[1]{\textsl {\small#1}}    % typeset a counter
\newcommand*{\pstyle}[1]{\textsl {#1}}          % typeset a pagestyle
\newcommand*{\Lenv}[1]{\texttt {#1}}            % typeset an environment
\newcommand*{\Lpack}[1]{\textsf {#1}}           % typeset a package
\newcommand*{\ctt}{\textsc{ctt}}
\newcommand{\Lclass}[1]{\textsf{#1}}
\newcommand{\ledmac}{ledmac}
\newcommand{\Ledmac}{\Lpack{\ledmac}}
\newcommand{\edmac}{\texttt{EDMAC}}
\newcommand{\tabmac}{\texttt{TABMAC}}
\newcommand{\PWcomment}[1]{}
\newenvironment{PW}{\itshape}{}
\renewenvironment{PW}{\sffamily}{}
\newcommand{\texbook}{\textit{TeXbook}}
\newcommand{\thetexbook}{\textit{The TeXbook}}
\newcommand{\egstart}{}
\newcommand{\egmid}{}
\newcommand{\egend}{}
\renewcommand{\egstart}{%
   \par
   \begingroup
   \centering
   \begin{minipage}{0.45\textwidth}}
\renewcommand{\egmid}{%
   \end{minipage}\hfill\begin{minipage}{0.45\textwidth}}
\renewcommand{\egend}{%
   \end{minipage}\par\endgroup}
%    \end{macrocode}
%    We want the full details printed.
%    \begin{macrocode}
\begin{document}
\DocInput{mempatch.dtx}
\PrintIndex
%% \PrintChanges
\end{document}
%</driver>
%    \end{macrocode}
%
% 
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}\
% \DoNotIndex{\@dotsep,\@empty,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
% \DoNotIndex{\@namedef,\@nameuse,\csname,\endcsname}
%
%
%
% \section{Patches for hyperref and friends} \label{sec:hyper}
%
% The \Lpack{hyperref} package~\cite{HYPERREF} is a marvel of macro coding but it does
% seem to have a habit of not working too well with classes or packages
% that contain anything out of the
% ordinary.
%
%    \begin{macrocode}
%<*hyper>
%    \end{macrocode}
%
%
% The \Lpack{memhfixc} package provides \Lpack{hyperref} related temporary 
% fixes and extensions for current version of the \Lpack{memoir} class.
% \begin{itemize}
% \item  hyperref fix for part and chapter entries in the ToC (v1.0)
%  \item Other fixes as and when
% \end{itemize}
% The class will automatically load the package after
% \Lpack{hyperref}.
% 
%    \begin{macrocode}
%%
%% The memhfixc package provides hyperref related temporary 
%% fixes and extensions for the memoir class.
%%     o hyperref fix for part and chapter entries in the ToC (v1.0)
%%     o Other fixes as and when
%% 
%% Only use this package in conjunction with the hyperref package. 
%% Memoir will automatically load the package after hyperref, no
%% interaction needed
%%
%% Version 1.24  2025/09/16
%% Version 1.23  2025/03/06
%% Version 1.22  2023/09/10
%% Version 1.21  2023/07/28
%% Version 1.21  2023/07/28
%% Version 1.20  2022/11/17
%% Version 1.19  2021/06/16
%% Version 1.18  2019/10/24
%% Version 1.17  2013/05/30
%% Version 1.16  2013/05/16
%% Version 1.15  2010/08/17
%% Version 1.14  2010/06/10
%% Version 1.13  2010/04/19
%% Version 1.12  2009/02/06
%% Version 1.11  2009/01/18
%% Version 1.10  2008/08/23
%% Version 1.9  2006/11/22
%% Version 1.8  2006/01/21
%% Version 1.7  2005/11/15
%% Version 1.6  2004/05/13
%% Version 1.5  2003/10/14
%% Version 1.4  2003/09/26
%% Version 1.3  2003/02/20
%% Version 1.2  2003/02/02
%% Version 1.1  2003/01/22
%% Version 1.0  2002/10/22
%%
%    \end{macrocode}
% 
%
%    \begin{macrocode}
\ProvidesPackage{memhfixc}[2025/09/16 v1.24 hyperref package fixes for memoir class]
%    \end{macrocode}
%
% \begin{macro}{\M@hfixcfinish}
% The \Lpack{memhfixc} package is only useful with the memoir class
%    \begin{macrocode}
\let\M@hfixcfinish\relax
\@ifclassloaded{memoir}{}%
                       {\let\M@hfixcfinish\endinput
                        \typeout{No memoir class: memhfixc does nothing}}
\M@hfixcfinish

%    \end{macrocode}
% \end{macro}
%
% \subsection{Patches for nameref}
%
% 
% \changes{v1.21}{2023/07/25}{Patches removed}
%
% As of Summer 2023, memoir now autoloads \Lpack{nameref} and adjusts
% it self to it. Thus no patches needed.
%
% 
% \bigskip\noindent
% We are done unless the \Lpack{hyperref} package has been loaded
%    \begin{macrocode}
%% We are done unless the hyperref package has been loaded
\@ifpackageloaded{hyperref}{}{\let\M@hfixcfinish\endinput}
\M@hfixcfinish

%    \end{macrocode}
%
% \subsection{Patches for hyperref}
%
% \begin{macro}{\H@old@sbook}
% \begin{macro}{\@sbook}
% \Lpack{hyperref} patches \cs{@spart}, we do the same for \cs{@sbook}.
% \changes{v1.24}{2025/09/17}{Updated to be similar to the code used for \cs{@spart} in hyperref v7}
%    \begin{macrocode}
\let\H@old@sbook\@sbook
\def\@sbook#1{%
  \Hy@MakeCurrentHrefAuto{book*}%
  \Hy@raisedlink{%
    \hyper@anchorstart{\@currentHref}\hyper@anchorend
  }%
  \H@old@sbook{#1}
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Names for book for hyperref autoref}
%
% Added via a loop and some AI. Might be better to add it to \Lpack{hyperref} (have sendt request on GitHub).
% \changes{v1.24}{2025/09/17}{Changed to do this via a loop. Also found names for all the languages currently supported in \Lpack{hyperref}}
%    \begin{macrocode}
\ExplSyntaxOn
\cs_new_protected:Npn \_memoir_append_bookautorefname:nn #1#2
{
  \@ifundefined{HyLang@#1}{}{%
    \ExpandArgs{c}\g@addto@macro{HyLang@#1}{\def\bookautorefname{#2}}}
}
\clist_set:Nn \l_tmpa_clist {
  {afrikaans}{Boek},
  {english}{Book},
  {french}{Livre},
  {german}{Buch},
  {italian}{Libro},
  {magyar}{K\"onyv},
  {portuges}{Livro},
  {russian}{\CYRK\cyrn\cyri\cyrg\cyrr\cyra},
  {spanish}{Libro},
  {catalan}{Llibre},
  {vietnamese}{T\d{\^{a}}p s\'{a}ch},
  {greek}{\textBeta\textiota\textbeta\textlambda\'\textiota\textomicron},
  {dutch}{Boek},
  {norsk}{Bok},
  {danish}{Bog},
  {swedish}{Bok},
}
\clist_map_inline:Nn \l_tmpa_clist
{ \_memoir_append_bookautorefname:nn #1 }
\ExplSyntaxOff

%    \end{macrocode}
%
%
% \begin{macro}{\bookautorefname}
% \begin{macro}{\subfigureautorefname}
% \changes{v1.21}{2023/07/28}{Added \cs{subfigureautorefname}}
%    \begin{macrocode}
\providecommand{\bookautorefname}{Book}
\providecommand{\subfigureautorefname}{Subfigure}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \changes{v1.24}{2025/09/16}{Removed some super old code what was moved to hyperref in 2006}
%
% \begin{macro}{\M@sect}
% \Lpack{hyperref} fix for memoir's redefinition of \cs{@sect}
% \changes{v1.14}{2010/06/10}{At some point hyperref changed the way
% it changed \cs{@sect} such that the link target goes above the
% section title. Here we bring memoir back up to speed}
% The change being made is quite simple. We use \cs{M@sect} and it
% takes 9 args not the standard 8. There are only 3 changes.
% \changes{v1.15}{2010/08/17}{Fixed typo, 8 -> \#8}
% \changes{v3.8.4}{2025/09/18}{No changes, just verification that this match hpdftex.def v7.01o}
%    \begin{macrocode}
\@ifundefined{H@old@sectm@m}{% haven't fiddled with \M@sect
  \let\H@old@sectm@m\M@sect
  \def\M@sect#1#2#3#4#5#6[#7][#8]#9{%
    \ifnum #2>\c@secnumdepth%
      \expandafter\@firstoftwo%
    \else%
      \expandafter\@secondoftwo%
    \fi%
    {%
      \Hy@MakeCurrentHrefAuto{section*}%
      \setlength{\Hy@SectionHShift}{#3}%
      \begingroup
      \toks@{\H@old@sectm@m{#1}{#2}{#3}{#4}{#5}{#6}[{#7}][{#8}]}% <--
      \toks\tw@\expandafter{%
        \expandafter\Hy@SectionAnchorHref\expandafter{\@currentHref}%
        #9% <---
      }%
      \edef\x{\endgroup%
        \the\toks@{\the\toks\tw@}%
      }\x%
    }{%
      \H@old@sectm@m{#1}{#2}{#3}{#4}{#5}{#6}[{#7}][{#8}]{#9}% <--
    }%
  }%
}%
{% already fiddled \M@sect 
}

%    \end{macrocode}
% \end{macro}
% ^^A moved addition to \@resets@pp to memoir proper
%
% ^^A moved addition to \@resets@ppsub and \endsubappendices to memoir proper
%
% \begin{macro}{\cftaddtitleline}
% \begin{macro}{\cftaddnumtitleline}
% \Lpack{hyperref} fix for memoir's add to contents macros
%      (discovered by Martin Siegumfeldt, \ctt{} 2003/09/25
%       \textit{`Combinig [sic] Tocloft and hyperref'}
%    \begin{macrocode}
\renewcommand{\cftaddtitleline}[4]{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{#4}{\@currentHref}}}
\renewcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{%
  \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}{\@currentHref}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\caption}
% Yet another little jolly (fixed in version 1.5). \Lpack{hyperref}'s
% \verb?\def? of \verb?\caption? cunningly messes up \Lpack{memoir}'s,
% thereby screwing up the labels for subcaptions.
% 
% \changes{v1.24}{2025/09/18}{Since this is just an prepend, we can do it with a patch}
%    \begin{macrocode}
 %\let\m@moldhypcaption\caption
 %\renewcommand{\caption}{\donemaincaptiontrue\m@moldhypcaption}
\xpretocmd\caption{\donemaincaptiontrue}
{}{\typeout{Preto patch for \string\caption\space failed}}

%    \end{macrocode}
% \end{macro}
%
% More tweaks are needed for continued captions and sidecaptions.  The
% need for these discovered by \v{Z}arko F \v{C}u\v{c}ej (for
% \cs{contcaption}) and by J{\o}rgen Larsen (for \cs{sidecaption}),
% and by Eitan Gurari (for \texttt{tex4ht}).
% \changes{v1.7}{2005/11/15}{Added tweaks for \cs{contcaption},
%                \cs{sidecaption} and \cs{sidecontcaption}}
%
% \begin{macro}{\c@memhycontfloat}
% \begin{macro}{\thememhycontfloat}
% \begin{macro}{\theHmemhycontfloat}
% We need an extra marker for continued captions.
% \changes{v1.7}{2005/11/15}{Added extra counter for continued captions}
% \changes{v1.10}{2008/08/23}{Fixed \cs{theHmemhycontfloat} undefined
%          problem (courtsesy Eitan Gurari)}
%    \begin{macrocode}
\newcounter{memhycontfloat}
\renewcommand*{\thememhycontfloat}{\arabic{memhycontfloat}}
\providecommand*{\theHmemhycontfloat}{}
\renewcommand*{\theHmemhycontfloat}{\arabic{memhycontfloat}}
\setcounter{memhycontfloat}{0}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\contcaption}
% Tweak the \cs{contcaption} macro.
% 
% \changes{v1.18}{2019/10/24}{Added a \cs{par} to get rid of a
% sporadic space comming from \cs{refstepcounter} under hyperref}
%    \begin{macrocode}
\renewcommand{\contcaption}{%
  \par%
  \refstepcounter{memhycontfloat}%
  \addtocounter{\@captype}{\m@ne}\H@refstepcounter{\@captype}%
  \@contcaption\@captype}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sidecaption@refstepcounter}
%   Under \Lpack{hyperref} we redefine what
%   \cs{sidecaption@refstepcounter} does. Here we use that it is
%   called with two args.
% \changes{v1.22}{2023/09/10}{Redef of new macro from memoir 3.8.2,
% that makes sidecaption handling easier.}
%    \begin{macrocode}
\renewcommand*\sidecaption@refstepcounter[2]{%
  \H@refstepcounter{#1}%
  \hyper@makecurrent{#2}%
}

%    \end{macrocode}
% \end{macro}
%
% \changes{v1.22}{2023/09/10}{Because of the redef in memoir 3.8.2 we
% no longer need this}
% ^^A \begin{macro}{\endsidecaption}
% ^^A % Tweak the \texttt{sidecaption} environment. I don't know why it 
% ^^A works but it took a lot of time trying all sorts of combinations
% ^^A of commands to get it to do so (if it really does).
% ^^A    \begin{macrocode}
 % \def\endsidecaption{%
 % \m@mscapend@fbox
 % \H@refstepcounter{\@captype}%
 % \hyper@makecurrent{\@captype}%
 % \m@mscaplabel
% ^^A    \end{macrocode}
% ^^A\changes{v1.17}{2013/05/30}{Forgot to add \cs{m@mscapcheckside}}
% ^^A    \begin{macrocode}
 % \m@mscapcheckside %<--- added 2013/05/30
 % \begin{lrbox}{\m@mscap@capbox}%
 %   \begin{minipage}[c]{\sidecapwidth}%
 %     \sidecapstyle
 %     \@caption\@captype[\m@mscap@fortoc]{\m@mscap@forcap}%
 %   \end{minipage}%
 % \end{lrbox}%
 % \m@mscapopboxes}

%  ^^A   \end{macrocode}
% ^^A \end{macro}
%
% \begin{macro}{\sidecontcaption}
% \begin{macro}{\endsidecontcaption}
% Tweaks for the \texttt{sidecontcaption} environment. Again it was 
% a miss, miss, \ldots hit method to get something that appears 
% to work.
% \changes{v1.22}{2023/09/10}{Because of the redef in memoir 3.8.2 we
% no longer need the redef of \cs{endsidecontcaption}}
%    \begin{macrocode}
\renewcommand*{\sidecontcaption}{%
  \refstepcounter{memhycontfloat}%
  \@sidecontcaption}
 % \def\endsidecontcaption{%
 % \m@mscapend@fbox
 % \addtocounter{\@captype}{\m@ne}\H@refstepcounter{\@captype}%
 % \hyper@makecurrent{memhycontfloat}%
 % \m@mscaplabel
% ^^A    \end{macrocode}
% ^^A \changes{v1.17}{2013/05/30}{Forgot to add \cs{m@mscapcheckside}}
% ^^A    \begin{macrocode}
 % \m@mscapcheckside %<--- added 2013/05/30
 % \begin{lrbox}{\m@mscap@capbox}%
 %   \begin{minipage}[c]{\sidecapwidth}%
 %     \sidecapstyle
 %     \@contcaption\@captype{\m@mscap@forcap}%
 %   \end{minipage}%
 % \end{lrbox}%
 % \m@mscapopboxes}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% ^^A % \begin{macro}{\@mem@titlerefnolink}
% ^^A %   \Lpack{hyperref} provide a \cs{ref*} command that does not give a
% ^^A %   hyperlink under \Lpack{hyperref}, we extend \cs{titleref} to
% ^^A %   support it.
% ^^A %   \changes{v1.21}{2023/08/07}{removed}
% ^^A %    \begin{macrocode}
% ^^A  %\def\@mem@titlerefnolink#1{\begingroup \let\numberline\@gobble
% ^^A  % \let\M@TitleReference\@mem@theTR % interrupt recursion of \ref
% ^^A  % \ref*{#1}\endgroup}
% ^^A 
% ^^A %    \end{macrocode}
% ^^A % \end{macro}
%
% \begin{macro}{\printpageinnoteshyperref}
% When \Lpack{hyperref} is active, page references in the page notes
% list looks better with a specialised macro. The macro is provided
% within the class, and here we activate it.
%    \begin{macrocode}
\AtBeginDocument{%
    \let\printpageinnotes\printpageinnoteshyperref%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@footnotemark}
%  \changes{v1.16}{2013/05/08}{Slight change to hyperfootnotes redefinition of \cs{@footnotemark}}
%   When \Lpack{hyperref} is loaded with the \texttt{hyperfootnotes}
%   options, then \cs{@footnotemark} is overwritten, and our added
%   feature which automatically separate multiple footnotes with
%   commas is lost. It is however very easy to resurrect.
%    \begin{macrocode}
\ifHy@hyperfootnotes
 \def\@footnotemark{%
    \leavevmode
    \ifhmode\edef\@x@sf{\the\spacefactor}%
      \m@mmf@check% <--- added
    \nobreak\fi
    \stepcounter{Hfootnote}%
    \global\let\Hy@saved@currentHref\@currentHref
    \hyper@makecurrent{Hfootnote}%
    \global\let\Hy@footnote@currentHref\@currentHref
    \global\let\@currentHref\Hy@saved@currentHref
    \hyper@linkstart{link}{\Hy@footnote@currentHref}%
    \@makefnmark
    \hyper@linkend
    \m@mmf@prepare% <--- added
    \ifhmode\spacefactor\@x@sf\fi
    \relax
  }%
\fi

%    \end{macrocode}
%   
% \end{macro}
%
% \changes{v1.16}{2013/05/14}{Added fix for \cs{@starttoc}}
% \changes{v1.20}{2022/11/17}{Patch removed, by 2022 hyperref no longer change \cs{@starttoc}}
% ^^A \begin{macro}{\@starttoc}
% ^^A In memoir we altered \cs{@starttoc} such that \cs{tableofcontents}
% ^^A could be used multiple times. \Lpack{hyperref} resets this. So here
% ^^A is our reset of that reset.
% ^^A   \begin{macrocode}
% ^^A % patch removed as per 2022 hyperref does not touch \@starttoc
% ^^A % \Hy@AtBeginDocument{%
% ^^A %   \ifx\hyper@last\@undefined
% ^^A %    \def\@starttoc#1{%
% ^^A %      \begingroup\makeatletter
% ^^A %        \IfFileExists{\jobname.#1}{%
% ^^A %          \Hy@WarningNoLine{%
% ^^A %            old #1 file detected, not used; run LaTeX again%
% ^^A %          }%
% ^^A %        }{}%
% ^^A %        \if@filesw
% ^^A %    \end{macrocode}
% ^^A We rewrite this part to match our definition. The rest is a copy
% ^^A from \texttt{hyperref.sty}.
% ^^A %    \begin{macrocode}
% ^^A %        \AtEndDocument{%
% ^^A %          \expandafter\ifx\csname tf@#1\endcsname\relax
% ^^A %            \expandafter\newwrite\csname tf@#1\endcsname
% ^^A %            \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
% ^^A %          \fi
% ^^A %        }
% ^^A %        \fi
% ^^A %        \@nobreakfalse
% ^^A %     \endgroup
% ^^A %    }%
% ^^A %  \fi
% ^^A  % }
% ^^A %    \end{macrocode}
% ^^A  \end{macro}
%
% \changes{v3.6k}{2013/05/16}{Added hyperref support for page notes}
% In order to enable hyperlinks for page notes, we need a few extra
% things. First of all we only enable hyperlinked page noted if hyper
% footnotes are enabled, seems a good choice.
%    \begin{macrocode}
\ifHy@hyperfootnotes
%    \end{macrocode}
% Record the current hyperref anchor in the page note data.
%    \begin{macrocode}
  \let\m@m@pnwrite@fourtharg\m@m@pnwrite@fourtharg@hyperref
%    \end{macrocode}  
% Make the note typesetter use the anchor data.
%    \begin{macrocode}
  \let\pagenoteanchor\pagenotehyperanchor
%    \end{macrocode}  
% Fill in two hook responsable for turning the note marker in the text
% into a hyperlink. The code is more or less copied from
% \Lpack{hyperref}'s footnote handling. TODO: Redefine this at some point.
% \changes{1.23}{2025/02/25}{Renaming the Hpagenote counter, to avoid hyperef warning.}
%    \begin{macrocode}
  \newcounter{mem@Hpagenote}
  \@namedef{mem@pnmm@start@hook}{%
    \stepcounter{mem@Hpagenote}%
    \global\let\Hy@saved@currentHref\@currentHref
    \hyper@makecurrent{mem@Hpagenote}%
    \global\let\Hy@pagenote@currentHref\@currentHref 
    \global\let\@currentHref\Hy@saved@currentHref
    \hyper@linkstart{link}{\Hy@pagenote@currentHref}%
  }
  \@namedef{mem@pnmm@end@hook}{\hyper@linkend}
\fi

%    \end{macrocode}
%
%
% \subsection{Patch after \Lpack{hypcap}}
%
% The \Lpack{hypcap} package can help with some hyperref anchor placement in
% figure refences. But it also requires every figure or table to have
% a caption, thus it does not understand our \cmd{\contcaption} command.
%
% \changes{v3.7i}{2019/10/26}{added patch for \cmd{\contcaption} when
% \Lpack{hypcap} is loaded}
%    \begin{macrocode}
\AtEndPackage{hypcap}{%
  \long\def\@@contcaption##1##2{%
  \par
  \begingroup
     \@parboxrestore
     \if@minipage
       \@setminipage
     \fi
     \global\@capstartfalse% added  
     \normalsize
     \@makecaption{\csname fnum@##1\endcsname}{\ignorespaces ##2}\par
  \endgroup}
}
%    \end{macrocode}
%
% The end of the \Lpack{hyperref} related patches.
%
%    \begin{macrocode}
%</hyper>
%    \end{macrocode}
%
%
% \section{Patches for the class code}     \label{sec:class}
%
% At this date, 2008/07/23, with the simultaneous release of memoir v1.6180339 
% and the patch file, by definition there are no patches.
%
% As of 2018, we no longer generate \Lpack{mempatch}.
% 
% \subsection{Identification} \label{sec:id}
%
% \changes{v2.0}{2004/01/31}{No code in mempatch.sty}
% \changes{v2.1}{2004/02/12}{Code now required in mempatch.sty}
% \changes{v2.1a}{2004/02/19}{Extra pagestyle code for handling \cs{linespread}}
% \changes{v2.4}{2004/04/26}{Removed extraneous spaces}
% \changes{v2.4+}{2004/04/26}{Stopped noting general changes}
% 
%    \begin{macrocode}
%<*patch>
%    \end{macrocode}
%
% ^^A \typeout{mempatch.sty 2002/12/12 v1.1 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/01/06 v1.2 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/01/22 v1.3 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/02/13 v1.4 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/04/26 v1.5 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/06/28 v1.6 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/07/23 v1.7 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/09/16 v1.8 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/10/06 v1.8a Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/11/16 v1.9 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2004/01/31 v2.0 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/02/12 v2.1 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/02/19 v2.1a Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/03/01 v2.2 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/03/28 v2.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/26 v2.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/27 v2.3a Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/30 v2.3b Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/05/10 v2.3c Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/05/14 v2.3d Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/12/14 v3.0 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/12/19 v3.1 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/01 v3.2 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/17 v3.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/18 v3.4 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/01 v3.5 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/07 v3.6 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/26 v3.7 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/03/06 v3.8 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/03/23 v3.9 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/05/16 v3.10 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/05/23 v3.11 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/06/06 v3.12 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/09/25 v4.0 Patches for memoir class v1.618}
% ^^A \ProvidesFile{mempatch.sty}[2005/10/06 v4.1 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2005/11/21 v4.2 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2005/12/13 v4.3 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/01/21 v4.4 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/01/23 v4.4a Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/07/10 v4.5 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/08/08 v4.5 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/12/11 v4.6 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/12/23 v4.7 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/01/22 v4.8 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/12/14 v4.9 Patches for memoir class v1.618]
%
% ^^A \ProvidesFile{mempatch.sty}[2007/12/24 v4.9a Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/12/31 v4.9a+ Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2008/05/26 v5.0 Patches for memoir class v1.61803]
% ^^A \ProvidesFile{mempatch.sty}[2008/07/11 v5.1 Patches for memoir class v1.618033]
%    \begin{macrocode}
\ProvidesPackage{mempatch}[2009/07/24 v6.0f Patches for memoir class v1.6180339]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Version 6.0 was released simultaneously with version 1.6180339 
%%% of memoir.
%%% By definition there were no patches.
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%    \end{macrocode}
%
%
% The end of the patch file.
%
%    \begin{macrocode}
%</patch>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
% \begingroup
% \raggedright
% \begin{thebibliography}{GMSN94A}
%
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock \emph{The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% \bibitem[Rahtz23a]{NAMEREF}
%  Sebastian Rahtz, Heiko Oberdiek, The \LaTeX3 Project.
%  \newblock \emph{Section name references in LaTeX}.
%  \newblock 2023. 
%  \newblock (Available from CTAN (the \texttt{nameref} package) via 
%            \texttt{/macros/latex/contrib/hyperref/})
%
%
% \bibitem[Rahtz23b]{HYPERREF}
%  Sebastian Rahtz, Heiko Oberdiek, The \LaTeX3 Project.
%  \newblock \emph{Hypertext marks in LaTeX}.
%  \newblock 2023. 
%  \newblock (Available from CTAN via 
%            \texttt{/macros/latex/contrib/hyperref/})
%
% \bibitem[Wil23]{MEMOIR}
% Peter Wilson.
% \newblock \emph{The LaTeX \Lpack{memoir} class for configurable 
%                 typesetting: Source code}.
% \newblock July 2023.
% \newblock (Available from CTAN in
%            \texttt{macros/latex/contrib/memoir})
%
%
% \end{thebibliography}
% \endgroup
%
% \ Finale
%
\endinput

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

