%%
%% 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')
%% 
%%   __________________________________________________
%%   Copyright (c) 2009--2019  Vafa Khalighi
%% 
%%   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{50084}
%% \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}[2018/10/07 v1.1 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@gfirstbox{%
       \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{%
  \ifnum\col@number<\tw@
     \LTR@column@boxes
  \else
     \process@cols\mult@gfirstbox{%
       \hskip\hsize
       \hss{\columnseprulecolor\vrule
              \@width\columnseprule}\hss
     }%
     \hskip\hsize
     \process@cols\mult@gfirstbox{%
       \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
  \fi
 }
\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>10
     \PackageError{multicol}%
      {Too many columns}%
      {Current implementation doesn't
       support more than 10 columns.%
       \MessageBreak
       I therefore use 10 columns instead}%
     \col@number10 \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@
  \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@csdef{footinsv@l}{%
    \def\bidi@leave@mult@footins@vr{%
       \advance\dimen@-\skip\footinsv@r
       \advance\dimen@-\ht\footinsv@r
     }%
    \def\bidi@leave@mult@footins@vl{%
       \advance\dimen@-\skip\footinsv@l
       \advance\dimen@-\ht\footinsv@l
     }%
    \def\bidi@init@mult@footinsv@r{%
      \multiply\count\footinsv@r\col@number
      \multiply\skip \footinsv@r\col@number
    }%
    \def\bidi@init@mult@footinsv@l{%
      \multiply\count\footinsv@l\col@number
      \multiply\skip \footinsv@l\col@number
    }%
    \def\bidi@reinsert@footnotesv@r{\ifvoid\footinsv@r\else
             \insert\footinsv@r{}\fi}%
    \def\bidi@reinsert@footnotesv@l{\ifvoid\footinsv@l\else
             \insert\footinsv@l{}\fi}%
    \bidi@patchcmd{\prepare@multicols}{%
      \reinsert@footnotes
    }{%
      \reinsert@footnotes
      \bidi@init@mult@footinsv@r
      \bidi@reinsert@footnotesv@r
      \bidi@init@mult@footinsv@l
      \bidi@reinsert@footnotesv@l
    }{}{}%
    \bidi@patchcmd{\multi@column@out}{%
      \ifnum \c@tracingmulticols>\thr@@
    }{%
       \ifvoid\footinsv@r
         \ifvoid\footinsv@l
         \else
           \PackageWarning{multicol}%
            {I moved some lines to
             the next page.\MessageBreak
             Footnotes on page
             \thepage\space might be wrong}%
         \fi
       \else
         \PackageWarning{multicol}%
          {I moved some lines to
           the next page.\MessageBreak
           Footnotes on page
           \thepage\space might be wrong}%
       \fi
  \ifnum \c@tracingmulticols>\thr@@
}{}{}%
\bidi@patchcmd{\endmulticols}{%
  \reinsert@footnotes
}{%
  \reinsert@footnotes
  \bidi@reinsert@footnotesv@r
  \bidi@reinsert@footnotesv@l
}{}{}%
\bidi@patchcmd{\speci@ls}{%
  \reinsert@footnotes
}{%
  \reinsert@footnotes
  \bidi@reinsert@footnotesv@r
  \bidi@reinsert@footnotesv@l
}{}{}%
\bidi@patchcmd{\speci@ls}{%
  \reinsert@footnotes
}{%
  \reinsert@footnotes
  \bidi@reinsert@footnotesv@r
  \bidi@reinsert@footnotesv@l
}{}{}%
  }{}%
  \bidi@patchcmd{\multi@column@out}{%
     \let\ifshr@kingsaved\ifshr@king
  }{%
    \if@bidi@csdef{footinsv@l}{%
      \divide\skip\footinsv@r\col@number
       \ifvoid\footinsv@r \else
          \bidi@leave@mult@footins@vr
       \fi
      \divide\skip\footinsv@l\col@number
       \ifvoid\footinsv@l \else
          \bidi@leave@mult@footins@vl
       \fi
     }{}%
     \ifvoid\@bidi@copyins@ \else
        \bidi@leave@mult@copyins
     \fi
     \let\ifshr@kingsaved\ifshr@king
  }{}{}%
}
\endinput
%%
%% End of file `multicol-xetex-bidi.def'.
