% \iffalse meta-comment
% SPDX-FileCopyrightText: Copyright (c) 2021-2026 Yegor Bugayenko
% SPDX-License-Identifier: MIT
% \fi

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

% \GetFileInfo{yb-book.dtx}
% \DoNotIndex{\end,\empty,\defined,\def,\begin,\if,\isempty,\endgroup,\begingroup,\let,\else,\fi,\newcommand,\newenvironment}

% \iffalse
%<*driver>
\ProvidesFile{yb-book.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}
%<class>\ProvidesClass{yb-book}
%<*class>
[2026-05-31 0.11.0 YB Branded Book Style]
%</class>
%<*driver>
\documentclass{ltxdoc}
\usepackage{lmodern}
\usepackage{microtype}
  \microtypesetup{verbose=false,nopatch=footnote}
  \AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
\usepackage{href-ul}
\usepackage{graphicx}
\PageIndex
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{yb-book.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi

% \title{\includegraphics[width=0.75in]{yb-book-logo.pdf} \\ \LaTeX{} Class |yb-book|\thanks{The sources are on GitHub at \href{https://github.com/yegor256/yb-book}{yegor256/yb-book}}}
% \author{Yegor Bugayenko \\ \texttt{yegor256@gmail.com}}
% \date{\filedate, \fileversion}
%
% \maketitle
%
% \section{Introduction}
%
% \index{Amazon}
% The class |yb-book| was devised to assist the author in producing
% \href{https://www.yegor256.com/books.html}{his books} and in publishing them
% \href{https://www.amazon.com/Yegor-Bugayenko/e/B01AM1QMDK}{on Amazon}.
% Others are welcome to employ it for their own books. The procedure is
% straightforward:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass{yb-book}
\renewcommand*\thetitle{New Book About OOP}
\renewcommand*\theauthor{Jeff Lebowski}
\renewcommand*\thevolume{1}
\renewcommand*\theversion{1.0}
\begin{document}
\ybPrintTitlePage
\chapter{First One}
\section{About Something Interesting}
Hello, world!
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi

% Suggestions for additional options and commands are welcome; nevertheless, the style
% of the author's books is intentionally as plain as possible, eschewing formatting
% to the greatest extent practicable. The reasoning is set out
% \href{https://www.yegor256.com/2019/05/21/dont-improvise.html}{here}.

% \section{Options}

% Several class options are available:

% \begin{macro}{compact}
% This package option is to be used when the text is required in a more compact
% form, occupying less vertical space. It proves convenient for works of fiction.
% The author employs it to render the \href{https://www.yegor256.com/code-ahead.html}{Code Ahead} book.
% \end{macro}

% \begin{macro}{sparse}
% Under this package option, every section commences on a new page.
% \end{macro}

% \begin{macro}{manuscript}
% Whenever the format is not intended for Amazon printing
% but for some other purpose (the page size being A4), this option proves
% convenient. The author likewise employs it whenever the book is to be rendered
% for printing on paper for review purposes.
% \end{macro}

% \begin{macro}{authordraft}
% \changes{v0.4.0}{2024/03/23}{The package option \texttt{draft} renamed to \texttt{authordraft}}
% This option is appropriate when the document is a draft for reviewers (the page size being A4)
% and a watermark together with a compact form of the content is desired. The
% option is used in conjunction with the |\thereviewer{}| command, which may be redefined
% to embed the name of the reviewer within the watermark. This serves
% as a deterrent to theft of the book:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass[authordraft]{yb-book}
\renewcommand*\thereviewer{Walter Sobchak}
\begin{document}
Hello, world!
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \end{macro}

% \section{Meta Commands}

% A number of commands may be redefined within the preamble:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass{yb-book}
\newcommand*\thetitle{My New Book About OOP}
\newcommand*\theauthor{Yegor Bugayenko}
\newcommand*\thevolume{1}
\newcommand*\thedate{24 Feb 2022}
\newcommand*\theversion{1.4}
\newcommand*\thereviewer{Jeff Lebowski}
\begin{document}
... the content goes here ...
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi

% \section{Printers}

% A number of printers are provided---commands that render substantial blocks of text
% in the expected format:

% \begin{macro}{\ybPrintTitlePage}
% Prints the first page of a book. At minimum, |\thetitle|
% and |\theauthor| must be defined:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass{yb-book}
\renewcommand*\thetitle{My New Book}
\renewcommand*\theauthor{Yegor Bugayenko}
\begin{document}
\ybPrintTitlePage
.. the rest of the book goes here
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \end{macro}

% \begin{macro}{\ybPrintTOC}
% Prints the table of contents.
% \end{macro}

% \begin{macro}{\ybQuote}
% Prints a side quote:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass{yb-book}
\begin{document}
Hello, world!
\ybQuote{Never tell the truth to people who
  are not worthy of it}{Mark Twain}{}
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% A warning is emitted to the log whenever the quotation falls very close to the top
% or the bottom of a page, since the underlying |wrapfig| environment behaves
% poorly in such positions.
% \end{macro}

% \begin{macro}{\ybPrintBibliography}
% Prints the list of bib references.
% \end{macro}

% \begin{macro}{\ybPrintIndex}
% Prints index with an optional name of the section (instead of ``Index''):
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\documentclass{yb-book}
\begin{document}
Hello, world!
\ybPrintIndex[Recommended Books]
\end{document}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \end{macro}

% \StopEventually{}

% \section{Implementation}

% \changes{v0.1.0}{2022/01/09}{Initial version}
% \changes{v0.2.0}{2022/10/02}{Started using l3build}

% First, we parse package options:
% \changes{v0.3.0}{2023/05/22}{The \texttt{pgfopts} package is now used to parse package options.}
% \changes{v0.5.0}{2024/01/02}{The \texttt{sparse} package option added, to place every section on a new page.}
% \changes{v0.6.0}{2025/01/08}{The \texttt{apa} package option added, to enable APA citation style.}
% \changes{v0.7.0}{2025/12/14}{The \texttt{colored} package option added, to enable colors.}
%    \begin{macrocode}
\RequirePackage{pgfopts}
\pgfkeys{
  /yb/.cd,
  apa/.store in=\yb@apa,
  authordraft/.store in=\yb@authordraft,
  compact/.store in=\yb@compact,
  manuscript/.store in=\yb@manuscript,
  colored/.store in=\yb@colored,
  sparse/.store in=\yb@sparse,
}
\ProcessPgfPackageOptions{/yb}
%    \end{macrocode}

% Then, depending on the options like |authordraft| and |manuscript|, we preset
% options of the class |book| and then load it:
%    \begin{macrocode}
\makeatletter
\ifdefined\yb@authordraft
  \PassOptionsToClass{11pt}{book}
  \PassOptionsToClass{oneside}{book}
\else
  \ifdefined\yb@manuscript
    \PassOptionsToClass{12pt}{book}
    \PassOptionsToClass{oneside}{book}
  \else
    \PassOptionsToClass{11pt}{book}
    \PassOptionsToClass{twoside}{book}
  \fi
\fi
\makeatother
\LoadClass{book}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/href-ul}{href-ul} to underline links correctly:
%    \begin{macrocode}
\RequirePackage{href-ul}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/cleveref}{cleveref} for the |\cref| command:
% \changes{v0.7.0}{2025/07/06}{Added \texttt{cleveref} package for the \texttt{\char`\\cref} command.}
%    \begin{macrocode}
\PassOptionsToPackage{capitalize}{cleveref}
\RequirePackage{amsmath}
\RequirePackage{cleveref}
  \crefformat{section}{\S#2#1#3}
%    \end{macrocode}

% The class does not change the main font; the default Computer Modern
% Roman is used. Document authors are free to select a different font in
% their own preamble.
% \changes{v0.5.1}{2025/01/05}{Added the usage of \texttt{inputenc} in order to ensure UTF-8 encoding for the sources.}
% \changes{v0.8.1}{2026/05/25}{Removed the CMU Concrete font setup; the class no longer changes the main font and works under any engine.}

% \begin{macro}{geometry}
% Then, using |geometry|, we set up page layout:
%    \begin{macrocode}
\RequirePackage{geometry}
\geometry{
  paperwidth=6in, paperheight=9in,
  bindingoffset=0.25in,
  left=0.75in, right=0.75in, top=0.75in, bottom=1.25in}
\makeatletter
\ifdefined\yb@authordraft
  \geometry{a4paper, margin=1in, left=1.5in}
\else
  \ifdefined\yb@manuscript
    \geometry{a4paper, margin=1.2in}
  \fi
\fi
\makeatother
%    \end{macrocode}
% \end{macro}

% Then, we load \href{https://ctan.org/pkg/anyfontsize}{anyfontsize} to enable all sizes of fonts:
%    \begin{macrocode}
\RequirePackage{anyfontsize}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/tikz}{tikz} for graphics:
%    \begin{macrocode}
\RequirePackage{tikz}
  \usetikzlibrary{positioning}
  \usetikzlibrary{shapes}
  \usetikzlibrary{fit}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/chngcntr}{chngcntr} for something else:
%    \begin{macrocode}
\RequirePackage{chngcntr}
  \counterwithout{footnote}{chapter}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/lastpage}{lastpage} to enable rendering of the last page number:
%    \begin{macrocode}
\RequirePackage{lastpage}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/paralist}{paralist} for inline enumeration:
%    \begin{macrocode}
\RequirePackage{paralist}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/xcolor}{xcolor} for colors:
%    \begin{macrocode}
\RequirePackage{xcolor}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/graphicx}{graphicx} to enable graphic files inclusion:
%    \begin{macrocode}
\RequirePackage{graphicx}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/enumitem}{enumitem} for inline enumeration:
%    \begin{macrocode}
\PassOptionsToPackage{inline}{enumitem}
\RequirePackage{enumitem}
  \setlist{nosep}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/float}{float} for floating figures:
%    \begin{macrocode}
\RequirePackage{float}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/xfp}{xfp} and
% \href{https://ctan.org/pkg/xifthen}{xifthen} for if-then-else:
%    \begin{macrocode}
\RequirePackage{xfp}
\RequirePackage{xifthen}
%    \end{macrocode}

% Then, we load \href{https://ctan.org/pkg/csquotes}{csquotes} for better rendering:
%    \begin{macrocode}
\PassOptionsToPackage{autostyle=try}{csquotes}
\RequirePackage{csquotes}
%    \end{macrocode}

% \begin{macro}{\pagestyle}
% Then, we set the layout of a page to |plain|:
%    \begin{macrocode}
\pagestyle{plain}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{setspace}
% Then, using |setspace| package we set the spacing between lines in the text,
% depending on the package options:
%    \begin{macrocode}
\RequirePackage{setspace}
  \setstretch{1.2}
  \makeatletter
  \ifdefined\yb@compact\setstretch{1.0}\fi
  \ifdefined\yb@manuscript\setstretch{1.1}\fi
  \ifdefined\yb@authordraft\setstretch{1.4}\fi
  \makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{biblatex}
% Then, we configure |biblatex| for citation management:
%    \begin{macrocode}
\PassOptionsToPackage{indexing=cite,
  natbib=true,maxnames=2,minnames=1,doi=true,
  url=false,isbn=false}{biblatex}
\makeatletter
\ifdefined\yb@apa
  \PassOptionsToPackage{style=authoryear}{biblatex}
\else
  \PassOptionsToPackage{style=numeric}{biblatex}
\fi
\makeatother
\RequirePackage{doi}
\RequirePackage{biblatex}
  \DeclareCiteCommand{\citetitle}
    {\boolfalse{citetracker}%
     \boolfalse{pagetracker}%
     \usebibmacro{prenote}}
    {\ifciteindex
       {\indexnames{labelname}}
       {}%
     \printfield[citetitle]{labeltitle}}
    {\multicitedelim}
    {\usebibmacro{postnote}}
  \DeclareCiteCommand*{\citetitle}
    {\boolfalse{citetracker}%
     \boolfalse{pagetracker}%
     \usebibmacro{prenote}}
    {\ifciteindex
       {\indexnames{labelname}}
       {}%
     \printfield[citetitle]{title}}
    {\multicitedelim}
    {\usebibmacro{postnote}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{condensed}
% Then, we define |condensed| environment for snippets:
%    \begin{macrocode}
\newenvironment{condensed}
  {\begingroup%
    \lstset{columns=fixed,basewidth=0.45em}}
  {\endgroup}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{microtype}
% Then, we include |microtype| for better rendering:
%    \begin{macrocode}
\makeatletter
\ifdefined\yb@authordraft
  \PassOptionsToPackage{nopatch=footnote}{microtype}
\else
  \PassOptionsToPackage{nopatch=footnote,protrusion=true}{microtype}
\fi
\makeatother
\RequirePackage{microtype}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\section}
% Then, we redefine the |\section| command:
%    \begin{macrocode}
\makeatletter
\let\yb@oldsection\section
\def\yb@secstart{\ifdefined\yb@sparse\newpage\fi}
\ifdefined\yb@authordraft
  \PassOptionsToPackage{medium}{titlesec}
  \RequirePackage{titlesec}
\else
  \PassOptionsToPackage{raggedright}{titlesec}
  \RequirePackage{titlesec}
    \titlespacing{\section}{0em}{2em}{1em}
  \renewcommand\section{\yb@secstart\yb@oldsection}
\fi
\ifdefined\yb@compact
  \renewcommand\section{\yb@secstart\vspace{2em}\yb@oldsection}
\fi
\makeatother
%    \end{macrocode}
% \end{macro}

% Then, we do small tweaking:
%    \begin{macrocode}
\makeatletter
\renewcommand\@makefntext[1]{%
  \raggedright%
  \parindent=1em%
  \noindent\hb@xt@1.8em{\hss\@makefnmark}#1}
\makeatother
%    \end{macrocode}

% Then, if it's an |authordraft|, we put a watermark comment:
%    \begin{macrocode}
\makeatletter
\ifdefined\yb@authordraft
  \PassOptionsToPackage{absolute}{textpos}
  \RequirePackage{textpos}
    \TPGrid{16}{16}
  \RequirePackage{fancyhdr}
  \pagestyle{fancy}
  \renewcommand\headrulewidth{0em}
  \renewcommand\footrulewidth{0em}
  \setlength{\headheight}{3em}
  \fancyhf{}
  \fancyhead[L,C,LO,CO]{}
  \fancyhead[R,RO]{
    \begin{textblock}{16}[0.5,0.5](8,8)%
      \tikz \node[minimum width=16\TPHorizModule] {%
        \fontsize{64}{64}\selectfont\bfseries%
        \rotatebox{45}{
          \tikz \node
          [fill=gray!6, font=\ttfamily\color{white}]
          {it is a draft};%
        }%
      };%
    \end{textblock}%
    \begin{textblock}{4}(11.5,1)%
      \tikz \node [color=gray, rotate=270,
        font=\ttfamily\scriptsize, text width=24em] at (0,0) {%
        Copyright \textcopyright{} \the\year{} by \theauthor{}.
        All rights reserved. No part of the contents of
        this book may be reproduced or transmitted in any
        form or by any means without the written permission
        of the publisher. This particular manuscript is
        printed for \textbf{\thereviewer{}} and may be used only
        for one-time review. The manuscript has to be destroyed
        after the review.%
      };
    \end{textblock}
  }
  \fancyfoot[C,CO,C]{\small\ttfamily%
    page \thepage{} of \pageref{LastPage}}
\fi
\makeatother
%    \end{macrocode}

% \begin{macro}{\maketitle}
% Then, we redefine the |\maketitle| command:
%    \begin{macrocode}
\renewcommand\maketitle{
  {\LARGE\textbf{\thetitle}}
  \\[1em]
  by \theauthor{}
  \\[4em]
  \ifx\thevolume\empty\else%
    Volume \thevolume{}\\
  \fi
  \ifx\thedate\empty\else%
    Rendered on \thedate{}\\
  \fi
  \ifx\theversion\empty\else%
    Ver. \theversion{}
  \fi
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\incolor}
% Then, we define the |\incolor| command:
%    \begin{macrocode}
\makeatletter
\newcommand\incolor[2]{%
  \ifdefined\yb@colored\textcolor{#1}{#2}\else#2\fi}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ix}
% Then, we define the |\ix| command:
%    \begin{macrocode}
\newcommand\ix[2][]{%
  \incolor{brown}{#2}%
  \def\ixparam{#1}%
  \ifx\ixparam\empty%
    \index{#2}%
  \else%
    \index{#1}%
  \fi}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\emph}
% Then, we redefine the |\emph| command:
%    \begin{macrocode}
\renewcommand\emph[1]{\incolor{orange}{\textit{#1}}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybPrintTitlePage}
% Then, we define the |\ybPrintTitlePage| command:
%    \begin{macrocode}
\makeatletter
\newcommand\ybPrintTitlePage{
  \ifdefined\yb@authordraft\else
    \begin{titlepage}
      \ttfamily
      \vspace*{\fill}
      \noindent
      {\Huge\thetitle}
      \\[1em]
      by \theauthor{}
      \\[4em]
      \ifx\thevolume\empty\else%
        Volume \thevolume{}\\
      \fi
      \ifx\thedate\empty\else%
        \thedate{}\\
      \fi
      \ifx\theversion\empty\else%
        \theversion{}
      \fi
      \vspace*{\fill}
    \end{titlepage}
  \fi
}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybEpigraph}
% Then, we define the |\ybEpigraph| command to print the epigraph:
%    \begin{macrocode}
\newcommand\ybEpigraph[3]{
  \cleardoublepage
  \vspace*{\fill}
  \begin{quote}
  \begin{raggedleft}
  ``#1'' \\[1em]
  {---} #2 \\
  \citetitle{#3}\\
  \citeyear{#3}\par
  \end{raggedleft}
  \end{quote}
  \vspace*{\fill}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybPrintTOC}
% Then, we define the |\ybPrintTOC| command to print the table of contents:
%    \begin{macrocode}
\makeatletter
\newcommand\ybPrintTOC{%
  \ifdefined\yb@authordraft\else%
    \ifdefined\yb@compact\else\cleardoublepage\fi%
    {\setstretch{0.7}\tableofcontents}%
  \fi%
}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybPrintIndex}
% Then, we configure the |imakeidx| package and define the |\ybPrintIndex| command:
%    \begin{macrocode}
\RequirePackage{imakeidx}
  \renewbibmacro*{citeindex}{\indexnames{labelname}{}}
  \makeindex
  \indexsetup{othercode={\hyphenpenalty=10000}}
\makeatletter
\newcommand\ybPrintIndex[1][Index]{%
  \ifdefined\yb@authordraft\else%
    \ifdefined\yb@compact\else\cleardoublepage\fi%
    {%
      \setstretch{1.0}%
      \small%
      \addcontentsline{toc}{chapter}{#1}%
      \printindex%
    }%
  \fi%
}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybQuote}
% Then, with the help of |wrapfig| and |mdframed|, we define the |\ybQuote| command:
%    \begin{macrocode}
\RequirePackage{wrapfig}
\RequirePackage{mdframed}
\RequirePackage{changepage}
  \strictpagecheck
\mdfdefinestyle{quoteodd}{backgroundcolor=black!0,
  leftmargin=1em,rightmargin=0em,
  innerleftmargin=1em,innerrightmargin=0em,
  innertopmargin=0em,innerbottommargin=0em,
  skipabove=0em,skipbelow=0em,
  linewidth=.2em,
  topline=false,bottomline=false,rightline=false}
\mdfdefinestyle{quoteeven}{backgroundcolor=black!0,
  rightmargin=1em,leftmargin=0em,
  innerrightmargin=1em,innerleftmargin=0em,
  innertopmargin=0em,innerbottommargin=0em,
  skipabove=0em,skipbelow=0em,
  linewidth=.2em,
  topline=false,bottomline=false,leftline=false}
\makeatletter
\newcommand\ybQuote[3]{%
  \ifthenelse{\isempty{#3}}{}{
    \ifx\hfuzz#2\hfuzz%
      \index{#3}%
    \else%
      \index{#3, #2}%
    \fi%
  }%
  \ifdim\pagetotal<4\baselineskip\relax%
    \ClassWarning{yb-book}{ybQuote stays at the top of a page: \detokenize{#1}}%
  \fi%
  \ifdim\dimexpr\pagegoal-\pagetotal\relax<8\baselineskip\relax%
    \ClassWarning{yb-book}{ybQuote stays at the bottom of a page: \detokenize{#1}}%
  \fi%
  \def\yb@body{%
    \raggedright%
    \ifx\hfuzz#3\hfuzz%
      #1%
    \else%
      ``#1''\\\raggedleft---#2 #3%
    \fi%
  }
  \ifdefined\yb@authordraft%
    \begin{wrapfigure}{r}{0.4\textwidth}%
      \begin{mdframed}[style=quoteodd]%
        \yb@body%
      \end{mdframed}%
    \end{wrapfigure}%
  \else%
    \begin{wrapfigure}{o}[2em]{0.4\textwidth}%
      \sffamily\checkoddpage%
      \ifoddpage%
        \begin{mdframed}[style=quoteodd]\yb@body\end{mdframed}%
      \else%
        \begin{mdframed}[style=quoteeven]\yb@body\end{mdframed}%
      \fi%
      \vspace{-1em}
    \end{wrapfigure}%
  \fi%
}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ybQuote}
% Then, we define the |\ybTweet| command:
% \changes{v0.11.0}{2026/05/31}{The \texttt{\char`\\ybTweet} command added.}
%    \begin{macrocode}
\makeatletter
\newcommand\ybTweet[1]{%
  \ifdefined\yb@authordraft\else%
    \ybQuote{#1}{}{}%
  \fi%
  }
\makeatother
%    \end{macrocode}
% \end{macro}

% Then, we use and configure |footmisc| as suggested
% \href{https://tex.stackexchange.com/questions/40072/incompatibility-between-footmisc-option-multiple-and-hyperref/62091#62091}{here}:
%    \begin{macrocode}
\RequirePackage{perpage}
\PassOptionsToPackage{bottom,perpage,multiple}{footmisc}
\RequirePackage{footmisc}
\makeatletter
\let\yb@oldfootnote\footnote
\newcommand\yb@nexttoken\relax
\newcommand\yb@isfootnote{%
  \ifx\footnote\yb@nexttoken\textsuperscript{,}\fi}
\renewcommand\footnote[1]{%
  \yb@oldfootnote{#1}\futurelet\yb@nexttoken\yb@isfootnote}
\makeatother
%    \end{macrocode}

% \begin{macro}{\ybPrintBibliography}
% Then, we define |\ybPrintBibliography|, to print a list of references:
% \changes{v0.6.2}{2025/01/19}{The \texttt{\char`\\ybPrintBibliography} command has an optional argument, which is the title of the chapter.}
%    \begin{macrocode}
\makeatletter
\newcommand\ybPrintBibliography[1][Bibliography]{%
  \AtNextBibliography{\small}%
  \raggedright%
  \ifdefined\yb@manuscript%
    \setlength\bibitemsep{0em}%
    \newpage%
    \begin{multicols}{2}%
      {\setstretch{1.0}\printbibliography}%
    \end{multicols}%
  \else%
    \setlength\bibitemsep{.2em}%
    \@openrightfalse%
    \printbibliography[heading=bibintoc,title={#1}]%
    \ifdefined\yb@compact\@openrighttrue\fi%
  \fi%
}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\highlight}
% Then, we define the |\highlight| command:
% \changes{v0.7.0}{2025/11/30}{The \texttt{\char`\\highlight} command was added.}
%    \begin{macrocode}
\makeatletter
\newcommand\highlight[1]{%
  \tikz[baseline=(text.base)] {
    \node[inner sep=0em, outer sep=0em] (text) {%
      {\ifdefined\yb@colored\color{orange}\fi#1}};
    \begin{scope}
      \path[use as bounding box] (text.east) rectangle (text.west);
      \draw[decorate,
        decoration={random steps, amplitude=0.05em, segment length=0.3em},
        line join=round,
        line cap=round,
        line width=.08em,
        draw=gray!80] ($(text.west) + (-0.2em, -.46em)$) rectangle ($(text.east) + (+0.2em, -.46em)$);
    \end{scope}
  }%
}
\makeatother
%    \end{macrocode}
% \end{macro}

% Then, a few layout configurations at the beginning of the document:
% \changes{v0.6.6}{2025/07/06}{Penalties for widows and clubs specified.}
%    \begin{macrocode}
\makeatletter
\AtBeginDocument{%
  \raggedbottom%
  \ifdefined\yb@authordraft%
    \raggedright%
  \fi%
  \setlength\topskip{0em}%
  \setlength\parindent{0em}%
  \setlength\fboxsep{0em}%
  \setlength\parskip{.5em}%
  \exhyphenpenalty=10000% to avoid line breaks before and after an em dash
  \widowpenalty=10000% to have fewer widows
  \clubpenalty=10000% to have fewer orphans
  \interfootnotelinepenalty=10000% to format footnotes better
  \hfuzz=3pt %
  \tolerance=1000 %
  \emergencystretch=1em %
  \hbadness=2000 %
}
\makeatother
%    \end{macrocode}

% Finally, a few meta commands with default values:
%    \begin{macrocode}
\newcommand*\thetitle{\textbackslash{}thetitle}
\let\thevolume\empty
\let\thedate\empty
\newcommand*\theversion{\textbackslash{}theversion}
\newcommand*\theauthor{\textbackslash{}theauthor}
\newcommand*\thereviewer{\textbackslash{}thereviewer}

\endinput
%    \end{macrocode}

% \Finale

%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
