%%
%% This is file `multicol-xetex-bidi.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bidi.dtx  (with options: `table,multicol-xetex-bidi.def')
%% 
%%   __________________________________________________
%%   Vafa Khalighi
%% 
%%   Copyright (c) 2007--2025  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{54357}
%% \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         \~}
%%
\ProvidesFile{multicol-xetex-bidi.def}[2025/09/30 v1.5 bidi adaptations for multicol package for XeTeX engine]
\def\page@sofar{%
   \process@cols\mult@rightbox
       {\ifvoid\count@
          \setbox\count@\hbox to\hsize{}%
        \else
          \wd\count@\hsize
        \fi}%
   \count@\col@number \advance\count@\m@ne
   \mult@info\z@
    {Column spec: \the\full@width\space = indent
                  + columns + sep =\MessageBreak
        \the\multicol@leftmargin\space
        + \the\col@number\space
        x \the\hsize\space
        + \the\count@\space
        x \the\columnsep
     }%
\ifvmode\else\errmessage{Multicol Error}\fi
   \nointerlineskip
   \setbox\z@\hbox{p}\global\dimen\tw@\dp\z@
   \moveright\multicol@leftmargin
    \hbox to\full@width{%
       \bidi@multicol@align@columns
       \rlap{\phantom p}%
    }%
 \prevdepth\z@
 \kern-\dimen\tw@
 \ifdim\dimen\tw@ > \mc@gridwarn
   \PackageWarning{multicol}%
     {Very deep columns!\MessageBreak
      Grid alignment might be broken}%
 \fi
}
\def\LTR@column@boxes{%
    \process@cols\mult@firstbox{%
       \ifdim\dp\count@>\dimen\tw@
         \global\dimen\tw@\dp\count@ \fi
       \mc@col@status@write
       \box\count@
       \hss{\columnseprulecolor\vrule
              \@width\columnseprule}\hss}%
     \ifdim\dp\mult@rightbox>\dimen\tw@
       \global\dimen\tw@\dp\mult@rightbox \fi
     \mc@lastcol@status@write
     \box\mult@rightbox
}

\def\RTL@column@boxes{%
     \process@cols\mult@firstbox{%
       \hskip\hsize
       \hss{\columnseprulecolor\vrule
              \@width\columnseprule}\hss
     }%
     \hskip\hsize
     \process@cols\mult@firstbox{%
       \ifdim\dp\count@>\dimen\tw@
         \global\dimen\tw@\dp\count@ \fi
       \hskip-\hsize
       \mc@col@status@write
       \box\count@
       \hskip-\hsize
       \hskip-\columnsep
     }%
     \ifdim\dp\mult@rightbox>\dimen\tw@
       \global\dimen\tw@\dp\mult@rightbox \fi
     \hskip-\hsize
     \mc@lastcol@status@write
     \box\mult@rightbox
     \hskip-\hsize
     \hskip\full@width
 }

\newcommand\RTLmulticolcolumns
    {\let\bidi@multicol@align@columns
         \RTL@column@boxes}
\newcommand\LTRmulticolcolumns
    {\let\bidi@multicol@align@columns
      \LTR@column@boxes}
\newcommand\bidi@multicol@align@columns
    {\if@RTLmain\RTL@column@boxes\else\LTR@column@boxes\fi}
\bidi@AtEndPreamble{%
  \if@bidi@csdef{footinsv@l}{%
    \def\footnoterule{\kern-3\p@
      \hrule \@width \textwidth \kern 2.6\p@}%
  }{}%
}
\def\multicols#1{\col@number#1\relax
  \ifnum\col@number<\tw@
     \PackageWarning{multicol}%
      {Using `\number\col@number'
       columns doesn't seem a good idea.^^J
       I therefore use two columns instead}%
     \col@number\tw@ \fi
  \ifnum\col@number>20
     \PackageError{multicol}%
      {Too many columns}%
      {Current implementation doesn't
       support more than 20 columns.%
       \MessageBreak
       I therefore use 20 columns instead}%
     \col@number20 \fi
     \ifx\@footnotetext\mult@footnotetext
     \else
       \let\orig@footnotetext\@footnotetext
       \let\@footnotetext\mult@footnotetext
     \fi
     \ifx\@LTRfootnotetext\mult@LTRfootnotetext
     \else
       \let\orig@LTRfootnotetext\@LTRfootnotetext
       \let\@LTRfootnotetext\mult@LTRfootnotetext
     \fi
     \ifx\@RTLfootnotetext\mult@RTLfootnotetext
     \else
       \let\orig@RTLfootnotetext\@RTLfootnotetext
       \let\@RTLfootnotetext\mult@RTLfootnotetext
     \fi
  \@ifnextchar[\mult@cols{\mult@cols[]}}
\long\def\mult@footnotetext#1{\begingroup
         \hsize\textwidth
         \columnwidth\textwidth
         \orig@footnotetext{#1}\endgroup}
\long\def\mult@LTRfootnotetext#1{\begingroup
         \hsize\textwidth
         \columnwidth\textwidth
         \orig@LTRfootnotetext{#1}\endgroup}
\long\def\mult@RTLfootnotetext#1{\begingroup
         \hsize\textwidth
         \columnwidth\textwidth
         \orig@RTLfootnotetext{#1}\endgroup}
\def\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \textwidth{\hskip \dimexpr\textwidth-.4\columnwidth\relax \hrulefill }
  \kern2.6\p@}
\def\textwidth@footnoterule{\kern-3\p@
  \hrule \@width \textwidth \kern 2.6\p@}
\def\bidi@leave@mult@copyins{%
   \advance\dimen@-\skip\@bidi@copyins@
   \advance\dimen@-\ht\@bidi@copyins@
}

\bidi@AtEndPreamble{%
  \if@bidi@csundef{footinsv@l}{%
    \bidi@patchcmd{\multi@column@out}{%
      \ifvbox \@kludgeins
    }{%
      \ifvoid\@bidi@copyins@ \else
        \bidi@leave@mult@copyins
      \fi
      \ifvbox \@kludgeins
    }{}{}%
  }{}%
}

\endinput
%%
%% End of file `multicol-xetex-bidi.def'.
