%%
%% This is file `bidituftefloat.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bidi.dtx  (with options: `table,bidituftefloat.sty')
%% 
%%   __________________________________________________
%%   Vafa Khalighi
%% 
%%   Copyright (c) 2007--2026  Vafa Khalighi
%%   Copyright (c) 2018--2020 bidi-tex GitHub Organization
%% 
%%   It may be distributed and/or modified under the LaTeX Project Public License,
%%   version 1.3c or higher (your choice). The latest version of
%%   this license is at: http://www.latex-project.org/lppl.txt
%% 
%%   This work is “author-maintained” (as per LPPL maintenance status)
%%   by Vafa Khalighi.
%% 
%% 

%% \CheckSum{54343}
%% \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         \~}
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftefloat}[2025/01/03 v0.3
bidi implementation of tufte float]
\RequirePackage{xifthen}
\newcommand{\@bidituftefloat@pkgname}{bidituftefloat}
\newcommand{\bidituftefloatError}[2]{\PackageError{\@bidituftefloat@pkgname}{#1}{#2}}
\newcommand{\bidituftefloatDebugInfoNL}[1]{\ifthenelse{\boolean{@bidituftefloat@debug}}{\bidituftefloatInfoNL{#1}}{}}
\newcommand{\bidituftefloatInfoNL}[1]{\PackageInfo{\@bidituftefloat@pkgname}{#1\@gobble}}
\newboolean{@bidituftefloat@reversegeometry}
\setboolean{@bidituftefloat@reversegeometry}{false}
\DeclareOption{reversegeometry}{\setboolean{@bidituftefloat@reversegeometry}{true}}
\newboolean{@bidituftefloat@afourpaper}
\DeclareOption{a4paper}{\setboolean{@bidituftefloat@afourpaper}{true}}
\newboolean{@bidituftefloat@bfivepaper}
\DeclareOption{b5paper}{\setboolean{@bidituftefloat@bfivepaper}{true}}
\newboolean{@bidituftefloat@symmetric}
\newboolean{@bidituftefloat@twoside}
\DeclareOption{twoside}{%
\@twosidetrue  \@mparswitchtrue%
\setboolean{@bidituftefloat@twoside}{true}%
\setboolean{@bidituftefloat@symmetric}{true}%
}
\DeclareOption{oneside}{%
\@twosidefalse  \@mparswitchfalse%
\setboolean{@bidituftefloat@twoside}{false}%
\setboolean{@bidituftefloat@symmetric}{false}%
}
\IfClassLoadedT{book}{\ExecuteOptions{twoside}}
\newboolean{@bidituftefloat@debug}
\newcommand*{\@bidituftefloat@caption@justification}{\@bidituftefloat@justification@autodetect}
\ProcessOptions
%% Globally sets the length
\newcommand*{\gsetlength}[2]{%
  \setlength{#1}{#2}%
  \global#1=#1\relax%
}

%% Set the font sizes and baselines to match bidituftefloat's books
\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt{14}%
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}
\normalbaselineskip=14pt
\normalsize
\renewcommand\footnotesize{%
   \@setfontsize\footnotesize\@viiipt{10}%
   \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
   \abovedisplayshortskip \z@ \@plus\p@
   \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
   \def\@listi{\leftmargin\leftmargini
               \topsep 3\p@ \@plus\p@ \@minus\p@
               \parsep 2\p@ \@plus\p@ \@minus\p@
               \itemsep \parsep}%
   \belowdisplayskip \abovedisplayskip
}
%% Paragraph indentation and separation for marginal text
\newcommand{\@bidituftefloat@margin@par}{%
  \setlength{\RaggedRightParindent}{0.5pc}%
  \setlength{\JustifyingParindent}{0.5pc}%
  \setlength{\parindent}{0.5pc}%
  \setlength{\parskip}{0pt}%
}
\RequirePackage{ragged2e}
\ifthenelse{\boolean{@bidituftefloat@reversegeometry}}{%
\RequirePackage[letterpaper,right=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
\ifthenelse{\boolean{@bidituftefloat@afourpaper}}
  {\geometry{a4paper,right=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  {}
\ifthenelse{\boolean{@bidituftefloat@bfivepaper}}
  {\geometry{paperwidth=176mm,paperheight=250mm,right=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
  {}}{%
\RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
\ifthenelse{\boolean{@bidituftefloat@afourpaper}}
  {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  {}
\ifthenelse{\boolean{@bidituftefloat@bfivepaper}}
  {\geometry{paperwidth=176mm,paperheight=250mm,left=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
  {}}
\ifthenelse{\boolean{@bidituftefloat@symmetric}}
  {}
  {\geometry{asymmetric}}% forces internal LaTeX `twoside'
\setlength\marginparpush{10pt}
%% Font for margin items
\newcommand{\@bidituftefloat@marginfont}{\normalfont\footnotesize}
\newcommand*{\@bidituftefloat@caption@font}{\@bidituftefloat@marginfont}
\newcommand*{\setcaptionfont}[1]{\renewcommand*{\@bidituftefloat@caption@font}{#1}}
\newcommand{\@bidituftefloat@justification}{\justifying}%
\setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
\setlength\belowdisplayskip{6pt plus 2pt minus 4pt}
\newboolean{@bidituftefloat@changepage}
\IfFileExists{changepage.sty}{%
  \bidituftefloatDebugInfoNL{Found changepage.sty}
  \RequirePackage[strict]{changepage}
  \setboolean{@bidituftefloat@changepage}{true}
}{%
  \bidituftefloatDebugInfoNL{Found chngpage.sty}
  \RequirePackage[strict]{chngpage}
  \setboolean{@bidituftefloat@changepage}{false}
}
\newboolean{@bidituftefloat@odd@page}
\setboolean{@bidituftefloat@odd@page}{true}
\newcommand*{\@bidituftefloat@checkoddpage}{%
  \checkoddpage%
  \ifthenelse{\boolean{@bidituftefloat@changepage}}{%
    \ifoddpage%
      \setboolean{@bidituftefloat@odd@page}{true}%
    \else%
      \setboolean{@bidituftefloat@odd@page}{false}%
    \fi%
  }{%
    \ifcpoddpage%
      \setboolean{@bidituftefloat@odd@page}{true}%
    \else%
      \setboolean{@bidituftefloat@odd@page}{false}%
    \fi%
  }%
}
\newlength{\@bidituftefloat@overhang}% used by the fullwidth environment and the running heads
\newlength{\@bidituftefloat@fullwidth}
\newlength{\@bidituftefloat@caption@fill}
\newcommand{\bidituftefloatRecalculate}{%
  \setlength{\@bidituftefloat@overhang}{\marginparwidth}
  \addtolength{\@bidituftefloat@overhang}{\marginparsep}

  \setlength{\@bidituftefloat@fullwidth}{\textwidth}
  \addtolength{\@bidituftefloat@fullwidth}{\marginparsep}
  \addtolength{\@bidituftefloat@fullwidth}{\marginparwidth}

  \setlength{\@bidituftefloat@caption@fill}{\textwidth}
  \addtolength{\@bidituftefloat@caption@fill}{\marginparsep}
}
\AtBeginDocument{\bidituftefloatRecalculate}
\RequirePackage{optparams}%  provides multiple optional arguments for commands
\RequirePackage{placeins}
\newsavebox{\@bidituftefloat@margin@floatbox}
\newenvironment{@bidituftefloat@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@bidituftefloat@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \@bidituftefloat@caption@font%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \@bidituftefloat@caption@justification%
    \@bidituftefloat@margin@par%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@bidituftefloat@margin@floatbox}}%
  }
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@bidituftefloat@margin@float}[#1]{figure}}
  {\end{@bidituftefloat@margin@float}}
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@bidituftefloat@margin@float}[#1]{table}}
  {\end{@bidituftefloat@margin@float}}
\newcommand*{\@bidituftefloat@justification@autodetect}{\justifying}%

\newcommand{\@bidituftefloat@float@debug@info}{}% contains debug info generated as the float is processed
\newcommand{\@bidituftefloat@float@debug}[1]{% adds debug info to the queue for output
  \ifthenelse{\equal{\@bidituftefloat@float@debug@info}{}}%
    {\def\@bidituftefloat@float@debug@info{#1}}%
    {\g@addto@macro\@bidituftefloat@float@debug@info{\MessageBreak#1}}%
}
\newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p)
\newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}\@bidituftefloat@float@debug{Forcing position: [#1]}}% manually sets the float alignment
\newboolean{@bidituftefloat@float@recto}
\newcommand{\forcerectofloat}{\GlobalSetBoolean{@bidituftefloat@float@recto}{true}\@bidituftefloat@float@debug{Forcing page: [recto]}}
\newcommand{\forceversofloat}{\GlobalSetBoolean{@bidituftefloat@float@recto}{false}\@bidituftefloat@float@debug{Forcing page: [verso]}}
\newsavebox{\@bidituftefloat@figure@box}
\newsavebox{\@bidituftefloat@caption@box}
\let\@bidituftefloat@orig@float\@float
\let\@bidituftefloat@orig@endfloat\end@float
\newlength{\@bidituftefloat@caption@vertical@offset}
\setlength{\@bidituftefloat@caption@vertical@offset}{0pt}
\newcommand{\@bidituftefloat@stored@shortcaption}{}
\newcommand{\@bidituftefloat@stored@caption}{}
\newcommand{\@bidituftefloat@stored@label}{}
\long\def\@bidituftefloat@caption[#1][#2]#3{%
  \ifthenelse{\isempty{#1}}%
    {\gdef\@bidituftefloat@stored@shortcaption{#3}}%
    {\gdef\@bidituftefloat@stored@shortcaption{#1}}%
  \gsetlength{\@bidituftefloat@caption@vertical@offset}{-#2}% we want a positive offset to lower captions
  \gdef\@bidituftefloat@stored@caption{#3}%
}
\newcommand{\@bidituftefloat@label}[1]{%
  \gdef\@bidituftefloat@stored@label{#1}%
}
\newcommand{\@bidituftefloat@fps}{}
\newboolean{@bidituftefloat@float@star}
\newlength{\@bidituftefloat@float@contents@width}
\newenvironment{@bidituftefloat@float}[3][htbp]%
  {% begin @bidituftefloat@float
    % Should this float be full-width or just text-width?
    \ifthenelse{\equal{#3}{star}}%
      {\GlobalSetBoolean{@bidituftefloat@float@star}{true}}%
      {\GlobalSetBoolean{@bidituftefloat@float@star}{false}}%
    % Check page side (recto/verso) and store detected value -- can be overriden in environment contents
    \@bidituftefloat@checkoddpage%
    \ifthenelse{\boolean{@bidituftefloat@odd@page}}%
      {\GlobalSetBoolean{@bidituftefloat@float@recto}{true}\@bidituftefloat@float@debug{Detected page: [recto/odd]}}%
      {\GlobalSetBoolean{@bidituftefloat@float@recto}{false}\@bidituftefloat@float@debug{Detected page: [verso/even]}}%
    % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them.
    \renewcommand{\@bidituftefloat@fps}{#1}%
    \@bidituftefloat@float@debug{Allowed positions: [#1]}%
    \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}%
      {\renewcommand{\floatalignment}{b}\@bidituftefloat@float@debug{Presumed position: [bottom]}}%
      {\renewcommand{\floatalignment}{t}\@bidituftefloat@float@debug{Presumed position: [top]}}%
    % Capture the contents of the \caption and \label commands to use later
    \global\let\@bidituftefloat@orig@caption\caption%
    \global\let\@bidituftefloat@orig@label\label%
    \renewcommand{\caption}{\optparams{\@bidituftefloat@caption}{[][0pt]}}%
    \renewcommand{\label}[1]{\@bidituftefloat@label{##1}}%
    % Handle subfigure package compatibility
    \ifthenelse{\boolean{@bidituftefloat@packages@subfigure}}{%
      \bidi@patchcmd{\subfigure}{%
      \let\subfig@oldlabel=\label
      }{%
      \let\subfig@oldlabel=\@bidituftefloat@orig@label
      }
      {}
      {}
      \let\subtable=\subfigure
    }{}% subfigure package is not loaded
    \@bidituftefloat@orig@float{#2}[#1]%
    \ifthenelse{\boolean{@bidituftefloat@float@star}}%
      {\setlength{\@bidituftefloat@float@contents@width}{\@bidituftefloat@fullwidth}}%
      {\setlength{\@bidituftefloat@float@contents@width}{\textwidth}}%
    \begin{lrbox}{\@bidituftefloat@figure@box}%
      \begin{minipage}[\floatalignment]{\@bidituftefloat@float@contents@width}\hbox{}%
  }{% end @bidituftefloat@float
      \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
      \end{minipage}%
    \end{lrbox}%
    % build the caption box
    \begin{lrbox}{\@bidituftefloat@caption@box}%
      \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
        \ifthenelse{\NOT\equal{\@bidituftefloat@stored@caption}{}}{\@bidituftefloat@orig@caption[\@bidituftefloat@stored@shortcaption]{\@bidituftefloat@stored@caption}}{}%
        \ifthenelse{\NOT\equal{\@bidituftefloat@stored@label}{}}{\@bidituftefloat@orig@label{\@bidituftefloat@stored@label}}{}%
        \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
      \end{minipage}%
    \end{lrbox}%
    % now typeset the stored boxes
    \begin{fullwidth}%
      \begin{minipage}[\floatalignment]{\linewidth}%
        \ifthenelse{\boolean{@bidituftefloat@float@star}}%
          {\@bidituftefloat@float@fullwidth[\@bidituftefloat@caption@vertical@offset]{\@bidituftefloat@figure@box}{\@bidituftefloat@caption@box}}%
          {\@bidituftefloat@float@textwidth[\@bidituftefloat@caption@vertical@offset]{\@bidituftefloat@figure@box}{\@bidituftefloat@caption@box}}%
      \end{minipage}%
    \end{fullwidth}%
    \@bidituftefloat@orig@endfloat% end original LaTeX float environment
    % output debug info
    \ifthenelse{\boolean{@bidituftefloat@debug}}{%
      \typeout{^^J^^J----------- bidituftefloat package float information ----------}%
      \ifthenelse{\equal{\@bidituftefloat@stored@label}{}}%
        {\typeout{Warning: Float unlabeled!}}%
        {\typeout{Float label: [\@bidituftefloat@stored@label]}}%
      \typeout{Page number: [\thepage]}%
      \def\MessageBreak{^^J}%
      \typeout{\@bidituftefloat@float@debug@info}%
      \ifthenelse{\boolean{@bidituftefloat@symmetric}}%
        {\typeout{Symmetric: [true]}}%
        {\typeout{Symmetric: [false]}}%
      \typeout{----------------------------------------------------^^J^^J}%
    }{}%
    % reset commands and temp boxes and captions
    \gdef\@bidituftefloat@float@debug@info{}%
    \let\caption\@bidituftefloat@orig@caption%
    \let\label\@bidituftefloat@orig@label%
    \begin{lrbox}{\@bidituftefloat@figure@box}\hbox{}\end{lrbox}%
    \begin{lrbox}{\@bidituftefloat@caption@box}\hbox{}\end{lrbox}%
    \gdef\@bidituftefloat@stored@shortcaption{}%
    \gdef\@bidituftefloat@stored@caption{}%
    \gdef\@bidituftefloat@stored@label{}%
    \gsetlength{\@bidituftefloat@caption@vertical@offset}{0pt}% reset caption offset
  }
\newcommand{\@bidituftefloat@float@textwidth}[3][0pt]{%
  \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}{%
    % asymmetric or page is odd, so caption is on the right
    \hbox{%
      \usebox{#2}%
      \hspace{\marginparsep}%
      \smash{\raisebox{#1}{\usebox{#3}}}%
    }
    \@bidituftefloat@float@debug{Caption position: [right]}%
  }{% symmetric pages and page is even, so caption is on the left
    \hbox{%
      \smash{\raisebox{#1}{\usebox{#3}}}%
      \hspace{\marginparsep}%
      \usebox{#2}%
    }
    \@bidituftefloat@float@debug{Caption position: [left]}%
  }%
}
\newcommand{\@bidituftefloat@float@fullwidth}[3][0pt]{%
  \ifthenelse{\equal{\floatalignment}{b}}%
    {% place caption above figure
      \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}%
        {\hfill\smash{\raisebox{#1}{\usebox{#3}}}\par\usebox{#2}\@bidituftefloat@float@debug{Caption position: [above right]}}% caption on the right
        {\smash{\raisebox{#1}{\usebox{#3}}}\hfill\par\usebox{#2}\@bidituftefloat@float@debug{Caption position: [above left]}}% caption on the left
    }{% place caption below figure
      \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}%
        {\usebox{#2}\par\hfill\smash{\raisebox{#1}{\usebox{#3}}}\@bidituftefloat@float@debug{Caption position: [below right]}}% caption on the right
        {\usebox{#2}\par\smash{\raisebox{#1}{\usebox{#3}}}\hfill\@bidituftefloat@float@debug{Caption position: [below left]}}% caption on the left
    }%
}
\renewenvironment{figure}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{figure}{}}
  {\end{@bidituftefloat@float}}
\renewenvironment{table}[1][htbp]
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{table}{}}
  {\end{@bidituftefloat@float}}
\renewenvironment{figure*}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{figure}{star}}
  {\end{@bidituftefloat@float}}
\renewenvironment{table*}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{table}{star}}
  {\end{@bidituftefloat@float}}
\newenvironment{fullwidth}
  {\ifthenelse{\boolean{@bidituftefloat@symmetric}}%
     {\ifthenelse{\boolean{@bidituftefloat@changepage}}{\begin{adjustwidth*}{}{-\@bidituftefloat@overhang}}{\begin{adjustwidth}[]{}{-\@bidituftefloat@overhang}}}%
     {\begin{adjustwidth}{}{-\@bidituftefloat@overhang}}%
  }%
  {\ifthenelse{\boolean{@bidituftefloat@symmetric}}%
    {\ifthenelse{\boolean{@bidituftefloat@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}%
    {\end{adjustwidth}}%
  }
\long\def\@caption#1[#2]#3{%
  \par%
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \begingroup%
    \@parboxrestore%
    \if@minipage%
      \@setminipage%
    \fi%
    \@bidituftefloat@caption@font\@bidituftefloat@caption@justification%
    \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
    %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
%%
\DeclareRobustCommand{\@biditufteheading@newlinetospace}{%
  \@ifstar{\@biditufteheading@newlinetospace@i}{\@biditufteheading@newlinetospace@i}%
}
\def\@biditufteheading@newlinetospace@i{%
  \ifdim\lastskip>\z@\else\space\fi
  \ignorespaces%
}
\DeclareRobustCommand{\newlinetospace}[1]{%
  \let\@biditufteheading@orig@cr\\% save the original meaning of \\
  \def\\{\@biditufteheading@newlinetospace}% turn \\ and \\* into \space
  \let\newline\\% turn \newline into \space
  #1%
  \let\\\@biditufteheading@orig@cr% revert to original meaning of \\
}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\AtBeginDocument{%
  \ifthenelse{\boolean{@bidituftefloat@symmetric}}
    {\fancyhfoffset[LE,RO]{\@bidituftefloat@overhang}}
    {\fancyhfoffset[RE,RO]{\@bidituftefloat@overhang}}
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{} % clear header and footer fields
    \ifthenelse{\boolean{@bidituftefloat@symmetric}}
    {\fancyhead[LE]{\thepage\quad\textsl{\newlinetospace{\plainauthor}}}%
    \fancyhead[RO]{\textsl{\newlinetospace{\plaintitle}}\quad\thepage}}%
    {\fancyhead[RE,RO]{\textsl{\newlinetospace{\plaintitle}}\quad\thepage}}%
\fancypagestyle{plain}{
  \fancyhf{} % clear header and footer fields
  % Uncomment the following five lines of code if you want the opening page
  % of the chapter to express the folio in the lower outside corner.
  %  \ifthenelse{\boolean{@bidituftefloat@symmetric}}
  %  {\fancyfoot[LE,RO]{\thepage}}
  %  {\fancyfoot[RE,RO]{\thepage}}
}
\fancypagestyle{empty}{
  \fancyhf{} % clear header and footer fields
}
\def\morefloats{% provides a total of 52 floats
  \ifthenelse{\isundefined{\bx@S}}{%
    \bidituftefloatDebugInfoNL{Adding 34 more float slots.}
    \newinsert\bx@S
    \newinsert\bx@T
    \newinsert\bx@U
    \newinsert\bx@V
    \newinsert\bx@W
    \newinsert\bx@X
    \newinsert\bx@Y
    \newinsert\bx@Z
    \newinsert\bx@a
    \newinsert\bx@b
    \newinsert\bx@c
    \newinsert\bx@d
    \newinsert\bx@e
    \newinsert\bx@f
    \newinsert\bx@g
    \newinsert\bx@h
    \newinsert\bx@i
    \newinsert\bx@j
    \newinsert\bx@k
    \newinsert\bx@l
    \newinsert\bx@m
    \newinsert\bx@n
    \newinsert\bx@o
    \newinsert\bx@p
    \newinsert\bx@q
    \newinsert\bx@r
    \newinsert\bx@s
    \newinsert\bx@t
    \newinsert\bx@u
    \newinsert\bx@v
    \newinsert\bx@w
    \newinsert\bx@x
    \newinsert\bx@y
    \newinsert\bx@z
    \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
                    \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
                    \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
                    \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
                    \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
                    \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
                    \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
                    \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
                    \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
                    \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
                    \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
                    \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z}%
  }{% we've already added another 34 floats, so we'll add 26 more, but that's it!
    \ifthenelse{\isundefined{\bx@AA}}{%
      \bidituftefloatDebugInfoNL{Adding 26 more float slots.}
      \newinsert\bx@AA
      \newinsert\bx@BB
      \newinsert\bx@CC
      \newinsert\bx@DD
      \newinsert\bx@EE
      \newinsert\bx@FF
      \newinsert\bx@GG
      \newinsert\bx@HH
      \newinsert\bx@II
      \newinsert\bx@JJ
      \newinsert\bx@KK
      \newinsert\bx@LL
      \newinsert\bx@MM
      \newinsert\bx@NN
      \newinsert\bx@OO
      \newinsert\bx@PP
      \newinsert\bx@QQ
      \newinsert\bx@RR
      \newinsert\bx@SS
      \newinsert\bx@TT
      \newinsert\bx@UU
      \newinsert\bx@VV
      \newinsert\bx@WW
      \newinsert\bx@XX
      \newinsert\bx@YY
      \newinsert\bx@ZZ
      \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
                      \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
                      \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
                      \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
                      \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
                      \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
                      \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
                      \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
                      \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
                      \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
                      \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
                      \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z
                      \@elt\bx@AA\@elt\bx@BB\@elt\bx@CC\@elt\bx@DD\@elt\bx@EE
                      \@elt\bx@FF\@elt\bx@GG\@elt\bx@HH\@elt\bx@II\@elt\bx@JJ
                      \@elt\bx@KK\@elt\bx@LL\@elt\bx@MM\@elt\bx@NN
                      \@elt\bx@OO\@elt\bx@PP\@elt\bx@QQ\@elt\bx@RR
                      \@elt\bx@SS\@elt\bx@TT\@elt\bx@UU\@elt\bx@VV
                      \@elt\bx@WW\@elt\bx@XX\@elt\bx@YY\@elt\bx@ZZ}%
    }{%
      \bidituftefloatError{You may only call \string\morefloats\space twice. See the\MessageBreak bidituftefloat package documentation for other workarounds}
        {There are already 78 float slots allocated. Try using \string\FloatBarrier\space or\MessageBreak \string\clearpage\space to place some floats before creating more.}
    }%
  }%
}
\newboolean{@bidituftefloat@packages@subfigure}
\setboolean{@bidituftefloat@packages@subfigure}{false}
\AtBeginDocument{%
  \@ifpackageloaded{subfigure}
    {\GlobalSetBoolean{@bidituftefloat@packages@subfigure}{true}}
    {\GlobalSetBoolean{@bidituftefloat@packages@subfigure}{false}}%
}
\AtBeginDocument{%
  \@ifpackageloaded{float}{%
    % Save the redefined float environment (instead of the LaTeX float environment)
    \let\@bidituftefloat@orig@float\@float
    \let\@bidituftefloat@orig@endfloat\end@float

    % Define Tuftian float styles (with the caption in the margin)
    \newcommand{\floatc@bidituftefloatplain}[2]{%
      \begin{lrbox}{\@bidituftefloat@caption@box}%
        \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
          \@bidituftefloat@caption@font{\@fs@cfont #1:} #2\par%
        \end{minipage}%
      \end{lrbox}%
      \smash{\hspace{\@bidituftefloat@caption@fill}\usebox{\@bidituftefloat@caption@box}}%
    }
    \newcommand{\fs@bidituftefloatplain}{%
      \def\@fs@cfont{\@bidituftefloat@caption@font}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{}%
      \def\@fs@post{}%
      \def\@fs@mid{}%
      \let\@fs@iftopcapt\iftrue%
    }
    \let\fs@bidituftefloatplaintop=\fs@bidituftefloatplain
    \let\floatc@bidituftefloatplaintop=\floatc@bidituftefloatplain
    \newcommand\floatc@bidituftefloatruled[2]{%
      {\@fs@cfont #1} #2\par%
    }
    \newcommand\fs@bidituftefloatruled{%
      \def\@fs@cfont{\@bidituftefloat@caption@font}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{\hrule height.8pt depth0pt width\textwidth \kern2pt}%
      \def\@fs@post{\kern2pt\hrule width\textwidth\relax}%
      \def\@fs@mid{}%
      \let\@fs@iftopcapt\iftrue%
    }
    \newcommand\fs@bidituftefloatboxed{%
      \def\@fs@cfont{}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{%
        \setbox\@currbox\vbox{\hbadness10000
        \moveleft3.4pt\vbox{\advance\hsize by6.8pt
          \hrule \hbox to\hsize{\vrule\kern3pt
            \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}}
      }%
      \def\@fs@mid{\kern2pt}%
      \def\@fs@post{}%
      \let\@fs@iftopcapt\iftrue%
    }
  }{%
    % Nothing to do
  }
}
\AtBeginDocument{%
  \@ifpackageloaded{algorithm}{%
    % Set the float style to the Tuftian version
    \ifthenelse{\equal{\ALG@floatstyle}{plain}\OR\equal{\ALG@floatstyle}{ruled}\OR\equal{\ALG@floatstyle}{boxed}}{%
      \bidituftefloatInfoNL{Switching algorithm float style from \ALG@floatstyle\MessageBreak to bidituftefloat\ALG@floatstyle}%
      \floatstyle{bidituftefloat\ALG@floatstyle}%
      \restylefloat{algorithm}%
    }{}%
  }{%
    % Nothing to do
  }
}
\PassOptionsToPackage{caption=false}{subfig}
\endinput
%%
%% End of file `bidituftefloat.sty'.
