% \iffalse 
%<*internal>
\iffalse
%</internal>
%<*readme>
___________________
The bidi package
v25.10.28

This package provides a convenient interface for typesetting
bidirectional texts with Plain TeX and LaTeX formats in XeTeX and
LuaTeX engines.

Current version release date: 2025/10/28

___________________________________________
Vafa Khalighi
  
Copyright (c) Vafa Khalighi 2007--2025
Copyright (c) bidi-tex GitHub Organization 2018--2020
                      
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.
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble

  __________________________________________________
  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.


\endpreamble
\askforoverwritefalse
\generate{\file{adjmulticol-xetex-bidi.def}{\from{\jobname.dtx}{table,adjmulticol-xetex-bidi.def}}}
\generate{\file{algorithm2e-xetex-bidi.def}{\from{\jobname.dtx}{table,algorithm2e-xetex-bidi.def}}}
\generate{\file{amsart-xetex-bidi.def}{\from{\jobname.dtx}{table,amsart-xetex-bidi.def}}}
\generate{\file{amsbook-xetex-bidi.def}{\from{\jobname.dtx}{table,amsbook-xetex-bidi.def}}}
\generate{\file{amsmath-xetex-bidi.def}{\from{\jobname.dtx}{table,amsmath-xetex-bidi.def}}}
\generate{\file{amstext-xetex-bidi.def}{\from{\jobname.dtx}{table,amstext-xetex-bidi.def}}}
\generate{\file{amsthm-xetex-bidi.def}{\from{\jobname.dtx}{table,amsthm-xetex-bidi.def}}}
\generate{\file{array-xetex-bidi.def}{\from{\jobname.dtx}{table,array-xetex-bidi.def}}}
\generate{\file{article-xetex-bidi.def}{\from{\jobname.dtx}{table,article-xetex-bidi.def}}}
\generate{\file{artikel1-xetex-bidi.def}{\from{\jobname.dtx}{table,artikel1-xetex-bidi.def}}}
\generate{\file{artikel2-xetex-bidi.def}{\from{\jobname.dtx}{table,artikel2-xetex-bidi.def}}}
\generate{\file{artikel3-xetex-bidi.def}{\from{\jobname.dtx}{table,artikel3-xetex-bidi.def}}}
\generate{\file{arydshln-xetex-bidi.def}{\from{\jobname.dtx}{table,arydshln-xetex-bidi.def}}}
\generate{\file{beamer-xetex-bidi.def}{\from{\jobname.dtx}{table,beamer-xetex-bidi.def}}}
\generate{\file{beamerbaseauxtemplates-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaseauxtemplates-xetex-bidi.def}}}
\generate{\file{beamerbaseboxes-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaseboxes-xetex-bidi.def}}}
\generate{\file{beamerbasecolor-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbasecolor-xetex-bidi.def}}}
\generate{\file{beamerbasecompatibility-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbasecompatibility-xetex-bidi.def}}}
\generate{\file{beamerbaseframecomponents-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaseframecomponents-xetex-bidi.def}}}
\generate{\file{beamerbaseframesize-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaseframesize-xetex-bidi.def}}}
\generate{\file{beamerbaselocalstructure-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaselocalstructure-xetex-bidi.def}}}
\generate{\file{beamerbasemisc-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbasemisc-xetex-bidi.def}}}
\generate{\file{beamerbasenavigation-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbasenavigation-xetex-bidi.def}}}
\generate{\file{beamerbaseoverlay-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerbaseoverlay-xetex-bidi.def}}}
\generate{\file{beamerinnerthemedefault-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemedefault-xetex-bidi.def}}}
\generate{\file{beamerinnerthemecircles-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemecircles-xetex-bidi.def}}}
\generate{\file{beamerinnerthemefocus-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemefocus-xetex-bidi.def}}}
\generate{\file{beamerinnerthemeinmargin-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemeinmargin-xetex-bidi.def}}}
\generate{\file{beamerinnerthememetropolis-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthememetropolis-xetex-bidi.def}}}
\generate{\file{beamerinnerthemerectangles-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemerectangles-xetex-bidi.def}}}
\generate{\file{beamerinnerthemerounded-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerinnerthemerounded-xetex-bidi.def}}}
\generate{\file{beamerouterthemedefault-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemedefault-xetex-bidi.def}}}
\generate{\file{beamerouterthemefocus-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemefocus-xetex-bidi.def}}}
\generate{\file{beamerouterthemeinfolines-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemeinfolines-xetex-bidi.def}}}
\generate{\file{beamerouterthememetropolis-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthememetropolis-xetex-bidi.def}}}
\generate{\file{beamerouterthememiniframes-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthememiniframes-xetex-bidi.def}}}
\generate{\file{beamerouterthemesidebar-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemesidebar-xetex-bidi.def}}}
\generate{\file{beamerouterthemesplit-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemesplit-xetex-bidi.def}}}
\generate{\file{beamerouterthemeshadow-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemeshadow-xetex-bidi.def}}}
\generate{\file{beamerouterthemesmoothbars-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemesmoothbars-xetex-bidi.def}}}
\generate{\file{beamerouterthemesmoothtree-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemesmoothtree-xetex-bidi.def}}}
\generate{\file{beamerouterthemetree-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerouterthemetree-xetex-bidi.def}}}
\generate{\file{beamerthemeHannover-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerthemeHannover-xetex-bidi.def}}}
\generate{\file{beamerthemeSingapore-xetex-bidi.def}{\from{\jobname.dtx}{table,beamerthemeSingapore-xetex-bidi.def}}}
\generate{\file{bidi.sty}{\from{\jobname.dtx}{table,bidi.sty}}}
\generate{\file{bidi.tex}{\from{\jobname.dtx}{table,bidi.tex}}}
\generate{\file{bidi2in1.sty}{\from{\jobname.dtx}{table,bidi2in1.sty}}}
\generate{\file{bidicode.sty}{\from{\jobname.dtx}{table,bidicode.sty}}}
\generate{\file{bidiftnxtra.sty}{\from{\jobname.dtx}{table,bidiftnxtra.sty}}}
\generate{\file{bidimoderncv.cls}{\from{\jobname.dtx}{table,bidimoderncv.cls}}}
\generate{\file{bidi-perpage.sty}{\from{\jobname.dtx}{table,bidi-perpage.sty}}}
\generate{\file{biditools.sty}{\from{\jobname.dtx}{table,biditools.sty}}}
\generate{\file{bidituftefloat.sty}{\from{\jobname.dtx}{table,bidituftefloat.sty}}}
\generate{\file{bidituftesidenote.sty}{\from{\jobname.dtx}{table,bidituftesidenote.sty}}}
\generate{\file{bidituftetoc.sty}{\from{\jobname.dtx}{table,bidituftetoc.sty}}}
\generate{\file{bidituftegeneralstructure.sty}{\from{\jobname.dtx}{table,bidituftegeneralstructure.sty}}}
\generate{\file{bidituftehyperref.sty}{\from{\jobname.dtx}{table,bidituftehyperref.sty}}}
\generate{\file{bidituftetitle.sty}{\from{\jobname.dtx}{table,bidituftetitle.sty}}}
\generate{\file{biditufte-handout.cls}{\from{\jobname.dtx}{table,biditufte-handout.cls}}}
\generate{\file{biditufte-book.cls}{\from{\jobname.dtx}{table,biditufte-book.cls}}}
\generate{\file{bidipoem.sty}{\from{\jobname.dtx}{table,bidipoem.sty}}}
\generate{\file{boek3-xetex-bidi.def}{\from{\jobname.dtx}{table,boek3-xetex-bidi.def}}}
\generate{\file{boek-xetex-bidi.def}{\from{\jobname.dtx}{table,boek-xetex-bidi.def}}}
\generate{\file{bookest-xetex-bidi.def}{\from{\jobname.dtx}{table,bookest-xetex-bidi.def}}}
\generate{\file{book-xetex-bidi.def}{\from{\jobname.dtx}{table,book-xetex-bidi.def}}}
\generate{\file{breqn-xetex-bidi.def}{\from{\jobname.dtx}{table,breqn-xetex-bidi.def}}}
\generate{\file{cals-xetex-bidi.def}{\from{\jobname.dtx}{table,cals-xetex-bidi.def}}}
\generate{\file{caption-xetex-bidi.def}{\from{\jobname.dtx}{table,caption-xetex-bidi.def}}}
\generate{\file{caption3-xetex-bidi.def}{\from{\jobname.dtx}{table,caption3-xetex-bidi.def}}}
\generate{\file{colortbl-xetex-bidi.def}{\from{\jobname.dtx}{table,colortbl-xetex-bidi.def}}}
\generate{\file{color-xetex-bidi.def}{\from{\jobname.dtx}{table,color-xetex-bidi.def}}}
\generate{\file{combine-xetex-bidi.def}{\from{\jobname.dtx}{table,combine-xetex-bidi.def}}}
\generate{\file{crop-xetex-bidi.def}{\from{\jobname.dtx}{table,crop-xetex-bidi.def}}}
\generate{\file{cutwin-xetex-bidi.def}{\from{\jobname.dtx}{table,cutwin-xetex-bidi.def}}}
\generate{\file{cuted-xetex-bidi.def}{\from{\jobname.dtx}{table,cuted-xetex-bidi.def}}}
\generate{\file{cvthemebidicasual.sty}{\from{\jobname.dtx}{table,cvthemebidicasual.sty}}}
\generate{\file{cvthemebidiclassic.sty}{\from{\jobname.dtx}{table,cvthemebidiclassic.sty}}}
\generate{\file{dblfnote-xetex-bidi.def}{\from{\jobname.dtx}{table,dblfnote-xetex-bidi.def}}}
\generate{\file{diagbox-xetex-bidi.def}{\from{\jobname.dtx}{table,diagbox-xetex-bidi.def}}}
\generate{\file{draftwatermark-xetex-bidi.def}{\from{\jobname.dtx}{table,draftwatermark-xetex-bidi.def}}}
\generate{\file{eso-pic-xetex-bidi.def}{\from{\jobname.dtx}{table,eso-pic-xetex-bidi.def}}}
\generate{\file{empheq-xetex-bidi.def}{\from{\jobname.dtx}{table,empheq-xetex-bidi.def}}}
\generate{\file{extarticle-xetex-bidi.def}{\from{\jobname.dtx}{table,extarticle-xetex-bidi.def}}}
\generate{\file{extbook-xetex-bidi.def}{\from{\jobname.dtx}{table,extbook-xetex-bidi.def}}}
\generate{\file{extletter-xetex-bidi.def}{\from{\jobname.dtx}{table,extletter-xetex-bidi.def}}}
\generate{\file{extrafootnotefeatures-xetex-bidi.def}{\from{\jobname.dtx}{table,extrafootnotefeatures-xetex-bidi.def}}}
\generate{\file{extreport-xetex-bidi.def}{\from{\jobname.dtx}{table,extreport-xetex-bidi.def}}}
\generate{\file{fancybox-xetex-bidi.def}{\from{\jobname.dtx}{table,fancybox-xetex-bidi.def}}}
\generate{\file{fancyhdr-xetex-bidi.def}{\from{\jobname.dtx}{table,fancyhdr-xetex-bidi.def}}}
\generate{\file{fix2col-xetex-bidi.def}{\from{\jobname.dtx}{table,fix2col-xetex-bidi.def}}}
\generate{\file{fleqn-xetex-bidi.def}{\from{\jobname.dtx}{table,fleqn-xetex-bidi.def}}}
\generate{\file{float-xetex-bidi.def}{\from{\jobname.dtx}{table,float-xetex-bidi.def}}}
\generate{\file{floatrow-xetex-bidi.def}{\from{\jobname.dtx}{table,floatrow-xetex-bidi.def}}}
\generate{\file{flowfram-xetex-bidi.def}{\from{\jobname.dtx}{table,flowfram-xetex-bidi.def}}}
\generate{\file{fnpct-xetex-bidi.def}{\from{\jobname.dtx}{table,fnpct-xetex-bidi.def}}}
\generate{\file{footnote-xetex-bidi.def}{\from{\jobname.dtx}{table,footnote-xetex-bidi.def}}}
\generate{\file{footnotebackref-xetex-bidi.def}{\from{\jobname.dtx}{table,footnotebackref-xetex-bidi.def}}}
\generate{\file{framed-xetex-bidi.def}{\from{\jobname.dtx}{table,framed-xetex-bidi.def}}}
\generate{\file{ftnright-xetex-bidi.def}{\from{\jobname.dtx}{table,ftnright-xetex-bidi.def}}}
\generate{\file{graphicx-xetex-bidi.def}{\from{\jobname.dtx}{table,graphicx-xetex-bidi.def}}}
\generate{\file{geometry-xetex-bidi.def}{\from{\jobname.dtx}{table,geometry-xetex-bidi.def}}}
\generate{\file{hgeneric-testphase-xetex-bidi.def}{\from{\jobname.dtx}{table,hgeneric-testphase-xetex-bidi.def}}}
\generate{\file{hvfloat-xetex-bidi.def}{\from{\jobname.dtx}{table,hvfloat-xetex-bidi.def}}}
\generate{\file{hyperref-xetex-bidi.def}{\from{\jobname.dtx}{table,hyperref-xetex-bidi.def}}}
\generate{\file{imsproc-xetex-bidi.def}{\from{\jobname.dtx}{table,imsproc-xetex-bidi.def}}}
\generate{\file{leqno-xetex-bidi.def}{\from{\jobname.dtx}{table,leqno-xetex-bidi.def}}}
\generate{\file{letter-xetex-bidi.def}{\from{\jobname.dtx}{table,letter-xetex-bidi.def}}}
\generate{\file{lettrine-xetex-bidi.def}{\from{\jobname.dtx}{table,lettrine-xetex-bidi.def}}}
\generate{\file{lineno-xetex-bidi.def}{\from{\jobname.dtx}{table,lineno-xetex-bidi.def}}}
\generate{\file{listings-xetex-bidi.def}{\from{\jobname.dtx}{table,listings-xetex-bidi.def}}}
\generate{\file{longtable-xetex-bidi.def}{\from{\jobname.dtx}{table,longtable-xetex-bidi.def}}}
\generate{\file{lscape-xetex-bidi.def}{\from{\jobname.dtx}{table,lscape-xetex-bidi.def}}}
\generate{\file{mathtools-xetex-bidi.def}{\from{\jobname.dtx}{table,mathtools-xetex-bidi.def}}}
\generate{\file{mdframed-xetex-bidi.def}{\from{\jobname.dtx}{table,mdframed-xetex-bidi.def}}}
\generate{\file{media9-xetex-bidi.def}{\from{\jobname.dtx}{table,media9-xetex-bidi.def}}}
\generate{\file{bidi-media9.sty}{\from{\jobname.dtx}{table,bidi-media9.sty}}}
\generate{\file{memoir-xetex-bidi.def}{\from{\jobname.dtx}{table,memoir-xetex-bidi.def}}}
\generate{\file{midfloat-xetex-bidi.def}{\from{\jobname.dtx}{table,midfloat-xetex-bidi.def}}}
\generate{\file{minitoc-xetex-bidi.def}{\from{\jobname.dtx}{table,minitoc-xetex-bidi.def}}}
\generate{\file{multicol-xetex-bidi.def}{\from{\jobname.dtx}{table,multicol-xetex-bidi.def}}}
\generate{\file{multienum-xetex-bidi.def}{\from{\jobname.dtx}{table,multienum-xetex-bidi.def}}}
\generate{\file{natbib-xetex-bidi.def}{\from{\jobname.dtx}{table,natbib-xetex-bidi.def}}}
\generate{\file{newfloat-xetex-bidi.def}{\from{\jobname.dtx}{table,newfloat-xetex-bidi.def}}}
\generate{\file{nicematrix-xetex-bidi.def}{\from{\jobname.dtx}{table,nicematrix-xetex-bidi.def}}}
\generate{\file{ntheorem-xetex-bidi.def}{\from{\jobname.dtx}{table,ntheorem-xetex-bidi.def}}}
\generate{\file{ntheorem-hyper-xetex-bidi.def}{\from{\jobname.dtx}{table,ntheorem-hyper-xetex-bidi.def}}}
\generate{\file{overpic-xetex-bidi.def}{\from{\jobname.dtx}{table,overpic-xetex-bidi.def}}}
\generate{\file{pdfbase-xetex-bidi.def}{\from{\jobname.dtx}{table,pdfbase-xetex-bidi.def}}}
\generate{\file{pdflscape-xetex-bidi.def}{\from{\jobname.dtx}{table,pdflscape-xetex-bidi.def}}}
\generate{\file{pgfcorescopes.code-xetex-bidi.def}{\from{\jobname.dtx}{table,pgfcorescopes.code-xetex-bidi.def}}}
\generate{\file{pgfsys-xetex-bidi.def}{\from{\jobname.dtx}{table,pgfsys-xetex-bidi.def}}}
\generate{\file{picinpar-xetex-bidi.def}{\from{\jobname.dtx}{table,picinpar-xetex-bidi.def}}}
\generate{\file{plain-xetex-bidi.def}{\from{\jobname.dtx}{table,plain-xetex-bidi.def}}}
\generate{\file{pstricks-xetex-bidi.def}{\from{\jobname.dtx}{table,pstricks-xetex-bidi.def}}}
\generate{\file{quotchap-xetex-bidi.def}{\from{\jobname.dtx}{table,quotchap-xetex-bidi.def}}}
\generate{\file{ragged2e-xetex-bidi.def}{\from{\jobname.dtx}{table,ragged2e-xetex-bidi.def}}}
\generate{\file{rapport1-xetex-bidi.def}{\from{\jobname.dtx}{table,rapport1-xetex-bidi.def}}}
\generate{\file{rapport3-xetex-bidi.def}{\from{\jobname.dtx}{table,rapport3-xetex-bidi.def}}}
\generate{\file{refrep-xetex-bidi.def}{\from{\jobname.dtx}{table,refrep-xetex-bidi.def}}}
\generate{\file{report-xetex-bidi.def}{\from{\jobname.dtx}{table,report-xetex-bidi.def}}}
\generate{\file{rotating-xetex-bidi.def}{\from{\jobname.dtx}{table,rotating-xetex-bidi.def}}}
\generate{\file{scrartcl-xetex-bidi.def}{\from{\jobname.dtx}{table,scrartcl-xetex-bidi.def}}}
\generate{\file{scrbook-xetex-bidi.def}{\from{\jobname.dtx}{table,scrbook-xetex-bidi.def}}}
\generate{\file{scrreprt-xetex-bidi.def}{\from{\jobname.dtx}{table,scrreprt-xetex-bidi.def}}}
\generate{\file{sidecap-xetex-bidi.def}{\from{\jobname.dtx}{table,sidecap-xetex-bidi.def}}}
\generate{\file{soul-xetex-bidi.def}{\from{\jobname.dtx}{table,soul-xetex-bidi.def}}}
\generate{\file{stabular-xetex-bidi.def}{\from{\jobname.dtx}{table,stabular-xetex-bidi.def}}}
\generate{\file{subfigure-xetex-bidi.def}{\from{\jobname.dtx}{table,subfigure-xetex-bidi.def}}}
\generate{\file{tabls-xetex-bidi.def}{\from{\jobname.dtx}{table,tabls-xetex-bidi.def}}}
\generate{\file{tabularx-xetex-bidi.def}{\from{\jobname.dtx}{table,tabularx-xetex-bidi.def}}}
\generate{\file{tabulary-xetex-bidi.def}{\from{\jobname.dtx}{table,tabulary-xetex-bidi.def}}}
\generate{\file{tc-xetex-xetex-bidi.def}{\from{\jobname.dtx}{table,tc-xetex-xetex-bidi.def}}}
\generate{\file{tcolorbox-xetex-bidi.def}{\from{\jobname.dtx}{table,tcolorbox-xetex-bidi.def}}}
\generate{\file{thmbox-xetex-bidi.def}{\from{\jobname.dtx}{table,thmbox-xetex-bidi.def}}}
\generate{\file{titlesec-xetex-bidi.def}{\from{\jobname.dtx}{table,titlesec-xetex-bidi.def}}}
\generate{\file{titletoc-xetex-bidi.def}{\from{\jobname.dtx}{table,titletoc-xetex-bidi.def}}}
\generate{\file{tocbibind-xetex-bidi.def}{\from{\jobname.dtx}{table,tocbibind-xetex-bidi.def}}}
\generate{\file{tocloft-xetex-bidi.def}{\from{\jobname.dtx}{table,tocloft-xetex-bidi.def}}}
\generate{\file{tocbasic-xetex-bidi.def}{\from{\jobname.dtx}{table,tocbasic-xetex-bidi.def}}}
\generate{\file{tocstyle-xetex-bidi.def}{\from{\jobname.dtx}{table,tocstyle-xetex-bidi.def}}}
\generate{\file{todonotes-xetex-bidi.def}{\from{\jobname.dtx}{table,todonotes-xetex-bidi.def}}}
\generate{\file{wrapfig-xetex-bidi.def}{\from{\jobname.dtx}{table,wrapfig-xetex-bidi.def}}}
\generate{\file{xcolor-xetex-bidi.def}{\from{\jobname.dtx}{table,xcolor-xetex-bidi.def}}}
\generate{\file{latex-xetex-bidi.def}{\from{\jobname.dtx}{table,latex-xetex-bidi.def}}}
\generate{\file{xltxtra-xetex-bidi.def}{\from{\jobname.dtx}{table,xltxtra-xetex-bidi.def}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\generate{\file{bidi-logo.tex}{\from{\jobname.dtx}{bidi-logo.tex}}}
\generate{\file{bidisample2e.tex}{\from{\jobname.dtx}{bidisample2e.tex}}}
\generate{\file{bidismall2e.tex}{\from{\jobname.dtx}{bidismall2e.tex}}}
\generate{\file{test1-colortbl.tex}{\from{\jobname.dtx}{test1-colortbl.tex}}}
\generate{\file{test1-wrapfig.tex}{\from{\jobname.dtx}{test1-wrapfig.tex}}}
\generate{\file{test2-colortbl.tex}{\from{\jobname.dtx}{test2-colortbl.tex}}}
\generate{\file{test2-wrapfig.tex}{\from{\jobname.dtx}{test2-wrapfig.tex}}}
\generate{\file{test3-wrapfig.tex}{\from{\jobname.dtx}{test3-wrapfig.tex}}}
\generate{\file{test-arydshln.tex}{\from{\jobname.dtx}{test-arydshln.tex}}}
\generate{\file{test-bidi.tex}{\from{\jobname.dtx}{test-bidi.tex}}}
\generate{\file{test-brochure.tex}{\from{\jobname.dtx}{test-brochure.tex}}}
\generate{\file{test-casualcv.tex}{\from{\jobname.dtx}{test-casualcv.tex}}}
\generate{\file{test-classiccv.tex}{\from{\jobname.dtx}{test-classiccv.tex}}}
\generate{\file{test-color.tex}{\from{\jobname.dtx}{test-color.tex}}}
\generate{\file{test-supertabular.tex}{\from{\jobname.dtx}{test-supertabular.tex}}}
\generate{\file{test-tabular.tex}{\from{\jobname.dtx}{test-tabular.tex}}}
\generate{\file{test-tabularx.tex}{\from{\jobname.dtx}{test-tabularx.tex}}}
\generate{\file{test-tabulary.tex}{\from{\jobname.dtx}{test-tabulary.tex}}}
\endgroup
\immediate\write18{mv README.txt README}
\immediate\write18{makeindex -s gind.ist -o \jobname.ind  \jobname.idx}
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls  \jobname.glo}
%</internal>
%
%<*driver>
\documentclass{ltxdoc}
\input{bidi-doc-preamble.ltx}
\hypersetup{%
  pdftitle={Source documentation for version 25.10.28 of the bidi
                package}%
}
\EnableCrossrefs
\CodelineIndex
%\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
  \PrintIndex
%  \PrintChanges
\end{document}
%</driver>
%
%
% \fi
%
% \GetFileInfo{\jobname.dtx}
% \title{\textcolor{bidiblue}{\Huge The \textsf{bidi} \textit{Package}}\\
%\LARGE Bidirectional typesetting with plain {\TeX} and {\LaTeX} formats in XeTeX and LuaTeX engines\\[5pt]
%\large Source documentation for \textcolor{bidiblue}{version 25.10.28}}
% \author{Vafa Khalighi\thanks{Thanks to the bidi-tex GitHub organization consisted of David Carlisle and other members of the  {\LaTeX} team for maintaining the package in the period 2018--2020.}}
%\setcounter{page}{0}
%\thispagestyle{empty}
%\includegraphics[width=.3\textwidth]{bidi-logo}\qquad
%\parindent 0pt
%\vbox{\Huge
%\textcolor{bidiblue}{\Huge The \textsf{bidi} \textit{Package}}
%
%\Large
%Source documentation for \textcolor{bidiblue}{version 25.10.28}}
%
%\vskip 0pt plus 3fill
%\textit{\large to my Master, \textbf{Ferdowsi The Great}}
%
%\vskip 0pt plus 3fill
%
%Copyright (c) 2007--2025 Vafa Khalighi
%
%Copyright (c) 2018--2020 bidi-tex GitHub Organization
%
%\medskip
%Permission is granted to distribute and/or modify \emph{both the documentation and the code} under the conditions of the \LaTeX{} Project Public License, either version 1.3c of this license or (at your option) any later version.
%
%\clearpage
%\maketitle
% \tableofcontents
%\clearpage
% \StopEventually{}
% \section{File \texttt{amsart-xetex-bidi.def}}
%\iffalse
%<*table>
%\fi
%% \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         \~}
%%
% \iffalse
%</table>
%<*amsart-xetex-bidi.def>
%\fi
%
%
%
%    \begin{macrocode}
\ProvidesFile{amsart-xetex-bidi.def}[2025/09/30 v1.2 bidi adaptations for amsart class for XeTeX engine]
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \if@RTL\rightskip\else\leftskip\fi#3\relax \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima\relax
    \if@RTL\leftskip\else\rightskip\fi\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima #6\nobreak\relax
    \hfil\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
\renewcommand\thesubsection    {\thesection\@SepMark\arabic{subsection}}
\renewcommand\thesubsubsection {\thesubsection \@SepMark\arabic{subsubsection}}
\renewcommand\theparagraph     {\thesubsubsection\@SepMark\arabic{paragraph}}
\renewcommand\thesubparagraph  {\theparagraph\@SepMark\arabic{subparagraph}}
\def\part{\@startsection{part}{0}%
  \z@{\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\bfseries\if@RTL\raggedleft\else\raggedright\fi}}
\def\right@footnoterule{%
  \kern-.4\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-5pc\relax \hrulefill }
  \kern11\p@\kern-\footnotesep}  
\def\left@footnoterule{\kern-.4\p@
        \hrule\@width 5pc\kern11\p@\kern-\footnotesep}
        

\long\def\@footnotetext#1{%
  \insert\footins{%
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
    \reset@font%
    \bidi@@footnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}
      
\long\def\@RTLfootnotetext#1{%
  \insert\footins{%
    \@RTLtrue%
    \reset@font%
    \bidi@@RTLfootnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}     
      
      
      
\long\def\@LTRfootnotetext#1{%
  \insert\footins{%
    \@RTLfalse%
    \reset@font%
    \bidi@@LTRfootnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}    
      
      
\footdir@temp\footdir@ORG@bidi@amsart@footnotetext\@footnotetext{\bidi@footdir@footnote}%    
\footdir@temp\footdir@ORG@bidi@amsart@RTLfootnotetext\@RTLfootnotetext{R}%
\footdir@temp\footdir@ORG@bidi@amsart@LTRfootnotetext\@LTRfootnotetext{L}%
      
\renewenvironment{thebibliography}[1]{%
  \@bibtitlestyle
  \normalfont\bibliofont\labelsep .5em\relax
  \renewcommand\theenumiv{\arabic{enumiv}}\let\p@enumiv\@empty
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook%
  \list{\@biblabel{\theenumiv}}{\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth \advance\leftmargin\labelsep
    \usecounter{enumiv}}%
  \sloppy \clubpenalty\@M \widowpenalty\clubpenalty
  \sfcode`\.=\@m
}{%
  \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
  \endlist
}
\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
  \columnseprule\z@ \columnsep 35\p@
  \@indextitlestyle
  \thispagestyle{plain}%
  \let\item\@idxitem
  \parindent\z@  \parskip\z@\@plus.3\p@\relax
  \if@RTL\raggedleft\else\raggedright\fi
  \hyphenpenalty\@M
  \footnotesize}
\def\@idxitem{\par\hangindent \if@RTL-\fi2em}
\def\subitem{\par\hangindent \if@RTL-\fi2em\hspace*{1em}}
\def\subsubitem{\par\hangindent \if@RTL-\fi3em\hspace*{2em}}
\def\maketitle{\par
  \@topnum\z@ % this prevents figures from falling at the top of page 1
  \@setcopyright
  \thispagestyle{firstpage}% this sets first page specifications
  \uppercasenonmath\shorttitle
  \ifx\@empty\shortauthors \let\shortauthors\shorttitle
  \else \andify\shortauthors
  \fi
  \@maketitle@hook
  \begingroup
  \@maketitle
  \toks@\@xp{\shortauthors}\@temptokena\@xp{\shorttitle}%
  \toks4{\def\\{ \ignorespaces}}% defend against questionable usage
  \edef\@tempa{%
    \@nx\markboth{\the\toks4
      \@nx\MakeUppercase{\the\toks@}}{\the\@temptokena}}%
  \@tempa
  \endgroup
  \c@footnote\z@
  \@cleartopmattertags
}
%    \end{macrocode}
%
%\iffalse
%</amsart-xetex-bidi.def>
%<*adjmulticol-xetex-bidi.def>
%\fi
% \section{File \texttt{adjmulticol-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{adjmulticol-xetex-bidi.def}[2015/04/25 v0.1 bidi adaptations for adjmulticol package for XeTeX engine]
\def\adjmulticols#1#2#3{\col@number#1\relax
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\adjmc@inner\z@\else\adjmc@inner#2\fi
  \def\@tempa{#3}%
  \ifx\@tempa\@empty\adjmc@outer\z@\else\adjmc@outer#3\fi
  \ifnum\col@number<\@ne
     \PackageWarning{adjmulticol}%
      {Using `\number\col@number'
       columns doesn't seem a good idea.^^J
       I therefore use one columns instead}%
     \col@number\@ne\fi
  \ifnum\col@number>10
     \PackageError{adjmulticol}%
      {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[\adjmult@cols{\adjmult@cols[]}}
\let\adjmc@page@sofar@orig=\page@sofar
%    \end{macrocode}
%
%\iffalse
%</adjmulticol-xetex-bidi.def>
%<*algorithm2e-xetex-bidi.def>
%\fi
% \section{File \texttt{algorithm2e-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{algorithm2e-xetex-bidi.def}[2025/01/03 v0.3 bidi adaptations for algorithm2e package for XeTeX engine]
\expandafter\ifx\csname algocf@within\endcsname\relax% if \algocf@within doesn't exist
\else%                                     else
\renewcommand\thealgocf{\csname the\algocf@within\endcsname\@SepMark\@arabic\c@algocf}%
\fi
\ApplyPatchIfPackageLoadedF{color}{%
  \bidi@patchcmd{\@algocf@start}{\bgroup}{%
    \bgroup
    \if@RTL
      \beginR
    \else
      \beginL
    \fi
  }{}{}
  \bidi@patchcmd{\@algocf@finish}{\egroup\end{lrbox}}{%
    \if@RTL
      \endR
    \else
      \endL
    \fi
    \egroup
    \end{lrbox}%
  }{}{}
  \bidi@patchcmd{\algocf@makecaption}{\hbox}{%
    \if@RTL
      \hboxR
    \else
      \hboxL
    \fi
  }{}{}
}

\@ifpackagewith{algorithm2e}{algonl}{%
\renewcommand{\theAlgoLine}{\expandafter\csname the\algocf@float\endcsname\@SepMark\arabic{AlgoLine}}%
}{}

\@ifpackagewith{algorithm2e}{algopart}{\renewcommand{\algocf@within}{part}}{}

\@ifpackagewith{algorithm2e}{algochapter}{\renewcommand{\algocf@within}{chapter}}{}

\@ifpackagewith{algorithm2e}{algosection}{\renewcommand{\algocf@within}{section}}{}
%    \end{macrocode}
%
%\iffalse
%</algorithm2e-xetex-bidi.def>
%<*amsbook-xetex-bidi.def>
%\fi
% \section{File \texttt{amsbook-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{amsbook-xetex-bidi.def}[2025/09/30 v1.3 bidi adaptations for amsbook class for XeTeX engine]
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \if@RTL\rightskip\else\leftskip\fi#3\relax \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima\relax
    \if@RTL\leftskip\else\rightskip\fi\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima #6\nobreak\relax
    \hfil\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
\renewcommand\thesubsection    {\thesection\@SepMark\arabic{subsection}}
\renewcommand\thesubsubsection {\thesubsection \@SepMark\arabic{subsubsection}}
\renewcommand\theparagraph     {\thesubsubsection\@SepMark\arabic{paragraph}}
\renewcommand\thesubparagraph  {\theparagraph\@SepMark\arabic{subparagraph}}
\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
  \columnseprule\z@ \columnsep 35\p@
  \@indextitlestyle
  \thispagestyle{plain}%
  \let\item\@idxitem
  \parindent\z@  \parskip\z@\@plus.3\p@\relax
  \if@RTL\raggedleft\else\raggedright\fi
  \hyphenpenalty\@M
  \footnotesize}
\def\@idxitem{\par\hangindent \if@RTL-\fi2em}
\def\subitem{\par\hangindent \if@RTL-\fi2em\hspace*{1em}}
\def\subsubitem{\par\hangindent \if@RTL-\fi3em\hspace*{2em}}
\def\right@footnoterule{%
  \kern-.4\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-5pc\relax \hrulefill }
  \kern11\p@\kern-\footnotesep}  
\def\left@footnoterule{\kern-.4\p@
        \hrule\@width 5pc\kern11\p@\kern-\footnotesep}

\long\def\@footnotetext#1{%
  \insert\footins{%
   \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
   \reset@font%
    \bidi@@footnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}

\long\def\@RTLfootnotetext#1{%
  \insert\footins{%
   \@RTLtrue%
   \reset@font%
    \bidi@@RTLfootnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}


\long\def\@LTRfootnotetext#1{%
  \insert\footins{%
   \@RTLfalse%
   \reset@font%
    \bidi@@LTRfootnotetext@font% \normalfont\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep \splitmaxdepth \dp\strutbox
    \floatingpenalty\@MM \hsize\columnwidth
    \@parboxrestore \parindent\normalparindent \sloppy
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces#1\unskip\strut\par}}}



\footdir@temp\footdir@ORG@bidi@amsbook@footnotetext\@footnotetext{\bidi@footdir@footnote}%    
\footdir@temp\footdir@ORG@bidi@amsbook@RTLfootnotetext\@RTLfootnotetext{R}%
\footdir@temp\footdir@ORG@bidi@amsbook@LTRfootnotetext\@LTRfootnotetext{L}%

\renewenvironment{thebibliography}[1]{%
  \@bibtitlestyle
  \normalfont\bibliofont\labelsep .5em\relax
  \renewcommand\theenumiv{\arabic{enumiv}}\let\p@enumiv\@empty
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook%
  \list{\@biblabel{\theenumiv}}{\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth \advance\leftmargin\labelsep
    \usecounter{enumiv}}%
  \sloppy \clubpenalty\@M \widowpenalty\clubpenalty
  \sfcode`\.=\@m
}{%
  \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
  \endlist
}
\def\@makechapterhead#1{\global\topskip 7.5pc\relax
  \begingroup
  \fontsize{\@xivpt}{18}\bfseries\centering
    \ifnum\c@secnumdepth>\m@ne
      \leavevmode \hskip-\if@RTL\rightskip\else\leftskip\fi
      \rlap{\vbox to\z@{\vss
          \centerline{\normalsize\mdseries
              \uppercase\@xp{\chaptername}\enspace\thechapter}
          \vskip 3pc}}\hskip\if@RTL\rightskip\else\leftskip\fi\fi
     #1\par \endgroup
  \skip@34\p@ \advance\skip@-\normalbaselineskip
  \vskip\skip@ }
\def\maketitle{\par
  \@topnum\z@ % this prevents figures from falling at the top of page 1
  \begingroup
  \@maketitle
  \endgroup
  \c@footnote\z@
  \def\do##1{\let##1\relax}%
  \do\maketitle \do\@maketitle \do\title \do\@xtitle \do\@title
  \do\author \do\@xauthor \do\address \do\@xaddress
  \do\email \do\@xemail \do\curraddr \do\@xcurraddr
  \do\dedicatory \do\@dedicatory \do\thanks \do\thankses
  \do\keywords \do\@keywords \do\subjclass \do\@subjclass
}
%    \end{macrocode}
% \iffalse
%</amsbook-xetex-bidi.def>
%<*amsmath-xetex-bidi.def>
%\fi
% \section{File \texttt{amsmath-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{amsmath-xetex-bidi.def}[2020/05/16 v1.2 bidi adaptations for amsmath package for XeTeX engine]
\let\veqno=\eqno
\iftagsleft@ \let\veqno=\leqno \fi
\renewcommand{\numberwithin}[3][\arabic]{%
  \@ifundefined{c@#2}{\@nocounterr{#2}}{%
    \@ifundefined{c@#3}{\@nocnterr{#3}}{%
      \@addtoreset{#2}{#3}%
      \@xp\xdef\csname the#2\endcsname{%
        \@xp\@nx\csname the#3\endcsname \@nx\@SepMark\@nx#1{#2}}}}%
}
\def\tagform@#1{\maketag@@@{\if@nonlatin\beginR\fi(\kern\z@\ignorespaces#1\unskip\@@italiccorr)\if@nonlatin\endR\fi}}

\bidi@patchcmd\math@cr@@@align\place@tag{%
    \place@tag
  \else
    \place@tag
}{}{}

%    \end{macrocode}
% \iffalse
%</amsmath-xetex-bidi.def>
%<*amstext-xetex-bidi.def>
%\fi
% \section{File \texttt{amstext-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{amstext-xetex-bidi.def}[2016/09/12 v0.2 bidi adaptations for amstext package for XeTeX engine]
\def\textdef@#1#2#3{\hbox{{%
                    \everymath{#1}%
                    \let\f@size#2\selectfont
                    \if@nonlatin\beginR\fi#3\if@nonlatin\endR\fi}}}
%    \end{macrocode}
% \iffalse
%</amstext-xetex-bidi.def>
%<*amsthm-xetex-bidi.def>
%\fi
% \section{File \texttt{amsthm-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{amsthm-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for amsthm package for XeTeX engine]
\def\@thmcountersep{\@SepMark}
%    \end{macrocode}
% \iffalse
%</amsthm-xetex-bidi.def>
%<*array-xetex-bidi.def>
%\fi
% \section{File \texttt{array-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{array-xetex-bidi.def}[2025/09/11 v0.7 bidi adaptations for array package for XeTeX engine]
\def\@testpach{\@chclass
 \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
  \ifnum \@lastchclass=7 5 \else
   \ifnum \@lastchclass=8 \tw@ \else
    \ifnum \@lastchclass=9 \thr@@
   \else \z@
   \ifnum \@lastchclass = 10 \else
   \edef\@nextchar{\expandafter\string\@nextchar}%
   \@chnum
   \if \@nextchar c\z@ \else
    \if \@nextchar \if@RTLtab r\else l\fi\@ne \else
     \if \@nextchar \if@RTLtab l\else r\fi\tw@ \else
   \z@ \@chclass
   \if\@nextchar |\@ne \else
    \if \@nextchar !6 \else
     \if \@nextchar @7 \else
      \if \@nextchar <8 \else
       \if \@nextchar >9 \else
  10
  \@chnum
  \if \@nextchar m\thr@@ \else
   \if \@nextchar p4 \else
    \if \@nextchar b5 \else
   \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi
   \fi \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi}
\def\@tabular{%
  \leavevmode
  \UseTaggingSocket{tbl/hmode/begin}%
  \hbox \bgroup\if@RTLtab\beginR \fi
    \MathCollectFalse$\MathCollectTrue
    \col@sep\tabcolsep \let\d@llarbegin\begingroup
                                    \let\d@llarend\endgroup
   \@kernel@tabular@init
  \@tabarray}
\def\endtabular{\endarray\m@th $\if@RTLtab\endR\fi\egroup
  \UseTaggingSocket{tbl/hmode/end}%
}
\expandafter\let\csname endtabular*\endcsname=\endtabular
\ExplSyntaxOn
\def\@array[#1]#2{
  \@tempdima \ht \strutbox
  \advance \@tempdima by\extrarowheight
  \setbox \@arstrutbox \hbox{\vrule
             \@height \arraystretch \@tempdima
             \@depth \arraystretch \dp \strutbox
             \@width \z@}%
  \tbl_save_outer_table_cols:
  \begingroup
  \@mkpream{#2}%
  \tbl_count_table_cols:
  \xdef\@preamble{
    \noexpand \ar@ialign
    \@halignto
       \bgroup \@arstrut
      \UseTaggingSocket{tbl/row/begin}
      \tbl_init_cell_data_for_row:
      \@preamble
      \tabskip \z@ \cr}
  \endgroup
  \@arrayleft
  \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi
  \bgroup
  \let \@sharp ##\let \protect \relax
  \lineskip \z@
  \baselineskip \z@
  \mathsurround \z@
  \let\\\@arraycr \let\tabularnewline\\\let\par\@empty
  \if@RTLtab\hbox\bgroup\beginR\@hboxRconstructtrue\if #1t\vtop \else \vbox  \fi\bgroup\fi
  \UseTaggingSocket{tbl/init}
  \@preamble
}
\let\@@array\@array
\def\endarray {
  \tbl_crcr:n{endarray}
  \tag_socket_use_expandable:n { math/luamml/array/save }
  \egroup
  \tag_socket_use:n { tbl/finalize }
  \tbl_restore_outer_cell_data:
  \if@RTLtab\egroup\endR\egroup\fi 
  \egroup
  \tag_socket_use:n { math/luamml/array/finalize }
  \@arrayright \gdef\@preamble{}%
}
\def\array{\col@sep\arraycolsep
  \def\d@llarbegin{$\tag_socket_use:n { math/luamml/array/initcol }}
  \def\d@llarend
   {
     \tag_socket_use:nn { math/luamml/save/nn }{{}{mtd}}
     $
     \tag_socket_use:nn { math/luamml/array/finalizecol}{\the\@chnum}
   }
  \def\@halignto{}%
  \@RTLtabfalse
  \@tabarray}
\ExplSyntaxOff
%    \end{macrocode}
% \iffalse
%</array-xetex-bidi.def>
%<*article-xetex-bidi.def>
%\fi
% \section{File \texttt{article-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{article-xetex-bidi.def}[2025/09/30 v1.2 bidi adaptations for standard article class for XeTeX engine]
\IfClassLoadedT{svmult}{\endinput}
\if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty\@secpenalty
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
       \if@compatibility
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
      \fi
    \endgroup
  \fi}
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
      \hskip -\if@RTL\rightskip\else\leftskip\fi
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}
\ApplyPatchIfPackageLoaded{nameref}{%
  \bidi@patchcmd\NR@part\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\NR@part' failed}}%
  \bidi@patchcmd\NR@spart\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\NR@spart' failed}}%
}{%
  \bidi@patchcmd\@part\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\@part' failed}}%
  \bidi@patchcmd\@spart\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\@spart' failed}}%
}
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
      \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \columnseprule \z@
                \columnsep 35\p@
                \twocolumn[\section*{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem}
               {\if@restonecol\onecolumn\else\clearpage\fi}
%    \end{macrocode}
% \iffalse
%</article-xetex-bidi.def>
%<*artikel1-xetex-bidi.def>
%\fi
% \section{File \texttt{artikel1-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{artikel1-xetex-bidi.def}[2025/09/30 v0.5 bidi adaptations for artikel1 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\section*{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\if@titlepage
  \renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont\abstractname}
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\else
  \renewenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \bgroup\if@RTL\leftskip\else\rightskip\fi=\unitindent
        \section*{\small\SectFont\abstractname}%
        \noindent\ignorespaces
      \fi}
      {\if@twocolumn\else\par\egroup\fi}
\fi
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty\@secpenalty
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
       \if@compatibility
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \fi
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty\@secpenalty
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\if@oldtoc
\renewcommand*\l@section[2]{%
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
   \endgroup}
\else
   \renewcommand*\l@section{\@regtocline{1}}
\fi
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
       \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\if@titlepage
\renewcommand*\TitleFont{\rmfamily}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\uc@nothanks#1\thanks{\uppercase{#1}\futurelet\@tempa\uc@tx}
\def\uc@authornothanks#1\and{\uc@nothanks#1\thanks\relax
    \futurelet\@tempa\uc@ax}
\def\uc@ax{%
  \ifx\@tempa\relax
  \else
    \\ \andname \\ \expandafter\uc@authornothanks
  \fi}
\def\uc@tx{\ifx\@tempa\relax
    \else \expandafter\uc@ty \fi}
\def\uc@ty#1{\thanks{#1}\uc@nothanks}
\else
\renewcommand*\maketitle{\par
  \begingroup
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext{\@xmakefntext{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
    \let \footnote \thanks
    {\LARGE \TitleFont \@title \par}%
    \vskip 1.5em%
    {\large \TitleFont
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \TitleFont \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
%    \end{macrocode}
% \iffalse
%</artikel1-xetex-bidi.def>
%<*artikel2-xetex-bidi.def>
%\fi
% \section{File \texttt{artikel2-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{artikel2-xetex-bidi.def}[2025/09/30 v0.5 bidi adaptations for artikel2 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\section*{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \advance\@tempdima by \othermargin
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@section[2]{%
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
   \endgroup}
\else
   \renewcommand*\l@section{\@regtocline{1}}
\fi
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty\@secpenalty
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
       \if@compatibility
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \fi
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty\@secpenalty
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\if@titlepage
  \renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont\abstractname}%
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\else
  \renewenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \section*{\hskip\unitindent\small\SectFont\abstractname}%
        \list{}{\setlength\listparindent{\unitindent}%
                \setlength\parindent    {\z@}%
                \setlength\leftmargin   {\unitindent}%
                \setlength\rightmargin  {\unitindent}%
                \setlength\parsep       {\z@}}%
        \item[]%
      \fi}
      {\if@twocolumn\else\par\endlist\fi}
\fi
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \hrule\@width 3\unitindent
  \kern 2.6\p@
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-3\unitindent\relax \hrulefill }
  \kern 2.6\p@}
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
       \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\if@titlepage
\renewcommand*\TitleFont{\rmfamily}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\uc@nothanks#1\thanks{\uppercase{#1}\futurelet\@tempa\uc@tx}
\def\uc@authornothanks#1\and{\uc@nothanks#1\thanks\relax
    \futurelet\@tempa\uc@ax}
\def\uc@ax{%
  \ifx\@tempa\relax
  \else
    \\ \andname \\ \expandafter\uc@authornothanks
  \fi}
\def\uc@tx{\ifx\@tempa\relax
    \else \expandafter\uc@ty \fi}
\def\uc@ty#1{\thanks{#1}\uc@nothanks}
\else
\renewcommand*\maketitle{\par
  \begingroup
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \long\def\@makefntext##1{\parindent\z@
      \def\labelitemi{\textendash}%
      \leavevmode\hb@xt@.5\unitindent{%
        \@textsuperscript{\normalfont\@thefnmark}\hfil}##1}
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
    \let \footnote \thanks
    {\LARGE \TitleFont \@title \par}%
    \vskip 1.5em%
    {\large \TitleFont
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \TitleFont \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
%    \end{macrocode}
% \iffalse
%</artikel2-xetex-bidi.def>
%<*artikel3-xetex-bidi.def>
%\fi
% \section{File \texttt{artikel3-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{artikel3-xetex-bidi.def}[2025/09/30 v0.6 bidi adaptations for artikel3 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\section*{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty\@secpenalty
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
       \if@compatibility
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \fi
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty\@secpenalty
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi

\if@oldtoc
\renewcommand*\l@section[2]{%
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
   \endgroup}
\else
   \renewcommand*\l@section{\@regtocline{1}}
\fi
\if@titlepage
  \renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont\abstractname}%
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\else
  \renewenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \bgroup\if@RTL\leftskip\else\rightskip\fi=\unitindent
        \section*{\small\SectFont\abstractname}%
        \noindent\ignorespaces
      \fi}
      {\if@twocolumn\else\par\egroup\fi}
\fi
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
       \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\if@titlepage
\renewcommand*\TitleFont{\rmfamily}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\uc@nothanks#1\thanks{\uppercase{#1}\futurelet\@tempa\uc@tx}
\def\uc@authornothanks#1\and{\uc@nothanks#1\thanks\relax
    \futurelet\@tempa\uc@ax}
\def\uc@ax{%
  \ifx\@tempa\relax
  \else
    \\ \andname \\ \expandafter\uc@authornothanks
  \fi}
\def\uc@tx{\ifx\@tempa\relax
    \else \expandafter\uc@ty \fi}
\def\uc@ty#1{\thanks{#1}\uc@nothanks}
\else
\renewcommand*\maketitle{\par
  \begingroup
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext{\@xmakefntext{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
\if@titlecentered
  \begin{center}%
    \let \footnote \thanks
    {\LARGE \TitleFont \@title \par}%
    \vskip 1.5em%
    {\large \TitleFont
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \TitleFont \@date}%
  \end{center}%
 \else
     {\LARGE \TitleFont \head@style \@title \par} \vskip 1.5em
     {\large \TitleFont \lineskip .5em \tabcolsep\z@
             \def\and{%%% \begin{tabular} has already started
                      \end{tabular}\hskip 1em plus .17fil
                      \if@RTL\begin{tabular}[t]{r}\else\begin{tabular}[t]{l}\fi}%% \end{tabular} will come
             \if@RTL\begin{tabular}[t]{r}\else\begin{tabular}[t]{l}\fi\@author\end{tabular}\par}
     \vskip 1em {\large \TitleFont \@date}
 \fi
  \par
  \vskip 1.5em}
\fi
%    \end{macrocode}
% \iffalse
%</artikel3-xetex-bidi.def>
%<*arydshln-xetex-bidi.def>
%\fi
% \section{File \texttt{arydshln-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{arydshln-xetex-bidi.def}[2025/10/28 v0.4 bidi adaptations for arydshln package for XeTeX engine]
\def\endarray{\adl@endarray \egroup \adl@arrayrestore \if@RTLtab\egroup\endR\egroup\fi\egroup}
\def\endtabular{\endarray $\if@RTLtab\endR\fi\egroup}
\expandafter\let\csname endtabular*\endcsname\endtabular
\let\adl@array\@array
\def\@array{\adl@everyvbox\everyvbox
        \everyvbox{\adl@arrayinit \the\adl@everyvbox \everyvbox\adl@everyvbox}%
        \ifadl@inactive \adl@inactivate \else \adl@activate \fi
        \let\adl@noalign\noalign
        \adl@array}
\ifx\@@array\adl@array \let\@@array\@array \fi
\ifadl@usingarypkg
\def\@testpach{\@chclass
 \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
  \ifnum \@lastchclass=7 5 \else
   \ifnum \@lastchclass=8 \tw@ \else
    \ifnum \@lastchclass=9 \thr@@
   \else \z@
   \ifnum \@lastchclass = 10 \else
   \edef\@nextchar{\expandafter\string\@nextchar}%
   \@chnum
   \if \@nextchar c\z@ \else
    \if \@nextchar \if@RTLtab r\else l\fi\@ne \else
     \if \@nextchar \if@RTLtab l\else r\fi\tw@ \else
   \z@ \@chclass
   \if\@nextchar |\@ne \let\@arrayrule\adl@arrayrule \else
   \if\@nextchar :\@ne \let\@arrayrule\adl@arraydashrule \else
   \if\@nextchar ;\@ne \let\@arrayrule\adl@argarraydashrule \else
    \if \@nextchar !6 \else
     \if \@nextchar @7 \else
      \if \@nextchar <8 \else
       \if \@nextchar >9 \else
  10
  \@chnum
  \if \@nextchar m\thr@@\else
   \if \@nextchar p4 \else
    \if \@nextchar b5 \else
   \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi \fi \fi
   \fi \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi}

\def\@classz{\@classx
   \@tempcnta \count@
   \prepnext@tok
   \@addtopreamble{\ifcase \@chnum
      \hfil
      \adl@putlrc{\d@llarbegin \insert@column \d@llarend}\hfil \or
      \hskip1sp\adl@putlrc{\d@llarbegin \insert@column \d@llarend}\hfil \or
      \hfil\hskip1sp\adl@putlrc{\d@llarbegin \insert@column \d@llarend}\or
   \setbox\adl@box\hbox \adl@startmbox{\@nextchar}\insert@column
        \adl@endmbox\or
   \setbox\adl@box\vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or
   \setbox\adl@box\vbox \@startpbox{\@nextchar}\insert@column \@endpbox
  \fi}\prepnext@tok}
\def\adl@class@start{4}
\def\adl@class@iiiorvii{7}

\else
\def\@testpach#1{\@chclass \ifnum \@lastchclass=\tw@ 4\relax \else
        \ifnum \@lastchclass=\thr@@ 5\relax \else
                \z@ \if #1c\@chnum \z@ \else
                    \if \if@RTLtab#1r\else#1l\fi\@chnum \@ne \else
                    \if \if@RTLtab#1l\else#1r\fi\@chnum \tw@ \else
                \@chclass
                    \if #1|\@ne \let\@arrayrule\adl@arrayrule \else
                    \if #1:\@ne \let\@arrayrule\adl@arraydashrule \else
                    \if #1;\@ne \let\@arrayrule\adl@argarraydashrule \else
                    \if #1@\tw@ \else
                    \if #1p\thr@@ \else \z@ \@preamerr 0\fi
        \fi  \fi  \fi  \fi  \fi  \fi  \fi  \fi  \fi}

\def\@arrayclassz{\ifcase \@lastchclass \@acolampacol \or \@ampacol \or
                \or \or \@addamp \or
                \@acolampacol \or \@firstampfalse \@acol \fi
        \edef\@preamble{\@preamble
                \ifcase \@chnum
                    \hfil\adl@putlrc{$\relax\@sharp$}\hfil
                \or \adl@putlrc{$\relax\@sharp$}\hfil
                \or \hfil\adl@putlrc{$\relax\@sharp$}\fi}}
\def\@tabclassz{\ifcase \@lastchclass \@acolampacol \or \@ampacol \or
                \or \or \@addamp \or
                \@acolampacol \or \@firstampfalse \@acol \fi
        \edef\@preamble{\@preamble
        \ifcase \@chnum
                    \hfil\adl@putlrc{\@sharp\unskip}\hfil
                \or \adl@putlrc{\@sharp\unskip}\hfil
                \or \hfil\hskip\z@ \adl@putlrc{\@sharp\unskip}\fi}}
\def\adl@class@start{6}
\def\adl@class@iiiorvii{3}
\fi
\ApplyPatchCodeToFile{colortbl-xetex-bidi}{%
\def\adl@inactivate{\adl@org@inactivate \let\CT@setup\adl@CT@setup}
\def\adl@activate{\adl@org@activate \let\CT@setup\adl@act@CT@setup
        \let\@endpbox\adl@org@endpbox}
\let\adl@CT@setup\CT@setup
\def\CT@setup{\adl@CT@setup
        \@tempdima\ht\z@ \advance\@tempdima\minrowclearance
        \ifdim\adl@height<\@tempdima \global\adl@height\@tempdima \fi
        \ifdim\adl@depth<\dp\z@ \global\adl@depth\dp\z@\fi}
\let\adl@act@CT@setup\CT@setup
\def\@classz{\@classx
        \@tempcnta\count@ \prepnext@tok
        \expandafter\CT@extract\the\toks\@tempcnta\columncolor!\@nil
        \expandafter\adl@extract@arc\the\toks\@tempcnta\arrayrulecolor!\@nil
        \expandafter\adl@extract@drsc
                \the\toks\@tempcnta\doublerulesepcolor!\@nil
        \expandafter\adl@extract@dgc\the\toks\@tempcnta\dashgapcolor!\@nil
        \@addtopreamble{\if@RTL\beginL\fi%
                \setbox\z@\hbox\bgroup\bgroup\if@RTL\beginR\fi
                \ifcase \@chnum
                        \hskip\stretch{.5}\kern\z@
                        \d@llarbegin
                        \insert@column
                        \d@llarend\hskip\stretch{.5}%
                \or \d@llarbegin \insert@column \d@llarend \hfill
                \or \hfill \kern\z@ \d@llarbegin \insert@column \d@llarend
                \or  $\vcenter
                        \@startpbox{\@nextchar}\insert@column \@endpbox $%
                \or  \vtop \@startpbox{\@nextchar}\insert@column \@endpbox
                \or  \vbox \@startpbox{\@nextchar}\insert@column \@endpbox
                \fi
                \if@RTL\endR\fi\egroup\egroup
                \begingroup
                        \CT@setup
                        \CT@column@color
                        \CT@row@color
                        \CT@cell@color
                        \CT@do@color
                \endgroup
                \@tempdima\ht\z@
                \advance\@tempdima\minrowclearance
                \vrule\@height\@tempdima\@width\z@
                \unhbox\z@\if@RTL\endL\fi}%
        \prepnext@tok}
\let\adl@act@classz\@classz
\let\adl@org@classz\@classz
}
%    \end{macrocode}
% \iffalse
%</arydshln-xetex-bidi.def>
%<*beamer-xetex-bidi.def>
%\fi
% \section{File \texttt{beamer-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamer-xetex-bidi.def}[2022/06/07 v0.3 bidi adaptations for beamer class for XeTeX engine]
\AtBeginDocument{%
  \if@RTLmain
    \raggedleft
  \else
    \raggedright
  \fi  
}

\renewcommand*{\bidi@beamer@ragged}{%
  \if@RTL
    \raggedleft
  \else
    \raggedright
  \fi
}


%    \end{macrocode}
% \iffalse
%</beamer-xetex-bidi.def>
%<*beamerbaseauxtemplates-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaseauxtemplates-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaseauxtemplates-xetex-bidi.def}[2025/01/03 v0.5 bidi adaptations for beamerbaseauxtemplates package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@subsection in toc@sections numbered}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@sections numbered}

\bidi@csundef{beamer@@tmpop@section in toc@subsections numbered}

\bidi@csundef{beamer@@tmpop@subsection in toc@subsections numbered}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@subsections numbered}

\defbeamertemplate{subsection in toc}{sections numbered}
{\leavevmode\bidi@beamer@leftskip=2.5em\inserttocsubsection\par}

\defbeamertemplate{subsubsection in toc}{sections numbered}
{\leavevmode\normalsize\usebeamerfont{subsection in toc}\bidi@beamer@leftskip=3.5em\usebeamerfont{subsubsection in toc}%
  \inserttocsubsubsection\par}
  
\defbeamertemplate{section in toc}{subsections numbered}
{\leavevmode\bidi@beamer@leftskip=2em\inserttocsection\par}

\defbeamertemplate{subsection in toc}{subsections numbered}
{\leavevmode\bidi@beamer@leftskip=2em\rlap{\hskip-2em\inserttocsectionnumber.\inserttocsubsectionnumber}\inserttocsubsection\par}

\defbeamertemplate{subsubsection in toc}{subsections numbered}
{\leavevmode\normalsize\usebeamerfont{subsection in
    toc}\bidi@beamer@leftskip=3em\usebeamerfont{subsubsection in toc}%
  \inserttocsubsubsection\par}
  
\bidi@csundef{beamer@@tmpop@section in toc@circle}

\bidi@csundef{beamer@@tmpop@subsection in toc@circle}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@circle}

\defbeamertemplate{section in toc}{circle}
{\leavevmode\bidi@beamer@leftskip=2ex%
  \llap{%
    \usebeamerfont*{section number projected}%
    \usebeamercolor{section number projected}%
    \begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
      \color{bg}
      \pgfpathcircle{\pgfpoint{0pt}{.75ex}}{1.2ex}
      \pgfusepath{fill}
      \pgftext[base]{\color{fg}\inserttocsectionnumber}
    \end{pgfpicture}\kern1.25ex%
  }%
  \inserttocsection\par}

\defbeamertemplate{subsection in toc}{circle}
{\leavevmode\bidi@beamer@leftskip=2em\inserttocsubsection\par}

\defbeamertemplate{subsubsection in toc}{circle}
{\leavevmode\normalsize\usebeamerfont{subsection in
    toc}\bidi@beamer@leftskip=3em\usebeamerfont{subsubsection in toc}%
  \inserttocsubsubsection\par}

\bidi@csundef{beamer@@tmpop@section in toc@square}

\bidi@csundef{beamer@@tmpop@subsection in toc@square}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@square}

\bidi@csundef{beamer@@tmpop@enumerate item@square}

\bidi@csundef{beamer@@tmpop@enumerate subitem@square}

\bidi@csundef{beamer@@tmpop@enumerate subsubitem@square}

\bidi@csundef{beamer@@tmpop@enumerate mini template@square}

\defbeamertemplate{section in toc}{square}
{\leavevmode\bidi@beamer@leftskip=3ex%
  \llap{{%
    \usebeamerfont*{section number projected}%
    \usebeamercolor[bg]{section number projected}%
    \if@RTL
    \else
      \vrule width2.25ex height1.85ex depth.4ex%
      \hskip-2.25ex%
    \fi
    \hbox to2.25ex{{\hfil\color{fg}\inserttocsectionnumber\hfil}}%
    \if@RTL
      \hskip-2.25ex%
      \vrule width2.25ex height1.85ex depth.4ex%
    \fi
    }\kern1.25ex}%
  \inserttocsection\par}
  
\defbeamertemplate{subsection in toc}{square}
{\leavevmode\bidi@beamer@leftskip=5ex\llap{{%
    \usebeamercolor[bg]{subsection number projected}%
    \vrule width1ex height1ex\kern1ex}}\inserttocsubsection\par}
    
\defbeamertemplate{subsubsection in toc}{square}
{\leavevmode\normalsize\usebeamerfont{subsection in
    toc}\bidi@beamer@leftskip=7ex\usebeamerfont{subsubsection in toc}%
  \llap{{%
    \usebeamercolor[bg]{subsubsection number projected}%
    \vrule width0.75ex height0.75ex\kern1ex}}\inserttocsubsubsection\par}
    
\defbeamertemplate{enumerate item}{square}
{
  \hbox{{%
    \usebeamerfont*{item projected}%
    \usebeamercolor[bg]{item projected}%
    \if@RTL
    \else
      \vrule width2.25ex height1.85ex depth.4ex%
      \hskip-2.25ex%
    \fi
    \hbox to2.25ex{{%
      \hfil%
      \color{fg}\insertenumlabel%
      \hfil}}%
      \if@RTL
        \hskip-2.25ex%
        \vrule width2.25ex height1.85ex depth.4ex%
      \fi
  }}%
}
[action]
{\setbeamerfont{item projected}{size=\scriptsize}}

\defbeamertemplate{enumerate subitem}{square}
{
  \hbox{{%
    \usebeamerfont*{subitem projected}%
    \usebeamercolor[bg]{subitem projected}%
    \if@RTL
    \else
      \vrule width2.25ex height1.85ex depth.4ex%
      \hskip-2.25ex%
    \fi
    \hbox to2.25ex{{%
      \hfil%
      \color{fg}\insertsubenumlabel%
      \hfil}}%
      \if@RTL
        \hskip-2.25ex%
        \vrule width2.25ex height1.85ex depth.4ex%
      \fi
  }}%
}

\defbeamertemplate{enumerate subsubitem}{square}
{
  \hbox{{%
    \usebeamerfont*{subitem projected}%
    \usebeamercolor[bg]{subsubitem projected}%
    \if@RTL
    \else
      \vrule width2.25ex height1.85ex depth.4ex%
      \hskip-2.25ex%
    \fi
    \hbox to2.25ex{{%
      \hfil%
      \color{fg}\insertsubsubenumlabel%
      \hfil}}%
      \if@RTL
        \hskip-2.25ex%
        \vrule width2.25ex height1.85ex depth.4ex%
      \fi
  }}%
}

\defbeamertemplate{enumerate mini template}{square}
{
  \hbox{{%
    \usebeamerfont*{\beameritemnestingprefix item projected}%
    \usebeamercolor[bg]{\beameritemnestingprefix item projected}%
    \if@RTL
    \else
      \vrule width2.25ex height1.85ex depth.4ex%
      \hskip-2.25ex%
    \fi
    \hbox to2.25ex{{%
      \hfil%
      \color{fg}\insertenumlabel%
      \hfil}}%
      \if@RTL
        \hskip-2.25ex%
        \vrule width2.25ex height1.85ex depth.4ex%
      \fi
  }}%
}

\bidi@csundef{beamer@@tmpop@section in toc@ball unnumbered}

\bidi@csundef{beamer@@tmpop@subsection in toc@ball unnumbered}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@ball unnumbered}

\defbeamertemplate{section in toc}{ball unnumbered}
{\leavevmode\bidi@beamer@leftskip=2.25ex%
  \llap{%
    \raise0.1ex\beamer@usesphere{section number projected}{bigsphere}\kern1.25ex}%
  \inserttocsection\par}

\defbeamertemplate{subsection in toc}{ball unnumbered}
{\leavevmode\bidi@beamer@leftskip=5.1ex\llap{%
    \raise0.2ex\beamer@usesphere{subsection number projected}{smallsphere}\kern1ex}\inserttocsubsection\par}

\defbeamertemplate{subsubsection in toc}{ball unnumbered}
{\leavevmode\normalsize\usebeamerfont{subsection in
    toc}\bidi@beamer@leftskip=8.2ex\usebeamerfont{subsubsection in toc}%
  \llap{%
    \beamer@usesphere{subsubsection number projected}{smallsphere}\kern0.75ex}\inserttocsubsubsection\par}
    
\bidi@csundef{beamer@@tmpop@section in toc@ball}

\bidi@csundef{beamer@@tmpop@subsection in toc@ball}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@ball}

\defbeamertemplate{section in toc}{ball}
{\leavevmode\bidi@beamer@leftskip=2.75ex%
  \llap{%
    \normalsize%
    \begin{pgfpicture}{-1ex}{-0.7ex}{1ex}{1ex}
      \pgftext{\beamer@usesphere{section number projected}{tocsphere}}
      \pgftext{%
        \usebeamerfont*{section number projected}%
        \usebeamercolor{section number projected}%
        \color{fg!90!bg}%
        \inserttocsectionnumber}
    \end{pgfpicture}%
    \kern1.25ex}%
  \inserttocsection\par
}
[action]
{\setbeamerfont{section number projected}{size=\scriptsize}}

\defbeamertemplate{subsection in toc}{ball}
{\leavevmode\bidi@beamer@leftskip=5ex%
  \llap{\raise0.1ex\beamer@usesphere{subsection number projected}{bigsphere}\kern1ex}%
  \inserttocsubsection\par%
}

\defbeamertemplate{subsubsection in toc}{ball}
{\leavevmode\normalsize\usebeamerfont{subsection in
    toc}\bidi@beamer@leftskip=7ex\usebeamerfont{subsubsection in toc}%
  \llap{\beamer@usesphere{subsubsection number projected}{bigsphere}\kern0.75ex}%
  \inserttocsubsubsection\par%
}

\bidi@csundef{beamer@@tmpop@block begin@rounded}

\bidi@csundef{beamer@@tmpop@block alerted begin@rounded}

\bidi@csundef{beamer@@tmpop@block example begin@rounded}

\defbeamertemplate{block begin}{rounded}[1][shadow=false]
{%
  \par\vskip\medskipamount%
  \begin{beamerboxesrounded}[upper=block title,lower=block body,#1]%
    {\raggedright\usebeamerfont*{block title}\insertblocktitle}%
    \bidi@beamer@ragged%
    \usebeamerfont{block body}%
}

\defbeamertemplate{block alerted begin}{rounded}[1][shadow=false]
{%
  \par\vskip\medskipamount%
  \begin{beamerboxesrounded}[upper=block title alerted,lower=block body alerted,#1]%
    {\raggedright\usebeamerfont*{block title alerted}\insertblocktitle}%
    \bidi@beamer@ragged%
    \usebeamerfont{block body alerted}%
}%

\defbeamertemplate{block example begin}{rounded}[1][shadow=false]
{%
  \par\vskip\medskipamount%
  \begin{beamerboxesrounded}[upper=block title example,lower=block body example,#1]
    {\raggedright\usebeamerfont*{block title example}\insertblocktitle}%
    \bidi@beamer@ragged%
    \usebeamerfont{block body example}%
}%

\bidi@csundef{beamer@@tmpop@caption@numbered}

\defbeamertemplate{caption}{numbered}
{%
  \leavevmode
  \bidi@beamer@ragged
  {%
    \usebeamercolor[fg]{caption name}%
    \usebeamerfont*{caption name}%
    \insertcaptionname~\insertcaptionnumber
    \usebeamertemplate{caption label separator}%
  }%
  \insertcaption\par
}

\bidi@csundef{beamer@@tmpop@caption@caption name own line}

\defbeamertemplate{caption}{caption name own line}
{%
  \begin{minipage}{\textwidth}
    \leavevmode
    \bidi@beamer@ragged
  {%
    \usebeamercolor[fg]{caption name}%
    \usebeamerfont*{caption name}%
    \insertcaptionname%
    }\\
      \insertcaption
    \end{minipage}
}

\ApplyPatchCodeToPackage{caption}{%
  \DeclareCaptionFont{beamer@font}{%
    \usebeamerfont*{caption}%
%    \usebeamercolor[fg]{caption}%
  }
  \SetCaptionDefault{font}{beamer@font}
  \DeclareCaptionJustification{bidi@beamer@ragged}{\bidi@beamer@ragged}
  \SetCaptionDefault{justification}{bidi@beamer@ragged}
}

%    \end{macrocode}
% \iffalse
%</beamerbaseauxtemplates-xetex-bidi.def>
%<*beamerbaseboxes-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaseboxes-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaseboxes-xetex-bidi.def}[2022/06/01 v0.1 bidi adaptations for beamerbaseboxes package for XeTeX engine]
\renewcommand\beamerboxesrounded[2][]{%
  \global\let\beamer@firstlineitemizeunskip=\relax%
  \vbox\bgroup%
  \setkeys{beamerboxes}{upper=block title,lower=block body,width=\textwidth,shadow=false}%
  \setkeys{beamerboxes}{#1}%
  {%
    \usebeamercolor{\bmb@lower}%
    \globalcolorstrue%
    \colorlet{lower.bg}{bg}%
  }%
  {%
    \usebeamercolor{\bmb@upper}%
    \globalcolorstrue%
    \colorlet{upper.bg}{bg}%
  }%
  %
  % Typeset head
  %
  \vskip4bp
  \setbox\bmb@box=\hbox{%
    \begin{minipage}[b]{\bmb@width}%
      \usebeamercolor[fg]{\bmb@upper}%
      #2%
    \end{minipage}}%
  \ifdim\wd\bmb@box=0pt%
    \setbox\bmb@box=\hbox{}%
    \ht\bmb@box=1.5pt%
    \bmb@prevheight=-4.5pt%
  \else%
    \wd\bmb@box=\bmb@width%
    \bmb@temp=\dp\bmb@box%
    \ifdim\bmb@temp<1.5pt%
      \bmb@temp=1.5pt%
    \fi%
    \setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
    \dp\bmb@box=0pt%
    \bmb@prevheight=\ht\bmb@box%
  \fi%
  \bmb@temp=\bmb@width%
  \bmb@dima=\bmb@temp\advance\bmb@dima by2.2bp%
  \bmb@dimb=\bmb@temp\advance\bmb@dimb by4bp%
  \hbox{%
    \begin{pgfpicture}{0bp}{+-\ht\bmb@box}{0bp}{+-\ht\bmb@box}
      \ifdim\wd\bmb@box=0pt%
        \color{lower.bg}%
      \else%
        \color{upper.bg}%
      \fi%
      \pgfpathqmoveto{-4bp}{-1bp}
      \pgfpathqcurveto{-4bp}{1.2bp}{-2.2bp}{3bp}{0bp}{3bp}
      \pgfpathlineto{\pgfpoint{\bmb@temp}{3bp}}
      \pgfpathcurveto%
      {\pgfpoint{\bmb@dima}{3bp}}%
      {\pgfpoint{\bmb@dimb}{1.2bp}}%
      {\pgfpoint{\bmb@dimb}{-1bp}}%
      \bmb@dima=-\ht\bmb@box%
      \advance\bmb@dima by-2pt%
      \pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
      \pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
      \pgfusepath{fill}
    \end{pgfpicture}%
    \copy\bmb@box%
  }%
  \nointerlineskip%
  \vskip-1pt%
  \ifdim\wd\bmb@box=0pt%
  \else%
  \hbox{%
    \begin{pgfpicture}{0pt}{0pt}{\bmb@width}{6pt}
      \bmb@dima=\bmb@width%
      \advance\bmb@dima by8bp%
      \pgfpathrectangle{\pgfpoint{-4bp}{-1bp}}{\pgfpoint{\bmb@dima}{8bp}}
      \pgfusepath{clip}
      {\pgftransformshift{\pgfpoint{-4bp}{0bp}}\pgftext[left,base]{\pgfuseshading{bmb@transition}}}%
    \end{pgfpicture}%
  }%
  \nointerlineskip%
  \vskip-0.5pt%
  \fi%
  \setbox\bmb@colorbox=\hbox{{\pgfpicturetrue\pgfsetcolor{lower.bg}}}%
  \setbox\bmb@box=\hbox\bgroup\begin{minipage}[b]{\bmb@width}%
    \vskip2pt%
    \usebeamercolor[fg]{\bmb@lower}%
    \colorlet{beamerstructure}{upper.bg}%
    \colorlet{structure}{upper.bg}%
    %\color{.}%
    \@bidi@list@minipage@parboxfalse
  }

\bidi@patchcmd{\endbeamerboxesrounded}{\begingroup}{%
  \begingroup
  \@RTLfalse
}{}{}
  

%    \end{macrocode}
% \iffalse
%</beamerbaseboxes-xetex-bidi.def>
%<*beamerbasecolor-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbasecolor-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbasecolor-xetex-bidi.def}[2022/06/07 v0.2 bidi adaptations for beamerbasecolor package for XeTeX engine]
\renewenvironment{beamercolorbox}[2][]{%
  \def\beamer@vmode{\leavevmode}%
  \setkeys{beamercolbox}{wd=\textwidth,ht={},dp={},%
    leftskip=0pt,rightskip=0pt plus1fil,%
    sep=0pt,colsep=0pt,colsep*=0pt,%
    shadow=false,rounded=false,ignorebg=false}%
  \if@RTL
    \setkeys{beamercolbox}{rightskip=0pt,leftskip=0pt plus1fil}%
  \else
    \setkeys{beamercolbox}{leftskip=0pt,rightskip=0pt plus1fil}%
  \fi
  \setkeys{beamercolbox}{#1}%
  \ifbeamercolorempty[bg]{#2}{\@tempswafalse}{\@tempswatrue}%
  \ifbeamer@colbox@ignorebg\@tempswafalse\fi%
  \def\beamer@colbox@color{#2}%
  \setbox\beamer@tempbox=\hbox\bgroup\color@begingroup
    \ifbeamer@colbox@ignorebg%
      \colorlet{beamer@temp@color}{bg}%
      \usebeamercolor[fg]{#2}%
      \colorlet{bg}{beamer@temp@color}%
    \else%
      \usebeamercolor[fg]{#2}%
    \fi%
    \beginL
    \vbox\bgroup%
    \hsize=\beamer@colbox@wd%
    \@arrayparboxrestore%
    \leftskip=\beamer@colbox@ls%
    \ifdim\beamer@colbox@sep>\z@\advance\leftskip\beamer@colbox@sep\fi%
    \rightskip=\beamer@colbox@rs%
    \ifdim\beamer@colbox@sep>\z@\advance\rightskip\beamer@colbox@sep\fi%
    \if@tempswa\ifdim\beamer@colbox@colsep>\z@%
      \advance\leftskip by\beamer@colbox@colsep%
      \advance\rightskip by\beamer@colbox@colsep%
      \vskip\beamer@colbox@colsep%
    \fi%
      \ifdim\beamer@colbox@colseps>\z@\vskip\beamer@colbox@colseps\fi%
    \fi%
    \ifdim\beamer@colbox@sep>\z@\vskip\beamer@colbox@sep\fi%
    \beamer@vmode\ignorespaces}{%
    \ifdim\beamer@colbox@sep>\z@\vskip\beamer@colbox@sep\fi%
    \if@tempswa
      \ifdim\beamer@colbox@colsep>\z@\vskip\beamer@colbox@colsep\fi%
      \ifdim\beamer@colbox@colseps>\z@\vskip\beamer@colbox@colseps\fi%
    \fi%
  \egroup\endL\color@endgroup\egroup%
  \wd\beamer@tempbox=\beamer@colbox@wd%
  \ifx\beamer@colbox@ht\@empty\else\ht\beamer@tempbox=\beamer@colbox@ht\fi%
  \ifx\beamer@colbox@dp\@empty\else\dp\beamer@tempbox=\beamer@colbox@dp\fi%
  \ifbeamer@colbox@rounded%
    \if@tempswa%
      \begin{beamerboxesrounded}[%
        shadow=\beamer@colbox@shadow,%
        lower=\beamer@colbox@color,%
        upper=normal text,%
        width=\beamer@colbox@wd]{}%
        \box\beamer@tempbox%
      \end{beamerboxesrounded}%
    \else%
      \ifdim\wd\beamer@tempbox>\textwidth%
        \setbox\beamer@tempbox=\hbox to\textwidth{\hss\box\beamer@tempbox\hss}%
      \fi%
      \box\beamer@tempbox%
    \fi%
  \else%
    \if@tempswa\setbox\beamer@tempbox=\hbox{%
      \usebeamercolor{\beamer@colbox@color}%
      \hskip-\beamer@colbox@colseps%
      \fboxsep=\z@\colorbox{bg}{%
        \hskip\beamer@colbox@colseps%
        \box\beamer@tempbox%
        \hskip\beamer@colbox@colseps%
      }%
      \hskip-\beamer@colbox@colseps%
      }\fi%
    \ifdim\wd\beamer@tempbox>\textwidth%
      \setbox\beamer@tempbox=\hbox to\textwidth{\hskip0pt minus\beamer@leftmargin\relax\box\beamer@tempbox\hskip0pt minus\beamer@rightmargin\relax}%
    \fi%
    \box\beamer@tempbox%
  \fi%
}


%    \end{macrocode}
% \iffalse
%</beamerbasecolor-xetex-bidi.def>
%<*beamerbasecompatibility-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbasecompatibility-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbasecompatibility-xetex-bidi.def}[2022/06/27 v0.1 bidi adaptations for beamerbasecompatibility package for XeTeX engine]
\def\insertvrule#1#2{\hbox{{\color{#2}\hskip-\Gm@lmargin\vrule width \paperwidth height #1\hskip-\Gm@rmargin}}}


%    \end{macrocode}
% \iffalse
%</beamerbasecompatibility-xetex-bidi.def>
%<*beamerbaseframecomponents-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaseframecomponents-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaseframecomponents-xetex-bidi.def}[2025/09/30 v0.8 bidi adaptations for beamerbaseframecomponents package for XeTeX engine]
\renewcommand{\setbeamersize}[1]{%
  \beamer@dogeometryfalse%
  \setkeys{beamer@margin}{#1}%
  \ifbeamer@dogeometry%
    % Reset left margin now
    \beamer@tempdim=\beamer@leftmargin%
    \advance\beamer@tempdim by\beamer@leftsidebar%
    \if@RTLmain
      \geometry{right=\the\beamer@tempdim}%
    \else
      \geometry{left=\the\beamer@tempdim}%
    \fi
    % Reset right margin now
    \beamer@tempdim=\beamer@rightmargin%
    \advance\beamer@tempdim by\beamer@rightsidebar%
    \if@RTLmain
      \geometry{left=\the\beamer@tempdim}%
    \else
      \geometry{right=\the\beamer@tempdim}%
    \fi
  \fi%
}

\newcommand*{\bidi@beamer@Gm@lmargin}{%
  \if@RTLmain
    \Gm@rmargin
  \else
    \Gm@lmargin
  \fi
}

\newcommand*{\bidi@beamer@Gm@rmargin}{%
  \if@RTLmain
    \Gm@lmargin
  \else
    \Gm@rmargin
  \fi
}

\def\ps@navigation{
  \def\@oddhead{%
    \begingroup%
    \setbox\beamer@tempbox=\hbox{\usebeamertemplate***{background canvas}\hyper@pagetransition\hyper@pageduration}%
    \beamer@tempdim=\ht\beamer@tempbox%
    \setbox\beamer@tempbox=\hbox{\lower\beamer@tempdim\hbox{\box\beamer@tempbox}}%
    \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
    \setbox\@tempboxa=\hbox{\usebeamertemplate***{background}}%
    \beamer@tempdim=\ht\@tempboxa%
    \setbox\@tempboxa=\hbox{\lower\beamer@tempdim\hbox{\box\@tempboxa}}%
    \wd\@tempboxa=0pt\ht\@tempboxa=0pt\dp\@tempboxa=0pt%
    \vbox{\hbox{\hskip-\bidi@beamer@Gm@lmargin\box\beamer@tempbox\box\@tempboxa}%
      \hbox{%
        {%
          \setbox\beamer@tempbox=\hbox{\hskip-\bidi@beamer@Gm@lmargin%
          \if@RTLmain
                      {%
              \vbox to \sidebarheight{%
                \usebeamertemplate***{sidebar left}%
                \vfil%
            }}%
            \ApplyPatchIfPackageLoadedF{beamerinnerthemeinmargin}{%
              \hskip-\textwidth
            }%
            \fi
            {\setbox\beamer@tempbox=\hbox{\vbox to \sidebarheight{%
                  \usebeamercolor*{sidebar left}%
                  \usebeamertemplate{sidebar canvas left}%
                  \vss%
                }}%
              \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
              \box\beamer@tempbox}%
              \if@RTLmain
              \else
            {%
              \vbox to \sidebarheight{%
                \usebeamertemplate***{sidebar left}%
                \vfil%
            }}\fi}%
          \beamer@tempdim=\ht\beamer@tempbox%
          \setbox\beamer@tempbox=\hbox{{\lower\beamer@tempdim\hbox{\box\beamer@tempbox}}}%
          \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
          \box\beamer@tempbox%
        }%
        {% print right sidebar first, since it should be overwritten by headline
          \setbox\beamer@tempbox=\hbox{\hskip\textwidth\hskip\beamer@rightmargin%
          \if@RTLmain
                      {%
              \vbox to \sidebarheight{%
                \usebeamertemplate***{sidebar right}%
                \vfil%
            }}%
            \hskip-\textwidth
            \fi
            {\setbox\beamer@tempbox=\hbox{\vbox to \sidebarheight{%
                  \usebeamercolor*{sidebar right}%
                  \usebeamertemplate{sidebar canvas right}%
                  \vss%
                }}%
              \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
              \box\beamer@tempbox}%
              \if@RTLmain
              \else
            {%
              \vbox to \sidebarheight{%
                \usebeamertemplate***{sidebar right}%
                \vfil%
            }}\fi}%
          \beamer@tempdim=\ht\beamer@tempbox%
          \setbox\beamer@tempbox=\hbox{{\lower\beamer@tempdim\hbox{\box\beamer@tempbox}}}%
          \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
          \box\beamer@tempbox%
        }%
        \beamer@typesetheadorfoot{headline}%
      }%
      \hfil}%
    \endgroup}
  \def\@oddfoot{%
    \vbox{\offinterlineskip\hbox{\beamer@typesetheadorfoot{footline}%
    \hfil}\hbox{}}\hfil
  }%
  \let\@evenhead\@oddhead
  \let\@evenfoot\@oddfoot}

\AtBeginDocument{%
  \pagestyle{navigation}%
}

\def\beamer@typesetheadorfoot#1{% typeset the head or footline
  {\parskip0pt\offinterlineskip%
    \hbox{%
      \hskip-\bidi@beamer@Gm@lmargin%
      \hbox{%
        \vbox{%
          \@tempdima=\textwidth%
          \textwidth=\paperwidth%
          \hsize=\textwidth%
          \def\\{,}%
          \usebeamertemplate***{#1}%
        }}%
      \hskip-\bidi@beamer@Gm@rmargin%
    }}\hfil%
}

\def\ps@empty{%
  \let\@mkboth\@gobbletwo%
  \def\@oddhead{\begingroup%
    \setbox\beamer@tempbox=\hbox{\usebeamertemplate***{background canvas}\hyper@pagetransition\hyper@pageduration}%
    \beamer@tempdim=\ht\beamer@tempbox%
    \setbox\beamer@tempbox=\hbox{\lower\beamer@tempdim\hbox{\box\beamer@tempbox}}%
    \wd\beamer@tempbox=0pt\ht\beamer@tempbox=0pt\dp\beamer@tempbox=0pt%
    \setbox\@tempboxa=\hbox{\usebeamertemplate***{background}}%
    \beamer@tempdim=\ht\@tempboxa%
    \setbox\@tempboxa=\hbox{\lower\beamer@tempdim\hbox{\box\@tempboxa}}%
    \wd\@tempboxa=0pt\ht\@tempboxa=0pt\dp\@tempboxa=0pt%
    \vbox{\hbox{\hskip-\Gm@lmargin\raise\headheight\box\beamer@tempbox\raise\headheight\box\@tempboxa}\hfil}%
    \endgroup%
  }
  \def\@oddfoot{{\normalcolor{\hfil%
    \setbox\beamer@tempbox=\hbox{\usebeamertemplate***{navigation symbols}\hskip-\bidi@beamer@Gm@rmargin\hskip2pt}%
    \ht\beamer@tempbox=0pt%
    \dp\beamer@tempbox=0pt%
    \box\beamer@tempbox}}}
  \let\@evenhead\@oddhead\let\@evenfoot\@oddfoot}
  
\renewenvironment<>{beamer@columnenv}[2][\beamer@colmode]{%
  \beamer@colclose\def\beamer@colclose{}%
  \begin{actionenv}#3%
    \setkeys{beamer@col}{#1}%
    \begin{minipage}[\beamer@colalign]{#2}%
      \leavevmode\bidi@beamer@ragged\beamer@colheadskip\ignorespaces}
    {\end{minipage}\hfill\end{actionenv}\@ignoretrue}
\let\endcolumn\endbeamer@columnenv

\renewcommand<>\beamer@columncom[2][\beamer@colmode]{%
  \beamer@colclose%
  \def\beamer@colclose{\end{minipage}\hfill\end{actionenv}\ignorespaces}%
\begin{actionenv}#3%
  \setkeys{beamer@col}{#1}%
  \begin{minipage}[\beamer@colalign]{#2}%
    \leavevmode\bidi@beamer@ragged\beamer@colheadskip\ignorespaces}

\renewenvironment<>{columns}[1][]{%
  \begin{actionenv}#2%
  \ifbeamer@onlytextwidth
    \def\beamer@colentrycode{\hbox to\textwidth\bgroup\ignorespaces}%
    \def\beamer@colexitcode{\unskip\egroup}
  \else%
    \def\beamer@colentrycode{%
      \hbox to\textwidth\bgroup%
      \leavevmode%
      \hskip-\beamer@leftmargin%
      \nobreak%
      \beamer@tempdim=\textwidth%
      \advance\beamer@tempdim by\beamer@leftmargin%
      \advance\beamer@tempdim by\beamer@rightmargin%
      \hbox to\beamer@tempdim\bgroup%
      \hbox{}\hfill\ignorespaces}%
    \def\beamer@colexitcode{\egroup%
      \nobreak%
      \hskip-\beamer@rightmargin\egroup}%
  \fi%
  \ifbeamer@centered\setkeys{beamer@col}{c}\else\setkeys{beamer@col}{t}\fi%
  \setkeys{beamer@col}{#1}%
  \par%
  \leavevmode
  \beamer@colentrycode%
  \def\beamer@colclose{}\ignorespaces}%
  {\beamer@colclose\def\beamer@colclose{}\beamer@colexitcode\end{actionenv}}%


\def\@makeRTLfntext#1{%
  \def\insertfootnotetext{#1}%
  \def\insertfootnotemark{\@makefnmark}%
  \usebeamertemplate***{RTLfootnote}}
  
\def\@makeLTRfntext#1{%
  \def\insertfootnotetext{#1}%
  \def\insertfootnotemark{\@makefnmark}%
  \usebeamertemplate***{LTRfootnote}}
  
\renewcommand<>\beamer@framefootnotetext[1]{%
  \global\setbox\beamer@footins\vbox{%
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
    \hsize\framewidth
    \textwidth\hsize
    \columnwidth\hsize
    \unvbox\beamer@footins
    \reset@font
    \bidi@@footnotetext@font
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\renewcommand<>\beamer@frameRTLfootnotetext[1]{%
  \global\setbox\beamer@footins\vbox{%
    \@RTLtrue
    \hsize\framewidth
    \textwidth\hsize
    \columnwidth\hsize
    \unvbox\beamer@footins
    \reset@font
    \bidi@@RTLfootnotetext@font
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makeRTLfntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\renewcommand<>\beamer@frameLTRfootnotetext[1]{%
  \global\setbox\beamer@footins\vbox{%
    \@RTLfalse
    \hsize\framewidth
    \textwidth\hsize
    \columnwidth\hsize
    \unvbox\beamer@footins
    \reset@font
    \bidi@@LTRfootnotetext@font
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makeLTRfntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\renewcommand<>\@mpfootnotetext[1]{%
\ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\if@RTL@footnote\global\let\bidi@mpfootnoterule\right@footnoterule\else\global\let\bidi@mpfootnoterule\left@footnoterule\fi\fi\fi
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \reset@font
    \bidi@@footnotetext@font
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\renewcommand<>\@mpRTLfootnotetext[1]{%
\ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\global\let\bidi@mpfootnoterule\right@footnoterule\fi\fi
  \global\setbox\@mpfootins\vbox{%
     \unvbox\@mpfootins
     \@RTLtrue
    \reset@font
    \bidi@@RTLfootnotetext@font
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makeRTLfntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\renewcommand<>\@mpLTRfootnotetext[1]{%
\ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\global\let\bidi@mpfootnoterule\left@footnoterule\fi\fi
  \global\setbox\@mpfootins\vbox{%
  \unvbox\@mpfootins
  \@RTLfalse
    \reset@font
    \bidi@@LTRfootnotetext@font
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \uncover#2{\@makeLTRfntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}}%
    \color@endgroup}}
    
\let\@footnotetext=\beamer@framefootnotetext
\let\@RTLfootnotetext=\beamer@frameRTLfootnotetext
\let\@LTRfootnotetext=\beamer@frameLTRfootnotetext

\footdir@temp\footdir@ORG@bidi@beamer@footnotetext\@footnotetext{\bidi@footdir@footnote}%  
\footdir@temp\footdir@ORG@bidi@beamer@RTLfootnotetext\@RTLfootnotetext{R}%
\footdir@temp\footdir@ORG@bidi@beamer@LTRfootnotetext\@LTRfootnotetext{L}%

\renewcommand<>{\footnote}[1][]{%
  \let\beamer@footnotetext=\@footnotetext%
  \let\beamer@mpfn=\@mpfn%
  \let\beamer@thempfn=\thempfn%
  \let\beamer@kvorig=\KV@errx%
  \let\beamer@xkvorig=\XKV@err
  \def\beamer@footarg{}%
  \def\KV@errx##1{\edef\beamer@footarg{\@tempa}}%
  \def\XKV@err##1{\edef\beamer@footarg{\XKV@tkey}}%
  \setkeys{beamerfootnote}{#1}%
  \let\KV@errx=\beamer@kvorig%
  \let\XKV@errx=\beamer@xkvorig
  \ifx\beamer@footarg\@empty%
    \def\beamer@next{\stepcounter\beamer@mpfn
      \protected@xdef\@thefnmark{\beamer@thempfn}%
      \@footnotemark\beamer@footnotetext#2}%
  \else%
    \def\beamer@next{%
      \begingroup
        \csname c@\beamer@mpfn\endcsname\beamer@footarg\relax
        \unrestored@protected@xdef\@thefnmark{\beamer@thempfn}%
      \endgroup
      \@footnotemark\beamer@footnotetext#2}%
  \fi%
  \beamer@next}
  
\renewcommand<>{\RTLfootnote}[1][]{%
  \let\beamer@RTLfootnotetext=\@RTLfootnotetext%
  \let\beamer@mpfn=\@mpfn%
  \let\beamer@thempfn=\thempfn%
  \let\beamer@kvorig=\KV@errx%
  \let\beamer@xkvorig=\XKV@err
  \def\beamer@footarg{}%
  \def\KV@errx##1{\edef\beamer@footarg{\@tempa}}%
  \def\XKV@err##1{\edef\beamer@footarg{\XKV@tkey}}%
  \setkeys{beamerfootnote}{#1}%
  \let\KV@errx=\beamer@kvorig%
  \let\XKV@errx=\beamer@xkvorig
  \ifx\beamer@footarg\@empty%
    \def\beamer@next{\stepcounter\beamer@mpfn
      \protected@xdef\@thefnmark{\beamer@thempfn}%
      \@footnotemark\beamer@RTLfootnotetext#2}%
  \else%
    \def\beamer@next{%
      \begingroup
        \csname c@\beamer@mpfn\endcsname\beamer@footarg\relax
        \unrestored@protected@xdef\@thefnmark{\beamer@thempfn}%
      \endgroup
      \@footnotemark\beamer@RTLfootnotetext#2}%
  \fi%
  \beamer@next}
  
\renewcommand<>{\LTRfootnote}[1][]{%
  \let\beamer@LTRfootnotetext=\@LTRfootnotetext%
  \let\beamer@mpfn=\@mpfn%
  \let\beamer@thempfn=\thempfn%
  \let\beamer@kvorig=\KV@errx%
  \let\beamer@xkvorig=\XKV@err
  \def\beamer@footarg{}%
  \def\KV@errx##1{\edef\beamer@footarg{\@tempa}}%
  \def\XKV@err##1{\edef\beamer@footarg{\XKV@tkey}}%
  \setkeys{beamerfootnote}{#1}%
  \let\KV@errx=\beamer@kvorig%
  \let\XKV@errx=\beamer@xkvorig
  \ifx\beamer@footarg\@empty%
    \def\beamer@next{\stepcounter\beamer@mpfn
      \protected@xdef\@thefnmark{\beamer@thempfn}%
      \@footnotemark\beamer@LTRfootnotetext#2}%
  \else%
    \def\beamer@next{%
      \begingroup
        \csname c@\beamer@mpfn\endcsname\beamer@footarg\relax
        \unrestored@protected@xdef\@thefnmark{\beamer@thempfn}%
      \endgroup
      \@footnotemark\beamer@LTRfootnotetext#2}%
  \fi%
  \beamer@next}
  
  
%    \end{macrocode}
% \iffalse
%</beamerbaseframecomponents-xetex-bidi.def>
%<*beamerbaseframesize-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaseframesize-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaseframesize-xetex-bidi.def}[2022/06/27 v0.1 bidi adaptations for beamerbaseframesize package for XeTeX engine]
\def\beamer@framezoom<#1><#2>[#3](#4,#5)(#6,#7){%
  \par\nointerlineskip%
  \global\beamer@slidehaszoomtrue%
  \advance\beamer@zoomcount by1\relax%
  \def\beamer@zoomborderwidth{0}%
  \edef\beamer@labelzoomed{beamer@labelzoomed@\the\beamer@zoomframecount @\the\beamer@zoomcount}%
  \setkeys{beamerzoom}{#3}%
  \only<#1>{%
    {\hypersetup{pdfhighlight={/P},pdfborder={0 0 \beamer@zoomborderwidth}}%
    \global\setbox\@tempboxa=\vbox{\hyperlink{\beamer@labelzoomed}{%
      \expandafter\ifx\csname XeTeXrevision\endcsname\relax
        \vbox to #7{%
          \hbox to#6{\hfil}%
          \vfil%
        }%      
      \else%
        \begingroup%
          \normalsize%
          \begin{pgfpicture}{0pt}{0pt}{#6}{#7}%
            \pgfsetfillopacity{0}
            \pgftext[x=0cm,y=3pt]{.}
            \pgftext[x=#6,y=\dimexpr#7-\baselineskip+3pt]{.}    
          \end{pgfpicture}%
        \endgroup%
      \fi%    
    }}}%
    \ht\@tempboxa=0pt%
    \wd\@tempboxa=0pt%
    \dp\@tempboxa=0pt%
    \setbox\@tempboxa=\vbox{\if@RTL\moveleft\else\moveright\fi#4\hbox{\lower#5\vbox{\box\@tempboxa}}}%
    \ht\@tempboxa=0pt%
    \wd\@tempboxa=0pt%
    \dp\@tempboxa=0pt%
    \global\setbox\beamer@zoombox=\vbox to0pt{\unvbox\beamer@zoombox\box\@tempboxa}%
  }%
  \only<#2>{%
    \@ifundefined{\beamer@labelzoomed}%
    {%
      \hypertarget{\beamer@labelzoomed}{}%
      \expandafter\gdef\csname\beamer@labelzoomed\endcsname{}%
    }{}%
    \gdef\beamer@zoomer{%
      % compute zoom factor
      \@tempdima=\beamer@frametextheight%
      \@tempdimb=#7\relax%
      \@tempcnta=\@tempdimb%
      \divide\@tempcnta by4096\relax%
      \multiply\@tempdima by16\relax%
      \divide\@tempdima by\@tempcnta%
      \@tempdimb=\paperwidth%
      \ifbeamer@plainframe%
      \else%
        \advance\@tempdimb by-\beamer@leftsidebar%
        \advance\@tempdimb by-\beamer@rightsidebar\relax%
      \fi%
      \@tempdimc=#6\relax%
      \@tempcntb=\@tempdimc%
      \divide\@tempcntb by4096\relax%
      \multiply\@tempdimb by16\relax%
      \divide\@tempdimb by\@tempcntb%
      \ifdim\@tempdimb<\@tempdima%
        \@tempdima=\@tempdimb%
      \fi%
      \edef\beamer@temp{\strip@pt\@tempdima}%
      \@tempdimc=\beamer@frametextheight%
      \advance\@tempdimc by4pt%
      \@tempdimb=\paperwidth%
      \ifbeamer@plainframe%
      \else%
        \advance\@tempdimb by-\beamer@leftsidebar%
        \advance\@tempdimb by-\beamer@rightsidebar\relax%
      \fi%
      \setbox\@tempboxa=\vbox{\hsize=\@tempdimb\Acrobatmenu{GoBack}{\vbox to
          \beamer@frametextheight{\hbox to\@tempdimb{\hfil}\vfil}}}%
      \ht\@tempboxa=0pt%
      \wd\@tempboxa=0pt%
      \dp\@tempboxa=0pt%
      \setbox\beamer@framebox=\vbox to\beamer@frametextheight{{%
          \ifbeamer@plainframe\beamer@leftmargin=\Gm@lmargin\fi%
          \if@RTL
          \begin{pgfpicture}{\paperwidth-\beamer@leftmargin}{-\beamer@frametextheight}{\paperwidth-\beamer@leftmargin}{0pt}
            \pgftext[right,top]{\box\@tempboxa}
            \pgfpathrectangle{\pgfpoint{0pt}{-\@tempdimc}}{\pgfpoint{\@tempdimb}{\@tempdimc}}%
            \pgfusepath{clip}
            \begingroup
              \pgftransformscale{\beamer@temp}
              \@tempdima=#4\relax%
              \@tempdimb=#5\relax%
              {\pgftransformshift{\pgfpoint{\@tempdima+#6}{\@tempdimb}}%
              \pgftext[right,top]{\vbox{\vbox{}\nointerlineskip\unvbox\beamer@framebox}}}
            \endgroup
          \end{pgfpicture}%
          \else
          \begin{pgfpicture}{\beamer@leftmargin}{-\beamer@frametextheight}{\beamer@leftmargin}{0pt}
            \pgftext[left,top]{\box\@tempboxa}
            \pgfpathrectangle{\pgfpoint{0pt}{-\@tempdimc}}{\pgfpoint{\@tempdimb}{\@tempdimc}}%
            \pgfusepath{clip}
            \begingroup
              \pgftransformscale{\beamer@temp}
              \@tempdima=#4\relax%
              \@tempdimb=#5\relax%
              {\pgftransformshift{\pgfpoint{-\@tempdima}{\@tempdimb}}%
              \pgftext[left,top]{\vbox{\vbox{}\nointerlineskip\unvbox\beamer@framebox}}}
            \endgroup
          \end{pgfpicture}%
          \fi
        }}%
      \setbox\beamer@framebox=\vbox{%
        \nobreak\vbox{}\nobreak\par\nobreak\beamer@entrycode\nobreak%
        \nointerlineskip\unvbox\beamer@frametitlebox%
        \nobreak%
        \box\beamer@framebox%
        \nobreak%
        \vss%
        \beamer@exitcode%
      }%
      \global\setbox\beamer@footins=\box\voidb@x% no footnotes in zoomed slides
    }%
  }%
}


%    \end{macrocode}
% \iffalse
%</beamerbaseframesize-xetex-bidi.def>
%<*beamerbaselocalstructure-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaselocalstructure-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaselocalstructure-xetex-bidi.def}[2022/05/24 v0.1 bidi adaptations for beamerbaselocalstructure package for XeTeX engine]
\def\beamer@enum@{%
  \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
  \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
  \bgroup
  \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
  \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
  \egroup
  \expandafter
    \list
      {\usebeamertemplate{\beamer@enumtempl}}
      {\usecounter\@enumctr%
        \def\makelabel##1{{\hss\llap{{%
                \usebeamerfont*{enumerate \beameritemnestingprefix item}%
                \usebeamercolor[fg]{enumerate \beameritemnestingprefix item}##1}}}}}%
  \beamer@cramped%
  \bidi@beamer@ragged%
  \beamer@firstlineitemizeunskip%
}

\renewcommand{\itemize}[1][]{%
  \ifblank{#1}{}{\def\beamer@defaultospec{#1}}%
  \ifnum \@itemdepth >2\relax\@toodeep\else
    \advance\@itemdepth\@ne
    \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
    \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
    \bgroup
    \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
    \egroup
    \list
      {\usebeamertemplate{itemize \beameritemnestingprefix item}}
      {\def\makelabel##1{%
          {%
            \hss\llap{{%
                \usebeamerfont*{itemize \beameritemnestingprefix item}%
                \usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
          }%
        }%
      }
  \fi%
  \beamer@cramped%
  \bidi@beamer@ragged%
  \beamer@firstlineitemizeunskip%
}

\def\@@description{%
  \advance\beamer@descdefault by \labelsep%
  \usebeamerfont{description body}%
  \bgroup
  \usebeamercolor[fg]{description body}%
  \usebeamertemplate{description body begin}%
  \egroup
  \list
  {}
  {\labelwidth\beamer@descdefault\leftmargin\beamer@descdefault\let\makelabel\beamer@descriptionitem}%
  \beamer@cramped%
  \bidi@beamer@ragged
  \beamer@firstlineitemizeunskip%
}

\renewenvironment{thebibliography}[1]
{%\leavevmode\unskip%
\if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
\bidi@@thebibliography@font@hook%
  \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\beamer@biblabeltemplate{\@biblabel{#1}}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \itemsep=0pt%
            \partopsep=0pt%
            \topsep=0pt%
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}
            \let\makelabel\beamer@biblabeltemplate}%
      \sloppy\bidi@beamer@ragged
      \clubpenalty10000
      \@clubpenalty \clubpenalty
      \widowpenalty10000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \ifhmode\unskip\fi\endlist}
      

%    \end{macrocode}
% \iffalse
%</beamerbaselocalstructure-xetex-bidi.def>
%<*beamerbasemisc-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbasemisc-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbasemisc-xetex-bidi.def}[2022/06/27 v0.1 bidi adaptations for beamerbasemisc package for XeTeX engine]
\define@key{beamerst}{width}{%
  \def\beamer@ststart{%
    \begin{minipage}[t]{#1}%
      \bidi@beamer@ragged
      \beamer@stalign
      \beamer@stlinebreakrule
    }%
  \def\beamer@stend{\end{minipage}}}
  

%    \end{macrocode}
% \iffalse
%</beamerbasemisc-xetex-bidi.def>
%<*beamerbasenavigation-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbasenavigation-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbasenavigation-xetex-bidi.def}[2022/06/27 v0.2 bidi adaptations for beamerbasenavigation package for XeTeX engine]
\def\slideentry#1#2#3#4#5#6{%
  %section number, subsection number, slide number, first/last frame, page number, part number
  \ifnum#6=\c@part\ifnum#1>0\ifnum#3>0%
    \ifbeamer@compress%
      \advance\beamer@xpos by1\relax%
    \else%
      \ifnum#2=0%
        \beamer@ypos@offset=1\relax%
      \fi
      \beamer@xpos=#3\relax%
      \beamer@ypos=#2\relax%
      \advance\beamer@ypos by \beamer@ypos@offset\relax
    \fi%
  \hbox to 0pt{%
    \beamer@tempdim=-\beamer@vboxoffset%
    \advance\beamer@tempdim by-\beamer@boxsize%
    \multiply\beamer@tempdim by\beamer@ypos%
    \advance\beamer@tempdim by -.05cm%
    \raise\beamer@tempdim\hbox{%
      \beamer@tempdim=\beamer@boxsize%
      \multiply\beamer@tempdim by\beamer@xpos%
      \advance\beamer@tempdim by -\beamer@boxsize%
      \advance\beamer@tempdim by 1pt%
      \kern\beamer@tempdim
      \global\beamer@section@min@dim\beamer@tempdim
      \hbox{\beamer@link(#4){{%
          \usebeamerfont{mini frame}%
          \ifnum\c@section=#1%
            \ifnum\c@subsection=#2%
              \usebeamercolor[fg]{mini frame}%
              \ifnum\c@subsectionslide=#3%
                \usebeamertemplate{mini frame}%\beamer@minislidehilight%
              \else%
                \usebeamertemplate{mini frame in current subsection}%\beamer@minisliderowhilight%
              \fi%
            \else%
              \usebeamercolor{mini frame}%
              %\color{fg!50!bg}%
              \usebeamertemplate{mini frame in other subsection}%\beamer@minislide%
            \fi%
          \else%
            \usebeamercolor{mini frame}%
            %\color{fg!50!bg}%
            \usebeamertemplate{mini frame in other subsection}%\beamer@minislide%
          \fi%
        }}}}\hskip-10cm plus 1fil%
  }\fi\fi%
  \else%
  \fakeslideentry{#1}{#2}{#3}{#4}{#5}{#6}%
  \fi\ignorespaces
  }
  
\pgfdefobject{bidi@beamer@RTL@gotosymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{5pt}{5pt}}
{
  \pgfpathqmoveto{3.5bp}{0.5bp}
  \pgfpathqlineto{1.5bp}{2bp}
  \pgfpathqlineto{3.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertgotosymbol{%
\if@RTL
  \begin{pgfpicture}{-1pt}{0pt}{4pt}{5pt}
    \pgfuseobject{bidi@beamer@RTL@gotosymbol}%
  \end{pgfpicture}%
\else
  \begin{pgfpicture}{1pt}{0pt}{6pt}{5pt}
    \pgfuseobject{beamergotosymbol}%
  \end{pgfpicture}%
\fi
}

\pgfdefobject{bidi@beamer@RTL@skipsymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{7pt}{5pt}}
{
  \pgfpathqmoveto{5.5bp}{0.5bp}
  \pgfpathqlineto{3.5bp}{2bp}
  \pgfpathqlineto{5.5bp}{3.5bp}
  \pgfpathqmoveto{3.5bp}{0.5bp}
  \pgfpathqlineto{1.5bp}{2bp}
  \pgfpathqlineto{3.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertskipsymbol{%
\if@RTL
  \begin{pgfpicture}{-1pt}{0pt}{6pt}{5pt}
    \pgfuseobject{bidi@beamer@RTL@skipsymbol}%
  \end{pgfpicture}%
\else
  \begin{pgfpicture}{1pt}{0pt}{8pt}{5pt}
    \pgfuseobject{beamerskipsymbol}%
  \end{pgfpicture}%
\fi
}

\pgfdefobject{bidi@beamer@RTL@returnsymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{5pt}{5pt}}
{
  \pgfpathqmoveto{1.5bp}{0.5bp}
  \pgfpathqlineto{3.5bp}{2bp}
  \pgfpathqlineto{1.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertreturnsymbol{%
\if@RTL
  \begin{pgfpicture}{-1pt}{0pt}{4pt}{5pt}
    \pgfuseobject{bidi@beamer@RTL@returnsymbol}%
  \end{pgfpicture}%
\else
  \begin{pgfpicture}{1pt}{0pt}{6pt}{5pt}
    \pgfuseobject{beamerreturnsymbol}%
  \end{pgfpicture}%
\fi
}
  

%    \end{macrocode}
% \iffalse
%</beamerbasenavigation-xetex-bidi.def>
%<*beamerbaseoverlay-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerbaseoverlay-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerbaseoverlay-xetex-bidi.def}[2022/06/10 v0.1 bidi adaptations for beamerbaseoverlay package for XeTeX engine]
\renewcommand<>{\color}{\alt#1{\beameroriginal{\color}}{\beamer@gobbleoptionalinsp}}


%    \end{macrocode}
% \iffalse
%</beamerbaseoverlay-xetex-bidi.def>
%<*beamerinnerthemedefault-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemedefault-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemedefault-xetex-bidi.def}[2022/06/27 v0.6 bidi adaptations for beamerinnerthemedefault package for XeTeX engine]
\newcommand*{\bidi@beamer@leftskip}{%
  \if@RTL
    \rightskip
  \else
    \leftskip
  \fi
}

\newcommand*{\bidi@beamer@rightskip}{%
  \if@RTL
    \leftskip
  \else
    \rightskip
  \fi
}

\bidi@csundef{beamer@@tmpop@subsection in toc@default}

\bidi@csundef{beamer@@tmpop@subsubsection in toc@default}

\defbeamertemplate*{subsection in toc}{default}
{\leavevmode\bidi@beamer@leftskip=1.5em\inserttocsubsection\par}

\defbeamertemplate*{subsubsection in toc}{default}
{\leavevmode\normalsize\usebeamerfont{subsection in toc}\bidi@beamer@leftskip=3em%
  \usebeamerfont{subsubsection in toc}\inserttocsubsubsection\par}

\newcommand*{\bidi@beamer@blacktriangle}{%
  \if@RTL
    $\blacktriangleleft$%
  \else
    $\blacktriangleright$%
  \fi
} 

\bidi@csundef{beamer@@tmpop@itemize item@default}

\bidi@csundef{beamer@@tmpop@itemize subitem@default}

\bidi@csundef{beamer@@tmpop@itemize subsubitem@default}

\defbeamertemplate*{itemize item}{default}{\usebeamerfont*{itemize item}\raise1.25pt\hbox{\donotcoloroutermaths\bidi@beamer@blacktriangle}}
\defbeamertemplate*{itemize subitem}{default}{\usebeamerfont*{itemize subitem}\raise1.5pt\hbox{\donotcoloroutermaths\bidi@beamer@blacktriangle}}
\defbeamertemplate*{itemize subsubitem}{default}{\usebeamerfont*{itemize subsubitem}\raise1.5pt\hbox{\donotcoloroutermaths\bidi@beamer@blacktriangle}}

\bidi@undef\beamer@@tmpop@footnote@default

\defbeamertemplate*{footnote}{default}
{
  \parindent 1em\noindent%
  \bidi@beamer@ragged
  \hbox to 1.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\defbeamertemplate*{RTLfootnote}{default}
{
  \parindent 1em\noindent%
  \raggedleft
  \hbox to 1.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\defbeamertemplate*{LTRfootnote}{default}
{
  \parindent 1em\noindent%
  \raggedright
  \hbox to 1.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\bidi@undef\beamer@@tmpop@caption@default

\defbeamertemplate*{caption}{default}
{%
  \bidi@beamer@ragged
  {%
    \leavevmode
    \usebeamercolor[fg]{caption name}%
    \usebeamerfont*{caption name}%
    \insertcaptionname
    \usebeamertemplate{caption label separator}%
  }%
  \insertcaption\par
}

\bidi@csundef{beamer@@tmpop@block begin@default}

\bidi@csundef{beamer@@tmpop@block alerted begin@default}

\bidi@csundef{beamer@@tmpop@block example begin@default}

\defbeamertemplate*{block begin}{default}
{
  \par\vskip\medskipamount%
  \begin{beamercolorbox}[colsep*=.75ex]{block title}
    \usebeamerfont*{block title}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body}%
    \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\leavevmode\vskip-\dimexpr.75ex+\baselineskip\relax}\vbox{}%
}

\defbeamertemplate*{block alerted begin}{default}
{
  \par\vskip\medskipamount%
  \begin{beamercolorbox}[colsep*=.75ex]{block title alerted}
    \usebeamerfont*{block title alerted}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title alerted}
  {}
  {\ifbeamercolorempty[bg]{block body alerted}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body alerted}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body alerted}%
    \ifbeamercolorempty[bg]{block body alerted}{\vskip-.25ex}{\leavevmode\vskip-\dimexpr.75ex+\baselineskip\relax}\vbox{}%
}

\defbeamertemplate*{block example begin}{default}
{
  \par\vskip\medskipamount%
  \begin{beamercolorbox}[colsep*=.75ex]{block title example}
    \usebeamerfont*{block title example}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title example}
  {}
  {\ifbeamercolorempty[bg]{block body example}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body example}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body example}%
    \ifbeamercolorempty[bg]{block body example}{\vskip-.25ex}{\leavevmode\vskip-\dimexpr.75ex+\baselineskip\relax}\vbox{}%
}

\bidi@csundef{beamer@@tmpop@abstract begin@default}

\defbeamertemplate*{abstract begin}{default}
{\beamercolorbox[vmode]{abstract}\bidi@beamer@leftskip2em\bidi@beamer@rightskip2em plus 1fill\usebeamerfont*{abstract}}

\bidi@undef\beamer@@tmpop@button@default

\defbeamertemplate*{button}{default}
{%
  \setbox\beamer@tempbox=\hbox{{\insertbuttontext}}%
  \ht\beamer@tempbox=6pt%
  \dp\beamer@tempbox=0pt%
  \setbox\beamer@tempbox=\vbox{\box\beamer@tempbox\vskip2pt}%
  \beamer@tempdim=\wd\beamer@tempbox%
  \beamer@dima=\beamer@tempdim\advance\beamer@dima by2.2pt
  \beamer@dimb=\beamer@tempdim\advance\beamer@dimb by4pt
  \if@RTL
    \kern4pt%
    \box\beamer@tempbox%
    \hskip-\beamer@tempdim%
  \fi
  \begin{pgfpicture}{-4pt}{0pt}{\the\beamer@tempdim}{8pt}
    \color{bg}
    \pgfsetlinewidth{0.8pt}
    \pgfpathqmoveto{0pt}{0pt}
    \pgfpathqcurveto{-2.2pt}{0pt}{-4pt}{1.8pt}{-4pt}{4pt}
    \pgfpathqcurveto{-4pt}{6.2pt}{-2.2pt}{8pt}{0pt}{8pt}
    \pgfpathlineto{\pgfpoint{\the\beamer@tempdim}{8pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dima}{8pt}}%
    {\pgfpoint{\the\beamer@dimb}{6.2pt}}%
    {\pgfpoint{\the\beamer@dimb}{4pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dimb}{1.8pt}}%
    {\pgfpoint{\the\beamer@dima}{0pt}}%
    {\pgfpoint{\the\beamer@tempdim}{0pt}}
    \pgfpathclose
    \pgfusepathqfill
    \colorlet{bg}{parent.bg}
    \usebeamercolor[fg]{button border}
    \pgfpathqmoveto{0pt}{0pt}
    \pgfpathqcurveto{-2.2pt}{0pt}{-4pt}{1.8pt}{-4pt}{4pt}
    \pgfpathqcurveto{-4pt}{6.2pt}{-2.2pt}{8pt}{0pt}{8pt}
    \pgfpathlineto{\pgfpoint{\the\beamer@tempdim}{8pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dima}{8pt}}%
    {\pgfpoint{\the\beamer@dimb}{6.2pt}}%
    {\pgfpoint{\the\beamer@dimb}{4pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dimb}{1.8pt}}%
    {\pgfpoint{\the\beamer@dima}{0pt}}%
    {\pgfpoint{\the\beamer@tempdim}{0pt}}
    \pgfpathclose
    \pgfusepathqstroke
  \end{pgfpicture}%
  \if@RTL
  \else
    \hskip-\beamer@tempdim%
    \box\beamer@tempbox%
    \kern4pt%
  \fi
}


%    \end{macrocode}
% \iffalse
%</beamerinnerthemedefault-xetex-bidi.def>
%<*beamerinnerthemecircles-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemecircles-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemecircles-xetex-bidi.def}[2022/06/06 v0.1 bidi adaptations for beamerinnerthemecircles package for XeTeX engine]
\setbeamertemplate{sections/subsections in toc}[circle]

%    \end{macrocode}
% \iffalse
%</beamerinnerthemecircles-xetex-bidi.def>
%<*beamerinnerthemefocus-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemefocus-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemefocus-xetex-bidi.def}[2022/06/13 v0.1 bidi adaptations for beamerinnerthemefocus package for XeTeX engine]
\setbeamertemplate{section in toc}[square]
\setbeamertemplate{subsection in toc}[square]

\setbeamertemplate{itemize items}[square]
\setbeamertemplate{itemize subitem}[triangle]

\bidi@csundef{beamer@@tmpop@title page@focus}

\defbeamertemplate*{title page}{focus}{%
    {%
       	\usebeamercolor{frametitle}\colorlet{focus@@temp}{bg}%
        \begin{tikzpicture}[overlay, remember picture]
            \fill[color=focus@@temp] (current page.north west) rectangle ([shift = {(0, -0.45\paperheight)}] current page.north east);
    \end{tikzpicture}
    }
    
    \vspace{-1.65\baselineskip}
    \begin{minipage}[b][0.35\paperheight]{\textwidth}
        \vspace{\baselineskip}
        \usebeamerfont{title}
        \usebeamercolor[fg]{frametitle}
        \inserttitle
    \end{minipage}
    
    \begin{minipage}[t][0.1\paperheight]{\textwidth}
        \usebeamerfont{subtitle}
        \usebeamercolor[fg]{frametitle}
        \insertsubtitle
    \end{minipage}
    
    % Set the title graphic in a zero-height box, so that
    % the position of other elements is not affected.
    {\vfuzz=9999pt\vbox to 0pt {
        \if@RTL
          \raggedright
        \else
          \raggedleft
        \fi
        \inserttitlegraphic
    }}
    
    \begin{minipage}[t]{\textwidth}
        \usebeamerfont{author}
        \insertauthor
    \end{minipage}
    
    \vspace*{\baselineskip}
    \begin{minipage}[t]{\textwidth}
        \usebeamerfont{institute}
        \insertinstitute
    \end{minipage}
    
    \vspace*{\baselineskip}
    \begin{minipage}[t]{\textwidth}
        \usebeamerfont{date}
        \insertdate
    \end{minipage}

   	\vspace*{0pt plus 100fill}
    
    \addtocounter{framenumber}{-1}
    \addtocounter{realframenumber}{-1}
}



%    \end{macrocode}
% \iffalse
%</beamerinnerthemefocus-xetex-bidi.def>
%<*beamerinnerthemeinmargin-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemeinmargin-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemeinmargin-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerinnerthemeinmargin package for XeTeX engine]
\AtBeginDocument{%
  \setbeamersize{sidebar width left=.25\paperwidth}%
}

\bidi@csundef{beamer@@tmpop@section in toc@inmargin}

\bidi@csundef{beamer@@tmpop@title page@inmargin}

\bidi@csundef{beamer@@tmpop@block begin@inmargin}

\bidi@csundef{beamer@@tmpop@block end@inmargin}

\bidi@csundef{beamer@@tmpop@block alerted begin@inmargin}

\bidi@csundef{beamer@@tmpop@block alerted end@inmargin}

\bidi@csundef{beamer@@tmpop@block example begin@inmargin}

\bidi@csundef{beamer@@tmpop@block example end@inmargin}

\defbeamertemplate*{section in toc}{inmargin}
{\leavevmode
  \beamer@putleft{{\usebeamercolor[fg]{section in toc}\inserttocsection}\strut}{2.5ex}}
  
\defbeamertemplate*{title page}{inmargin}
{
  \begin{block}{\inserttitleindicator}
    \bgroup\usebeamercolor[fg]{title}\usebeamerfont{title}\inserttitle\egroup\par
    \usebeamercolor[fg]{subtitle}\usebeamerfont{subtitle}\insertsubtitle
  \end{block}
  \vfill
  \ifx\insertauthor\@empty
  \else
  \begin{block}{\insertauthorindicator}
    \bgroup\usebeamercolor[fg]{author}\usebeamerfont{author}\insertauthor\egroup\par
  \end{block}
  \fi
  \ifx\insertinstitute\@empty
  \else
  \begin{block}{\insertinstituteindicator}
    \bgroup\usebeamercolor[fg]{institute}\usebeamerfont{institute}\insertinstitute\egroup\par
  \end{block}
  \fi
  \ifx\insertdate\@empty
  \else
  \begin{block}{\insertdateindicator}
    \bgroup\usebeamercolor[fg]{date}\usebeamerfont{date}\insertdate\egroup\par
  \end{block}
  \fi
}

\defbeamertemplate*{block begin}{inmargin}
{
  \par\vskip\medskipamount%
  \leavevmode%
  \beamer@putleft{\normalfont{\usebeamercolor[fg]{block title}\usebeamerfont*{block title}\insertblocktitle}}{2.5ex}%
  \beginL\beamer@putright
  %\usebeamercolor[fg]{block body}% to be done!
}

\defbeamertemplate*{block end}{inmargin}
{\endbeamer@putright\endL\vskip\smallskipamount}

\defbeamertemplate*{block alerted begin}{inmargin}
{
  \par\vskip\medskipamount%
  \leavevmode%
  \beamer@putleft{\normalfont{\usebeamercolor[fg]{block title alerted}\usebeamerfont*{block title alerted}\insertblocktitle}}{2.5ex}%
  \beginL\beamer@putright
  %\usebeamercolor[fg]{block body alerted}% to be done!
}

\defbeamertemplate*{block alerted end}{inmargin}
{\endbeamer@putright\endL\vskip\smallskipamount}

\defbeamertemplate*{block example begin}{inmargin}
{
  \par\vskip\medskipamount%
  \leavevmode%
  \beamer@putleft{\normalfont{\usebeamercolor[fg]{block title example}\usebeamerfont*{block title example}\insertblocktitle}}{2.5ex}%
  \beginL\beamer@putright
  %\usebeamercolor[fg]{block body example}% to be done
}

\defbeamertemplate*{block example end}{inmargin}
{\endbeamer@putright\endL\vskip\smallskipamount}

\bidi@AfterFile{beamerinnerthemerectangles-xetex-bidi.def}{%
  \setbeamertemplate{section in toc}[inmargin]%
  \setbeamertemplate{subsection in toc}[inmargin]%
  \setbeamertemplate{subsubsection in toc}[inmargin]%
}


%    \end{macrocode}
% \iffalse
%</beamerinnerthemeinmargin-xetex-bidi.def>
%<*beamerinnerthememetropolis-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthememetropolis-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthememetropolis-xetex-bidi.def}[2022/06/13 v0.1 bidi adaptations for beamerinnerthememetropolis package for XeTeX engine]
\setbeamertemplate{title}{
  \bidi@beamer@ragged%
  \linespread{1.0}%
  \inserttitle%
  \par%
  \vspace*{0.5em}
}

\setbeamertemplate{subtitle}{
  \bidi@beamer@ragged%
  \insertsubtitle%
  \par%
  \vspace*{0.5em}
}

\bidi@csundef{beamer@@tmpop@section page@progressbar}

\defbeamertemplate{section page}{progressbar}{
  \centering
  \begin{minipage}{22em}
    \bidi@beamer@ragged
    \usebeamercolor[fg]{section title}
    \usebeamerfont{section title}
    \insertsectionhead\\[-1ex]
    \usebeamertemplate*{progress bar in section page}
    \par
    \ifx\insertsubsectionhead\@empty\else%
      \usebeamercolor[fg]{subsection title}%
      \usebeamerfont{subsection title}%
      \insertsubsectionhead
    \fi
  \end{minipage}
  \par
  \vspace{\baselineskip}
}

\setbeamertemplate{progress bar in section page}{
  \setlength{\metropolis@progressonsectionpage}{%
    \textwidth * \ratio{\insertframenumber pt}{\inserttotalframenumber pt}%
  }%
  \begin{tikzpicture}
    \fill[bg] (0,0) rectangle (\textwidth, \metropolis@progressonsectionpage@linewidth);
\if@RTLmain
    \fill[fg] (\textwidth-\metropolis@progressonsectionpage,0) rectangle (\textwidth, \metropolis@progressonsectionpage@linewidth);
\else
    \fill[fg] (0,0) rectangle (\metropolis@progressonsectionpage, \metropolis@progressonsectionpage@linewidth);
\fi
  \end{tikzpicture}%
}

\renewcommand{\metropolis@block}[1]{
  \par\vskip\medskipamount%
  \setlength{\parskip}{0pt}
  \ifbeamercolorempty[bg]{block title#1}{%
    \if@RTL
      \begin{beamercolorbox}[leftskip=0pt plus 4em]{block title#1}%
    \else
      \begin{beamercolorbox}[rightskip=0pt plus 4em]{block title#1}%
    \fi
  }{%
  \ifbeamercolorempty[bg]{block title}{%
    \if@RTL
      \begin{beamercolorbox}[leftskip=0pt plus 4em]{block title#1}%
    \else
      \begin{beamercolorbox}[rightskip=0pt plus 4em]{block title#1}%
    \fi
  }%
  {%
  \if@RTL
    \begin{beamercolorbox}[
      sep=\dimexpr\metropolis@blocksep-\metropolis@blockadjust\relax,
      rightskip=\metropolis@blockadjust,
      leftskip=\dimexpr\metropolis@blockadjust plus 4em\relax
    ]{block title#1}%
    \else
    \begin{beamercolorbox}[
      sep=\dimexpr\metropolis@blocksep-\metropolis@blockadjust\relax,
      leftskip=\metropolis@blockadjust,
      rightskip=\dimexpr\metropolis@blockadjust plus 4em\relax
    ]{block title#1}%
    \fi
  }}%
      \usebeamerfont*{block title#1}%
      \metropolis@strut%
      \insertblocktitle%
      \metropolis@strut%
  \end{beamercolorbox}%
  \nointerlineskip%
  \ifbeamercolorempty[bg]{block body#1}{%
    \begin{beamercolorbox}[vmode]{block body#1}}{
  \ifbeamercolorempty[bg]{block body}{%
    \begin{beamercolorbox}[vmode]{block body#1}%
  }{%
    \begin{beamercolorbox}[sep=\metropolis@blocksep, vmode]{block body#1}%
    \vspace{-\metropolis@parskip}
  }}%
      \usebeamerfont{block body#1}%
      \setlength{\parskip}{\metropolis@parskip}%
}


\setbeamertemplate{footnote}{%
  \parindent 0em\noindent%
  \bidi@beamer@ragged
  \usebeamercolor{footnote}\hbox to 0.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\setbeamertemplate{RTLfootnote}{%
  \parindent 0em\noindent%
  \raggedleft
  \usebeamercolor{footnote}\hbox to 0.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\setbeamertemplate{LTRfootnote}{%
  \parindent 0em\noindent%
  \raggedright
  \usebeamercolor{footnote}\hbox to 0.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}

\setbeamertemplate{itemize items}{\textbullet}

\setbeamertemplate{section page}[progressbar]


%    \end{macrocode}
% \iffalse
%</beamerinnerthememetropolis-xetex-bidi.def>
%<*beamerinnerthemerectangles-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemerectangles-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemerectangles-xetex-bidi.def}[2022/06/06 v0.1 bidi adaptations for beamerinnerthemerectangles package for XeTeX engine]
\setbeamertemplate{sections/subsections in toc}[square]
\setbeamertemplate{items}[square]

%    \end{macrocode}
% \iffalse
%</beamerinnerthemerectangles-xetex-bidi.def>
%<*beamerinnerthemerounded-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerinnerthemerounded-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerinnerthemerounded-xetex-bidi.def}[2022/06/01 v0.1 bidi adaptations for beamerinnerthemerounded package for XeTeX engine]
\setbeamertemplate{blocks}[rounded][shadow=\beamer@themerounded@shadow]
\setbeamertemplate{items}[ball]
\setbeamertemplate{sections/subsections in toc}[ball]

%    \end{macrocode}
% \iffalse
%</beamerinnerthemerounded-xetex-bidi.def>
%<*beamerouterthemedefault-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemedefault-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemedefault-xetex-bidi.def}[2022/06/27 v0.2 bidi adaptations for beamerouterthemedefault package for XeTeX engine]
\def\beamer@fteleft{\if@RTLmain\vskip0.35cm\advance\leftskip by 1.7cm\advance\rightskip by1.7cm\else\fi}

\def\beamer@fteright{\if@RTLmain\else\vskip0.35cm\advance\leftskip by 1.7cm\advance\rightskip by1.7cm\fi}

\AtBeginDocument{%
  \if@RTLmain
    \setbeamertemplate{frametitle}[default][right]
  \fi
}

\bidi@csundef{beamer@@tmpop@note page@default}

\newcommand*{\bidi@beamer@today}{%
\the\year-\ifnum\month<10\relax0\fi\the\month-\ifnum\day<10\relax0\fi\the\day}

\defbeamertemplate*{note page}{default}
{%
  {%
    \scriptsize
    \usebeamerfont{note title}\usebeamercolor[fg]{note title}%
    \ifbeamercolorempty[bg]{note title}{}{%
      \insertvrule{.25\paperheight}{note title.bg}%
      \vskip-.25\paperheight%
      \nointerlineskip%
    }%
    \vbox{
      \hfill\insertslideintonotes{0.25}\hskip-\Gm@rmargin\hskip0pt%
      \vskip-0.25\paperheight%
      \nointerlineskip
      \if@RTL
      \begin{pgfpicture}{-\textwidth}{0cm}{-\textwidth}{0cm}
        \begin{pgflowlevelscope}{\pgftransformrotate{-90}}
          {\pgftransformshift{\pgfpoint{2cm}{0.2cm}}%
          \pgftext[base,right]{\usebeamerfont{note date}\usebeamercolor[fg]{note date}\bidi@beamer@today}}
        \end{pgflowlevelscope}
      \end{pgfpicture}%
      \else
      \begin{pgfpicture}{0cm}{0cm}{0cm}{0cm}
        \begin{pgflowlevelscope}{\pgftransformrotate{90}}
          {\pgftransformshift{\pgfpoint{-2cm}{0.2cm}}%
          \pgftext[base,left]{\usebeamerfont{note date}\usebeamercolor[fg]{note date}\bidi@beamer@today}}
        \end{pgflowlevelscope}
      \end{pgfpicture}%
      \fi}
    \nointerlineskip
    \vbox to .25\paperheight{\vskip0.5em
    \if@RTL
      \moveright0.25\textwidth
    \fi
      \hbox{\insertshorttitle[width=0.75\textwidth]}%
      \setbox\beamer@tempbox=\hbox{\insertsection}%
      
\if@RTL
  \moveright\dimexpr0.29\textwidth-14pt\relax
\fi
\hbox{\if@RTL\beginR\fi\ifdim\wd\beamer@tempbox>1pt{\hskip4pt\raise3pt\hbox{\vrule
            width0.4pt height7pt\vrule width 9pt
            height0.4pt}}\hskip1pt\hbox{\begin{minipage}[t]{0.71\textwidth}\def\breakhere{}\insertsection\end{minipage}}\fi%
      \if@RTL\endR\fi}%
      \setbox\beamer@tempbox=\hbox{\insertsubsection}%
      
\if@RTL
  \moveright\dimexpr0.29\textwidth-27.4pt\relax
\fi      \hbox{\if@RTL\beginR\fi\ifdim\wd\beamer@tempbox>1pt{\hskip17.4pt\raise3pt\hbox{\vrule
            width0.4pt height7pt\vrule width 9pt
            height0.4pt}}\hskip1pt\hbox{\begin{minipage}[t]{0.71\textwidth}\def\breakhere{}\insertsubsection\end{minipage}}\fi%
      \if@RTL\endR\fi}%
      \setbox\beamer@tempbox=\hbox{\insertshortframetitle}%
      
\if@RTL
  \moveright\dimexpr0.33\textwidth-40.8pt\relax
\fi      \hbox{\if@RTL\beginR\fi\ifdim\wd\beamer@tempbox>1pt{\hskip30.8pt\raise3pt\hbox{\vrule
            width0.4pt height7pt\vrule width 9pt
            height0.4pt}}\hskip1pt\hbox{\insertshortframetitle[width=0.67\textwidth]}\fi%
      \if@RTL\endR\fi}%
      \vfil}%
  }%
  \ifbeamercolorempty[bg]{note page}{}{%
    \nointerlineskip%
    \insertvrule{.75\paperheight}{note page.bg}%
    \vskip-.75\paperheight%
  }%
  \vskip.25em
  \nointerlineskip
  \insertnote
}



%    \end{macrocode}
% \iffalse
%</beamerouterthemedefault-xetex-bidi.def>
%<*beamerouterthemefocus-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemefocus-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemefocus-xetex-bidi.def}[2022/06/13 v0.1 bidi adaptations for beamerouterthemefocus package for XeTeX engine]
\bidi@undef\beamer@@tmpop@footline@progressbar

\defbeamertemplate*{footline}{progressbar}{%
    % If not appendix.
    \ifnum\mainend<0% From package appendixnumberbeamer.
        %
        \settowidth{\focus@pbar@leftoffset}{1}%
        \addtolength{\focus@pbar@leftoffset}{1.5em}%
        %
        \ifx\beamer@focus@totalframenumbering\no%
            \settowidth{\focus@pbar@rightoffset}{}%
            \addtolength{\focus@pbar@rightoffset}{0.5em}%
        \else%
            \settowidth{\focus@pbar@rightoffset}{\inserttotalframenumber}%
            \addtolength{\focus@pbar@rightoffset}{1.5em}%
        \fi%
        %
        % If not title page.
        \ifnum\value{realframenumber}>0%
            \ifnum\value{framenumber}<\inserttotalframenumber%
                \begin{tikzpicture}[inner xsep=0.5em, inner ysep=0.5ex]\usebeamerfont{footline}
                    \pgfmathsetmacro{\focus@pbar@progress}%
                        {(\paperwidth-\focus@pbar@leftoffset-\focus@pbar@rightoffset)*(\insertframenumber/\inserttotalframenumber)}
                
                    \clip (0,0) rectangle ++(\paperwidth,\the\focus@pbar@height);
\if@RTLmain
                    \fill[footline.bg] (\paperwidth,0) rectangle ++(-\the\focus@pbar@leftoffset,\the\focus@pbar@height);
                    \fill[footline.bg] (\paperwidth-\the\focus@pbar@leftoffset,0) rectangle ++(-\focus@pbar@progress pt,\the\focus@pbar@height)
                                       ++(0,{-0.5*\the\focus@pbar@height}) node[anchor=west, text=footline.fg] {\strut\insertframenumber};
\else
                    \fill[footline.bg] (0,0) rectangle ++(\the\focus@pbar@leftoffset,\the\focus@pbar@height);
                    \fill[footline.bg] (\the\focus@pbar@leftoffset,0) rectangle ++(\focus@pbar@progress pt,\the\focus@pbar@height)
                                       ++(0,{-0.5*\the\focus@pbar@height}) node[anchor=east, text=footline.fg] {\strut\insertframenumber};
\fi                   
                    \ifx\beamer@focus@totalframenumbering\no%
                    \else%
\if@RTLmain
                        \fill[footline.bg] (0,0) rectangle ++(\the\focus@pbar@rightoffset,\the\focus@pbar@height)
                                           ++(0,{-0.5*\the\focus@pbar@height}) node[anchor=east, text=footline.fg] {\strut\inserttotalframenumber};
\else
                        \fill[footline.bg] (\paperwidth,0) rectangle ++(-\the\focus@pbar@rightoffset,\the\focus@pbar@height)
                                           ++(0,{-0.5*\the\focus@pbar@height}) node[anchor=west, text=footline.fg] {\strut\inserttotalframenumber};
\fi
                    \fi%
                \end{tikzpicture}%
            \else%
                \begin{tikzpicture}[inner xsep=0.5em, inner ysep=0.5ex]
                    \clip (0,0) rectangle ++(\paperwidth,\the\focus@pbar@height);
                    \fill[footline.bg] (0,0) rectangle ++(\paperwidth,\the\focus@pbar@height);
\if@RTLmain
                    \node[anchor=west, footline.fg] at ({\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut\insertframenumber};
\else                    
                    \node[anchor=east, footline.fg] at ({\paperwidth-\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut\insertframenumber};
\fi
                    \ifx\beamer@focus@totalframenumbering\no%
                    \else%
\if@RTLmain
                        \node[footline.fg] at ({\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut/};
                        \node[anchor=east, footline.fg] at ({\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut\inserttotalframenumber};
\else
                        \node[footline.fg] at ({\paperwidth-\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut/};
                        \node[anchor=west, footline.fg] at ({\paperwidth-\the\focus@pbar@rightoffset},{0.5*\focus@pbar@height}) {\strut\inserttotalframenumber};
\fi
                    \fi%
                \end{tikzpicture}%
            \fi%
        \fi%
    \fi%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemefocus-xetex-bidi.def>
%<*beamerouterthemeinfolines-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemeinfolines-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemeinfolines-xetex-bidi.def}[2022/06/09 v0.2 bidi adaptations for beamerouterthemeinfolines package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@footline@infolines theme}

\defbeamertemplate*{footline}{infolines theme}
{%
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortauthor\expandafter\ifblank\expandafter{\beamer@shortinstitute}{}{~~(\insertshortinstitute)}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,leftskip=2ex,rightskip=2ex,sep=0pt]{date in head/foot}%
    \hfill%
    \usebeamerfont{date in head/foot}%
    \insertshortdate{}%
    \hfill%
    \bgroup
    \usebeamercolor[fg]{page number in head/foot}%
    \usebeamerfont{page number in head/foot}%
    \usebeamertemplate{page number in head/foot}%
    \egroup
  \end{beamercolorbox}}%
  \vskip0pt%
}

\bidi@csundef{beamer@@tmpop@headline@infolines theme}

\defbeamertemplate*{headline}{infolines theme}
{%
  \leavevmode%
  \hbox{%
  \if@RTL
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{section in head/foot}%
\else
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
\fi
    \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
  \end{beamercolorbox}%
\if@RTL
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{subsection in head/foot}%
\else
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
\fi
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
  \end{beamercolorbox}}%
  \vskip0pt%
}

\bidi@AfterFile{beamerouterthemesplit-xetex-bidi.def}{%
  \setbeamertemplate{footline}[infolines theme]%
}

%    \end{macrocode}
% \iffalse
%</beamerouterthemeinfolines-xetex-bidi.def>
%<*beamerouterthememetropolis-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthememetropolis-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthememetropolis-xetex-bidi.def}[2022/06/13 v0.1 bidi adaptations for beamerouterthememetropolis package for XeTeX engine]
\setbeamertemplate{progress bar in head/foot}{
  \nointerlineskip
  \setlength{\metropolis@progressinheadfoot}{%
    \paperwidth * \ratio{\insertframenumber pt}{\inserttotalframenumber pt}%
  }%
  \begin{beamercolorbox}[wd=\paperwidth]{progress bar in head/foot}
    \begin{tikzpicture}
      \fill[bg] (0,0) rectangle (\paperwidth, \metropolis@progressinheadfoot@linewidth);
\if@RTLmain
      \fill[fg] (\paperwidth-\metropolis@progressinheadfoot,0) rectangle (\paperwidth, \metropolis@progressinheadfoot@linewidth);
\else
      \fill[fg] (0,0) rectangle (\metropolis@progressinheadfoot, \metropolis@progressinheadfoot@linewidth);
\fi
    \end{tikzpicture}%
  \end{beamercolorbox}
}

\AtBeginDocument{%
  \setbeamertemplate{frametitle}[plain]%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthememetropolis-xetex-bidi.def>
%<*beamerouterthememiniframes-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthememiniframes-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthememiniframes-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerouterthememiniframes package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@headline@miniframes theme}

\defbeamertemplate*{headline}{miniframes theme}
{%
  \begin{beamercolorbox}[colsep=1.5pt]{upper separation line head}
  \end{beamercolorbox}
  \begin{beamercolorbox}{section in head/foot}
    \vskip2pt\if@RTL\beginR\fi\insertnavigation{\paperwidth}\if@RTL\endR\fi\vskip2pt
  \end{beamercolorbox}%
  \ifbeamer@theme@subsection%
    \begin{beamercolorbox}[colsep=1.5pt]{middle separation line head}
    \end{beamercolorbox}
    \if@RTL
    \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{subsection in head/foot}
    \else
    \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \fi
      \usebeamerfont{subsection in head/foot}\insertsubsectionhead
    \end{beamercolorbox}%
  \fi%
  \begin{beamercolorbox}[colsep=1.5pt]{lower separation line head}
  \end{beamercolorbox}
}


%    \end{macrocode}
% \iffalse
%</beamerouterthememiniframes-xetex-bidi.def>
%<*beamerouterthemesidebar-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemesidebar-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemesidebar-xetex-bidi.def}[2022/06/07 v0.2 bidi adaptations for beamerouterthemesidebar package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@frametitle@sidebar theme}

\bidi@csundef{beamer@@tmpop@headline@sidebar theme}

\bidi@csundef{beamer@@tmpop@sidebar left@sidebar theme}

\bidi@csundef{beamer@@tmpop@sidebar right@sidebar theme}

\ifdim\beamer@headheight>0pt

  \defbeamertemplate*{frametitle}{sidebar theme}
  {%
    \nointerlineskip%
    \ifbeamer@plainframe%
      \hbox{\usebeamercolor[bg]{frametitle}%
        \@tempdima\paperwidth\advance\@tempdima-\beamer@sidebarwidth
        \hskip-\beamer@leftmargin\vrule height\beamer@headheight width\@tempdima\hskip-\beamer@rightmargin}%
      \nointerlineskip%
    \fi%
    \vskip-\beamer@headheight%
    \vbox to \beamer@headheight{%
      \vfil
      \bidi@beamer@leftskip=-\beamer@leftmargin%
      \advance\bidi@beamer@leftskip by0.3cm%
      \bidi@beamer@rightskip=-\beamer@rightmargin%
      \advance\bidi@beamer@rightskip by0.3cm plus1fil%
      {\usebeamercolor[fg]{frametitle}\usebeamerfont{frametitle}\strut\insertframetitle\par}%
      \ifx\insertframesubtitle\@empty\else%
        {\usebeamercolor[fg]{framesubtitle}\usebeamerfont{framesubtitle}\strut\insertframesubtitle\par}%
      \fi%
      \vbox{}%
      \vskip-1em%
      \vfil
    }%
  }
  
\AtBeginDocument{%
  \setbeamertemplate{frametitle}[sidebar theme]%
}

  \defbeamertemplate*{headline}{sidebar theme}
  {%
    \begin{beamercolorbox}[wd=\paperwidth]{frametitle}
      \ifx\beamer@sidebarside\beamer@lefttext%
      \else%
        \hfill%
      \fi%
      \ifdim\beamer@sidebarwidth>0pt%  
        \bgroup
        \usebeamercolor[bg]{logo}%
        \if@RTLmain
        \else
          \vrule width\beamer@sidebarwidth height \beamer@headheight%
          \hskip-\beamer@sidebarwidth%
        \fi
        \hbox to \beamer@sidebarwidth{\hss\vbox to
          \beamer@headheight{\vss\hbox{{\color{fg}\insertlogo}}\vss}\hss}%
          \if@RTLmain
            \hskip-\beamer@sidebarwidth%
            \vrule width\beamer@sidebarwidth height \beamer@headheight%
          \fi
          \egroup
      \else%
        \vrule width0pt height \beamer@headheight%  
      \fi%
    \end{beamercolorbox}
  }
\fi

\def\beamer@sidebarformat#1#2#3{%
\if@RTL
  \begin{beamercolorbox}[wd=\beamer@sidebarwidth,rightskip=#1,leftskip=1ex plus1fil,vmode]{#2}
\else
  \begin{beamercolorbox}[wd=\beamer@sidebarwidth,leftskip=#1,rightskip=1ex plus1fil,vmode]{#2}
 \fi
    \vbox{}%
    #3\par%
    \vbox{}%
    \vskip-1.5ex%
  \end{beamercolorbox}
}

\ifdim\beamer@sidebarwidth>0pt

\AtBeginDocument{%
  \setbeamersize{sidebar width \beamer@sidebarside=\beamer@sidebarwidth}%
}

  \defbeamertemplate*{sidebar \beamer@sidebarside}{sidebar theme}
  {
    \beamer@tempdim=\beamer@sidebarwidth%
    \advance\beamer@tempdim by -6pt%
    {\usebeamerfont{title in sidebar}%
      \vskip1.5em%
      \hskip3pt%
      \bgroup
      \usebeamercolor[fg]{title in sidebar}%
      \insertshorttitle[width=\beamer@tempdim,center,respectlinebreaks]\egroup\par%
      \vskip1.25em%
    }%
    {%
      \hskip3pt%
      \bgroup
      \usebeamercolor[fg]{author in sidebar}%
      \usebeamerfont{author in sidebar}%
      \insertshortauthor[width=\beamer@tempdim,center,respectlinebreaks]\egroup\par%
      \vskip1.25em%
    }%
    \insertverticalnavigation{\beamer@sidebarwidth}%
    \vfill
    \ifx\beamer@sidebarside\beamer@lefttext%
    \else%
      \usebeamercolor{normal text}%
      \llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
      \vskip2pt%
    \fi%
  }%
\fi

%    \end{macrocode}
% \iffalse
%</beamerouterthemesidebar-xetex-bidi.def>
%<*beamerouterthemesplit-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemesplit-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemesplit-xetex-bidi.def}[2022/06/09 v0.2 bidi adaptations for beamerouterthemesplit package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@footline@split theme}

\defbeamertemplate*{footline}{split theme}
{%
  \leavevmode%
  \hbox{\if@RTL\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,rightskip=.3cm plus1fill,leftskip=.3cm]{author in head/foot}%
\else
\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm plus1fill,rightskip=.3cm]{author in head/foot}%
\fi
    \usebeamerfont{author in head/foot}\insertshortauthor
  \end{beamercolorbox}%
 \if@RTL
   \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,rightskip=.3cm,leftskip=.3cm plus1fil]{title in head/foot}%
\else
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
\fi
    \usebeamerfont{title in head/foot}\insertshorttitle\nobreak\hfill\bgroup\usebeamercolor[fg]{page number in head/foot}\usebeamerfont{page number in head/foot}\usebeamertemplate{page number in head/foot}\egroup
  \end{beamercolorbox}}%
  \vskip0pt%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemesplit-xetex-bidi.def>
%<*beamerouterthemeshadow-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemeshadow-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemeshadow-xetex-bidi.def}[2022/06/11 v0.3 bidi adaptations for beamerouterthemeshadow package for XeTeX engine]
\pgfdeclarehorizontalshading[frametitle.bg,frametitle right.bg]{bidi@beamer@RTL@frametitleshade}{\paperheight}{%
  color(0pt)=(frametitle right.bg);
  color(\paperwidth)=(frametitle.bg)
}

\newcommand*{\bidi@beamer@frametitleshade}{%
  \if@RTLmain
    \pgfuseshading{bidi@beamer@RTL@frametitleshade}%
  \else
    \pgfuseshading{beamer@frametitleshade}%
  \fi
}

\bidi@csundef{beamer@@tmpop@frametitle@shadow theme}

\defbeamertemplate*{frametitle}{shadow theme}
{%
  \nointerlineskip%
  \vskip-2pt%
  \hbox{\leavevmode
    \advance\beamer@leftmargin by -12bp%
    \advance\beamer@rightmargin by -12bp%
    \beamer@tempdim=\textwidth%
    \advance\beamer@tempdim by \beamer@leftmargin%
    \advance\beamer@tempdim by \beamer@rightmargin%
    \hskip-\Gm@lmargin\hbox{%
      \setbox\beamer@tempbox=\hbox{\begin{minipage}[b]{\paperwidth}%
          \vbox{}\vskip-.75ex%
          \bidi@beamer@leftskip0.3cm%
          \bidi@beamer@rightskip0.3cm plus1fil\leavevmode
          \bgroup\usebeamercolor[fg]{frametitle}\usebeamerfont{frametitle}\strut\insertframetitle\strut\egroup\par%
          \ifx\insertframesubtitle\@empty\else%
            {\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
          \fi%
          \nointerlineskip
          \vbox{}%
          \end{minipage}}%
      \beamer@tempdim=\ht\beamer@tempbox%
      \advance\beamer@tempdim by 2pt%
      \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
        \begin{pgfscope}
          \pgfsetfillcolor{black}%
          \pgfpathrectangle{\pgfpoint{0pt}{-4pt}}{\pgfpoint{\paperwidth}{8pt}}%
          \pgfsetfading{beamer@topshadowmask}{}%
          \pgfusepath{fill}%
        \end{pgfscope}
        \begin{pgfscope}
          \usebeamercolor{frametitle right}%
          \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}%
          \pgfusepath{clip}%
          \pgftext[left,base]{\bidi@beamer@frametitleshade}%
        \end{pgfscope}
      \end{pgfpicture}
      \hskip-\paperwidth%
      \box\beamer@tempbox%
    }%
    \hskip-\Gm@rmargin%
  }%
  \vskip-2pt
}

\AtBeginDocument{%
  \setbeamertemplate{frametitle}[shadow theme]%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemeshadow-xetex-bidi.def>
%<*beamerouterthemesmoothbars-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemesmoothbars-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemesmoothbars-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerouterthemesmoothbars package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@headline@smoothbars theme}

\bidi@csundef{beamer@@tmpop@frametitle@smoothbars theme}

\defbeamertemplate*{headline}{smoothbars theme}
{%
  \pgfuseshading{beamer@barshade}%
  \vskip-0.05ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1ex,dp=0ex]{empty}
  \begin{pgfpicture}
    \begin{pgfscope}%
      \ifbeamer@sb@subsection%
        \pgfsetfillcolor{subsection in head/foot.bg}%
      \else%
        \pgfsetfillcolor{section in head/foot.bg}%
      \fi%
      \pgfpathrectangle{\pgfpoint{-.5\paperwidth}{-0.5ex}}{\pgfpoint{\paperwidth}{1ex}}%
      \pgfsetfading{beamer@belowframetitlemask}{}%
      \pgfusepath{fill}%
    \end{pgfscope}%
  \end{pgfpicture}%
  \end{beamercolorbox}%
  \ifbeamer@sb@subsection%
    \vskip-9.75ex%
  \else%
    \vskip-6.85ex%
  \fi%
  \begin{beamercolorbox}[ignorebg,ht=2.25ex,dp=3.75ex]{section in head/foot}
    \insertnavigation{\paperwidth}
  \end{beamercolorbox}%
  \ifbeamer@sb@subsection%
  \if@RTL
      \begin{beamercolorbox}[ignorebg,ht=2.125ex,dp=1.125ex,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{subsection in head/foot}
    \else
    \begin{beamercolorbox}[ignorebg,ht=2.125ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \fi
      \usebeamerfont{subsection in head/foot}\insertsubsectionhead
    \end{beamercolorbox}%
  \fi%
}%

\defbeamertemplate*{frametitle}{smoothbars theme}
{%
  \nointerlineskip%
  \vskip-0.19ex%
  \usebeamerfont{headline}%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1ex,dp=1ex,vmode]{empty}
    \pgfuseshading{beamer@aboveframetitle}%
  \end{beamercolorbox}%
  \vskip-1ex%
  \nointerlineskip%
  \if@RTL
  \begin{beamercolorbox}[wd=\paperwidth,rightskip=.3cm,leftskip=.3cm plus1fil,vmode]{frametitle}
  \else
  \begin{beamercolorbox}[wd=\paperwidth,leftskip=.3cm,rightskip=.3cm plus1fil,vmode]{frametitle}
  \fi
    \vskip0.5ex%
    \usebeamerfont*{frametitle}\strut\insertframetitle%
      \ifx\insertframesubtitle\@empty%
        \strut\par%
      \else
        \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle}\strut\par}%
      \fi%%
    \usebeamerfont{headline}%
    \vskip0.05ex%
  \end{beamercolorbox}%
  \nointerlineskip%
  \vskip-0.05ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1ex,dp=0ex]{empty}
  \begin{pgfpicture}
    \begin{pgfscope}%
      \pgfsetfillcolor{frametitle.bg}%
      \pgfpathrectangle{\pgfpoint{-.5\paperwidth}{-.5ex}}{\pgfpoint{\paperwidth}{1ex}}%
      \pgfsetfading{beamer@belowframetitlemask}{}%
      \pgfusepath{fill}%
    \end{pgfscope}%
  \end{pgfpicture}%
  \end{beamercolorbox}%
}

\AtBeginDocument{%
  \setbeamertemplate{frametitle}[smoothbars theme]%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemesmoothbars-xetex-bidi.def>
%<*beamerouterthemesmoothtree-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemesmoothtree-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemesmoothtree-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerouterthemesmoothtree package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@headline@smoothtree theme}

\bidi@csundef{beamer@@tmpop@frametitle@smoothtree theme}

\defbeamertemplate*{headline}{smoothtree theme}
{%
  \pgfuseshading{beamer@treeshade}%
  \vskip-0.05ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1ex,dp=0ex]{empty}
  \begin{pgfpicture}
    \begin{pgfscope}%
      \pgfsetfillcolor{subsection in head/foot.bg}%
      \pgfpathrectangle{\pgfpoint{-.5\paperwidth}{-0.5ex}}{\pgfpoint{\paperwidth}{1ex}}%
      \pgfsetfading{beamer@belowframetitlemask}{}%
      \pgfusepath{fill}%
    \end{pgfscope}%
  \end{pgfpicture}%
  \end{beamercolorbox}%  
  \vskip-9.15ex%
  \if@RTL
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.125ex,dp=1.125ex,ignorebg,%
    rightskip=.3cm,leftskip=.3cm plus1fil]{title in head/foot}
  \else
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.125ex,dp=1.125ex,ignorebg,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
    \fi
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}
  \if@RTL
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
    rightskip=.3cm,leftskip=.3cm plus1fil]{section in head/foot}
  \else
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
    \fi
    \usebeamerfont{section in head/foot}%
    \hskip6pt\insertsectionhead
  \end{beamercolorbox}
  \if@RTL
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{subsection in head/foot}
  \else
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \fi
    \usebeamerfont{subsection in head/foot}%
    \hskip12pt\insertsubsectionhead
  \end{beamercolorbox}
  \vskip-0.4ex%
}

\defbeamertemplate*{frametitle}{smoothtree theme}
{%
  \nointerlineskip%
  \vskip-0.05ex%
  \usebeamerfont{headline}%
  \begin{beamercolorbox}[wd=\paperwidth,ht=0.85ex,dp=0ex]{empty}
    \pgfuseshading{beamer@aboveframetitle}%
  \end{beamercolorbox}
  \nointerlineskip%
  \if@RTL
  \begin{beamercolorbox}[wd=\paperwidth,rightskip=.935cm,leftskip=.3cm plus1fil]{frametitle}
 \else
  \begin{beamercolorbox}[wd=\paperwidth,leftskip=.935cm,rightskip=.3cm plus1fil]{frametitle}
  \fi
    \vskip-1.2ex%
    \usebeamerfont*{frametitle}\strut\insertframetitle%
      \ifx\insertframesubtitle\@empty%
        \strut\par%
      \else
        \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle}\strut\par}%
      \fi%%
    \usebeamerfont{headline}%
  \end{beamercolorbox}%
  \nointerlineskip
  \vskip-0.2ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1ex,dp=0ex]{empty}
  \begin{pgfpicture}
    \begin{pgfscope}%
      \pgfsetfillcolor{frametitle.bg}%
      \pgfpathrectangle{\pgfpoint{-.5\paperwidth}{-0.5ex}}{\pgfpoint{\paperwidth}{1ex}}%
      \pgfsetfading{beamer@belowframetitlemask}{}%
      \pgfusepath{fill}%
    \end{pgfscope}%
  \end{pgfpicture}%
  \end{beamercolorbox}%  
}


\AtBeginDocument{%
  \setbeamertemplate{frametitle}[smoothtree theme]%
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemesmoothtree-xetex-bidi.def>
%<*beamerouterthemetree-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerouterthemetree-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerouterthemetree-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerouterthemetree package for XeTeX engine]
\bidi@csundef{beamer@@tmpop@headline@tree theme}

\defbeamertemplate*{headline}{tree theme}
{%
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
    \end{beamercolorbox}
    \if@RTL
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{title in head/foot}
    \else
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
    \fi
      \usebeamerfont{title in head/foot}\insertshorttitle
    \end{beamercolorbox}
    \if@RTL
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{section in head/foot}
    \else
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
    \fi
      \usebeamerfont{section in head/foot}%
      \ifbeamer@tree@showhooks
        \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
        \ifdim\wd\beamer@tempbox>1pt%
          \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
          \hskip1pt%
        \fi%
      \else%  
        \hskip6pt%
      \fi%
      \insertsectionhead
    \end{beamercolorbox}
    \if@RTL
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      rightskip=.3cm,leftskip=.3cm plus1fil]{subsection in head/foot}
    \else
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \fi
      \usebeamerfont{subsection in head/foot}%
      \ifbeamer@tree@showhooks
        \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
        \ifdim\wd\beamer@tempbox>1pt%
          \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
          \hskip1pt%
        \fi%
      \else%  
        \hskip12pt%
      \fi%
      \insertsubsectionhead
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
    \end{beamercolorbox}
}


%    \end{macrocode}
% \iffalse
%</beamerouterthemetree-xetex-bidi.def>
%<*beamerthemeHannover-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerthemeHannover-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerthemeHannover-xetex-bidi.def}[2022/06/07 v0.1 bidi adaptations for beamerthemeHannover package for XeTeX engine]
\AtBeginDocument{%
  \if@RTLmain
    \setbeamertemplate{frametitle}[default][left]%
  \else
    \setbeamertemplate{frametitle}[default][right]%
  \fi
}


%    \end{macrocode}
% \iffalse
%</beamerthemeHannover-xetex-bidi.def>
%<*beamerthemeSingapore-xetex-bidi.def>
%\fi
% \section{File \texttt{beamerthemeSingapore-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{beamerthemeSingapore-xetex-bidi.def}[2022/06/09 v0.1 bidi adaptations for beamerthemeSingapore package for XeTeX engine]
\addtoheadtemplate{\pgfuseshading{beamer@headfade}\vskip-1.25cm}{}

\beamertemplatedotitem

\AtBeginDocument{%
  \setbeamertemplate{frametitle}[default][center]%
}


%    \end{macrocode}
% \iffalse
%</beamerthemeSingapore-xetex-bidi.def>
%<*bidi.sty>
%\fi
% \section{File \texttt{bidi.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\def\bididate{2025/10/28}
\def\bidi@version{25.10.28}
\def\bidi@releasename{Iran}
\newcommand*{\bidireleasename}{\bidi@releasename}
\ProvidesPackage{bidi}[\bididate\space v\bidi@version\space (Release \bidi@releasename)\space
Bidirectional typesetting in plain TeX and LaTeX]
\newif\if@bidi@banner
\newif\if@bidi@pdfbanner
\newif\iffootdir@debug
\newif\if@extrafootnotefeatures
\newif\if@nonlatin
\newif\if@bidi@pdfm@mark
\newif\if@bidi@perpage@footnote
\ExplSyntaxOn
\msg_new:nnn {bidi} {cannot-use-engine}
  {
    Oops!~can~not~use~\c_sys_engine_str.\\\\
    The~bidi~package~requires~XeTeX.
  }
 \sys_if_engine_xetex:F
  {
    \msg_fatal:nn {bidi} {cannot-use-engine}
  } 
  
\keys_define:nn { bidi }
  {
    banner .choice: ,
    banner / on .code:n = \@bidi@bannertrue ,
    banner / off .code:n = \@bidi@bannerfalse ,
    banner .default:n = on
  }
\keys_define:nn { bidi }
  {
    PDFbanner .choice: ,
    PDFbanner / on .code:n = \@bidi@pdfbannertrue ,
    PDFbanner / off .code:n = \@bidi@pdfbannerfalse ,
    PDFbanner .default:n = on
  }
\keys_define:nn { bidi }
  {
    RTLdocument .choice: ,
    RTLdocument / on .code:n = \AtEndOfPackage{\@RTLtrue} ,
    RTLdocument / off .code:n = \AtEndOfPackage{\@RTLfalse} ,
    RTLdocument .default:n = on
  }
\keys_define:nn { bidi }
  {
    rldocument .choice: ,
    rldocument / on .code:n = \AtEndOfPackage{\@RTLtrue} ,
    rldocument / off .code:n = \AtEndOfPackage{\@RTLfalse} ,
    rldocument .default:n = on
  }  
\keys_define:nn { bidi }
  {
    documentdirection .choice: ,
    documentdirection / righttoleft .code:n = \AtEndOfPackage{\@RTLtrue} ,
    documentdirection / lefttoright .code:n = \AtEndOfPackage{\@RTLfalse} 
  }
\keys_define:nn { bidi }
  {
    tabledirection .choice: ,
    tabledirection / righttoleft .code:n = \AtEndOfPackage{\@RTLtabtrue} ,
    tabledirection / lefttoright .code:n = \AtEndOfPackage{\@RTLtabfalse} 
  }
\keys_define:nn { bidi }
  {
    footnotedirection .choice: ,
    footnotedirection / righttoleft .code:n = \AtEndOfPackage{\@RTL@footnotetrue} ,
    footnotedirection / lefttoright .code:n = \AtEndOfPackage{\@RTL@footnotefalse} 
  }
\keys_define:nn { bidi }
  {
    debugfootnotedirection .choice: ,
    debugfootnotedirection / on .code:n = \footdir@debugtrue ,
    debugfootnotedirection / off .code:n = \footdir@debugfalse ,
    debugfootnotedirection .default:n = on
  }
\keys_define:nn { bidi }
  {
    footnoterule .choice: ,
    footnoterule / automatic .code:n = \AtEndOfPackage{\autofootnoterule} ,
    footnoterule / left .code:n = \AtEndOfPackage{\leftfootnoterule} ,
    footnoterule / right .code:n = \AtEndOfPackage{\rightfootnoterule} ,
    footnoterule / split .code:n = \AtEndOfPackage{\SplitFootnoteRule} ,
    footnoterule / textwidth .code:n = \AtEndOfPackage{\textwidthfootnoterule} 
  }
\keys_define:nn { bidi }
  {
    extrafootnotefeatures .choice: ,
    extrafootnotefeatures / on .code:n = \@extrafootnotefeaturestrue ,
    extrafootnotefeatures / off .code:n = \@extrafootnotefeaturesfalse ,
    extrafootnotefeatures .default:n = on
  }
\keys_define:nn { bidi }
  {
    script .choice: ,
    script / latin .code:n = \@nonlatinfalse ,
    script / nonlatin .code:n = \@nonlatintrue ,
    script .default:n = latin
  }
\keys_define:nn { bidi }
  {
    DetectColumn .choice: ,
    DetectColumn / on .code:n = 
      \def\bidi@firstcolumn@status@write{% 
        \protected@write\@auxout{}%
          {\string\bidi@column@status
            {1}}} 
      \def\bidi@lastcolumn@status@write{%
        \protected@write\@auxout{}%
          {\string\bidi@column@status{2}}} ,
    DetectColumn / off .code:n = 
       \let\bidi@firstcolumn@status@write\relax
       \let\bidi@lastcolumn@status@write\relax ,
    DetectColumn .default:n = on
  }
\keys_define:nn { bidi }
  {
    logo .choice: ,
    logo / on .code:n = \AtEndOfPackage{\AtBeginDocument{\@bidi@inslogo@}} ,
    logo / off .code:n = \AtEndOfPackage{\let\@bidi@logo@\@empty \let\@bidi@inslogo@\@empty} ,
    logo .default:n = on
  }
\keys_define:nn { bidi }
  {
    pdfinfo .choice: ,
    pdfinfo / on .code:n = \@bidi@pdfm@marktrue ,
    pdfinfo / off .code:n = \@bidi@pdfm@markfalse ,
    pdfinfo .default:n = on
  }
% The `perpagefootnote' option is documented in UK TeX FAQ at 
%  <https://texfaq.org/FAQ-footnpp> (see last paragraph)
\keys_define:nn { bidi }
  {
    perpagefootnote .choice: ,
    perpagefootnote / on .code:n = \@bidi@perpage@footnotetrue ,
    perpagefootnote / off .code:n = \@bidi@perpage@footnotefalse ,
    perpagefootnote .default:n = on
  }
\keys_set:nn { bidi }
  {
    banner = on ,
    PDFbanner = on ,
    DetectColumn = off
    
  }
\ExplSyntaxOff
\ProcessKeyOptions
\edef\@bidi@info{****************************************************^^J%
* ^^J%
* bidi package (Bidirectional typesetting with^^J% 
* plain TeX and LaTeX formats in XeTeX and LuaTeX engines)^^J%
* ^^J%
* Description: A convenient interface for^^J% 
* typesetting bidirectional texts in plain TeX^^J% 
* and LaTeX.  The package includes adaptations^^J%
* for use with many other commonly-used packages.^^J%
* ^^J%
* Copyright (c) 2007--2025 Vafa Khalighi^^J%
* Copyright (c) 2018--2020 bidi-tex GitHub organization^^J%
* ^^J%
* v\bidi@version\space (Release \bidi@releasename), \bididate^^J%
* ^^J%
* License: LaTeX Project Public License, version^^J%
* 1.3c or higher (your choice)^^J%
* ^^J%
* Location on CTAN: /macros/unicodetex/generic/bidi^^J%
* ^^J%
* Primary author of bidi package: Vafa Khalighi.^^J%
* ^^J%
****************************************************}
\edef\bidi@everyjob{\the\everyjob}
\if@bidi@banner
  \typeout{\@bidi@info}
  \everyjob{\bidi@everyjob\typeout{\@bidi@info}}
\fi
\newcommand*{\bidiversion}{\ensuremath\bidi@version}
\RequirePackage{biditools}
\RequirePackage{zref-abspage}
\RequirePackage{auxhook}
\RequirePackage{ltxcmds}
\eqnewif{\if@RTLmain}{\if@rlmain}
\eqnewif{\if@RTL}{\if@rl}
\newcommand*{\setlatin}{\@nonlatinfalse}
\newcommand*{\setnonlatin}{\@nonlatintrue}
\eqnewif{\if@RTLtab}{\if@tab@rl}
\newif\if@hboxRconstruct
\newif\if@bidi@pdfencrypt
\newcommand*{\setRTLtable}{\@RTLtabtrue}
\newcommand*{\setLTRtable}{\@RTLtabfalse}
\newif\if@RTLmarginpar
\newif\if@LTRmarginpar
\newif\if@LTRbibitems
\newif\if@RTLbibitems
\eqnewif{\if@RTL@footnote}{\if@rl@footnote}
\newif\if@bidi@list@minipage@parbox
\newif\if@bidi@list@minipage@parbox@not@nob
\newcommand*{\@bidi@pdfcreator}{%
  The bidi package, v\bidi@version\space (Release \bidi@releasename), \bididate
}
\newcommand*{\@bidi@pdfproducer}{%
  The bidi package, v\bidi@version\space (Release \bidi@releasename), \bididate
}
\newcommand*{\@bidi@pdfcustomproperties}{%
  This is the bidi package, Version \bidi@version\space (Release \bidi@releasename),
  Released October 28, 2025. 
}
\newcommand*{\bidi@beamer@ragged}{}
\@RTLmainfalse
\AtBeginDocument{%
  \if@RTLmain\else
    \if@RTL\@RTLmaintrue%
    \else\@RTLmainfalse%
    \fi%
  \fi%
}
\let\n@xt=\
\bidi@newrobustcmd*{\LRE}{\protect\pLRE}%
\def\pLRE{\protect\afterassignment\moreLRE \let\n@xt= }
\bidi@newrobustcmd*{\RLE}{\protect\pRLE}
\def\pRLE{\protect\afterassignment\moreRLE \let\n@xt= }
\def\bracetext{\ifcat\n@xt{\else\ifcat\n@xt}\fi
  \errmessage{Missing left brace has been substituted}\fi \bgroup}
\newinsert\@bidi@copyins@
\skip\@bidi@copyins@=12\p@
\dimen\@bidi@copyins@=40pc
\count\@bidi@copyins@=1000
\newcommand*{\@bidi@inslogo@}{\insert\@bidi@copyins@{\@bidi@logo@}}
\newcommand*{\@bidi@logo@hb@xt@columnwidth}{%
  \if@RTLmain
    \if@twocolumn
      \hboxR to \columnwidth
    \else
      \hboxR to \textwidth
    \fi    
  \else
    \if@twocolumn
      \hboxL to \columnwidth
    \else
      \hboxL to \textwidth
    \fi 
  \fi
}
\newcommand*{\@bidi@logo}[1]{%
  \toks@{%
    \setbox\z@\hbox{%
      \special{%
        pdf:image width 50pt height 50pt (#1)%
      }
    }%
    \dp\z@\z@
    \ht\z@=50pt
    \wd\z@=50pt
    \beginL
      \lower20pt\box\z@
    \endL
  }%
  \the\toks@
}
\newcount\bidi@typesethour
\newcount\bidi@typesetminute
\bidi@typesethour=\time
\divide\bidi@typesethour 60
\bidi@typesetminute=-\bidi@typesethour
\multiply\bidi@typesetminute 60
\advance\bidi@typesetminute \time
\newcommand*{\TypesetHour}{\two@digits\bidi@typesethour}
\newcommand*{\TypesetMinute}{\two@digits\bidi@typesetminute}
\newcommand*{\TypesetTime}{\TypesetHour:\TypesetMinute}
\newcommand*{\@bidi@logo@}{%
  \@bidi@logo@hb@xt@columnwidth
    {\hss\LRE{\bfseries Typeset {\today} at {\TypesetTime} by the \textsf{bidi} 
    package\quad\@bidi@logo{bidi-logo.pdf}}}}
\ExplSyntaxOn
\keys_define:nn { bidi / pdfencrypt }
  {
    userpassword .code:n = \def\bidi@pdfencrypt@userpassword{#1} ,
    userpassword .default:n =
  }
\keys_define:nn { bidi / pdfencrypt }
  {
    ownerpassword .code:n = \def\bidi@pdfencrypt@ownerpassword{#1} ,
    ownerpassword .default:n =
  }
\keys_define:nn { bidi / pdfencrypt }
  {
    keylength .code:n = \def\bidi@pdfencrypt@keylength{#1} ,
    keylength .default:n = 128
  }
\keys_define:nn { bidi / pdfencrypt }
  {
    permissionflags .code:n = \def\bidi@pdfencrypt@permissionflags{#1} ,
    permissionflags .default:n = 2052
  }
\NewDocumentCommand \pdfencryptsetup {m} { \keys_set:nn { bidi / pdfencrypt } {#1} }
\ExplSyntaxOff
\@onlypreamble\pdfencryptsetup
\input{latex-xetex-bidi.def}

\pdfencryptsetup{%
  userpassword,%
  ownerpassword,%
  keylength,%
  permissionflags%
}

\if@extrafootnotefeatures
  \input{extrafootnotefeatures-xetex-bidi.def}
\fi
\newcount\bidi@digits
\XeTeXinterchartokenstate=\@ne
\newXeTeXintercharclass\bidi@digits@charclass
\newXeTeXintercharclass\bidi@sepmark@charclass
\XeTeXcharclass `\. \bidi@sepmark@charclass
\XeTeXcharclass `\- \bidi@sepmark@charclass
\bidi@digits=`\0 \loop \XeTeXcharclass \bidi@digits \bidi@digits@charclass \ifnum\bidi@digits<`\9 \advance\bidi@digits \@ne \repeat
\bidi@digits=`\٠ \loop \XeTeXcharclass \bidi@digits \bidi@digits@charclass \ifnum\bidi@digits<`\٩ \advance\bidi@digits \@ne \repeat
\bidi@digits=`\۰ \loop \XeTeXcharclass \bidi@digits \bidi@digits@charclass \ifnum\bidi@digits<`\۹ \advance\bidi@digits \@ne \repeat
\XeTeXinterchartoks \bidi@sepmark@charclass  \bidi@digits@charclass = {\DigitsDotDashInterCharToks}
\newcommand*{\DigitsDotDashInterCharToks}{\if@nonlatin\char"200F \fi}
\bidi@AtEndPreamble{%
  \if@bidi@perpage@footnote
    \RequirePackage{bidi-perpage}%
    \ResetCounterPerPage{footnote}%
  \fi
  \ifx\bidi@pdfencrypt@ownerpassword\bidi@empty
    \ifx\bidi@pdfencrypt@userpassword\bidi@empty
      \@bidi@pdfencryptfalse
    \else
      \@bidi@pdfencrypttrue
    \fi
  \else
    \@bidi@pdfencrypttrue 
  \fi
  \if@bidi@pdfencrypt
    \special{pdf:encrypt
      userpw (\bidi@pdfencrypt@userpassword)
      ownerpw (\bidi@pdfencrypt@ownerpassword)
      length \bidi@pdfencrypt@keylength
      perm \bidi@pdfencrypt@permissionflags
    }%
  \fi
}
\if@bidi@pdfbanner
  \if@bidi@pdfm@mark
    \AtEndDocument{%
      \special{pdf:%
        docinfo<<%
          /Creator(\@bidi@pdfcreator)%
          /Producer(\@bidi@pdfproducer)%
          /BIDI.Fullbanner(\@bidi@pdfcustomproperties)%
          \if@bidi@csdef{@xepersian@pdfcustomproperties}{%
            /XEPERSIAN.Fullbanner(\@xepersian@pdfcustomproperties)%
          }{}%
        >>%
      }%
    }
  \else
    \AtEndDocument{%
      \special{pdf:%
        docinfo<<%
          /BIDI.Fullbanner(\@bidi@pdfcustomproperties)%
          \if@bidi@csdef{@xepersian@pdfcustomproperties}{%
            /XEPERSIAN.Fullbanner(\@xepersian@pdfcustomproperties)%
          }{}%
        >>%
      }%
    }
  \fi
\else
  \if@bidi@pdfm@mark
    \AtEndDocument{%
      \special{pdf:%
        docinfo<<%
          /Creator(\@bidi@pdfcreator)%
          /Producer(\@bidi@pdfproducer)%
        >>%
      }%
    }
  \fi
\fi
%    \end{macrocode}
% \iffalse
%</bidi.sty>
%<*bidi.tex>
%\fi
% \section{File \texttt{bidi.tex}}
%    \begin{macrocode}
\def\bididate{2025/10/28}
\catcode`@=11
\def\bidi@version{25.10.28}
\def\bidi@releasename{Iran}
\def\bidireleasename{\bidi@releasename}
\let \protect \relax
\newlinechar`\^^J
\edef\@bidi@info{****************************************************^^J%
* ^^J%
* bidi package (Bidirectional typesetting with^^J% 
* plain TeX and LaTeX formats in XeTeX and LuaTeX engines)^^J%
* ^^J%
* Description: A convenient interface for^^J% 
* typesetting bidirectional texts in plain TeX^^J% 
* and LaTeX.  The package includes adaptations^^J%
* for use with many other commonly-used packages.^^J%
* ^^J%
* Copyright (c) 2007--2025 Vafa Khalighi^^J%
* Copyright (c) 2018--2020 bidi-tex GitHub organization^^J%
* ^^J%
* v\bidi@version\space (Release \bidi@releasename), \bididate^^J%
* ^^J%
* License: LaTeX Project Public License, version^^J%
* 1.3c or higher (your choice)^^J%
* ^^J%
* Location on CTAN: /macros/unicodetex/generic/bidi^^J%
* ^^J%
* Primary author of bidi package: Vafa Khalighi.^^J%
* ^^J%
****************************************************}
\edef\bidi@everyjob{\the\everyjob}
\message{\@bidi@info}
\everyjob{\bidi@everyjob\message{\@bidi@info}}
\def\bidiversion{%
  \relax
  \ifmmode
    \bidi@version
  \else
    $\bidi@version$
  \fi
}
\input iftex.sty
\RequireXeTeX
\newif\if@bidi@pdfm@mark
\newif\if@RTLmain
\newif\if@RTL
\newif\if@hboxRconstruct
\newif\if@sentdir
\newif\if@RTL@footnote
\@RTLmainfalse
\def\setRTLmain{%
  \if@RTLmain\else
    \if@RTL\@RTLmaintrue%
    \else\@RTLmainfalse%
    \fi%
  \fi%
}
\let\n@xt=\
\protected\def\LRE{\protect\pLRE}%
\def\pLRE{\protect\afterassignment\moreLRE \let\n@xt= }
\protected\def\RLE{\protect\pRLE}
\def\pRLE{\protect\afterassignment\moreRLE \let\n@xt= }
\def\bracetext{\ifcat\n@xt{\else\ifcat\n@xt}\fi
  \errmessage{Missing left brace has been substituted}\fi \bgroup}
\newinsert\@bidi@copyins@
\skip\@bidi@copyins@=12\p@
\dimen\@bidi@copyins@=40pc
\count\@bidi@copyins@=1000
\def\@bidi@inslogo@{\insert\@bidi@copyins@{\@bidi@logo@}}
\def\@bidi@logo@hb@xt@{%
  \if@RTLmain
    \hboxR to
  \else
    \hboxL to
  \fi
}
\def\@bidi@logo#1{%
  \toks@{%
    \setbox\z@\hbox{%
      \special{%
        pdf:image width 50pt height 50pt (#1)%
      }
    }%
    \dp\z@\z@
    \ht\z@=50pt
    \wd\z@=50pt
    \beginL
      \lower20pt\box\z@
    \endL
  }%
  \the\toks@
}
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}
\def\two@digits#1{\ifnum#1<10 0\fi\number#1}
\newcount\bidi@typesethour
\newcount\bidi@typesetminute
\bidi@typesethour=\time
\divide\bidi@typesethour 60
\bidi@typesetminute=-\bidi@typesethour
\multiply\bidi@typesetminute 60
\advance\bidi@typesetminute \time
\def\TypesetHour{\two@digits\bidi@typesethour}
\def\TypesetMinute{\two@digits\bidi@typesetminute}
\def\TypesetTime{\TypesetHour:\TypesetMinute}
\def\@bidi@logo@{\@bidi@logo@hb@xt@\hsize{\hss\LRE{\bf Typeset {\today} at {\TypesetTime} by the bidi package\quad\@bidi@logo{bidi-logo.pdf}}}}
\def\bidilogo{\@bidi@inslogo@}
\def\nobidilogo{\let\@bidi@logo@\@empty \let\@bidi@inslogo@\@empty}
\def\@bidi@pdfcreator{%
  The bidi package, v\bidi@version\space (Release \bidi@releasename), \bididate
}
\def\@bidi@pdfproducer{%
  The bidi package, v\bidi@version\space (Release \bidi@releasename), \bididate
}
\def\@bidi@pdfcustomproperties{%
  This is the bidi package, Version \bidi@version\space (Release \bidi@releasename),
  Released October 28, 2025. 
}
\def\bidi@pdfm@mark{%
  \special{pdf:%
    docinfo<<%
    \if@bidi@pdfm@mark
      /Creator(\@bidi@pdfcreator)%
      /Producer(\@bidi@pdfproducer)%
    \fi
    /BIDI.Fullbanner(\@bidi@pdfcustomproperties)%
      >>%
    }%
}
\def\bidipdfinfoon{\@bidi@pdfm@marktrue}
\def\bidipdfinfooff{\@bidi@pdfm@markfalse}
\input plain-xetex-bidi.def
\outer\def\bye{\bidi@pdfm@mark\par\vfill\supereject\end}
\catcode`@=12
\bidipdfinfoon
%    \end{macrocode}
% \iffalse
%</bidi.tex>
%<*bidi2in1.sty>
%\fi
% \section{File \texttt{bidi2in1.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidi2in1}
\pagestyle{plain}
\newcount\evenpage
\newcount\oddpage
\twocolumn
\def\@oddfoot{\evenpage=\thepage%
\multiply\evenpage by 2%
\oddpage=\the\evenpage%
\advance\oddpage by -1%
\hfil\the\evenpage\hfil\hfil\the\oddpage\hfil}%
\def\@evenfoot{\evenpage=\thepage%
\multiply\evenpage by 2%
\oddpage=\the\evenpage%
\advance\oddpage by -1%
\hfil\the\oddpage\hfil\hfil\the\evenpage\hfil}%
\textwidth 9.49in
\textheight 6.7in
\columnsep 0.9in
\columnseprule 0.125pt
\headheight 0cm
\topmargin 0in
\marginparwidth 0in
\marginparsep 0in
\hoffset 0.05in % Corrected
\voffset -0.5in %top margin space is 1.0in by default
\oddsidemargin 0in
\evensidemargin 0in
\headsep 0cm
\topskip 0cm
\parskip 0.15in       %
\headsep 0pt
\special{papersize=11.69in,8.26in}
\renewcommand\maketitle{\par
\begingroup
\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
\def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
\long\def\@makefntext##1{\parindent 1em\noindent
\hb@xt@1.8em{%
\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
\@maketitle
\@thanks
\endgroup
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@maketitle\relax
\global\let\@thanks\@empty
\global\let\@author\@empty
\global\let\@date\@empty
\global\let\@title\@empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
%    \end{macrocode}
% \iffalse
%</bidi2in1.sty>
%<*bidicode.sty>
%\fi
% \section{File \texttt{bidicode.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidicode}
\RequirePackage{xcolor}
\RequirePackage{showexpl}
\definecolor{hellgelb}{rgb}{1,1,0.85}
\definecolor{colKeys}{rgb}{0.2,0.4,0.8}
\definecolor{colCS}{rgb}{0.2,0.4,0.8}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{rgb}{1,0,0}
\definecolor{colString}{rgb}{0,0.5,0}
\lstset{%
    language=[LaTeX]TeX,%
    float=hbp,%
    basicstyle=\ttfamily\small,%
    identifierstyle=\color{colIdentifier},% 
    keywordstyle=\color{colKeys},% 
    texcsstyle=*\color{colCS},%
    stringstyle=\color{colString},% 
    commentstyle=\color{colComments},% 
    backgroundcolor=\color{hellgelb},%
    columns=flexible,% 
    tabsize=4,% 
    extendedchars=true,% 
    showspaces=false,% 
    showstringspaces=false,% 
    numbers=left,%
    numbersep=0.9em,%
    numberstyle=\tiny,%
    frame=single,%
    captionpos=b,%
    xleftmargin=1em,%
    breaklines=true,%
    breakautoindent=false,%
    breakindent=0pt,%
    escapeinside=**,%
    pos=r,%
    explpreset={%
      xleftmargin=1em,%
      columns=flexible,%
      language=[LaTeX]TeX%
    },%
    moretexcs={%
      bididate,%
      bidiversion,%
      deflatinfont,%
      defpersianfont,%
      ding,%
      endLTR,%
      endRTL,%
      false,%
      falsesymbol,%
      junicode,%
      lr,%
      LR,%
      LRE,%
      LTR,%
      maketitle,%
      Nastaliq,%
      newfontfamily,%
      Parsifont,%
      part,%
      RL,%
      RLE,%
      RTL,%
      RTLcases,%
      SepMark,%
      setLR,%
      setLTR,%
      setRL,%
      setRTL,%
      settextfont,%
      subsection,%
      subsubsection,%
      tableofcontents,%
      text,%
      theequation,%
      thesection,%
      true,%
      truesymbol,%
      XePersian,%
      xepersiandate,%
      xepersianversion%
    }%
}
\newcommand\HLON{%
  \gdef\lst@alloverstyle##1{%
    \fboxrule=0pt
    \fboxsep=0pt
    \fcolorbox{hellgelb}{hellgelb}{\bfseries\strut##1}%
}}
\newcommand\HLOFF{%
  \xdef\lst@alloverstyle##1{##1}%
}
\newcommand\Larg [1]{{\normalfont\itshape#1\/}}
\newcommand\Larga[1]{$\langle$\Larg{#1}$\rangle$}
\newcommand\Largb[1]{\lcb\Larg{#1}\rcb}
\newcommand\Largs[1]{\lsb\Larg{#1}\rsb}
\newcommand\Largr[1]{\lrb\Larg{#1}\rrb}
\newcommand\LBEG[1]{{\normalfont\ttfamily\bs{}begin\lcb#1\rcb}}
\newcommand\LEND[1]{{\normalfont\ttfamily\bs{}end\lcb#1\rcb}}

\DeclareRobustCommand\bs{{\normalfont\ttfamily\symbol{92}}}
\DeclareRobustCommand\lcb{{\normalfont\ttfamily\char`\{}}
\DeclareRobustCommand\rcb{{\normalfont\ttfamily\char`\}}}
\DeclareRobustCommand\lsb{{\normalfont\ttfamily[}}
\DeclareRobustCommand\rsb{{\normalfont\ttfamily]}}
\DeclareRobustCommand\lrb{{\normalfont\ttfamily(}}
\DeclareRobustCommand\rrb{{\normalfont\ttfamily)}}

\def\Lcs#1{\nxLcs{#1}}
\def\LcsStar#1{\nxLcs{#1}\OptArg*{*}}
\def\nxLcs#1{\texttt{\symbol{92}#1}}

\def\Coordx#1{$x_{#1}$}
\def\Coordy#1{$y_{#1}$}
\def\Coordz#1{$z_{#1}$}
\def\Coord#1{\Coordx{#1},\kern 1pt\Coordy{#1}}
\def\Coordn{\Coordx{n},\kern 1pt\Coordy{n}}
\def\CoordIII#1{\Coordx{#1},\kern 1pt\Coordy{#1},\kern 1pt\Coordz{#1}}
\def\CAny{\Coordx{},\kern 1pt\Coordy{}}
\def\CIIIAny{\Coordx{},\kern 1pt\Coordy{},\kern 1pt\Coordz{}}
\def\coord#1{(\Coordx{#1},\kern 1pt\Coordy{#1})}
\def\coordn{(\Coordx{n},\kern 1pt\Coordy{n})}
\def\coordiii#1{(\Coordx{#1},\kern 1pt\Coordy{#1},\kern 1pt\Coordz{#1})}
\def\coordx#1{($x_{#1}$)}
\def\coordy#1{($y_{#1}$)}
\def\coordz#1{($z_{#1}$)}
\def\cAny{(\Coordx{},\kern 1pt\Coordy{})}
\def\ciiiAny{(\Coordx{},\kern 1pt\Coordy{},\kern 1pt\Coordz{})}

\newsavebox{\boxdef}
\newenvironment{BDef}
  {\begin{lrbox}\boxdef
      \def\arraystretch{1.0}
      \begin{tabular}{@{}l@{}l@{}l@{}}
  }
  {\end{tabular}\end{lrbox}

   {\BCmd\fbox{\usebox\boxdef}\endBCmd}
   \aftergroup\@afterindentfalse\aftergroup\@afterheading
  }

\newenvironment{BDef*}
  {\begin{lrbox}\boxdef
      \def\arraystretch{1.0}
      \begin{tabular}{@{}l@{}l@{}l@{}}
  }
  {\end{tabular}\end{lrbox}
   {\begin{BCmd*}\fbox{\usebox\boxdef}\end{BCmd*}}
   \aftergroup\@afterindentfalse\aftergroup\@afterheading
  }
\newenvironment{BCmd}{
  \@beginparpenalty-\@lowpenalty
  \topsep\BDefaboveskip
  \fboxsep3pt
  \flushleft}
 {\@endparpenalty\@M
  \@topsepadd\BDefbelowskip
  \endflushleft}

\newenvironment{BCmd*}{
  \@beginparpenalty\@M
  \topsep\BDefinlineskip
  \fboxsep3pt
  \flushleft}
 {\@endparpenalty5000
  \endflushleft}

\newskip\BDefaboveskip
\newskip\BDefbelowskip
\newskip\BDefinlineskip
\setlength\BDefaboveskip{10pt plus 4pt}
\setlength\BDefbelowskip{6pt}
\setlength\BDefinlineskip{6pt}

\def\OptArgs{\colorbox{black!20}{\texttt{[Options]}}\kern1pt}
\def\OptArg{\@ifnextchar*\OptArg@i{\OptArg@ii*}}
\def\OptArg@i*#1{\colorbox{black!20}{\texttt{#1}}\kern1pt}
\def\OptArg@ii*#1{\colorbox{black!20}{\texttt{[#1]}}\kern1pt}
%    \end{macrocode}
% \iffalse
%</bidicode.sty>
%<*bidiftnxtra.sty>
%\fi
% \section{File \texttt{bidiftnxtra.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidiftnxtra}
\newtoks\bidi@p@ftn
\let\FN@sf@@footnote\footnote
\let\FN@sf@@LTRfootnote\LTRfootnote
\let\FN@sf@@RTLfootnote\RTLfootnote
\def\footnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\def\LTRfootnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@LTRfootnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\def\RTLfootnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@RTLfootnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\edef\FN@sf@gobble@opt{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@opt \endcsname}
\expandafter\def\csname FN@sf@gobble@opt \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@twobracket
    \@gobble
}
\def\FN@sf@gobble@twobracket[#1]#2{}
\let\FN@sf@@footnotemark\footnotemark
\def\footnotemark{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnotemark
  \else
    \expandafter\FN@sf@gobble@optonly
  \fi
}
\edef\FN@sf@gobble@optonly{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@optonly \endcsname}
\expandafter\def\csname FN@sf@gobble@optonly \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@bracket
    {}%
}
\def\FN@sf@gobble@bracket[#1]{}
\def\@tabular{%
   \leavevmode \hbox \bgroup
   \let\@footnotetext\bidi@p@ftntext
   \let\@LTRfootnotetext\bidi@p@LTRftntext
   \let\@RTLfootnotetext\bidi@p@RTLftntext
   \let\@xfootnotenext\bidi@p@xftntext
   \let\@xfootnote\bidi@p@xfootnote
   \let\@xLTRfootnotenext\bidi@p@xLTRftntext
   \let\@xLTRfootnote\bidi@p@xLTRfootnote
    \let\@xRTLfootnotenext\bidi@p@xRTLftntext
   \let\@xRTLfootnote\bidi@p@xRTLfootnote
   \if@RTLtab\beginR \fi
   $\let\@acol\@tabacol
   \let\@classz\@tabclassz
   \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray}
\def\endtabular{\crcr\egroup\if@RTLtab\egroup\endR\egroup\fi
                 \egroup $\if@RTLtab\endR\fi\egroup
                  \ifx\@captype\@undefined
                   \global\bidi@p@ftn\expandafter{\expandafter}\the\bidi@p@ftn\fi}
\long\def\bidi@p@ftntext#1{%
  \edef\@tempy{\the\bidi@p@ftn\noexpand\footnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidi@p@ftn\expandafter{\@tempy{#1}}}%
\long\def\bidi@p@LTRftntext#1{%
  \edef\@tempyi{\the\bidi@p@ftn\noexpand\LTRfootnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidi@p@ftn\expandafter{\@tempyi{#1}}}%
\long\def\bidi@p@RTLftntext#1{%
  \edef\@tempyii{\the\bidi@p@ftn\noexpand\RTLfootnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidi@p@ftn\expandafter{\@tempyii{#1}}}%
  

\long\def\bidi@p@xftntext[#1]#2{%
  \global\bidi@p@ftn\expandafter{\the\bidi@p@ftn\footnotetext[#1]{#2}}}
  
\long\def\bidi@p@xLTRftntext[#1]#2{%
  \global\bidi@p@ftn\expandafter{\the\bidi@p@ftn\LTRfootnotetext[#1]{#2}}}
  
\long\def\bidi@p@xRTLftntext[#1]#2{%
  \global\bidi@p@ftn\expandafter{\the\bidi@p@ftn\RTLfootnotetext[#1]{#2}}}
  
  
\def\bidi@p@xfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidi@p@xftntext[#1]}
   
   
\def\bidi@p@xLTRfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidi@p@xLTRftntext[#1]}


\def\bidi@p@xRTLfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidi@p@xRTLftntext[#1]}

\def\@xfloat #1[#2]{%
  \@nodocument
  \def \@captype {#1}%
   \def \@fps {#2}%
   \@onelevel@sanitize \@fps
   \def \reserved@b {!}%
   \ifx \reserved@b \@fps
     \@fpsadddefault
   \else
     \ifx \@fps \@empty
       \@fpsadddefault
     \fi
   \fi
   \ifhmode
     \@bsphack
     \@floatpenalty -\@Mii
   \else
     \@floatpenalty-\@Miii
   \fi
  \ifinner
     \@parmoderr\@floatpenalty\z@
  \else
    \@next\@currbox\@freelist
      {%
       \@tempcnta \sixt@@n
       \expandafter \@tfor \expandafter \reserved@a
         \expandafter :\expandafter =\@fps
         \do
          {%
           \if \reserved@a h%
             \ifodd \@tempcnta
             \else
               \advance \@tempcnta \@ne
             \fi
           \fi
           \if \reserved@a t%
             \@setfpsbit \tw@
           \fi
           \if \reserved@a b%
             \@setfpsbit 4%
           \fi
           \if \reserved@a p%
             \@setfpsbit 8%
           \fi
           \if \reserved@a !%
             \ifnum \@tempcnta>15
               \advance\@tempcnta -\sixt@@n\relax
             \fi
           \fi
           }%
       \@tempcntb \csname ftype@\@captype \endcsname
       \multiply \@tempcntb \@xxxii
       \advance \@tempcnta \@tempcntb
       \global \count\@currbox \@tempcnta
       }%
    \@fltovf
  \fi
  \global \setbox\@currbox
    \color@vbox
      \normalcolor
      \vbox \bgroup
       \let\@footnotetext\bidi@p@ftntext
       \let\@LTRfootnotetext\bidi@p@LTRftntext
       \let\@RTLfootnotetext\bidi@p@RTLftntext
       \let\@xfootnotenext\bidi@p@xftntext
        \let\@xfootnote\bidi@p@xfootnote
        \let\@xLTRfootnotenext\bidi@p@xLTRftntext
        \let\@xLTRfootnote\bidi@p@xLTRfootnote
        \let\@xRTLfootnotenext\bidi@p@xRTLftntext
        \let\@xRTLfootnote\bidi@p@xRTLfootnote
        \hsize\columnwidth
        \@parboxrestore
        \@floatboxreset
}
\def \@endfloatbox{%
      \par\vskip\z@skip      %% \par\vskip\z@ added 15 Dec 87
      \@minipagefalse
      \outer@nobreak
    \egroup                  %% end of vbox
    \global\bidi@p@ftn\expandafter{\expandafter}\the\bidi@p@ftn
  \color@endbox
}
%    \end{macrocode}
% \iffalse
%</bidiftnxtra.sty>
%<*bidimoderncv.cls>
%\fi
% \section{File \texttt{bidimoderncv.cls}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{bidimoderncv}
\newif\if@DEBUG\@DEBUGfalse
\DeclareOption{a4paper}{
  \setlength\paperheight{297mm}
  \setlength\paperwidth{210mm}}
\DeclareOption{a5paper}{
  \setlength\paperheight{210mm}
  \setlength\paperwidth{148mm}}
\DeclareOption{b5paper}{
  \setlength\paperheight{250mm}
  \setlength\paperwidth{176mm}}
\DeclareOption{letterpaper}{
  \setlength\paperheight{11in}
  \setlength\paperwidth{8.5in}}
\DeclareOption{legalpaper}{
  \setlength\paperheight{14in}
  \setlength\paperwidth{8.5in}}
\DeclareOption{executivepaper}{
  \setlength\paperheight{10.5in}
  \setlength\paperwidth{7.25in}}
\DeclareOption{landscape}{
  \setlength\@tempdima{\paperheight}
  \setlength\paperheight{\paperwidth}
  \setlength\paperwidth{\@tempdima}}
\newcommand\@ptsize{}
\DeclareOption{10pt}{\renewcommand\@ptsize{0}}
\DeclareOption{11pt}{\renewcommand\@ptsize{1}}
\DeclareOption{12pt}{\renewcommand\@ptsize{2}}
\DeclareOption{draft}{\setlength\overfullrule{5pt}}
\DeclareOption{final}{\setlength\overfullrule{0pt}}
\newif\if@colour\@colourtrue
\DeclareOption{nocolour}{\@colourfalse}
\ExecuteOptions{a4paper,11pt,colour,final}
\ProcessOptions\relax
\input{size1\@ptsize.clo}
\RequirePackage{color}
\RequirePackage{graphicx}
\RequirePackage{ifthen}
\RequirePackage{marvosym}
\addtolength{\oddsidemargin}{-54pt}
\addtolength{\textwidth}{109pt}
\addtolength{\topmargin}{-70pt}
\addtolength{\textheight}{122pt}
\addtolength{\marginparsep}{-5pt}
\addtolength{\marginparwidth}{-10pt}
\RequirePackage{url}
\RequirePackage{hyperref}
\hypersetup{%
  breaklinks,
  baseurl       = http://,%
  pdfborder     = 0 0 0,%
  pdfpagemode   = UseNone,%
  pdfstartpage  = 1}
\AtEndOfClass{%
  \AtBeginDocument{%
    \hypersetup{%
      pdfauthor     = \@firstname~\@familyname,%
      pdftitle      = \@title,%
      pdfsubject    = \@firstname~\@familyname,%
      pdfkeywords   = \@resumename~\@firstname~\@familyname}}}
\urlstyle{tt}
\RequirePackage{fancyhdr}
\fancypagestyle{plain}{%
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyhf{}}
\pagestyle{plain}
\setlength\lineskip{1\p@}
\setlength\normallineskip{1\p@}
\renewcommand\baselinestretch{}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength\columnsep{10\p@}
\setlength\columnseprule{0\p@}
\pagestyle{empty}
\pagenumbering{arabic}
\raggedbottom
\onecolumn
\providecommand*{\listitemsymbol}{\textbullet}
\providecommand*{\addresssymbol}{}
\providecommand*{\mobilesymbol}{\Mobilefone}
\providecommand*{\phonesymbol}{\Telefon}
\providecommand*{\faxsymbol}{\FAX}
\providecommand*{\emailsymbol}{\Letter}
\definecolor{firstnamecolor}{rgb}{0,0,0}
\def\firstnamecolour#1{\gdef\@firstnamecolour{\addfontfeature{Color=#1}}}
\def\familynamecolour#1{\gdef\@familynamecolour{\addfontfeature{Color=#1}}}
\def\titlecolour#1{\gdef\@titlecolour{\addfontfeature{Color=#1}}}
\def\addresscolour#1{\gdef\@addresscolour{\addfontfeature{Color=#1}}}
\def\quotecolour#1{\gdef\@quotecolour{\addfontfeature{Color=#1}}}
\def\sectiontitlecolour#1{\gdef\@sectiontitlecolour{\addfontfeature{Color=#1}}}
\definecolor{sectionrectanglecolor}{rgb}{0,0,0}
\def\subsectioncolour#1{\gdef\@subsectioncolour{\addfontfeature{Color=#1}}}
\def\hintcolour#1{\gdef\@hintcolour{\addfontfeature{Color=#1}}}
\providecommand*{\firstnamefont}{}
\providecommand*{\familynamefont}{}
\providecommand*{\titlefont}{}
\providecommand*{\addressfont}{}
\providecommand*{\quotefont}{}
\providecommand*{\sectionfont}{}
\providecommand*{\subsectionfont}{}
\providecommand*{\hintfont}{\small}
\providecommand*{\firstnamestyle}[1]{{\firstnamefont\@firstnamecolour#1}}
\providecommand*{\familynamestyle}[1]{{\familynamefont\@familynamecolour#1}}
\providecommand*{\titlestyle}[1]{{\titlefont\@titlecolour#1}}
\providecommand*{\addresstyle}[1]{{\addressfont\@addresscolour#1}}
\providecommand*{\quotestyle}[1]{{\quotefont\@quotecolour#1}}
\providecommand*{\sectionstyle}[1]{{\sectionfont\@sectiontitlecolour#1}}
\providecommand*{\subsectionstyle}[1]{{\subsectionfont\@subsectioncolour#1}}
\providecommand*{\hintstyle}[1]{{\hintfont\@hintcolour#1}}
\newcommand*{\cvtheme}[2][]{
  \def\@cvtheme{#2}
  \def\@cvthemeoptions{#1}}
\cvtheme{bidi-casual}
\AtBeginDocument{\RequirePackage[\@cvthemeoptions]{cvtheme\@cvtheme}}
\newcommand*{\resumename}[1]{\def\@resumename{#1}}
\newcommand*{\firstname}[1]{\def\@firstname{#1}}
\newcommand*{\familyname}[1]{\def\@familyname{#1}}
\renewcommand*{\title}[1]{\def\@title{#1}}
\newcommand*{\address}[1]{\def\@address{#1}}
\newcommand*{\mobile}[1]{\def\@mobile{#1}}
\newcommand*{\phone}[1]{\def\@phone{#1}}
\renewcommand*{\fax}[1]{\def\@fax{#1}}
\newcommand*{\email}[1]{\def\@email{#1}}
\newcommand*{\extrainfo}[1]{\def\@extrainfo{#1}}
\def\@photowidth{0pt}
\newcommand*{\photo}[2][64pt]{\def\@photowidth{#1}\def\@photo{#2}}
\newcommand*{\quote}[1]{\def\@quote{#1}}
\newlength{\quotewidth}
\newlength{\hintscolumnwidth}
\newlength{\separatorcolumnwidth}
\setlength{\separatorcolumnwidth}{0.025\textwidth}
\newlength{\maincolumnwidth}
\newlength{\doubleitemmaincolumnwidth}
\newlength{\listitemsymbolwidth}
\settowidth{\listitemsymbolwidth}{\listitemsymbol{}~}
\newlength{\listitemmaincolumnwidth}
\newlength{\listdoubleitemmaincolumnwidth}
\newcommand*{\recomputethemelengths}{}
\newcommand*{\recomputelengths}{%
\setlength{\quotewidth}{0.65\textwidth}%
\setlength{\maincolumnwidth}{\textwidth}%
\addtolength{\maincolumnwidth}{-\separatorcolumnwidth}%
\addtolength{\maincolumnwidth}{-\hintscolumnwidth}%
\setlength{\listitemmaincolumnwidth}{\maincolumnwidth}%
\addtolength{\listitemmaincolumnwidth}{-\listitemsymbolwidth}%
\setlength{\doubleitemmaincolumnwidth}{\maincolumnwidth}%
\addtolength{\doubleitemmaincolumnwidth}{-\hintscolumnwidth}%
\addtolength{\doubleitemmaincolumnwidth}{-\separatorcolumnwidth}%
\setlength{\doubleitemmaincolumnwidth}{0.5\doubleitemmaincolumnwidth}%
\setlength{\listdoubleitemmaincolumnwidth}{\maincolumnwidth}%
\addtolength{\listdoubleitemmaincolumnwidth}{-\listitemsymbolwidth}%
\setlength{\listdoubleitemmaincolumnwidth}{0.475\listdoubleitemmaincolumnwidth}%
\renewcommand{\headwidth}{\textwidth}%
\recomputethemelengths}
\setlength{\hintscolumnwidth}{0.15\textwidth}
\recomputelengths
\title{}
\renewcommand*{\maketitle}{}
\newcommand*{\section}[1]{%
\vspace*{2.5ex \@plus 1ex \@minus .2ex}%
  \phantomsection{}%
  \addcontentsline{toc}{part}{#1}%
  \parbox[m]{\hintscolumnwidth}{\bidi@raggedleft\hintfont{\leavevmode\color{sectionrectanglecolor}\rule{\hintscolumnwidth}{1ex}}}%
  \hspace{\separatorcolumnwidth}%
  \parbox[m]{\maincolumnwidth}{\sectionstyle{#1}}\\[1ex]}
\newcommand*{\subsection}[1]{%
  \cvline[0.45em]{}{\subsectionstyle{#1}}}
\newcommand*{\cvline}[3][.25em]{%
  \begin{tabular}{@{}p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}@{}}%
    \bidi@raggedleft\hintfont{#2} &{#3}%
  \end{tabular}\\[#1]}
\newcommand*{\cvdoubleitem}[4]{%
 \cvline{#1}{\begin{minipage}[t]{\doubleitemmaincolumnwidth}#2\end{minipage}%
 \hfill%
 \begin{minipage}[t]{\hintscolumnwidth}\bidi@raggedleft\hintfont{#3}\end{minipage}\hspace*{\separatorcolumnwidth}\begin{minipage}[t]{\doubleitemmaincolumnwidth}#4\end{minipage}}}
\newcommand*{\cvlistitem}[2][\listitemsymbol{}]{%
  \cvline[0pt]{}{#1~\begin{minipage}[t]{\listitemmaincolumnwidth}#2\end{minipage}}}
\newcommand*{\cvlistdoubleitem}[3][\listitemsymbol{}]{%
  \cvline[0pt]{}{#1~\begin{minipage}[t]{\listdoubleitemmaincolumnwidth}#2\end{minipage}%
  \hfill%
  \ifthenelse{\equal{#3}{}}%
    {}%
    {#1~\begin{minipage}[t]{\listdoubleitemmaincolumnwidth}#3\end{minipage}}}}
\newcommand*{\cventry}[6]{%
  \cvline{#1}{%
    {\bfseries#2}%
    \ifx#3\else{, {\slshape#3}}\fi%
    \ifx#4\else{, #4}\fi%
    \ifx#5\else{, #5}\fi%
    .%
    \ifx#6\else{\newline{}\begin{minipage}[t]{\linewidth}\small#6\end{minipage}}\fi
    }}%
\newcommand*{\cvlanguage}[3]{%
  \cvline{#1}{\begin{minipage}[t]{.225\maincolumnwidth}\textbf{#2}\end{minipage}\hfill\begin{minipage}[t]{0.725\maincolumnwidth}\bidi@raggedleft\footnotesize\itshape #3\end{minipage}}}
\newcommand*{\cvcomputer}[4]{%
  \cvdoubleitem{#1}{\small#2}{#3}{\small#4}}
\newcommand*{\link}[2][]{%
  \ifthenelse{\equal{#1}{}}%
    {\href{#2}{#2}}%
    {\href{#2}{#1}}}
\newcommand*{\httplink}[2][]{%
  \ifthenelse{\equal{#1}{}}%
    {\href{http://#2}{#2}}%
    {\href{http://#2}{#1}}}
\newcommand*{\emaillink}[2][]{%
  \ifthenelse{\equal{#1}{}}%
    {\href{mailto:#2}{#2}}%
    {\href{mailto:#2}{#1}}}
\newif\if@displaypagenumbers\@displaypagenumberstrue
\newcommand*{\nopagenumbers}{\@displaypagenumbersfalse}
\AtBeginDocument{%
  \if@displaypagenumbers%
    \@ifundefined{r@lastpage}{}{%
      \ifthenelse{\pageref{lastpage} > 1}{%
      \fancypagestyle{plain}{%
        \fancyfoot[r]{\beginL\addressfont\@quotecolour\footnotesize\thepage\beginL/\endL\pageref{lastpage}\endL}}%
      \pagestyle{plain}}{}}%
  \AtEndDocument{\label{lastpage}}%
  \fi}
\newlength{\bibindent}
\setlength{\bibindent}{1.5em}
\newcommand*{\bibliographyitemlabel}{\includegraphics{bidi-bibitem.pdf}}
\newenvironment{thebibliography}[1]%
  {%
    \section{\refname}%
    \small%
    \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
    \bidi@@thebibliography@font@hook%
    \begin{list}{\bibliographyitemlabel}%
      {%
        \setlength{\topsep}{0pt}%
        \setlength{\labelwidth}{\hintscolumnwidth}%
        \setlength{\labelsep}{\separatorcolumnwidth}%
        \leftmargin\labelwidth%
        \advance\leftmargin\labelsep%
        \@openbib@code%
        \usecounter{enumiv}%
        \let\p@enumiv\@empty%
        \renewcommand\theenumiv{\@arabic\c@enumiv}}%
        \sloppy\clubpenalty4000\widowpenalty4000%
  }%
  {%
    \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
    \end{list}%
  }
\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
\let\@openbib@code\@empty
%    \end{macrocode}
% \iffalse
%</bidimoderncv.cls>
%<*bidi-perpage.sty>
%\fi
% \section{File \texttt{bidi-perpage.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidi-perpage}[2025/09/15 v0.5 Reset counter(s) on every page]
\newcommand*{\bidi@checkvlist}{%
  \ifcase
    \ifvmode
      \ifx\lastnodetype\bidi@undefined
        \ifdim-\@m\p@=\prevdepth
          \ifdim\lastskip=\z@
            \ifnum\lastpenalty=\z@
              \@ne
            \fi
          \fi
        \fi
      \else
         \ifnum\lastnodetype=\m@ne
           \@ne
         \fi
       \fi
     \fi
     \z@
   \or
     \PackageWarning{bidi-perpage}{%
       `\string\stepcounter' is probably at the beginning of vertical
       list.
       You may need to use `\string\leavevmode' before it to avoid
       vertical shifts%
     }%
  \fi
}
\newcount\bidi@page@count 
\bidi@page@count\@ne
\newcommand*{\ResetCounterPerPage}[2][\z@]{%
  \if@bidi@csundef{bidi@stepcounterhook@@#2}{%
    \expandafter\gdef\csname bidi@stepcounterhook@@#2\endcsname{}%
  }{}%
  \if@bidi@csundef{if@bidi@reset@#2@rerun}{%
    \expandafter\newif\csname if@bidi@reset@#2@rerun\endcsname
  }{}%
  \if@bidi@csundef{bidi@#2@count}{%
    \expandafter\newcount\csname bidi@#2@count\endcsname
  }{}%
  \csname bidi@#2@count\endcsname\z@
  \if@bidi@csundef{bidi@previous@page@@#2@count}{%
    \expandafter\newcount\csname
    bidi@previous@page@@#2@count\endcsname
  }{}%
  \csname bidi@previous@page@@#2@count\endcsname\z@  
  \if@bidi@csundef{bidi@reset@#2@perpage}{%
    \bidi@AfterEndDocumentCheckLabelsRerun{%
      \csname if@bidi@reset@#2@rerun\endcsname
        \PackageWarningNoLine{bidi-perpage}{%
          Counter `#2' may not have been reset per page.
          Rerun to reset counter `#2' per page%
        }%
      \fi
    }%
  }{}%
  \expandafter\gdef\csname bidi@reset@#2@perpage\endcsname{%
    \global\advance\csname bidi@#2@count\endcsname\@ne
    \if@filesw
      \edef\@tempa{%
        \write\@auxout{%
          \string\bidi@counter@page{#2}%
          {\number\csname bidi@#2@count\endcsname}%
          {\noexpand\number\noexpand\bidi@page@count}%
        }%
      }%
      \bidi@checkvlist
      \dimen@=\lastkern
      \ifdim\dimen@=\z@ 
      \else 
        \unkern
      \fi
      \count@=\lastpenalty
      \@tempa
       \ifdim\dimen@=\z@
         \penalty
         \ifnum\count@<\@M 
           \@M 
         \else 
           \count@ 
         \fi
       \else 
         \kern\dimen@
       \fi
    \fi
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname bidi@#2@@\number\csname
  bidi@#2@count\endcsname\endcsname\relax
    \global\csname @bidi@reset@#2@reruntrue\endcsname
  \else
    \global\csname @bidi@reset@#2@rerunfalse\endcsname
    \expandafter\@tempcnta\csname bidi@#2@@\number
    \csname bidi@#2@count\endcsname\endcsname\relax
    \ifnum\@tempcnta=\csname
    bidi@previous@page@@#2@count\endcsname
    \else
      \global\csname
      bidi@previous@page@@#2@count\endcsname\@tempcnta
      \global\csname c@#2\endcsname#1\relax
    \fi
  \fi
  }%
  \expandafter\bidi@gappto\csname 
  bidi@stepcounterhook@@#2\endcsname{%
    \csname bidi@reset@#2@perpage\endcsname
  }%
}
\def\bidi@counter@page#1#2#3{\bidi@namegdef{bidi@#1@@#2}{#3}}    
\bidi@AtEndOutputPage{%
  \global\advance\bidi@page@count\@ne
}
%    \end{macrocode}
% \iffalse
%</bidi-perpage.sty>
%<*biditools.sty>
%\fi
% \section{File \texttt{biditools.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{biditools}[2025/02/02 v2.7 Programming tools for bidi package]
\providecommand{\@bidi@saveprimitive}[2]{\begingroup\escapechar`\\\relax
  \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
  \ifx\@tempa\@tempb \global\let#2#1%
  \else
    \edef\@tempb{\meaning#2}%
    \ifx\@tempa\@tempb
    \else
      \@latex@error{Unable to properly define \string#2; primitive
      \noexpand#1no longer primitive}\@eha
    \fi
  \fi
  \endgroup}
\newtoks\@bidi@envbody
\newtoks\@bidi@emptytoks
\def\bidi@addto@envbody#1{\global\@bidi@envbody\expandafter{\the\@bidi@envbody#1}}
\def\bidi@collect@body#1{%
  \@bidi@envbody{\expandafter#1\expandafter{\the\@bidi@envbody}}%
  \edef\bidi@process@envbody{\the\@bidi@envbody\noexpand\end{\@currenvir}}%
  \@bidi@envbody\@bidi@emptytoks \def\begin@bidi@stack{b}%
  \begingroup
  \expandafter\let\csname\@currenvir\endcsname\bidi@collect@@body
  \edef\bidi@process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}%
  \bidi@process@envbody
}
\def\bidi@push@begins#1\begin#2{%
  \ifx\end#2\else b\expandafter\bidi@push@begins\fi
}
\def\bidi@collect@@body#1\end#2{%
  \edef\begin@bidi@stack{\bidi@push@begins#1\begin\end \expandafter\@gobble\begin@bidi@stack}%
  \ifx\@empty\begin@bidi@stack
    \endgroup
    \@checkend{#2}%
    \bidi@addto@envbody{#1}%
  \else
    \bidi@addto@envbody{#1\end{#2}}%
  \fi
  \bidi@process@envbody % A little tricky! Note the grouping
}
\long\def\bidi@addto@long@envbody#1{\global\@bidi@envbody\expandafter{\the\@bidi@envbody#1}}
\long\def\bidi@collect@long@body#1{%
  \@bidi@envbody{\expandafter#1\expandafter{\the\@bidi@envbody}}%
  \edef\bidi@process@envbody{\the\@bidi@envbody\noexpand\end{\@currenvir}}%
  \@bidi@envbody\@bidi@emptytoks \def\begin@bidi@stack{b}%
  \begingroup
  \expandafter\let\csname\@currenvir\endcsname\bidi@collect@long@@body
  \edef\bidi@process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}%
  \bidi@process@envbody
}
\long\def\bidi@push@long@begins#1\begin#2{%
  \ifx\end#2\else b\expandafter\bidi@push@long@begins\fi
}
\long\def\bidi@collect@long@@body#1\end#2{%
  \edef\begin@bidi@stack{\bidi@push@long@begins#1\begin\end \expandafter\@gobble\begin@bidi@stack}%
  \ifx\@empty\begin@bidi@stack
    \endgroup
    \@checkend{#2}%
    \bidi@addto@long@envbody{#1}%
  \else
    \bidi@addto@long@envbody{#1\end{#2}}%
  \fi
  \bidi@process@envbody % A little tricky! Note the grouping
}
\long\def\bidi@new@ifnextchar#1#2#3{%
  \let\reserved@d= #1%
  \def\reserved@a{#2}\def\reserved@b{#3}%
  \futurelet\@let@token\bidi@new@ifnch
}
\def\bidi@new@ifnch{%
  \ifx\@let@token\reserved@d \let\reserved@b\reserved@a \fi
  \reserved@b
}
\def\bidi@matrix@check#1{%
  \expandafter\ifx\csname\@currenvir\endcsname#1%
  \else\bidi@matrix@error#1%
    \expandafter\@gobble
  \fi
}
\def\bidi@matrix@error#1{%
  \PackageError{biditools}{%
Old form `\string#1' should be \string\begin{\expandafter\@gobble\string#1}%
  }{%
`\string#1{...}' is old bidi package syntax whose use is
ill-advised in the old versions of bidi package.%
  }%
}
\def\eqnewif#1#2{%
  \count@\escapechar \escapechar\m@ne
    \let#1\iffalse
    \let#2\iffalse
    \eq@if#1#2\iftrue
    \eq@if#1#2\iffalse
  \escapechar\count@}
\def\eq@if#1#2#3{%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
                    \expandafter\@gobbletwo\string#3\endcsname
                       {\let#1#3%
                       \let#2#3}%
  \expandafter\def\csname\expandafter\@gobbletwo\string#2%
                    \expandafter\@gobbletwo\string#3\endcsname
                       {\let#2#3%
                       \let#1#3}}
\def\noteqnewif#1#2{%
  \count@\escapechar \escapechar\m@ne
    \let#1\iffalse
    \let#2\iffalse
    \not@eq@if#1#2\iftrue\iffalse
  \escapechar\count@}
\def\not@eq@if#1#2#3#4{%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
                    \expandafter\@gobbletwo\string#3\endcsname
                       {\let#1#3%
                       \let#2#4}%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
                    \expandafter\@gobbletwo\string#4\endcsname
                       {\let#1#4%
                       \let#2#3}%
  \expandafter\def\csname\expandafter\@gobbletwo\string#2%
                    \expandafter\@gobbletwo\string#3\endcsname
                       {\let#2#3%
                       \let#1#4}%
  \expandafter\def\csname\expandafter\@gobbletwo\string#2%
                    \expandafter\@gobbletwo\string#4\endcsname
                       {\let#2#4%
                       \let#1#3}}
\newcommand*{\SetBoolean}[2]{%
  \lowercase{\def\@tempa{#2}}%
  \@ifundefined{@tempswa\@tempa}%
    {\PackageError{biditools}%
       {You can only set a boolean to `true' or `false'}\@ehc}%
    {\@ifundefined{#1\@tempa}%
      {\PackageError{biditools}{Boolean #1 undefined}\@ehc}%
      {\csname#1\@tempa\endcsname}}}
\newcommand*{\GlobalSetBoolean}[2]{%
  \lowercase{\def\@tempa{#2}}%
  \@ifundefined{@tempswa\@tempa}%
    {\PackageError{biditools}%
       {You can only set a boolean to `true' or `false'}\@ehc}%
    {\@ifundefined{#1\@tempa}%
      {\PackageError{biditools}{Boolean #1 undefined}\@ehc}%
      {\global\csname#1\@tempa\endcsname}}}
\newcommand*{\SetatBoolean}[2]{%
  \lowercase{\def\@tempa{#2}}%
  \@ifundefined{@tempswa\@tempa}%
    {\PackageError{biditools}%
       {You can only set a boolean to `true' or `false'}\@ehc}%
    {\@ifundefined{@#1\@tempa}%
      {\PackageError{biditools}{Boolean @#1 undefined}\@ehc}%
      {\csname @#1\@tempa\endcsname}}}
\newcommand*{\GlobalSetatBoolean}[2]{%
  \lowercase{\def\@tempa{#2}}%
  \@ifundefined{@tempswa\@tempa}%
    {\PackageError{biditools}%
       {You can only set a boolean to `true' or `false'}\@ehc}%
    {\@ifundefined{@#1\@tempa}%
      {\PackageError{biditools}{Boolean @#1 undefined}\@ehc}%
      {\global\csname @#1\@tempa\endcsname}}}
\def\@bidi@removefromreset#1#2{{%
  \expandafter\let\csname c@#1\endcsname\@bidi@removefromreset
  \def\@elt##1{%
    \expandafter\ifx\csname c@##1\endcsname\@bidi@removefromreset
    \else
      \noexpand\@elt{##1}%
    \fi}%
  \expandafter\xdef\csname cl@#2\endcsname{%
    \csname cl@#2\endcsname}}}
\newcommand*{\ifRtoL}{%
  \if@RTL
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand*{\ifLtoR}{%
  \if@RTL
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}  
\newcommand*{\ifRtoLtable}{%
  \if@RTLtab
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand*{\ifLtoRtable}{%
  \if@RTLtab
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}  
\newcommand*{\ifRtoLhboxconstruct}{%
  \if@hboxRconstruct
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand*{\ifLtoRhboxconstruct}{%
  \if@hboxRconstruct
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi} 
\newcommand*{\iflatin}{%
  \if@nonlatin
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi} 
\newcommand*{\ifnonlatin}{%
  \if@nonlatin
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
  
\newcommand*{\bidi@@convert@dimen@t@unit}[2]{%
    \strip@pt\dimexpr #1*65536/\dimexpr 1#2\relax #2}
  
\newcommand*{\bidi@@convert@dimen@t@pt}[1]{%
    \dimexpr #1*65536/\dimexpr 1pt\relax}
    
\newcommand*{\IfPackageVersionAtLeastTF}[1]{%
  \expandafter\@if@ver@pkg@least\csname #1@version\endcsname
}
\newcommand*{\@if@ver@pkg@least}[2]{%
  \ifnum\expandafter\bidi@parse@ver@#100\@nil<\expandafter\bidi@parse@ver@#200\@nil
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
\newcommand*{\bidi@parse@ver@}[1]{\bidi@parse@ver0#1}
\def\bidi@parse@ver#1.#2.#3#4#5\@nil{%
  \if\relax#2\relax\else#1\fi#2#3#4
}
\newcommand*{\IfPackageVersionAtMostTF}[1]{%
  \expandafter\@if@ver@pkg@most\csname #1@version\endcsname
}
\newcommand*{\@if@ver@pkg@most}[2]{%
  \ifnum\expandafter\bidi@parse@ver@#100\@nil>\expandafter\bidi@parse@ver@#200\@nil
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
\newcommand*{\IfPackageVersionTF}[1]{%
  \expandafter\@if@ver@pkg@\csname #1@version\endcsname
}
\newcommand*{\@if@ver@pkg@}[2]{%
  \ifnum\expandafter\bidi@parse@ver@#100\@nil=\expandafter\bidi@parse@ver@#200\@nil
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
  
\newcommand*{\if@bidi@csdef}[1]{%
  \ifcsname#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand*{\if@bidi@csundef}[1]{%
  \ifcsname#1\endcsname
    \expandafter\ifx\csname#1\endcsname\relax
      \expandafter\expandafter
      \expandafter\@firstoftwo
    \else
      \expandafter\expandafter
      \expandafter\@secondoftwo
    \fi
  \else
    \expandafter\@firstoftwo
  \fi}
\newcommand{\if@bidi@def}[1]{%
  \ifdefined#1%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand{\if@bidi@undef}[1]{%
  \ifdefined#1%
    \ifx#1\relax
      \expandafter\expandafter
      \expandafter\@firstoftwo
    \else
      \expandafter\expandafter
      \expandafter\@secondoftwo
    \fi
  \else
    \expandafter\@firstoftwo
  \fi}
\newcommand{\if@bidi@blank}[1]{% from url.sty
  \bidi@ifblank@i#1&&\@secondoftwo\@firstoftwo:}
\long\def\bidi@ifblank@i#1#2&#3#4#5:{#4}
\newcommand{\bidi@notblank}[1]{%
  \bidi@ifblank@i#1&&\@firstoftwo\@secondoftwo:}
\newcommand{\if@bidi@defmacro}{}
\long\edef\if@bidi@defmacro#1{%
  \noexpand\expandafter\noexpand\bidi@ifdefmacro
  \noexpand\meaning#1\detokenize{macro}:&}
\edef\bidi@ifdefmacro{%
  \def\noexpand\bidi@ifdefmacro##1\detokenize{macro}:##2&}
\bidi@ifdefmacro{\bidi@notblank{#2}}
\newcommand*{\if@bidi@csmacro}[1]{%
  \if@bidi@csdef{#1}
    {\expandafter\if@bidi@defmacro\csname#1\endcsname}
    {\@secondoftwo}}
\newcommand{\if@bidi@defprimitive}[1]{%
  \ifprimitive#1%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand{\if@bidi@csprimitive}[1]{%
 \begingroup\expandafter\expandafter\expandafter\endgroup%
  \expandafter\ifprimitive\csname#1\endcsname%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newcommand*{\bidi@csdefcs}[2]{%
\expandafter\@ifdefinable  \csname#1\endcsname{%
\expandafter\def\csname#1\expandafter\endcsname{\csname#2\endcsname}}}
\newcommand*{\bidi@csletcs}[2]{%
\expandafter\@ifdefinable  \csname#1\endcsname{%
\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}}
\newcommand*{\bidi@cslet}[2]{%
\expandafter\@ifdefinable  \csname#1\endcsname{%
\expandafter\let\csname#1\endcsname#2}}
\newcommand{\bidi@namelongdef}[1]{%
  \long\expandafter\def\csname #1\endcsname}
\newcommand{\bidi@namelonggdef}[1]{%
  \long\expandafter\gdef\csname #1\endcsname}
\newcommand{\bidi@namelongedef}[1]{%
  \long\expandafter\edef\csname #1\endcsname}
\newcommand{\bidi@namelongxdef}[1]{%
  \long\expandafter\xdef\csname #1\endcsname}
\def\bidi@ensure@newcommand{\@star@or@long\bidi@ensure@new@command}
\def\bidi@ensure@new@command#1{%
  \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
  \expandafter\if@bidi@csundef\@gtempa
     {\new@command#1}{\relax%
  \let\@ifdefinable\@rc@ifdefinable%
  \new@command#1}}
\def\bidi@ensure@newlength#1{\if@bidi@undef#1{\newskip#1}{}}

\protected\def\bidi@error{\PackageError{bidi}}
\protected\def\bidi@warning{\PackageWarning{bidi}}
\protected\def\bidi@warningnoline{\PackageWarningNoLine{bidi}}
\protected\def\bidi@info{\PackageInfo{bidi}}

\def\bidi@pos#1#2#3#4{\bidi@namegdef{bidi@#1pos@@#2@#3}{#4}}

\newcount\bidi@poscount

\newcommand*{\WriteStartXPostoaux}{%
  \global\advance\bidi@poscount\@ne
    \edef\@tempa{%
      \write\@auxout{%
        \string\bidi@pos{x}{start}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastxpos}%
      }%
    }%
    \ifvmode
      \leavevmode
    \fi
  \if@RTL
       \if@filesw
    \@tempa
  \fi
  \pdfsavepos
    \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi
  \if@bidi@csundef{bidi@xpos@@start@\number\bidi@poscount}{%
        \PackageWarningNoLine{biditools}{%
          The start x position `\number\bidi@poscount' is not known yet.
          Rerun to get this x position%
          }%
  }{}%
}

\newcommand*{\WriteEndXPostoaux}{%
      \edef\@tempa{%
        \write\@auxout{%
          \string\bidi@pos{x}{end}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastxpos}%
      }%
    }%
  \if@RTL
    \if@filesw
    \@tempa
  \fi
  \pdfsavepos
  \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi  
  \if@bidi@csundef{bidi@xpos@@end@\number\bidi@poscount}{%
          \PackageWarningNoLine{biditools}{%
          The end x position `\number\bidi@poscount' is not known yet.
          Rerun to get this x position%
          }%
  }{}%
}

\newcommand*{\WriteStartYPostoaux}{%
  \global\advance\bidi@poscount\@ne
    \edef\@tempa{%
      \write\@auxout{%
        \string\bidi@pos{y}{start}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastypos}%
      }%
    }%
    \ifvmode
      \leavevmode
    \fi
  \if@RTL
       \if@filesw
    \@tempa
  \fi
  \pdfsavepos
    \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi
  \if@bidi@csundef{bidi@ypos@@start@\number\bidi@poscount}{%
        \PackageWarningNoLine{biditools}{%
          The start y position `\number\bidi@poscount' is not known yet.
          Rerun to get this y position%
          }%
  }{}%
}

\newcommand*{\WriteEndYPostoaux}{%
      \edef\@tempa{%
        \write\@auxout{%
          \string\bidi@pos{y}{end}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastypos}%
      }%
    }%
  \if@RTL
    \if@filesw
    \@tempa
  \fi
  \pdfsavepos
  \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi  
  \if@bidi@csundef{bidi@ypos@@end@\number\bidi@poscount}{%
          \PackageWarningNoLine{biditools}{%
          The end y position `\number\bidi@poscount' is not known yet.
          Rerun to get this y position%
          }%
  }{}%
}

\newcommand*{\WriteStartXYPostoaux}{%
  \global\advance\bidi@poscount\@ne
    \edef\@tempa{%
      \write\@auxout{%
        \string\bidi@pos{x}{start}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastxpos}%
      }%
      \write\@auxout{%
        \string\bidi@pos{y}{start}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastypos}%
      }%
    }%
    \ifvmode
      \leavevmode
    \fi
  \if@RTL
       \if@filesw
    \@tempa
  \fi
  \pdfsavepos
    \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi
  \if@bidi@csundef{bidi@xpos@@start@\number\bidi@poscount}{%
        \PackageWarningNoLine{biditools}{%
          The start x position `\number\bidi@poscount' is not known yet.
          Rerun to get this x position%
          }%
  }{}%
  \if@bidi@csundef{bidi@ypos@@start@\number\bidi@poscount}{%
        \PackageWarningNoLine{biditools}{%
          The start y position `\number\bidi@poscount' is not known yet.
          Rerun to get this y position%
          }%
  }{}%
}

\newcommand*{\WriteEndXYPostoaux}{%
      \edef\@tempa{%
        \write\@auxout{%
          \string\bidi@pos{x}{end}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastxpos}%
      }%
        \write\@auxout{%
          \string\bidi@pos{y}{end}{\number\bidi@poscount}{\noexpand\number\noexpand\pdflastypos}%
      }%
    }%
  \if@RTL
    \if@filesw
    \@tempa
  \fi
  \pdfsavepos
  \else
  \pdfsavepos
  \if@filesw
    \@tempa
  \fi
  \fi  
  \if@bidi@csundef{bidi@xpos@@end@\number\bidi@poscount}{%
          \PackageWarningNoLine{biditools}{%
          The end x position `\number\bidi@poscount' is not known yet.
          Rerun to get this x position%
          }%
  }{}%
  \if@bidi@csundef{bidi@ypos@@end@\number\bidi@poscount}{%
          \PackageWarningNoLine{biditools}{%
          The end y position `\number\bidi@poscount' is not known yet.
          Rerun to get this y position%
          }%
  }{}%
}

\newcommand*{\currentposxwidth}{%  
  \if@bidi@csundef{bidi@xpos@@end@\number\bidi@poscount}{\z@}
  {%
    \ifnum\csname bidi@xpos@@start@\number\bidi@poscount
    \endcsname < \csname   bidi@xpos@@end@\number\bidi@poscount
    \endcsname
    \dimexpr \csname bidi@xpos@@end@\number\bidi@poscount
    \endcsname sp - \csname   bidi@xpos@@start@\number\bidi@poscount
    \endcsname sp\relax
  \else
    \dimexpr \csname bidi@xpos@@start@\number\bidi@poscount
    \endcsname sp - \csname   bidi@xpos@@end@\number\bidi@poscount
    \endcsname sp\relax
  \fi
  }%
}

\newcommand*{\currentposyheight}{%  
  \if@bidi@csundef{bidi@ypos@@end@\number\bidi@poscount}{\z@}
  {%
    \dimexpr \csname bidi@ypos@@start@\number\bidi@poscount
    \endcsname sp - \csname   bidi@ypos@@end@\number\bidi@poscount
    \endcsname sp\relax
  }%
}



\newcommand*{\setbaselineskip}[1]{%
    \linespread{\strip@pt\dimexpr\numexpr\dimexpr#1\relax*65536/\dimexpr\baselineskip\relax\relax sp\relax}
    \selectfont
}


\newcommand*{\bidi@newrobustcmd}{}
\protected\def\bidi@newrobustcmd{\@star@or@long\bidi@new@command}

\def\bidi@new@command#1{\@testopt{\bidi@newcommand#1}0}

\def\bidi@newcommand#1[#2]{%
  \@ifnextchar[%]
    {\bidi@xargdef#1[#2]}
    {\ifx\l@ngrel@x\relax
       \let\l@ngrel@x\protected
     \else
       \protected\def\l@ngrel@x{\protected\long}%
     \fi
     \@argdef#1[#2]}}

\long\def\bidi@xargdef#1[#2][#3]#4{%
  \@ifdefinable#1{%
    \expandafter\protected
    \expandafter\def
    \expandafter#1%
    \expandafter{%
      \expandafter\@testopt
      \csname\string#1\endcsname{#3}}%
    \expandafter\@yargdef\csname\string#1\endcsname\tw@{#2}{#4}}}

\bidi@newrobustcmd*{\bidi@renewrobustcmd}{\@star@or@long\bidi@renew@command}

\def\bidi@renew@command#1{%
  \if@bidi@undef{#1}
     {\bidi@error{\string#1 undefined}\@ehc}
     {}%
  \let\@ifdefinable\@rc@ifdefinable
  \bidi@new@command#1}



\bidi@newrobustcmd*{\bidi@providerobustcmd}{\@star@or@long\bidi@provide@command}

\def\bidi@provide@command#1{%
  \if@bidi@undef{#1}
    {\def\reserved@a{\bidi@new@command#1}}
    {\def\reserved@a{\bidi@renew@command\reserved@a}}%
  \reserved@a}

\newcommand*{\bidi@csuse}[1]{%
  \ifcsname#1\endcsname
    \csname#1\expandafter\endcsname
  \fi}

\newcommand{\bidi@expandonce}[1]{%
  \unexpanded\expandafter{#1}}

\def\bidi@protected{%
  \let\@@protect\protect
  \let\protect\@unexpandable@protect
  \afterassignment\restore@protect}

\bidi@newrobustcmd{\bidi@appto}[2]{%
  \if@bidi@undef{#1}
    {\edef#1{\unexpanded{#2}}}
    {\edef#1{\bidi@expandonce#1\unexpanded{#2}}}}
\bidi@newrobustcmd{\bidi@eappto}[2]{%
  \if@bidi@undef{#1}
    {\edef#1{#2}}
    {\edef#1{\bidi@expandonce#1#2}}}
\bidi@newrobustcmd{\bidi@gappto}[2]{%
  \if@bidi@undef{#1}
    {\xdef#1{\unexpanded{#2}}}
    {\xdef#1{\bidi@expandonce#1\unexpanded{#2}}}}
\bidi@newrobustcmd{\bidi@xappto}[2]{%
  \if@bidi@undef{#1}
    {\xdef#1{#2}}
    {\xdef#1{\bidi@expandonce#1#2}}}

\bidi@newrobustcmd*{\bidi@protected@eappto}{\bidi@protected\bidi@eappto}
\bidi@newrobustcmd*{\bidi@protected@xappto}{\bidi@protected\bidi@xappto}



\bidi@newrobustcmd{\bidi@preto}[2]{%
  \if@bidi@undef{#1}
    {\edef#1{\unexpanded{#2}}}
    {\edef#1{\unexpanded{#2}\bidi@expandonce#1}}}
\bidi@newrobustcmd{\bidi@epreto}[2]{%
  \if@bidi@undef{#1}
    {\edef#1{#2}}
    {\edef#1{#2\bidi@expandonce#1}}}
\bidi@newrobustcmd{\bidi@gpreto}[2]{%
  \if@bidi@undef{#1}
    {\xdef#1{\unexpanded{#2}}}
    {\xdef#1{\unexpanded{#2}\bidi@expandonce#1}}}
\bidi@newrobustcmd{\bidi@xpreto}[2]{%
  \if@bidi@undef{#1}
    {\xdef#1{#2}}
    {\xdef#1{#2\bidi@expandonce#1}}}

\bidi@newrobustcmd*{\bidi@protected@epreto}{\bidi@protected\bidi@epreto}
\bidi@newrobustcmd*{\bidi@protected@xpreto}{\bidi@protected\bidi@xpreto}



\bidi@newrobustcmd*{\bidi@csappto}[1]{\expandafter\bidi@appto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@cseappto}[1]{\expandafter\bidi@eappto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@csgappto}[1]{\expandafter\bidi@gappto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@csxappto}[1]{\expandafter\bidi@xappto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@protected@cseappto}{\bidi@protected\bidi@cseappto}
\bidi@newrobustcmd*{\bidi@protected@csxappto}{\bidi@protected\bidi@csxappto}



\bidi@newrobustcmd*{\bidi@cspreto}[1]{\expandafter\bidi@preto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@csepreto}[1]{\expandafter\bidi@epreto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@csgpreto}[1]{\expandafter\bidi@gpreto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@csxpreto}[1]{\expandafter\bidi@xpreto\csname#1\endcsname}
\bidi@newrobustcmd*{\bidi@protected@csepreto}{\bidi@protected\bidi@csepreto}
\bidi@newrobustcmd*{\bidi@protected@csxpreto}{\bidi@protected\bidi@csxpreto}



\bidi@newrobustcmd{\if@bidi@patchable}{%
  \bidi@dbg@trce\if@bidi@patchable
  \begingroup
  \@makeother\#%
  \@ifstar\bidi@ifpatchable@i\bidi@ifpatchable}

\long\def\bidi@ifpatchable#1#2{%
  \endgroup
  \bidi@dbg@init#1%
  \if@bidi@undef{#1}
    {\bidi@dbg@fail{def}\@secondoftwo}
    {\bidi@dbg@info{def}%
     \if@bidi@defmacro{#1}
       {\bidi@dbg@info{mac}%
        \bidi@ifscanable{#1}
          {\bidi@ifhashcheck{#2}
             {\bidi@dbg@info{tok}%
              \bidi@ifpattern#1{#2}
                 {\bidi@dbg@info{pat}%
                  \bidi@dbg@info{pos}\@firstoftwo}
                 {\bidi@dbg@fail{pat}\@secondoftwo}}
             {\bidi@dbg@fail{hsh}\@secondoftwo}}
          {\bidi@dbg@fail{tok}\@secondoftwo}}
       {\bidi@dbg@fail{mac}\@secondoftwo}}}

\long\def\bidi@ifpatchable@i#1{%
  \endgroup
  \bidi@dbg@init#1%
  \if@bidi@undef{#1}
    {\bidi@dbg@fail{def}\@secondoftwo}
    {\bidi@dbg@info{def}%
     \if@bidi@defmacro{#1}
       {\bidi@dbg@info{mac}%
        \if@bidi@defparam{#1}
          {\bidi@dbg@info{prm}%
           \bidi@ifscanable{#1}
             {\bidi@dbg@info{tok}%
              \bidi@dbg@info{pos}\@firstoftwo}
             {\bidi@dbg@fail{tok}\@secondoftwo}}
          {\bidi@dbg@info{prl}%
           \if@bidi@defprotected{#1}
             {\bidi@dbg@info{pro}}
             {}%
           \bidi@dbg@info{pos}\@firstoftwo}}
       {\bidi@dbg@fail{mac}\@secondoftwo}}}

\bidi@newrobustcmd*{\bidi@patchcmd}{%
  \bidi@dbg@trce\bidi@patchcmd
  \begingroup
  \@makeother\#%
  \bidi@@patchcmd}

\newcommand{\bidi@@patchcmd}[4][########1]{%
  \bidi@ifpatchable#2{#3}
    {\bidi@dbg@succ{ret}%
     \begingroup
     \edef\bidi@resrvda{%
       \def\noexpand\bidi@resrvda####1\detokenize{macro:}####2->####3&{%
         #1\def\string\bidi@resrvda\space####2{\noexpand\bidi@resrvdb####3&}}%
       \def\noexpand\bidi@resrvdb####1\detokenize{#3}####2&{%
         ####1\detokenize{#4}####2}%
       \edef\noexpand\bidi@resrvda{%
         \noexpand\bidi@resrvda\meaning#2&}}%
     \bidi@resrvda
     \bidi@patchcmd@scantoks\bidi@resrvda
     \let#2\bidi@resrvda
     \bidi@undef\bidi@resrvda
     \@firstoftwo}
    {\@secondoftwo}}

\def\bidi@patchcmd@scantoks#1{%
  \edef\bidi@resrvda{\endgroup
    \unexpanded{\makeatletter\scantokens}{#1}%
    \catcode\number`\@=\the\catcode`\@\relax}%
  \bidi@resrvda}

\protected\def\bidi@ifscanable#1{%
  \begingroup
  \edef\bidi@resrvda{%
    \def\noexpand\bidi@resrvda####1\detokenize{macro}:####2->####3&{%
      ####1\def\string\bidi@resrvda####2{####3}}%
    \edef\noexpand\bidi@resrvda{\noexpand\bidi@resrvda\meaning#1&}}%
  \bidi@resrvda
  \makeatletter
  \scantokens\expandafter{\bidi@resrvda}%
  \expandafter\endgroup\ifx#1\bidi@resrvda
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}


\protected\long\def\bidi@ifhashcheck#1{%
  \begingroup
  \edef\bidi@resrvda{\detokenize{#1}}%
  \expandafter\endgroup
  \expandafter\bidi@ifhashcheck@i\meaning\bidi@resrvda&}

\edef\bidi@ifhashcheck@i#1&{%
  \noexpand\expandafter
  \noexpand\bidi@ifhashcheck@ii
  \noexpand\strip@prefix#1\string#\string#&}

\edef\bidi@ifhashcheck@ii{%
  \def\noexpand\bidi@ifhashcheck@ii##1\string#\string###2&}
\bidi@ifhashcheck@ii{\if@bidi@blank{#2}}


\protected\long\def\bidi@ifpattern#1#2{%
  \begingroup
  \edef\bidi@resrvda{%
    \def\noexpand\bidi@resrvda####1\detokenize{#2}####2&{%
      \endgroup\noexpand\noexpand\noexpand\if@bidi@blank{####2}}%
    \edef\noexpand\bidi@resrvda{\noexpand\bidi@resrvda
      \expandafter\strip@prefix\meaning#1\detokenize{#2}&}%
    \noexpand\bidi@resrvda}
  \bidi@resrvda\@secondoftwo\@firstoftwo}


\newcommand{\if@bidi@defparam}{}
\long\edef\if@bidi@defparam#1{%
  \noexpand\expandafter\noexpand\bidi@ifdefparam
  \noexpand\meaning#1\detokenize{macro}:->&}
\edef\bidi@ifdefparam{%
  \def\noexpand\bidi@ifdefparam##1\detokenize{macro}:##2->##3&}
\bidi@ifdefparam{\bidi@notblank{#2}}


\newcommand{\if@bidi@defprotected}{}
\long\edef\if@bidi@defprotected#1{%
  \noexpand\expandafter\noexpand\bidi@ifdefprotected
  \noexpand\meaning#1\string\protected&}
\edef\bidi@ifdefprotected{%
  \def\noexpand\bidi@ifdefprotected##1\string\protected##2&}
\bidi@ifdefprotected{\bidi@notblank{#2}}


\bidi@newrobustcmd{\bidi@undef}[1]{\let#1\bidi@undefined}
\bidi@newrobustcmd{\bidi@csundef}[1]{%
  \expandafter\let\csname #1\endcsname\bidi@undefined
}

\let\bidi@dbg@trce\@gobble
\let\bidi@dbg@init\@gobble
\let\bidi@dbg@info\@gobble
\let\bidi@dbg@succ\@gobble
\let\bidi@dbg@fail\@gobble



\bidi@newrobustcmd*{\bidi@apptocmd}{%
  \bidi@dbg@trce\bidi@apptocmd
  \begingroup
  \@makeother\#%
  \bidi@hooktocmd\bidi@append}



\bidi@newrobustcmd*{\bidi@pretocmd}{%
  \bidi@dbg@trce\bidi@pretocmd
  \begingroup
  \@makeother\#%
  \bidi@hooktocmd\bidi@prepend}

\long\def\bidi@hooktocmd#1#2#3{%
  \endgroup
  \bidi@dbg@init#2%
  \if@bidi@undef{#2}
    {\bidi@dbg@fail{def}\@secondoftwo}
    {\bidi@dbg@info{def}%
     \if@bidi@defmacro{#2}
       {\bidi@dbg@info{mac}%
        \if@bidi@defparam{#2}
          {\bidi@dbg@info{prm}%
           \bidi@ifscanable{#2}
             {\bidi@ifhashcheck{#3}
                {\bidi@dbg@info{tok}%
                 \bidi@dbg@succ{ret}%
                 \bidi@hooktocmd@i#1#2{#3}%
                 \@firstoftwo}
                {\bidi@dbg@fail{hsh}\@secondoftwo}}
             {\bidi@dbg@fail{tok}\@secondoftwo}}
          {\bidi@dbg@info{prl}%
           \if@bidi@defprotected{#2}
             {\bidi@dbg@info{pro}%
              \bidi@dbg@succ{red}%
              \protected}
             {\bidi@dbg@succ{red}}%
           \edef#2{#1{\bidi@expandonce#2}{\unexpanded{#3}}}%
           \@firstoftwo}}
       {\bidi@dbg@fail{mac}\@secondoftwo}}}

\long\def\bidi@hooktocmd@i#1#2#3{%
  \begingroup
  \edef\bidi@resrvda{%
    \def\noexpand\bidi@resrvda####1\detokenize{macro}:####2->####3&{%
      ####1\def\string\bidi@resrvda\space####2{#1{####3}{\detokenize{#3}}}}%
    \edef\noexpand\bidi@resrvda{%
      \noexpand\bidi@resrvda\meaning#2&}}%
  \bidi@resrvda
  \bidi@patchcmd@scantoks\bidi@resrvda
  \let#2\bidi@resrvda
  \bidi@undef\bidi@resrvda}

\long\def\bidi@append#1#2{#1#2}
\long\def\bidi@prepend#1#2{#2#1}

%\bidi@newrobustcmd*{\bidi@AtEndPreamble}{\bidi@gappto\bidi@endpreamblehook}
%\newcommand*{\bidi@endpreamblehook}{}

\bidi@newrobustcmd*{\bidi@AtEndPreamble}{\AddToHook{begindocument/before}}%

\bidi@newrobustcmd*{\bidi@BeforeOutputPageShipOut}{\bidi@gappto\bidi@beforeoutputpageshipouthook}
\newcommand*{\bidi@beforeoutputpageshipouthook}{}

\bidi@newrobustcmd*{\bidi@BeforeHeader}{\bidi@gappto\bidi@beforeheaderhook}
\newcommand*{\bidi@beforeheaderhook}{}

\bidi@newrobustcmd*{\bidi@BeforeOutputBoxOutputPage}{\bidi@gappto\bidi@beforeoutputboxoutputpagehook}
\newcommand*{\bidi@beforeoutputboxoutputpagehook}{}

\bidi@newrobustcmd*{\bidi@AfterOutputBoxOutputPage}{\bidi@gappto\bidi@afteroutputboxoutputpagehook}
\newcommand*{\bidi@afteroutputboxoutputpagehook}{}

\bidi@newrobustcmd*{\bidi@BeforeFooter}{\bidi@gappto\bidi@beforefooterhook}
\newcommand*{\bidi@beforefooterhook}{}

\bidi@newrobustcmd*{\bidi@AfterFooter}{\bidi@gappto\bidi@afterfooterhook}
\newcommand*{\bidi@afterfooterhook}{}


\bidi@newrobustcmd*{\bidi@AfterOutputPageShipOut}{\bidi@gappto\bidi@afteroutputpageshipouthook}
\newcommand*{\bidi@afteroutputpageshipouthook}{}

\bidi@newrobustcmd*{\bidi@AtEndOutputPage}{\bidi@gappto\bidi@atendoutputpagehook}
\newcommand*{\bidi@atendoutputpagehook}{}

%\bidi@preto\document{%
%  \endgroup
%  \let\bidi@AtEndPreamble\@firstofone
%  \bidi@endpreamblehook
%  \protected\def\bidi@AtEndPreamble{\@notprerr\@gobble}%
%  \bidi@undef\bidi@endpreamblehook
%  \begingroup}

\bidi@newrobustcmd*{\bidi@AfterPreamble}{\AtBeginDocument}
\bidi@AtEndPreamble{\let\bidi@AfterPreamble\@firstofone}

%\bidi@newrobustcmd*{\bidi@AfterEndPreamble}{\bidi@gappto\bidi@afterendpreamblehook}
%\newcommand*{\bidi@afterendpreamblehook}{}

\bidi@newrobustcmd*{\bidi@AfterEndPreamble}{\AddToHook{begindocument/end}}%

%\bidi@appto\document{%
%  \let\bidi@AfterEndPreamble\@firstofone
%  \bidi@afterendpreamblehook
%  \protected\def\bidi@AfterEndPreamble{\@notprerr\@gobble}%
%  \bidi@undef\bidi@afterendpreamblehook
%  \ignorespaces}
  
\bidi@newrobustcmd*{\bidi@AfterEndDocumentCheckLabelsRerun}{\bidi@gappto\bidi@afterenddocumentchecklabelsrerunhook}
\newcommand*{\bidi@afterenddocumentchecklabelsrerunhook}{}

\bidi@patchcmd\enddocument
  {\fi}
  {\let\bidi@AfterEndDocumentCheckLabelsRerun\@firstofone
   \bidi@afterenddocumentchecklabelsrerunhook
   \fi}
   {}
   {\PackageWarning{biditools}{Patching `\string\enddocument' failed}}

\AtEndDocument{\let\bidi@AfterEndPreamble\@gobble}

\bidi@newrobustcmd*{\bidi@AfterLastShipout}{\bidi@gappto\bidi@afterlastshipouthook}
\newcommand*{\bidi@afterlastshipouthook}{}

\bidi@patchcmd\enddocument
  {\clearpage}
  {\clearpage
   \let\bidi@AfterLastShipout\@firstofone
   \bidi@afterlastshipouthook}
  {}
  {\let\bidi@clearpage\clearpage
   \def\clearpage{%
     \bidi@clearpage
     \let\bidi@AfterLastShipout\@firstofone
     \bidi@afterlastshipouthook}}

%\bidi@newrobustcmd*{\bidi@AfterEndDocument}{\bidi@gappto\bidi@afterenddocumenthook}
%\newcommand*{\bidi@afterenddocumenthook}{}

\bidi@newrobustcmd*{\bidi@AfterEndDocument}{\AddToHook{enddocument/end}}%

%\bidi@patchcmd\enddocument
%  {\deadcycles}
%  {\let\bidi@AfterEndDocument\@firstofone
%   \bidi@afterenddocumenthook
%   \deadcycles}
%  {}
%  {\let\bidi@@end\@@end
%   \def\@@end{%
%     \let\bidi@AfterEndDocument\@firstofone
%     \bidi@afterenddocumenthook
%     \bidi@@end}}

\bidi@newrobustcmd{\bidi@AtBeginEnvironment}[1]{%
  \bidi@csgappto{@bidi@begin@#1@hook}}

% Patch \begin<space> and \end<space> in newer LaTeX releases
% \begin and \end in older ones.	 
\expandafter\bidi@patchcmd\csname begin\ifcsname begin \endcsname\space\fi\endcsname
  {\csname #1\endcsname}
  {\bidi@csuse{@bidi@begin@#1@hook}%
   \csname #1\endcsname}
  {}
  {\bidi@warning{%
     Patching '\string\begin' failed!\MessageBreak
     '\string\bidi@AtBeginEnvironment' will not work\@gobble}}



\bidi@newrobustcmd{\bidi@AtEndEnvironment}[1]{%
  \bidi@csgappto{@bidi@end@#1@hook}}

\expandafter\bidi@patchcmd\csname end\ifcsname end \endcsname\space\fi\endcsname
  {\csname end#1\endcsname}
  {\bidi@csuse{@bidi@end@#1@hook}%
   \csname end#1\endcsname}
  {}
  {\bidi@warning{%
     Patching '\string\end' failed!\MessageBreak
     '\string\bidi@AtEndEnvironment' will not work\@gobble}}



\bidi@newrobustcmd{\bidi@BeforeBeginEnvironment}[1]{%
  \bidi@csgappto{@bidi@beforebegin@#1@hook}}

\expandafter\bidi@pretocmd\csname begin\ifcsname begin \endcsname\space\fi\endcsname
  {\bidi@csuse{@bidi@beforebegin@#1@hook}}
  {}
  {\bidi@warning{%
     Patching '\string\begin' failed!\MessageBreak
     '\string\bidi@BeforeBeginEnvironment' will not work\@gobble}}

\bidi@newrobustcmd{\bidi@AfterEndEnvironment}[1]{%
  \bidi@csgappto{@bidi@afterend@#1@hook}}

\expandafter\bidi@patchcmd\csname end\ifcsname end \endcsname\space\fi\endcsname
  {\if@ignore}
  {\bidi@csuse{@bidi@afterend@#1@hook}%
   \if@ignore}
  {}
  {\bidi@warning{%
     Patching '\string\end' failed!\MessageBreak
     '\string\bidi@AfterEndEnvironment' will not work\@gobble}}

\def\bidi@namedef#1{\expandafter\def\csname #1\endcsname} 
\def\bidi@namegdef#1{\expandafter\gdef\csname #1\endcsname} 
\def\bidi@nameedef#1{\expandafter\edef\csname #1\endcsname}   
\def\bidi@namexdef#1{\expandafter\xdef\csname #1\endcsname}

% From David Carlisle:
% The \@stpelt redefinition below belongs to Heiko Oberdiek
% See also https://github.com/ho-tex/oberdiek/issues/26

\let\@bidi@stepcounter\stepcounter
\let\@bidi@@stpelt\@stpelt

\def\@stpelt#1{%
  \ifcsname bidi@reset@#1@perpage\endcsname
    \begingroup
      \let\stepcounter\@bidi@stepcounter
      \@bidi@@stpelt{#1}%
    \endgroup
    \expandafter\@gobbletwo
  \fi
  \@bidi@@stpelt{#1}%
}
  
\bidi@pretocmd\stepcounter
  {%
    \if@bidi@csundef{bidi@stepcounterhook@@#1}{}{%
      \csname bidi@stepcounterhook@@#1\endcsname
    }%
  }{}%
  {\PackageWarning{biditools}{Patching `\string\stepcounter' failed}}
     
\chardef\bidi@backslash`\\
\def\bidics#1{\texttt{\char\bidi@backslash#1}}

% anonymous control sequences
\newcount\bidi@tempcountb
\newtoks\bidi@temptoksa
\newtoks\bidi@temptoksb
     
% Catcode (re)storing
%
\def\bidi@storecatcode#1%
   {\escapechar\m@ne
    \bidi@csarg\edef{bidi@restorecatcode\string#1}%
          {\catcode`\string#1=
                \the\catcode\expandafter`\string#1}%
    \catcode\expandafter`\string#1=12\relax
    \escapechar`\\\relax}
\def\bidi@restorecatcode#1%
   {\escapechar\m@ne
    \csname bidi@restorecatcode\string#1\endcsname
    \escapechar`\\\relax}
    
% Construct a control sequence inside \edef
%
\def\bidi@csname#1{\expandafter\noexpand\csname#1\endcsname}

% Construct a control sequence out of #2, and give it to #1
%
\def\bidi@csarg#1#2{\expandafter#1\csname#2\endcsname}

% Pick an escapecharacter
% this presumes that its argument is a character.
%
\def\bidi@pickescape#1{\ifnum`#1=\escapechar\else#1\fi}

% Equality of strings.
% the fast approach: does not work in expansion-only environment.
%
\def\bidi@EqualString#1#2{00\fi\def\bidi@eqs@a{#1}\def\bidi@eqs@b{#2}%
    \ifx\bidi@eqs@a\bidi@eqs@b}

% Test by expansion only
%
\def\bidi@EqualStringX#1#2{00\fi
    \csname if\@bidi@EqualStringX#1&$#2&$\endcsname}
\def\@bidi@EqualStringX#1#2$#3#4${\ifx#1#3%
        \ifx#1&true\else\bidi@hop@ES\@bidi@EqualStringX#2$#4$\fi
    \else false\fi}
\def\bidi@hop@ES#1\fi#2\fi{\fi\fi#1}

% Lexicographic ordering
% note the use of \def
% also note the characters 0,127,255 that are used,
% these are not supposed to appear in the strings
%
{\catcode0=12 \catcode255=12 \catcode127=12
\gdef\bidi@StringBeforeNC#1#2{00\fi
  \bidi@CharsBefore#1^^@^^?#2^^ff^^?}
\gdef\bidi@CharsBeforeNC#1#2^^?#3#4^^?{%
  \ifcat#1\relax\def\bidi@next{\bidi@CharsBefore#2^^@^^?#3#4^^ff^^?}%
  \else\ifcat#3\relax\def\bidi@next{\bidi@CharsBefore#1#2^^@^^?#4^^ff^^?}%
       \else\ifnum\lccode`#1<\lccode`#3
              \def\bidi@next{\csname iftrue\endcsname}%
            \else\ifnum\lccode`#1>\lccode`#3
                   \def\bidi@next{\csname iffalse\endcsname}%
                 \else\def\bidi@next{\bidi@CharsBefore#2^^?#4^^?}%
  \fi  \fi  \fi  \fi
  \bidi@next}
\gdef\bidi@StringBefore#1#2{00\fi
  \bidi@CharsBefore#1^^@^^?#2^^ff^^?}
\gdef\bidi@CharsBefore#1#2^^?#3#4^^?{%
  \ifnum`#1<`#3
       \def\bidi@next{\csname iftrue\endcsname}%
  \else\ifnum`#1>`#3
       \def\bidi@next{\csname iffalse\endcsname}%
       \else\def\bidi@next{\bidi@CharsBefore#2^^?#4^^?}%
  \fi\fi
  \bidi@next}
}

% Null argument test
%
\def\bidi@empty{}
\def\bidi@ifempty#1{00\fi\expandafter\ifx\csname bidi@#1@null\endcsname\bidi@@null}
\def\bidi@ifEmptyX#1{\expandafter\ifx\csname bidi@#1@null\endcsname\bidi@@null}
%\def\bidi@ifEmpty#1{\def\bidi@cs@a{#1}\ifx\bidi@cs@a\bidi@empty}
\def\bidi@IsEmptyList#1{00\fi\def\bidi@cs@a{#1}\ifx\cs@a\bidi@empty}

% Next character test
%
\def\bidi@NextChar#1#2#3{00\fi
    \let\bidi@nxt@ch#1\def\bidi@nxt@a{#2}\def\bidi@nxt@b{#3}%
    \futurelet\bidi@nxt@c\@bidi@ifnxtc}
\def\bidi@ifNextChar#1#2#3{%
    \let\bidi@nxt@ch#1\def\bidi@nxt@a{#2}\def\bidi@nxt@b{#3}%
    \futurelet\bidi@nxt@c\@bidi@ifnxtc}
\def\@bidi@ifnxtc{\ifx\bidi@nxt@ch\bidi@nxt@c \expandafter\bidi@nxt@a 
    \else \expandafter\bidi@nxt@b \fi}
    
% Test for defined-ness of string as control sequence.
% works inside \edef
%
\def\bidi@undefinedcs#1{00\fi\bidi@csarg\ifx{#1}\relax}    

% Define uniquely defined dummy macros,
% usually to serve as bumper blocks at the end of a list
%
\newcount\bidi@dummies
\def\DefNewDummy#1{
    \if\bidi@undefinedcs{#1}\bidi@csarg\edef{#1}{bidi@dum\the\bidi@dummies}
        \advance\bidi@dummies\@ne
    \else
        \bidi@error{Attempt at second definition of `#1'}
    \fi}
    
% string case statement
% use: \bidi@switch \iftest{...} in:
%      item1 action1
%      ...
%      itemn actionn
%      default defaultaction [optional]
%      \endbidi@switch
% inspired by Jonathan Fine: Some Basic Control Macros
% Tugboat 12 #4
%
\let\@bidi@fi\fi \let\endbidi@switch\relax \DefNewDummy{bidi@default}
\def\bidi@switch@exit #1 \@bidi@fi #2 \endbidi@switch {\fi #1}
\def\bidi@switch #1#2#3{\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1{#2}\bidi@switch@exit #3 \@bidi@fi
  \bidi@switch {#1}
}
% this version puts the test object in {}
\def\bidi@oswitch #1 in: #2 #3; {\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1{#2}\bidi@switch@exit #3 \@bidi@fi
  \bidi@switch #1 in:
}
% this version assumes that the test object is just one character
\def\bidi@cswitch #1 in: #2 #3; {\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1#2\bidi@switch@exit #3 \@bidi@fi
  \bidi@cswitch #1 in:
}
% this version assumes that the test object can have an optional space
\def\bidi@bswitch #1 in: #2 #3; {\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1#2 \bidi@switch@exit #3 \@bidi@fi
  \bidi@bswitch #1 in:
}
% this version can cope with significant spaces at the start of #3;
% #2 is macro argument
\def\bidi@mswitch #1 in: #2:#3; {\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1{#2}\bidi@switch@exit #3 \@bidi@fi
  \bidi@mswitch #1 in:
}
% idem; #2 does not have to be enclosed in braces
\def\bidi@fswitch #1 in: #2:#3; {\bidi@csarg\ifx{#2}\bidi@default\bidi@switch@exit #3 \@bidi@fi
  #1#2 \bidi@switch@exit #3 \@bidi@fi
  \bidi@fswitch #1 in:
}

% Routines for taking the value of a string: 
% if the string is defined as control sequence
% take the value of that, otherwise take the string itself

% String or value of control sequence
%
\def\bidi@w@w#1{\if\bidi@undefinedcs{#1}#1\else \the\csname#1\endcsname\fi}

% String or control sequence
%
\def\@bidi@ww#1{\if\bidi@undefinedcs{#1}#1\else \csname#1\endcsname \fi}

% String or \noexpand-ed control sequence;
% for use in \edef
%
\newif\ifbidi@in@label
\def\@bidi@w@w#1{\if\bidi@undefinedcs{#1}#1\else 
            \ifbidi@in@label\noexpand\protect\fi \bidi@csname{#1}\fi}
\newtoks\bidi@are@these@correct
\def\bidi@t@w@w#1{%
    \if\bidi@undefinedcs{#1}#1%
        \ifdefining\bidi@append@to@list\bidi@are@these@correct{#1 }\fi
    \else 
        \ifin@label\noexpand\protect\fi \bidi@csname{#1}\fi}
        
% List Manipulation ................
% this assumes that #1 is a list of tokens, #2 is the name of a list
%
% Names of lists (and of items to pop into) are given as strings;
% not as control sequences.
%
\newtoks\bidi@toks@lista \newtoks\bidi@toks@listb
% basic append/prepend macro
\long\def\@bidi@append@to@cslist#1#2#3{\begingroup\bidi@toks@lista=#2{#3}%
  \global#1=\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\the\bidi@toks@lista}\endgroup}
\long\def\@bidi@prepend@to@cslist#1#2#3{\begingroup\bidi@toks@lista=#2{#3}%
  \global#1=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\bidi@toks@lista\the#1}\endgroup}
\def\@bidi@append@to@list{\bidi@csarg\@bidi@append@to@cslist}
\def\@bidi@prepend@to@list{\bidi@csarg\@bidi@prepend@to@cslist}
% variations:
\long\def\bidi@append@to@list#1#2{\@bidi@append@to@list{#1}{}{#2}}
\long\def\bidi@prepend@to@list#1#2{\@bidi@prepend@to@list{#1}{}{#2}}
\def\bidi@append@list@to@list#1#2{%
  \@bidi@append@to@list{#1}{\expandafter\expandafter\expandafter}{\expandafter\the\csname#2\endcsname}}
\def\bidi@prepend@list@to@list#1#2{%
  \@bidi@prepend@to@list{#1}{\expandafter\expandafter\expandafter}{\expandafter\the\csname#2\endcsname}}
\def\bidi@append@cslist@to@cslist#1#2{%
  \@bidi@append@to@cslist{#1}\expandafter{\the#2}}
\def\bidi@prepend@cslist@to@cslist#1#2{%
  \@bidi@prepend@to@cslist{#1}\expandafter{\the#2}}
\def\bidi@append@toks@cs@to@list#1#2{\@bidi@append@to@list{#1}\expandafter{\the#2}}
\def\bidi@prepend@toks@cs@to@list#1#2{\@bidi@prepend@to@list{#1}\expandafter{\the#2}}

\let\bidi@willbeunhskip\unhskip

% A few list macros for the user
\def\NewTokenList:#1 {\bidi@csarg\newtoks{#1}\global\csname#1\endcsname{}}
\def\EmptyTokenList:#1 {\global\csname#1\endcsname{}}
\long\def\AppendToTokenList:#1=#2 {\@bidi@append@to@list{#1}{}{#2}}
\long\def\PrependToTokenList:#1=#2 {\@bidi@prepend@to@list{#1}{}{#2}}
\def\TheTokenList:#1 {\let\bidi@oldwbuskip\bidi@willbeunhskip \let\bidi@willbeunhskip\@empty
    \if\bidi@undefinedcs{#1}\bidi@error{Token List <#1> undefined}
    \else\bidi@csarg\the{#1}\fi
    \let\bidi@willbeunhskip\bidi@oldwbuskip}

\def\bidi@del@tok@from@list#1#2{\begingroup
    \long\def\bidi@cs@liste##1#2##2\bidi@tok@SM
       {\bidi@toks@lista{##1}\bidi@toks@listb{##2}%
        \edef\bidi@cs@listb{\global\bidi@csname{#1}=
                {\the\bidi@toks@lista\the\bidi@toks@listb}}%
        \bidi@cs@listb}%
    \edef\bidi@cs@lista{\noexpand\bidi@cs@liste{}\expandafter\the\csname#1\endcsname\noexpand\bidi@tok@SM}%
    \bidi@cs@lista \endgroup}
\def\bidi@in@front@of@list#1{\bidi@csarg{\let\expandafter\bidi@cs@lista}{#1}%
  \bidi@in@front@of@cslist\bidi@cs@lista}
\long\def\bidi@in@front@of@cslist#1#2{\begingroup\bidi@toks@lista={#2}%
  \global#1=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\bidi@toks@lista \the#1}%
  \endgroup}
\long\def\bidi@local@in@front@of@list#1#2{\bidi@toks@lista={#2}%
    \csname#1\endcsname\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
                {\expandafter\expandafter\expandafter\the\expandafter\expandafter\expandafter\bidi@toks@lista 
                 \expandafter\the\csname#1\endcsname}%
    }
\def\bidi@set@list#1{\bidi@csarg{\let\expandafter\bidi@cs@lista}{#1}%
  \bidi@set@cslist\bidi@cs@lista}
\long\def\bidi@set@cslist#1#2{\begingroup\bidi@toks@lista={#2}%
   \global#1=\expandafter{\the\bidi@toks@lista}\endgroup}
   
%%%%%%%%%%%%%%%% Stack macros
%
% push in terms of prepending of lists
\def\bidi@push@cs@onto@cs#1#2{\@bidi@prepend@to@cslist#1\expandafter{\expandafter\\\expandafter{\the#2}}}
\def\bidi@push@onto#1{\bidi@csarg\bidi@push@onto@cs{#1}}
\def\bidi@push@onto@cs#1#2{\@bidi@prepend@to@cslist#1{}{\\{#2}}}
\def\bidi@local@push@onto#1#2{\let\\=\relax 
    \bidi@local@in@front@of@list{#1}{\\{#2}}}
% pop via auxiliary macro: #1 is result, #2 is stack
% two cs arguments
\def\bidi@pop@cs@into#1#2{\edef\bidi@cs@e
   {\noexpand\@@bidi@popinto\noexpand#1\noexpand#2\the#2\noexpand\@@bidi@pop}\bidi@cs@e}
% two string arguments
\def\bidi@pop@into#1#2{\edef\bidi@cs@e
   {\noexpand\@@bidi@popinto\bidi@csname{#1}\bidi@csname{#2}\bidi@csarg\the{#2}\noexpand\@@bidi@pop}\bidi@cs@e}
\long\def\@@bidi@popinto#1#2\\#3#4\@@bidi@pop{#1{#3}#2{#4}}
\def\bidi@copy@stacktop#1#2{%
    \edef\bidi@cs@e{\noexpand\@bidi@copy@stacktop
                   {#1}\bidi@csarg\the{#2}\noexpand\@@bidi@pop}%
    \bidi@cs@e}
\def\@bidi@copy@stacktop#1\\#2#3\@@bidi@pop{\csname#1\endcsname#2\relax}
\newcount\bidi@stack@length \newtoks\bidi@empty@stack \bidi@empty@stack{\\{}}
\def\bidi@length@of@stack#1{\bidi@csarg\bidi@length@of@csstack{#1}}
\def\bidi@length@of@csstack#1{\def\\##1{\advance\bidi@stack@length\@ne}%
  \bidi@stack@length\m@ne \the#1}
% turn a stack upside down
\def\bidi@invert@csstack#1{\bidi@length@of@csstack{#1}%
  \bidi@tempcountb\z@ \bidi@temptoksa\bidi@empty@stack
  \loop\ifnum\bidi@tempcountb<\bidi@stack@length
    \bidi@pop@cs@into\bidi@temptoksb#1\advance\bidi@stack@length\m@ne
    \bidi@push@cs@onto@cs\bidi@temptoksa\bidi@temptoksb
%    \bidi@append@cslist@to@cslist\bidi@temptoksb\bidi@temptoksa% append a to b
%    \bidi@temptoksa\bidi@temptoksb
    \repeat% copy b to a
  #1\bidi@temptoksa \bidi@temptoksa\bidi@empty@toks}
% invert a stack into a list
\def\bidi@x@stack@to@list#1{\bidi@length@of@stack{#1}%
  \bidi@tempcountb\z@ \bidi@temptoksa\bidi@empty@toks
  \loop\ifnum\bidi@tempcountb<\bidi@stack@length
    \bidi@pop@into{bidi@temptoksb}{#1}\advance\bidi@stack@length\m@ne
    \bidi@append@list@to@list{bidi@temptoksb}{bidi@temptoksa}\repeat
  \csname#1\endcsname\bidi@temptoksa \bidi@temptoksa\bidi@empty@toks}   


% General loop macro:
% \looprepeat
%   \forvariable{<var>} \fromvalue{<start>} \bystep{<step>} \tovalue{<end>} \downtovalue{<end>}
%               \untilcondition{<cond>} \whilecondition{<cond>}
%   \doloopbody { <loop body> }
% where all control sequences in between \looprepeat and \doloopbody are optional.
%
% var: characters to form a control sequence;
%    after \forvariable{index} you can access the loop counter as \index.
%    This is a count register; to print it use \number\index.
% start,step,end: integers with obvious relations to the loop counter;
%    start and step have a default value of 1
% cond: (sequence of commands ending in) any TeX \if... test.
%
% Count down instead of up with \downtovalue; the increment given in \bystep
% is always positive, and is added or subtracted accordingly.
%
% Tests: \untilcondition is evaluated at the end of the loop body; \whilecondition
% at the beginning of the loop body.
%
% Exit from middle of loop: \breaklooprepeat
% use this at any place in the loop; in case of a conditional use
%   \ifsomething ... \expandafter \breaklooprepeat \fi
%
% Note that the line ends do not cause spaces in the output.
%
% Technical details:
% The loop body is not executed in a group: the braces are those
% of a token list.
% The `forvariable' variable is \let to a \count register.



% Auxiliary stuff
\def\bidi@looprepeat@csarg#1#2{\expandafter#1\csname#2\endcsname}
\def\bidi@looprepeat@csromannumeral#1{\csname #1\romannumeral\bidi@looprepeat@depth\endcsname}
\def\bidi@looprepeat@csargromannumeral#1#2{\expandafter#1\csname#2\romannumeral\bidi@looprepeat@depth\endcsname}

\newcount\bidi@looprepeat@depth
\let\endlooprepeat\relax \def\bidi@csprotect{}
% Trace switches may later be defined by PAC_utils
\let\bidi@looprepeat@traceinit\relax \let\bidi@looprepeat@traceexit\relax

% Main repeatloop macro
% - go to next level and allocate unique counter/toks if this is the
%   first time we visit this level
% - setup: gather bounds and termination conditions
% - scoop up body in token list; after the assignment define and
%   execute body
\def\looprepeat#1\doloopbody{\bidi@looprepeat@traceinit % exit in \breakrepeatloop
  \advance\bidi@looprepeat@depth\@ne\relax
  \bidi@looprepeat@csargromannumeral\ifx{bidi@looprepeat@count}\relax
    \bidi@looprepeat@csargromannumeral{\csname newcount\expandafter\endcsname}{bidi@looprepeat@count}%
    \bidi@looprepeat@csargromannumeral{\csname newtoks\expandafter\endcsname}{bidi@looprepeat@toks}%
    \bidi@looprepeat@csargromannumeral{\csname newtoks\expandafter\endcsname}{bidi@looprepeat@wtest}%
    \bidi@looprepeat@csargromannumeral{\csname newtoks\expandafter\endcsname}{bidi@looprepeat@utest}%
  \fi \bidi@looprepeat@zero \def\bidi@looprepeat@sign{}\def\bidi@looprepeat@comp{>}\bidi@looprepeat@setup{#1}%
  \edef\bidi@looprepeat@tmp
     {\def\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@looprepeat}{\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@body}}}\bidi@looprepeat@tmp
  \afterassignment\bidi@looprepeat@dxbody\bidi@looprepeat@csromannumeral{bidi@looprepeat@toks}}
  
% Define and execute loop body
% This is done with an \edef to construct the actual sequence
\def\bidi@looprepeat@dxbody{\bidi@looprepeat@csargromannumeral\edef{bidi@looprepeat@body}{%
    \bidi@looprepeat@csargromannumeral\the{bidi@looprepeat@wtest}%
      \noexpand\the\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@toks}%
        \bidi@looprepeat@csargromannumeral\the{bidi@looprepeat@utest}%
    \global\bidi@looprepeat@csargromannumeral\advance{bidi@looprepeat@count} by \bidi@looprepeat@sign\bidi@looprepeat@csromannumeral{bidi@looprepeat@inc}\relax
    \noexpand\endlooprepeat
    \bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@looprepeat}}%
  \bidi@looprepeat@csromannumeral{bidi@looprepeat@body}\ignorespaces}
  
% Stop test
%% In order to stop, issue a
% \breaklooprepeat which scoops up the rest of the body and exits
\def\breaklooprepeat#1\endlooprepeat{\bidi@looprepeat@zero\bidi@looprepeat@csargromannumeral\let{bidi@looprepeat@looprepeat}\relax
  \advance\bidi@looprepeat@depth\m@ne \bidi@looprepeat@traceexit
  }
  

% Setup
% gather bounds and termination conditions
\def\bidi@looprepeat@setup#1{%
  \begingroup
    \def\forvariable##1{%
      \edef\bidi@looprepeat@tmp{%
        \global\let\bidi@looprepeat@csarg\noexpand{##1}\bidi@looprepeat@csromannumeral{bidi@looprepeat@count}\ignorespaces}%
      \bidi@looprepeat@tmp}%
    \def\fromvalue##1{\bidi@looprepeat@csargromannumeral\global{bidi@looprepeat@count}##1\ignorespaces}%
    \def\tovalue##1{%
      \edef\bidi@looprepeat@tmp{\global\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@wtest}=
       {\bidi@looprepeat@csargromannumeral\the{bidi@looprepeat@wtest}%
        \noexpand\ifnum\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@count}\bidi@looprepeat@comp##1\relax
          \noexpand\expandafter \noexpand\breaklooprepeat 
        \noexpand\fi}\ignorespaces}%
      \bidi@looprepeat@tmp}%
    \def\downtovalue##1{%
      \gdef\bidi@looprepeat@sign{-}\gdef\bidi@looprepeat@comp{<}\tovalue{##1}\ignorespaces}%
    \def\bystep##1{\ifnum##1<0 \bidi@error{LOOPREPEAT: increment has to be a positive value}\@ehc%
               \bidi@looprepeat@csargromannumeral\gdef{bidi@looprepeat@inc}{-##1}\else
               \bidi@looprepeat@csargromannumeral\gdef{bidi@looprepeat@inc}{##1}\fi\ignorespaces}%
    \def\untilcondition##1{%
      \edef\bidi@looprepeat@tmp{\global\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@utest}=
         {\noexpand##1\relax
          \noexpand\expandafter \noexpand\breaklooprepeat \noexpand\fi}\ignorespaces}%
      \bidi@looprepeat@tmp}%
    \def\whilecondition##1{%
      \edef\bidi@looprepeat@tmp{\global\bidi@looprepeat@csargromannumeral\noexpand{bidi@looprepeat@wtest}=
         {\noexpand##1\relax \noexpand\else
          \noexpand\expandafter \noexpand\breaklooprepeat \noexpand\fi}\ignorespaces}%
    \bidi@looprepeat@tmp}%
    \fromvalue{\@ne}\bystep{\@ne}#1%
  \endgroup}
\def\bidi@looprepeat@zero
   {\bidi@looprepeat@csromannumeral{bidi@looprepeat@toks}{}\bidi@looprepeat@csromannumeral{bidi@looprepeat@utest}{}\bidi@looprepeat@csromannumeral{bidi@looprepeat@wtest}{}%
    \bidi@looprepeat@csargromannumeral\def{bidi@looprepeat@body}{}}     

%\tracingmacros2
%\newcount\tmpcount % used in some examples below

%\looprepeat \forvariable{i}
%        \bystep{2}
%  \doloopbody {%
%     \ifnum\i=13 \expandafter\breaklooprepeat \fi
%     \number\i{} %
%}%

%\looprepeat \forvariable{iii}
%        \tovalue{8}
%   \doloopbody {}
%After loop: \number\iii%

%\looprepeat \forvariable{i}
%        \fromvalue{10}
%        \bystep{2}
%        \downtovalue{0}
%   \doloopbody {\number\i{} }

%\looprepeat \forvariable{x} \whilecondition{\ifnum\x<7}
%   \doloopbody {\number\x{} }

%\looprepeat \tovalue{3} \doloopbody {Hello world! }

%\looprepeat \forvariable{j}
%        \untilcondition{\tmpcount\j \divide\tmpcount by 37 \noexpand\ifnum\tmpcount=1}
%  \doloopbody {\number\j{} }

%\looprepeat \forvariable{i} \bystep{2} \tovalue{10} \doloopbody
% {\looprepeat \forvariable{j} \fromvalue{\i} \bystep{3} \tovalue{18} 
%  \doloopbody {(\number\i.\number\j) }
% }

% infinite loop
%\looprepeat \doloopbody {}

\ExplSyntaxOn
\NewDocumentCommand \bidi@AfterClass { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \@ifclassloaded{ #2 }
          { #4 }
          {
            \hook_gput_code:nnn
              { file / #2.\@clsextension / after }
              { #3 }
              { #4 }
          }
      }
      {
        \hook_gput_code:nnn { file / #2.\@clsextension / after } { #3 } { #4 }
      }
  }
  
\seq_new:N \g__biditools_input_file_seq

\prg_new_protected_conditional:Npnn \__bidi_if_loading:n #1 { T, F, TF }
  {
    \str_set:Nx \l_tmpa_str { #1 }
    \seq_if_in:NxTF \g__biditools_input_file_seq { \str_use:N \l_tmpa_str }
      { \prg_return_true: }
      { \prg_return_false: }
  }

\prg_new_protected_conditional:Npnn \bidi_if_class_loaded:n #1 { T, F, TF }
  {
    \@ifclassloaded { #1 }
      {
        \__bidi_if_loading:nTF { #1.\@clsextension }
          { \prg_return_false: }
          { \prg_return_true: }
      }
      {
        \prg_return_false:
      }
  }
  
\prg_new_protected_conditional:Npnn \bidi_if_package_loaded:n #1 { T, F, TF }
  {
    \@ifpackageloaded { #1 }
      {
        \__bidi_if_loading:nTF { #1.\@pkgextension }
          { \prg_return_false: }
          { \prg_return_true: }
      }
      {
        \prg_return_false:
      }
  }

\NewDocumentCommand \bidi@AfterAtEndOfClass { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \bidi_if_class_loaded:nTF { #2 }
          { #4 }
          { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
      }
      {
        \bidi_if_class_loaded:nF
          { #2 }
          { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
      }
  }
  
\NewDocumentCommand \bidi@AfterPackage { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \@ifpackageloaded{ #2 }
          { #4 }
          {
            \hook_gput_code:nnn
              { file / #2.\@pkgextension / after }
              { #3 }
              { #4 }
          }
      }
      {
        \hook_gput_code:nnn { file / #2.\@pkgextension / after } { #3 } { #4 }
      }
  }
  
\NewDocumentCommand \bidi@AfterAtEndOfPackage { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \bidi_if_package_loaded:nTF { #2 }
          { #4 }
          { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
      }
      {
        \bidi_if_package_loaded:nF
          { #2 }
          { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
      }
  }
  
\clist_new:N \l__biditools_package_clist
\msg_new:nnn { biditools } { cannot-prevent-for-already-loaded-package }
  {
    Can~not~prevent~package~`#1'~from~being~loaded,~
    since~it~has~been~loaded~already~before~line~\msg_line_number:
  }
\clist_new:N \g__biditools_prevent_clist

\NewDocumentCommand \bidi@PreventPackageFromLoading { s +o m }
  {
    \clist_set:Nx \l__biditools_package_clist { #3 }
    \clist_map_inline:Nn \l__biditools_package_clist
      {
        \@ifpackageloaded { ##1 }
          {
            \IfBooleanTF { #1 } { \msg_info:nnn } { \msg_warning:nnn }
              { biditools } { cannot-prevent-for-already-loaded-package } { ##1 }
          }
          {
            \clist_if_in:NnF \g__biditools_prevent_clist { ##1 }
              { \clist_gput_right:Nn \g__biditools_prevent_clist { ##1 } }
            \tl_if_exist:cF { g__biditools_exclude_package_##1_tl }
              {
                \tl_new:c { g__biditools_exclude_package_##1_tl }
              }
            \IfValueT { #2 }
              {
                \tl_gput_right:cn { g__biditools_exclude_package_##1_tl } { #2 }
              }
            \disable@package@load { ##1 }
              { \tl_use:c { g__biditools_exclude_package_##1_tl } }
          }
      }
    \clist_clear:N \l__biditools_package_clist
  }
  
\NewDocumentCommand \bidi@ResetPreventPackageFromLoading {}
  {
    \clist_map_function:NN \g__biditools_prevent_clist \reenable@package@load
    \clist_gclear:N \g__biditools_prevent_clist
  }
  
\NewDocumentCommand \bidi@StorePreventPackageFromLoading { m }
  { \edef #1 { \clist_use:Nn \g__biditools_prevent_clist { , } } }

\NewDocumentCommand \bidi@UnPreventPackageFromLoading { s m }
  {
    \clist_set:Nx \l__biditools_package_clist { #2 }
    \clist_map_inline:Nn \l__biditools_package_clist
      {
        \clist_if_in:NnT \g__biditools_prevent_clist { ##1 }
          {
            \clist_gremove_all:Nn \g__biditools_prevent_clist { ##1 }
            \reenable@package@load { ##1 }
            \IfBooleanT { #1 }
              { \cs_undefine:c { g__biditools_exclude_package_##1_tl } }
          }
      }
  }

\NewDocumentCommand \bidi@BeforeClosingMainAux { o m }
  {
    \hook_gput_code:nnn { enddocument / afterlastpage } { #1 }
      {
        \debug_suspend:
        \RenewDocumentCommand \bidi@BeforeClosingMainAux { m } { ##1 }
        \cs_set_eq:NN \__biditools_protected@write:Nnn \protected@write
        \cs_set_eq:NN \protected@write \bidi@protected@immediate@write
        #2
        \cs_set_eq:NN \protected@write \__biditools_protected@write:Nnn
        \debug_resume:
      }
  }

\NewDocumentCommand \bidi@AfterReadingMainAux { o m }
  {
    \hook_gput_code:nnn { enddocument / afteraux } { #1 }
      {
        \debug_suspend:
        \RenewDocumentCommand \bidi@AfterReadingMainAux { m } { ##1 }
        \cs_set_eq:NN \__biditools_protected@write:Nnn \protected@write
        \cs_set_eq:NN \protected@write \bidi@protected@immediate@write
        #2
        \cs_set_eq:NN \protected@write \__biditools_protected@write:Nnn
        \debug_resume:
      }
  }
  
\clist_new:N \l__biditools_file_patch_clist  
  
\NewDocumentCommand \ApplyPatchToFiles { m O{def} O{bidi} }
  {
    \clist_set:Nx \l__biditools_file_patch_clist { #1 }
    \clist_map_inline:Nn \l__biditools_file_patch_clist
      {
        \ApplyPatchToFile { ##1 } [ #2 ] [ #3 ]
      }
    \clist_clear:N \l__biditools_file_patch_clist
  }

\clist_new:N \l__biditools_package_patch_clist  
  
\NewDocumentCommand \ApplyPatchToPackages { m O{bidi} }
  {
    \clist_set:Nx \l__biditools_package_patch_clist { #1 }
    \clist_map_inline:Nn \l__biditools_package_patch_clist
      {
        \ApplyPatchToPackage { ##1 } [ #2 ]
      }
    \clist_clear:N \l__biditools_package_patch_clist
  }
  
\clist_new:N \l__biditools_class_patch_clist  
  
\NewDocumentCommand \ApplyPatchToClasses { m O{bidi} }
  {
    \clist_set:Nx \l__biditools_class_patch_clist { #1 }
    \clist_map_inline:Nn \l__biditools_class_patch_clist
      {
        \ApplyPatchToClass { ##1 } [ #2 ]
      }
    \clist_clear:N \l__biditools_class_patch_clist
  }
  
\NewDocumentCommand \ApplyPatchToClassesIfPackageLoadedF { m m O{bidi} }
  {
    \clist_set:Nx \l__biditools_class_patch_clist { #1 }
    \clist_map_inline:Nn \l__biditools_class_patch_clist
      {
        \ApplyPatchToClassIfPackageLoadedF { ##1 } { #2 } [ #3 ]
      }
    \clist_clear:N \l__biditools_class_patch_clist
  }
\ExplSyntaxOff

\newcommand*{\bidi@ReplaceInput}{\declare@file@substitution}
\newcommand*{\bidi@UnReplaceInput}
{\undeclare@file@substitution}
\newcommand*{\bidi@ReplacePackage}[2]{%
  \declare@file@substitution{#1.\@pkgextension}{#2.\@pkgextension}%
}
\newcommand*{\bidi@UnReplacePackage}[1]{%
  \undeclare@file@substitution{#1.\@pkgextension}%
}
\newcommand*{\bidi@ReplaceClass}[2]{%
  \declare@file@substitution{#1.\@clsextension}{#2.\@clsextension}%
}
\newcommand*{\bidi@UnReplaceClass}[1]{%
  \undeclare@file@substitution{#1.\@clsextension}%
}
\newcommand*{\bidi@BeforeFile}[1]{%
  \AddToHook{file/#1/before}%
}
\newcommand*{\bidi@AfterFile}[1]{%
  \AddToHook{file/#1/after}%
}
\newcommand*{\bidi@BeforeClass}[1]{%
    \bidi@BeforeFile{#1.\@clsextension}%
}
\newcommand*{\bidi@BeforePackage}[1]{%
  \bidi@BeforeFile{#1.\@pkgextension}%
}

\long\def\bidi@protected@immediate@write#1#2#3{%
  \begingroup
    #2%
    \let\protect\@unexpandable@protect
    \edef\reserved@a{\immediate\write#1{#3}}%
    \reserved@a
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi
}

\def\bidi@patch@AfterPackage#1{%
  \@ifpackageloaded{#1}{%
    \@firstofone
  }{%
    \AddToHook{package/#1/after}%
  }%
}

\def\bidi@patch@AfterFile#1{%
  \IfFileLoadedTF{#1}{%
    \@firstofone
  }{%
    \AddToHook{file/#1/after}%
  }%
}

\NewDocumentCommand \ApplyPatchToFile { m O{def} O{bidi} }
  {
    \bidi@patch@AfterFile{#1.#2}{%
      \ifnum\catcode`\@=11
        \input{#1-xetex-#3.def}%
      \else
        \bidi@storecatcode\@
        \makeatletter
        \input{#1-xetex-#3.def}%
        \bidi@restorecatcode\@
      \fi
    }%
  }
  
\NewDocumentCommand \ApplyPatchCodeToFile { m +m O{def} }
  {
    \bidi@patch@AfterFile{#1.#3}{#2}%
  }
  
\NewDocumentCommand \ApplyPatchToFilesIfPackageLoadedF { m m O{def} O{bidi} }
  {
    \AddToHook{begindocument/before}{%
      \IfPackageLoadedF{#1}{%
        \ApplyPatchToFiles{#2}[#3][#4]%
      }%
    }
  }
  
\NewDocumentCommand \ApplyPatchToClassIfPackageLoadedF { m m O{bidi} }
  {
    \AddToHook{begindocument/before}{%
      \IfPackageLoadedF{#2}{%
        \ifnum\catcode`\@=11
          \@ifclassloaded{#1}{%
            \input{#1-xetex-#3.def}%
          }{}%
        \else
          \bidi@storecatcode\@
          \makeatletter
          \@ifclassloaded{#1}{%
            \input{#1-xetex-#3.def}%
          }{}%
          \bidi@restorecatcode\@
        \fi
      }%
    }
  }
  
\NewDocumentCommand \ApplyPatchToPackageIfPackageLoadedF { m m O{bidi} }
  {
    \AddToHook{begindocument/before}{%
      \IfPackageLoadedF{#2}{%
        \IfPackageLoadedT{#1}{%
          \ifnum\catcode`\@=11
            \input{#1-xetex-#3.def}%
          \else
            \bidi@storecatcode\@
            \makeatletter
            \input{#1-xetex-#3.def}%
            \bidi@restorecatcode\@
          \fi
        }%
      }%
    }
  }
  
\NewDocumentCommand \ApplyPatchIfPackageLoaded { m +m +m }
  {
    \AddToHook{begindocument/before}{%
       \ifnum\catcode`\@=11
         \@ifpackageloaded{#1}{#2}{#3}%
       \else
         \bidi@storecatcode\@
         \makeatletter
         \@ifpackageloaded{#1}{#2}{#3}%
         \bidi@restorecatcode\@
       \fi
    }
  }
  
\NewDocumentCommand \ApplyPatchIfPackageLoadedT { m +m }
  {
    \ApplyPatchIfPackageLoaded{#1}{#2}{}%
  }
  
\NewDocumentCommand \ApplyPatchIfPackageLoadedF { m +m }
  {
    \ApplyPatchIfPackageLoaded{#1}{}{#2}%
  }

\NewDocumentCommand \ApplyPatchToPackage { m O{bidi} }
  {
    \bidi@patch@AfterPackage{#1}{\input{#1-xetex-#2.def}}%
  }

\NewDocumentCommand \ApplyPatchCodeToPackage { m +m }
  {
    \bidi@patch@AfterPackage{#1}{#2}%
  }
  
\NewDocumentCommand \ApplyPatchToClass { m O{bidi} }
  {
    \@ifclassloaded{#1}{\input{#1-xetex-#2.def}}{}%
  }
%    \end{macrocode}
% \iffalse
%</biditools.sty>
%<*bidituftefloat.sty>
%\fi
% \section{File \texttt{bidituftefloat.sty}}
%    \begin{macrocode}
\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}
%%
% Turns newlines into spaces.  Based on code from the `titlesec' package.
\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}}
}
% The running heads/feet don't have rules
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
% The 'fancy' page style is the default style for all pages.
\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}}%
% The `plain' page style is used on chapter opening pages.
% In Tufte's /Beautiful Evidence/ he never puts page numbers at the
% bottom of pages -- the folios are unexpressed.
\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}}
}
% The `empty' page style suppresses all headers and footers.
% It's used on title pages and `intentionally blank' pages.
\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}
%    \end{macrocode}
% \iffalse
%</bidituftefloat.sty>
%<*bidituftesidenote.sty>
%\fi
% \section{File \texttt{bidituftesidenote.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftesidenote}[2017/08/09 v0.4
bidi implementation of tufte sidenote]
\RequirePackage{xifthen}
\RequirePackage{ragged2e}
\RequirePackage{setspace}
\RequirePackage{biditools}
\def\bidituftesidenotemarginpar{%
  \ifhmode
    \@bsphack
    \@floatpenalty -\@Mii
  \else
    \@floatpenalty-\@Miii
  \fi
  \ifinner
    \@parmoderr
    \@floatpenalty\z@
  \else
    \@next\@currbox\@freelist{}{}%
    \@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
       {\@floatpenalty\z@
        \@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
  \fi
  \@ifnextchar [\@bidituftesidenotexmpar\@bidituftesidenoteympar}
\long\def\@bidituftesidenotexmpar[#1]#2{%
  \@bidituftesidenotesavemarbox\@marbox{#1}%
  \@bidituftesidenotesavemarbox\@currbox{#2}%
  \@xympar}
\long\def\@bidituftesidenoteympar#1{%
  \@bidituftesidenotesavemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\long\def \@bidituftesidenotesavemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@bidituftesidenotemarginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\def \@bidituftesidenotemarginparreset {%
        \reset@font
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\if@RTL@footnote\beginR\else\beginL\fi}%
}
\def\LTRbidituftesidenotemarginpar{%
  \ifhmode
    \@bsphack
    \@floatpenalty -\@Mii
  \else
    \@floatpenalty-\@Miii
  \fi
  \ifinner
    \@parmoderr
    \@floatpenalty\z@
  \else
    \@next\@currbox\@freelist{}{}%
    \@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
       {\@floatpenalty\z@
        \@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
  \fi
  \@ifnextchar [\@LTRbidituftesidenotexmpar\@LTRbidituftesidenoteympar}
\long\def\@LTRbidituftesidenotexmpar[#1]#2{%
  \@LTRbidituftesidenotesavemarbox\@marbox{#1}%
  \@LTRbidituftesidenotesavemarbox\@currbox{#2}%
  \@xympar}
\long\def\@LTRbidituftesidenoteympar#1{%
  \@LTRbidituftesidenotesavemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\long\def \@LTRbidituftesidenotesavemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@LTRbidituftesidenotemarginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\def \@LTRbidituftesidenotemarginparreset {%
        \reset@font
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\beginL}%
}
\def\RTLbidituftesidenotemarginpar{%
  \ifhmode
    \@bsphack
    \@floatpenalty -\@Mii
  \else
    \@floatpenalty-\@Miii
  \fi
  \ifinner
    \@parmoderr
    \@floatpenalty\z@
  \else
    \@next\@currbox\@freelist{}{}%
    \@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
       {\@floatpenalty\z@
        \@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
  \fi
  \@ifnextchar [\@RTLbidituftesidenotexmpar\@RTLbidituftesidenoteympar}
\long\def\@RTLbidituftesidenotexmpar[#1]#2{%
  \@RTLbidituftesidenotesavemarbox\@marbox{#1}%
  \@RTLbidituftesidenotesavemarbox\@currbox{#2}%
  \@xympar}
\long\def\@RTLbidituftesidenoteympar#1{%
  \@RTLbidituftesidenotesavemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\long\def \@RTLbidituftesidenotesavemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@RTLbidituftesidenotemarginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\def \@RTLbidituftesidenotemarginparreset {%
        \reset@font
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\beginR}%
}
\newcommand*{\@bidituftesidenote@marginfont}{\normalfont\footnotesize}
\newcommand*{\@bidituftesidenote@LTRmarginfont}{\normalfont\footnotesize}
\newcommand*{\@bidituftesidenote@RTLmarginfont}{\normalfont\footnotesize}
\newcommand*{\@bidituftesidenote@sidenote@font}{\@bidituftesidenote@marginfont}
\newcommand*{\@bidituftesidenote@LTRsidenote@font}{\@bidituftesidenote@LTRmarginfont}
\newcommand*{\@bidituftesidenote@RTLsidenote@font}{\@bidituftesidenote@RTLmarginfont}
\newcommand*{\@bidituftesidenote@marginnote@font}{\@bidituftesidenote@marginfont}
\newcommand*{\@bidituftesidenote@LTRmarginnote@font}{\@bidituftesidenote@LTRmarginfont}
\newcommand*{\@bidituftesidenote@RTLmarginnote@font}{\@bidituftesidenote@RTLmarginfont}
\newcommand*{\@bidituftesidenote@citation@font}{\@bidituftesidenote@marginfont}
\newcommand*{\@bidituftesidenote@LTRcitation@font}{\@bidituftesidenote@LTRmarginfont}
\newcommand*{\@bidituftesidenote@RTLcitation@font}{\@bidituftesidenote@RTLmarginfont}
\newcommand*{\setsidenotefont}[1]{\renewcommand*{\@bidituftesidenote@sidenote@font}{#1}}
\newcommand*{\setLTRsidenotefont}[1]{\renewcommand*{\@bidituftesidenote@LTRsidenote@font}{#1}}
\newcommand*{\setRTLsidenotefont}[1]{\renewcommand*{\@bidituftesidenote@RTLsidenote@font}{#1}}
\newcommand*{\setmarginnotefont}[1]{\renewcommand*{\@bidituftesidenote@marginnote@font}{#1}}
\newcommand*{\setLTRmarginnotefont}[1]{\renewcommand*{\@bidituftesidenote@LTRmarginnote@font}{#1}}
\newcommand*{\setRTLmarginnotefont}[1]{\renewcommand*{\@bidituftesidenote@RTLmarginnote@font}{#1}}
\newcommand*{\setcitationfont}[1]{\renewcommand*{\@bidituftesidenote@citation@font}{#1}}
\newcommand*{\setLTRcitationfont}[1]{\renewcommand*{\@bidituftesidenote@LTRcitation@font}{#1}}
\newcommand*{\setRTLcitationfont}[1]{\renewcommand*{\@bidituftesidenote@RTLcitation@font}{#1}}
\newcommand*{\@bidituftesidenote@sidenote@justification}{\@bidituftesidenote@justification@autodetect}
\newcommand*{\@bidituftesidenote@marginnote@justification}{\@bidituftesidenote@justification@autodetect}
\newcommand*{\@bidituftesidenote@citation@justification}{\@bidituftesidenote@justification@autodetect}
\newcommand*{\@bidituftesidenote@justification@autodetect}{\justifying}%
\newcommand{\@bidituftesidenote@margin@par}{%
  \setlength{\RaggedRightParindent}{0.5pc}%
  \setlength{\JustifyingParindent}{0.5pc}%
  \setlength{\parindent}{0.5pc}%
  \setlength{\parskip}{0pt}%
}
%%
% Globally sets the length
\@ifundefined{gsetlength}{%
\newcommand*{\gsetlength}[2]{%
  \setlength{#1}{#2}%
  \global#1=#1\relax%
}%
}{}

%%
% A function that removes leading and trailling spaces from the supplied macro.
% Based on code written by Michael Downes (See ``Around the Bend'', #15.)
% Executing \@bidituftesidenote@trim@spaces\xyzzy will result in the contents of \xyzzy
% being trimmed of leading and trailing white space.
\catcode`\Q=3
\def\@bidituftesidenote@trim@spaces#1{%
  % Use grouping to emulate a multi-token afterassignment queue
  \begingroup%
  % Put `\toks 0 {' into the afterassignment queue
  \aftergroup\toks\aftergroup0\aftergroup{% 
  % Apply \trimb to the replacement text of #1, adding a leading
  % \noexpand to prevent brace stripping and to serve another purpose
  % later.
  \expandafter\@bidituftesidenote@trim@b\expandafter\noexpand#1Q Q}%
  % Transfer the trimmed text back into #1.
  \edef#1{\the\toks0}%
}
% \trimb removes a trailing space if present, then calls \@bidituftesidenote@trim@c to
% clean up any leftover bizarre Qs, and trim a leading space. In
% order for \trimc to work properly we need to put back a Q first.
\def\@bidituftesidenote@trim@b#1 Q{\@bidituftesidenote@trim@c#1Q}
% Execute \vfuzz assignment to remove leading space; the \noexpand
% will now prevent unwanted expansion of a macro or other expandable
% token at the beginning of the trimmed text. The \endgroup will feed
% in the \aftergroup tokens after the \vfuzz assignment is completed.
\def\@bidituftesidenote@trim@c#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1}
\catcode`\Q=11
%%
% Citations should go in the margin as sidenotes

\RequirePackage{natbib}
\RequirePackage{bibentry}        % allows bibitems to be typeset outside thebibliography environment
% Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style
\renewcommand\BR@b@bibitem[2][]{%
  \ifthenelse{\isempty{#1}}%
    {\BR@bibitem{#2}}%
    {\BR@bibitem[#1]{#2}}%
  \BR@c@bibitem{#2}%
}
\bidi@AtEndPreamble{\nobibliography*}                % pre-loads the bibliography keys
%%
% Normal \cite behavior
\newcounter{@bidituftesidenote@num@bibkeys}%
\newcommand{\@bidituftesidenote@normal@cite}[2][0pt]{%
  % Snag the last bibentry in the list for later comparison
  \let\@temp@last@bibkey\@empty%
  \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  \sidenote[][#1]{%
    % Loop through all the bibentries, separating them with semicolons and spaces
    \normalsize\normalfont\@bidituftesidenote@citation@font%
    \setcounter{@bidituftesidenote@num@bibkeys}{0}%
    \@for\@temp@bibkeyx:=#2\do{%
      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
        {\ifthenelse{\equal{\value{@bidituftesidenote@num@bibkeys}}{0}}{}{and\ }%
         \@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx}}%
        {\@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx};\ }%
      \stepcounter{@bidituftesidenote@num@bibkeys}%
    }%
  }%
}
\newcommand{\@biditufteLTRsidenote@normal@cite}[2][0pt]{%
  % Snag the last bibentry in the list for later comparison
  \let\@temp@last@bibkey\@empty%
  \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  \LTRsidenote[][#1]{%
    % Loop through all the bibentries, separating them with semicolons and spaces
    \normalsize\normalfont\@bidituftesidenote@LTRcitation@font%
    \setcounter{@bidituftesidenote@num@bibkeys}{0}%
    \@for\@temp@bibkeyx:=#2\do{%
      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
        {\ifthenelse{\equal{\value{@bidituftesidenote@num@bibkeys}}{0}}{}{and\ }%
         \@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx}}%
        {\@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx};\ }%
      \stepcounter{@bidituftesidenote@num@bibkeys}%
    }%
  }%
}
\newcommand{\@biditufteRTLsidenote@normal@cite}[2][0pt]{%
  % Snag the last bibentry in the list for later comparison
  \let\@temp@last@bibkey\@empty%
  \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  \RTLsidenote[][#1]{%
    % Loop through all the bibentries, separating them with semicolons and spaces
    \normalsize\normalfont\@bidituftesidenote@citation@font%
    \setcounter{@bidituftesidenote@num@bibkeys}{0}%
    \@for\@temp@bibkeyx:=#2\do{%
      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
        {\ifthenelse{\equal{\value{@bidituftesidenote@num@bibkeys}}{0}}{}{and\ }%
         \@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx}}%
        {\@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx};\ }%
      \stepcounter{@bidituftesidenote@num@bibkeys}%
    }%
  }%
}
%%
% Macros for holding the list of cite keys until after the \sidenote
\gdef\@bidituftesidenote@citations{}% list of cite keys
\newcommand\@bidituftesidenote@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
  \ifx\@bidituftesidenote@citations\@empty\else
    \g@addto@macro\@bidituftesidenote@citations{,}% separate by commas
  \fi
  \g@addto@macro\@bidituftesidenote@citations{#1}
}
\newcommand{\@bidituftesidenote@print@citations}[1][0pt]{% puts the citations in a margin note
  % Snag the last bibentry in the list for later comparison
  \let\@temp@last@bibkey\@empty%
  \@for\@temp@bibkey:=\@bidituftesidenote@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
  \marginpar{%
    \hbox{}\vspace*{#1}%
    \@bidituftesidenote@citation@font%
    \@bidituftesidenote@citation@justification%
    \@bidituftesidenote@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}%
    % Loop through all the bibentries, separating them with semicolons and spaces
    \setcounter{@bidituftesidenote@num@bibkeys}{0}%
    \@for\@temp@bibkeyx:=\@bidituftesidenote@citations\do{%
      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
        {\ifthenelse{\equal{\value{@bidituftesidenote@num@bibkeys}}{0}}{}{and\ }%
         \@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx}}%
        {\@bidituftesidenote@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \bibentry{\@temp@bibkeyx};\ }%
      \stepcounter{@bidituftesidenote@num@bibkeys}%
    }%
  }%
}
%%
% \cite behavior when executed within a sidenote
\newcommand{\@bidituftesidenote@sidenote@citations}{}% contains list of \cites in sidenote
\newcommand{\@bidituftesidenote@infootnote@cite}[1]{%
  \@bidituftesidenote@add@citation{#1}
}
%%
% Set the default \cite style.  This is set and reset by the \sidenote command.
\let\cite\@bidituftesidenote@normal@cite
\let\LTRcite\@biditufteLTRsidenote@normal@cite
\let\RTLcite\@biditufteRTLsidenote@normal@cite
%%
% Transform existing \footnotes into \sidenotes
% Sidenote: ``Where God meant footnotes to go.'' ---bidituftesidenote
\RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
\providecommand{\footnotelayout}{\@bidituftesidenote@sidenote@font\@bidituftesidenote@sidenote@justification}
\renewcommand{\footnotelayout}{\@bidituftesidenote@sidenote@font\@bidituftesidenote@sidenote@justification}
% Override footmisc's definition to set the sidenote marks (numbers) inside the
% sidenote's text block.
\bidi@patch@AfterPackage{bidi}{\long\def\@makefntext#1{\@textsuperscript{\@bidituftesidenote@sidenote@font\tiny\@thefnmark}\,\footnotelayout#1}}
% Set the in-text footnote mark in the same typeface as the body text itself.
\bidi@patch@AfterPackage{bidi}{\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}}}
\providecommand*{\multiplefootnotemarker}{3sp}
\providecommand*{\multfootsep}{,}
\bidi@patch@AfterPackage{bidi}{%
\renewcommand{\@footnotemark}{%
  \leavevmode%
  \ifhmode%
    \edef\@x@sf{\the\spacefactor}%
    \@bidituftesidenote@check@multiple@sidenotes%
    \nobreak%
  \fi%
  \@makefnmark%
  \ifhmode\spacefactor\@x@sf\fi%
  \relax%
}%
}
\newcommand{\@bidituftesidenote@check@multiple@sidenotes}{%
  \ifdim\lastkern=\multiplefootnotemarker\relax%
    \edef\@x@sf{\the\spacefactor}%
    \unkern%
    \textsuperscript{\multfootsep}%
    \spacefactor\@x@sf\relax%
  \fi
}
\bidi@patch@AfterPackage{bidi}{%
\renewcommand\@footnotetext[2][0pt]{%
  \bidituftesidenotemarginpar{%
    \hbox{}\vspace*{#1}%
    \def\baselinestretch {\setspace@singlespace}%
    \reset@font%
    \bidi@@footnotetext@font% \reset@font\footnotesize%
    \@bidituftesidenote@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}\noindent%
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark%
    }%
    \color@begingroup%
       \@makefntext{%
         \ignorespaces#2%
       }%
    \color@endgroup%
  }%
}%
\renewcommand\@LTRfootnotetext[2][0pt]{%
  \LTRbidituftesidenotemarginpar{%
    \hbox{}\vspace*{#1}%
    \def\baselinestretch {\setspace@singlespace}%
    \reset@font%
    \bidi@@LTRfootnotetext@font% \reset@font\footnotesize%
    \@bidituftesidenote@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}\noindent%
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark%
    }%
    \color@begingroup%
       \@makefntext{%
         \ignorespaces#2%
       }%
    \color@endgroup%
  }%
}%
\renewcommand\@RTLfootnotetext[2][0pt]{%
  \RTLbidituftesidenotemarginpar{%
    \hbox{}\vspace*{#1}%
    \def\baselinestretch {\setspace@singlespace}%
    \reset@font%
    \bidi@@RTLfootnotetext@font% \reset@font\footnotesize%
    \@bidituftesidenote@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}\noindent%
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark%
    }%
    \color@begingroup%
       \@makefntext{%
         \ignorespaces#2%
       }%
    \color@endgroup%
  }%
}%
}
%
% Define \sidenote command.  Can handle \cite.
\newlength{\@bidituftesidenote@sidenote@vertical@offset}
\setlength{\@bidituftesidenote@sidenote@vertical@offset}{0pt}
% #1 = footnote num, #2 = vertical offset, #3 = footnote text
\long\def\@bidituftesidenote@sidenote[#1][#2]#3{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \ifthenelse{\NOT\isempty{#2}}{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{#2}%
  }{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{0pt}%
  }%
  \ifthenelse{\isempty{#1}}{%
    % no specific footnote number provided
    \stepcounter\@mpfn%
    \protected@xdef\@thefnmark{\thempfn}%
    \@footnotemark\@footnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }{%
    % specific footnote number provided
    \begingroup%
      \csname c@\@mpfn\endcsname #1\relax%
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup%
    \@footnotemark\@footnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
  \unskip\ignorespaces%               remove extra white space
  \kern-\multiplefootnotemarker%      remove \kern left behind by sidenote
  \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
}
\long\def\@LTRbidituftesidenote@sidenote[#1][#2]#3{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \ifthenelse{\NOT\isempty{#2}}{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{#2}%
  }{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{0pt}%
  }%
  \ifthenelse{\isempty{#1}}{%
    % no specific footnote number provided
    \stepcounter\@mpfn%
    \protected@xdef\@thefnmark{\thempfn}%
    \@footnotemark\@LTRfootnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }{%
    % specific footnote number provided
    \begingroup%
      \csname c@\@mpfn\endcsname #1\relax%
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup%
    \@footnotemark\@LTRfootnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
  \unskip\ignorespaces%               remove extra white space
  \kern-\multiplefootnotemarker%      remove \kern left behind by sidenote
  \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
}
\long\def\@RTLbidituftesidenote@sidenote[#1][#2]#3{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \ifthenelse{\NOT\isempty{#2}}{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{#2}%
  }{%
    \gsetlength{\@bidituftesidenote@sidenote@vertical@offset}{0pt}%
  }%
  \ifthenelse{\isempty{#1}}{%
    % no specific footnote number provided
    \stepcounter\@mpfn%
    \protected@xdef\@thefnmark{\thempfn}%
    \@footnotemark\@RTLfootnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }{%
    % specific footnote number provided
    \begingroup%
      \csname c@\@mpfn\endcsname #1\relax%
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup%
    \@footnotemark\@RTLfootnotetext[\@bidituftesidenote@sidenote@vertical@offset]{#3}%
  }%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
  \unskip\ignorespaces%               remove extra white space
  \kern-\multiplefootnotemarker%      remove \kern left behind by sidenote
  \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
}
\newcommand{\sidenote}{\optparams{\@bidituftesidenote@sidenote}{[][0pt]}}
\newcommand{\LTRsidenote}{\optparams{\@LTRbidituftesidenote@sidenote}{[][0pt]}}
\newcommand{\RTLsidenote}{\optparams{\@RTLbidituftesidenote@sidenote}{[][0pt]}}
\bidi@patch@AfterPackage{bidi}{%
\renewcommand{\footnote}{\optparams{\@bidituftesidenote@sidenote}{[][0pt]}}%
\renewcommand{\LTRfootnote}{\optparams{\@LTRbidituftesidenote@sidenote}{[][0pt]}}%
\renewcommand{\RTLfootnote}{\optparams{\@RTLbidituftesidenote@sidenote}{[][0pt]}}%
}
%%
% Sidenote without the footnote mark
\newcommand\marginnote[2][0pt]{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \bidituftesidenotemarginpar{\hbox{}\vspace*{#1}\@bidituftesidenote@marginnote@font\@bidituftesidenote@marginnote@justification\@bidituftesidenote@margin@par\vspace*{-1\baselineskip}\noindent #2}%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
}
\newcommand\LTRmarginnote[2][0pt]{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \LTRbidituftesidenotemarginpar{\hbox{}\vspace*{#1}\@bidituftesidenote@LTRmarginnote@font\@bidituftesidenote@marginnote@justification\@bidituftesidenote@margin@par\vspace*{-1\baselineskip}\noindent #2}%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
}
\newcommand\RTLmarginnote[2][0pt]{%
  \let\cite\@bidituftesidenote@infootnote@cite%   use the in-sidenote \cite command
  \gdef\@bidituftesidenote@citations{}%           clear out any old citations
  \RTLbidituftesidenotemarginpar{\hbox{}\vspace*{#1}\@bidituftesidenote@RTLmarginnote@font\@bidituftesidenote@marginnote@justification\@bidituftesidenote@margin@par\vspace*{-1\baselineskip}\noindent #2}%
  \@bidituftesidenote@print@citations%            print any citations
  \let\cite\@bidituftesidenote@normal@cite%       go back to using normal in-text \cite command
  \let\LTRcite\@biditufteLTRsidenote@normal@cite%       go back to using normal in-text \LTRcite command
  \let\RTLcite\@biditufteRTLsidenote@normal@cite%       go back to using normal in-text \RTLcite command
}
%    \end{macrocode}
% \iffalse
%</bidituftesidenote.sty>
%<*bidituftetoc.sty>
%\fi
% \section{File \texttt{bidituftetoc.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftetoc}[2011/06/17 v0.1
bidi implementation of tufte toc]
\RequirePackage{titlesec,titletoc,xifthen,biditools}
\newcommand{\@bidituftetoc@pkgname}{bidituftetoc}
\newcommand{\bidituftetocError}[2]{\PackageError{\@bidituftetoc@pkgname}{#1}{#2}}
%%
% Turn off section numbering
\setcounter{secnumdepth}{-1}
\newboolean{@bidituftetoc@toc}
\setboolean{@bidituftetoc@toc}{true}
\DeclareOption{notoc}{\setboolean{@bidituftetoc@toc}{false}}
\DeclareOption{toc}{\setboolean{@bidituftetoc@toc}{true}}
\ProcessOptions
%%
% Make Tuftian-style section headings and TOC formatting
\bidi@patch@AfterPackage{bidi}{%
\titleformat{\chapter}%
  [display]% shape
  {\relax\ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
  {\itshape\huge\thechapter}% label
  {0pt}% horizontal separation between label and title body
  {\huge\rmfamily\itshape}% before the title body
  [\ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}}{\end{fullwidth}}{}]% after the title body
\titleformat{\section}%
  [hang]% shape
  {\normalfont\Large\itshape}% format applied to label+text
  {\thesection}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body
\titleformat{\subsection}%
  [hang]% shape
  {\normalfont\large\itshape}% format applied to label+text
  {\thesubsection}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body
\titleformat{\paragraph}%
  [runin]% shape
  {\normalfont\itshape}% format applied to label+text
  {\theparagraph}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body
\titlespacing*{\chapter}{0pt}{50pt}{40pt}
\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus.2ex}
}
% Subsubsection and following section headings shouldn't be used.
% See Bringhurst's _The Elements of Typography_, section 4.2.2.
\renewcommand\subsubsection{%
  \bidituftetocError{\noexpand\subsubsection is undefined by this class.%
    \MessageBreak See Robert Bringhurst's _The Elements of 
    \MessageBreak Typographic Style_, section 4.2.2.
    \MessageBreak \noexpand\subsubsection was used}
    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as 
    \MessageBreak many levels of headings as you need, no more and no fewer.  Also see the many 
    \MessageBreak related threads on Ask E.T. at http://www.edwardbidituftetoc.com/.}
}
\renewcommand\subparagraph{%
  \bidituftetocError{\noexpand\subparagraph is undefined by this class.%
    \MessageBreak See Robert Bringhurst's _The Elements of 
    \MessageBreak Typographic Style_, section 4.2.2.
    \MessageBreak \noexpand\subparagraph was used}
    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as 
    \MessageBreak many levels of headings as you need, no more and no fewer.  Also see the many 
    \MessageBreak related threads on Ask E.T. at http://www.edwardbidituftetoc.com/.}
}
% Formatting for main TOC (printed in front matter)
% {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
\ifthenelse{\boolean{@bidituftetoc@toc}}{%
 \bidi@patch@AfterPackage{bidi}{%
 \titlecontents{part}% FIXME
    [0em] % distance from left margin
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
    {\contentslabel{2em}} % before w/label (label = ``II'')
    {} % before w/o label
    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
    [\end{fullwidth}] % after
  \titlecontents{chapter}%
    [0em] % distance from left margin
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
    {\hspace*{0em}\contentslabel{2em}} % before w/label (label = ``2'')
    {\hspace*{0em}} % before w/o label
    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
    [\end{fullwidth}] % after
  \titlecontents{section}% FIXME
    [0em] % distance from left margin
    {\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape} % above (global formatting of entry)
    {\hspace*{2em}\contentslabel{2em}} % before w/label (label = ``2.6'')
    {\hspace*{2em}} % before w/o label
    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
    [\end{fullwidth}] % after
  \titlecontents{subsection}% FIXME
    [0em] % distance from left margin
    {\vspace{0\baselineskip}\begin{fullwidth}\large\rmfamily\itshape} % above (global formatting of entry)
    {\hspace*{4em}\contentslabel{4em}} % before w/label (label = ``2.6.1'')
    {\hspace*{4em}} % before w/o label
    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
    [\end{fullwidth}] % after
  \titlecontents{paragraph}% FIXME
    [0em] % distance from left margin
    {\vspace{0\baselineskip}\begin{fullwidth}\normalsize\rmfamily\itshape} % above (global formatting of entry)
    {\hspace*{6em}\contentslabel{2em}} % before w/label (label = ``2.6.0.0.1'')
    {\hspace*{6em}} % before w/o label
    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
    [\end{fullwidth}] % after
}%
}{}
%%
% Format lists of figures/tables
\renewcommand\listoffigures{%
  \@ifundefined{chapter}%
    {\section*{\listfigurename}}%
    {\chapter*{\listfigurename}}%
%  \begin{fullwidth}%
    \@starttoc{lof}%
%  \end{fullwidth}%
}
\renewcommand\listoftables{%
  \@ifundefined{chapter}%
    {\section*{\listtablename}}%
    {\chapter*{\listtablename}}%
%  \begin{fullwidth}%
    \@starttoc{lot}%
%  \end{fullwidth}%
}
\newcommand{\@bidituftetoc@lof@line}[2]{%
  % #1 is the figure/table number and its caption text
  % #2 is the page number on which the figure/table appears
  \leftskip 0.0em
  \rightskip 0em
  \parfillskip 0em plus 1fil
  \parindent 0.0em
  \@afterindenttrue
  \interlinepenalty\@M
  \leavevmode
  \@tempdima 2.0em
  \if@RTL\advance\rightskip\@tempdima\else\advance\leftskip\@tempdima\fi
  \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
  {#1}\nobreak\qquad\nobreak#2%
  \par%
}
\renewcommand*\l@figure{\@bidituftetoc@lof@line}
\let\l@table\l@figure
%    \end{macrocode}
% \iffalse
%</bidituftetoc.sty>
%<*bidituftegeneralstructure.sty>
%\fi
% \section{File \texttt{bidituftegeneralstructure.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftegeneralstructure}[2011/06/18 v0.1
bidi implementation of tufte general structure]
\renewcommand\small{%
   \@setfontsize\small\@ixpt{12}%
   \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
   \abovedisplayshortskip \z@ \@plus2\p@
   \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
   \def\@listi{\leftmargin\leftmargini
               \topsep 4\p@ \@plus2\p@ \@minus2\p@
               \parsep 2\p@ \@plus\p@ \@minus\p@
               \itemsep \parsep}%
   \belowdisplayskip \abovedisplayskip
}
\renewcommand\scriptsize{\@setfontsize\scriptsize\@viipt\@viiipt}
\renewcommand\tiny{\@setfontsize\tiny\@vpt\@vipt}
\renewcommand\large{\@setfontsize\large\@xipt{15}}
\renewcommand\Large{\@setfontsize\Large\@xiipt{16}}
\renewcommand\LARGE{\@setfontsize\LARGE\@xivpt{18}}
\renewcommand\huge{\@setfontsize\huge\@xxpt{30}}
\renewcommand\Huge{\@setfontsize\Huge{24}{36}}
\setlength\leftmargini   {1pc}
\setlength\leftmarginii  {1pc}
\setlength\leftmarginiii {1pc}
\setlength\leftmarginiv  {1pc}
\setlength\leftmarginv   {1pc}
\setlength\leftmarginvi  {1pc}
\setlength\labelsep      {.5pc}
\setlength\labelwidth    {\leftmargini}
\addtolength\labelwidth{-\labelsep}
\setlength{\parindent}{1.0pc}%
\setlength{\parskip}{0pt}%
\RequirePackage{ragged2e}
\setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize}
% Paragraph indentation and separation for normal text
\newcommand{\@bidituftegeneralstructure@reset@par}{%
  \setlength{\RaggedRightParindent}{1.0pc}%
  \setlength{\JustifyingParindent}{1.0pc}%
  \setlength{\parindent}{1pc}%
  \setlength{\parskip}{0pt}%
}
\@bidituftegeneralstructure@reset@par
% Require paralist package for tighter lists
\RequirePackage{paralist}
% Add rightmargin to compactenum
\def\@compactenum@{%
  \expandafter\list\csname label\@enumctr\endcsname{%
    \usecounter{\@enumctr}%
    \rightmargin=2em% added this
    \parsep\plparsep
    \itemsep\plitemsep
    \topsep\pltopsep
    \partopsep\plpartopsep
    \def\makelabel##1{\hss\llap{##1}}}}
%%
% An environment for paragraph-style section
\providecommand\newthought[1]{%
   \addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}%
   \noindent\textbf{#1}%
}
%%
% Redefine the display environments (quote, quotation, etc.)
\renewenvironment{verse}
               {\let\\\@centercr
                \list{}{\itemsep      \z@
                        \itemindent   -1pc%
                        \listparindent\itemindent
                        \rightmargin  \leftmargin
                        \advance\leftmargin 1pc}%
                \small%
                \item\relax}
               {\endlist}
\renewenvironment{quotation}
               {\list{}{\listparindent 1pc%
                        \itemindent    \listparindent
                        \rightmargin   \leftmargin
                        \parsep        \z@ \@plus\p@}%
                \small%
                \item\relax\noindent\ignorespaces}
               {\endlist}
\renewenvironment{quote}
               {\list{}{\rightmargin\leftmargin}%
                \small%
                \item\relax}
               {\endlist}
% Italicize description run-in headings (instead of the default bold)
\renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\em #1}
%%
% Redefine \bibsection to not mark the running heads.
% (Code modified from natbib.sty.)
\@ifundefined{chapter}%
  {\renewcommand\bibsection{\section*{\refname}}}
  {\@ifundefined{NAT@sectionbib}%
    {\renewcommand\bibsection{\chapter{\bibname}}}
    {\renewcommand\bibsection{\section*{\bibname}}}}
\RequirePackage{multicol}
\renewenvironment{theindex}{%
\@ifundefined{chapter}%
    {\section*{\indexname}}%
    {\chapter{\indexname}}%
  \begin{fullwidth}%
  \small%
  \parskip0pt%
  \parindent0pt%
  \let\item\@idxitem%
  \begin{multicols}{3}%
}{%
  \end{multicols}%
  \end{fullwidth}%
}
\AtBeginDocument{%
\renewcommand\@idxitem{\par\hangindent \if@RTL-\fi2em}%
\renewcommand\subitem{\par\hangindent \if@RTL-\fi3em\hspace*{1em}}%
\renewcommand\subsubitem{\par\hangindent \if@RTL-\fi4em\hspace*{2em}}}
\renewcommand\indexspace{\par\addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}\relax}%
\newcommand{\lettergroup}[1]{}% swallow the letter heading in the index
%    \end{macrocode}
% \iffalse
%</bidituftegeneralstructure.sty>
%<*bidituftehyperref.sty>
%\fi
% \section{File \texttt{bidituftehyperref.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftehyperref}[2011/06/18 v0.1
bidi implementation of tufte hyperref]
%%
% Color
\RequirePackage[usenames,dvipsnames,svgnames]{xcolor}% 
\newboolean{@bidituftehyperref@loadhyper}
\setboolean{@bidituftehyperref@loadhyper}{true}
\DeclareOption{hyper}{\setboolean{@bidituftehyperref@loadhyper}{true}}
\DeclareOption{nohyper}{\setboolean{@bidituftehyperref@loadhyper}{false}}
\ProcessOptions
%% Loads the hyperref package and sets some default options.
\newcommand{\bidituftehyperrefLoadHyperref}{%
\RequirePackage[hyperfootnotes=false,colorlinks=true]{hyperref}
  \hypersetup{%
    bookmarksdepth = section,
    citecolor = DarkGreen,
    linkcolor = DarkBlue,
%    pagecolor = DarkBlue,
    urlcolor = DarkGreen,
  }%
}
\ifthenelse{\boolean{@bidituftehyperref@loadhyper}}{%
  \bidituftehyperrefLoadHyperref%
}{% hyperfootnotes override our modifications to the \footnote* and \@footnote* commands.
  \PassOptionsToPackage{hyperfootnotes=false}{hyperref}
}
%    \end{macrocode}
% \iffalse
%</bidituftehyperref.sty>
%<*bidituftetitle.sty>
%\fi
% \section{File \texttt{bidituftetitle.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftetitle}[2011/06/18 v0.1
bidi implementation of tufte title]
\RequirePackage{biditools}
%%
% `titlepage' option -- creates a full title page with \maketitle
\newboolean{@bidituftetitle@titlepage}
\DeclareOption{titlepage}{\setboolean{@bidituftetitle@titlepage}{true}}
\DeclareOption{notitlepage}{\setboolean{@bidituftetitle@titlepage}{false}}
% Default `book' and `handout' options
\@ifclassloaded{book}{%
\ExecuteOptions{titlepage}}{%
\@ifclassloaded{article}{%
\ExecuteOptions{notitlepage}}%
{}}
\ProcessOptions
%%
% Modified \title, \author, and \date commands.  These store the
% (footnote-less) values in \plaintitle, \plainauthor, and \thedate, respectively.
\newcommand{\plaintitle}{}%     plain-text-only title
\newcommand{\plainauthor}{}%    plain-text-only author
\newcommand{\plainpublisher}{}% plain-text-only publisher
\newcommand{\thanklesstitle}{}%     full title text minus \thanks{}
\newcommand{\thanklessauthor}{}%    full author text minus \thanks{}
\newcommand{\thanklesspublisher}{}% full publisher minus \thanks{}
\newcommand{\@publisher}{}% full publisher with \thanks{}
\newcommand{\thedate}{\today}
\bidi@patch@AfterPackage{bidi}{%
\renewcommand{\thanks}[1]{\footnote{#1}}
\renewcommand{\LTRthanks}[1]{\LTRfootnote{#1}}
\renewcommand{\RTLthanks}[1]{\RTLfootnote{#1}}
}
\renewcommand{\title}[2][]{%
  \gdef\@title{#2}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \renewcommand{\LTRthanks}[1]{}% swallow \LTRthanks contents
    \renewcommand{\RTLthanks}[1]{}% swallow \RTLthanks contents
    \protected@xdef\thanklesstitle{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}%
    {\renewcommand{\plaintitle}{\thanklesstitle}}% use thankless title
    {\renewcommand{\plaintitle}{#1}}% use provided plain-text title
  \@ifundefined{hypersetup}%
    {}% hyperref is not loaded; do nothing
    {\hypersetup{pdftitle={\plaintitle}}}% set the PDF metadata title
}
\let\@author\@empty% suppress default latex.ltx ``no author'' warning
\renewcommand{\author}[2][]{%
  \ifthenelse{\isempty{#2}}{}{\gdef\@author{#2}}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \renewcommand{\LTRthanks}[1]{}% swallow \LTRthanks contents
    \renewcommand{\RTLthanks}[1]{}% swallow \RTLthanks contents
    \protected@xdef\thanklessauthor{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}%
    {\renewcommand{\plainauthor}{\thanklessauthor}}% use thankless author
    {\renewcommand{\plainauthor}{#1}}% use provided plain-text author
  \@ifundefined{hypersetup}%
    {}% hyperref is not loaded; do nothing
    {\hypersetup{pdfauthor={\plainauthor}}}% set the PDF metadata author
}
\renewcommand{\date}[1]{%
  \gdef\@date{#1}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \renewcommand{\LTRthanks}[1]{}% swallow \LTRthanks contents
    \renewcommand{\RTLthanks}[1]{}% swallow \RTLthanks contents
    \protected@xdef\thedate{#1}%
  \endgroup%
}
%%
% Provides a \publisher command to set the publisher
\newcommand{\publisher}[2][]{%
  \gdef\@publisher{#2}%
  \begingroup%
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \renewcommand{\LTRthanks}[1]{}% swallow \LTRthanks contents
    \renewcommand{\RTLthanks}[1]{}% swallow \RTLthanks contents
    \protected@xdef\thanklesspublisher{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}
    {\renewcommand{\plainpublisher}{\thanklesspublisher}}% use thankless publisher
    {\renewcommand{\plainpublisher}{#1}}% use provided plain-text publisher
}
%%
% Produces a full title page
\newcommand{\maketitlepage}[0]{%
  \cleardoublepage%
  {%
  \bfseries%
  \begin{fullwidth}%
  \fontsize{18}{20}\selectfont\par\noindent\thanklessauthor%
  \vspace{11.5pc}%
  \fontsize{36}{40}\selectfont\par\noindent\thanklesstitle%
  \vfill%
  \fontsize{14}{16}\selectfont\par\noindent\thanklesspublisher%
  \end{fullwidth}%
  }
  \thispagestyle{empty}%
  \clearpage%
}
%%
% Title block
\bidi@AfterEndPreamble{%
\renewcommand{\maketitle}{%
  \newpage%
  \global\@topnum\z@% prevent floats from being placed at the top of the page
  \begingroup%
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{4pt}%
    \let\@@title\@empty%
    \let\@@author\@empty%
    \let\@@date\@empty%
      \gdef\@@title{\LARGE\itshape\@title\par}%
      \gdef\@@author{\Large\itshape\@author\par}%
      \gdef\@@date{\Large\itshape\@date\par}%
    \@@title%
    \@@author%
    \@@date%
  \endgroup%
  \thispagestyle{plain}% suppress the running head
}%
}
%%
% Title page (if the `titlepage' option was passed to the bidituftetitle-handout
% class.)
\bidi@AfterEndPreamble{%
\ifthenelse{\boolean{@bidituftetitle@titlepage}}
  {\renewcommand{\maketitle}{\maketitlepage}}
  {}
}
%%
% When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
% without headers and footers
\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
  \hbox{}
  %\vspace*{\fill}
  %\begin{center}
  %  This page intentionally contains only this sentence.
  %\end{center}
  %\vspace{\fill}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
%    \end{macrocode}
% \iffalse
%</bidituftetitle.sty>
%<*biditufte-handout.cls>
%\fi
% \section{File \texttt{biditufte-handout.cls}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{biditufte-handout}[2011/06/18 v0.1 biditufte-handout class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftefloat}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftetoc}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftehyperref}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftetitle}}
\ProcessOptions\relax
\LoadClass{article}
\RequirePackage{bidituftefloat}
\RequirePackage{bidituftesidenote}
\RequirePackage{bidituftetoc}
\RequirePackage{bidituftegeneralstructure}
\RequirePackage{bidituftehyperref}
\RequirePackage{bidituftetitle}
\renewenvironment{abstract}
  {\begin{quotation}}
  {\end{quotation}}
\AtBeginDocument{%
\IfFileExists{biditufte-handout.cfg}
  {\input{biditufte-handout.cfg}
   \ClassInfo{biditufte-handout}{Loading biditufte-handout configuration file \@gobble}}
  {}%
}
%    \end{macrocode}
% \iffalse
%</biditufte-handout.cls>
%<*biditufte-book.cls>
%\fi
% \section{File \texttt{biditufte-book.cls}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{biditufte-book}[2011/06/18 v0.1 biditufte-book class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftefloat}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftetoc}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftehyperref}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{bidituftetitle}}
\ProcessOptions\relax
\LoadClass{book}
\RequirePackage{bidituftefloat}
\RequirePackage{bidituftesidenote}
\RequirePackage{bidituftetoc}
\RequirePackage{bidituftegeneralstructure}
\RequirePackage{bidituftehyperref}
\RequirePackage{bidituftetitle}
%%
% Set up any book-specific stuff now
%%
% The front matter in Tufte's /Beautiful Evidence/ contains everything up
% to the opening page of Chapter 1.  The running heads, when they appear,
% contain only the (arabic) page number in the outside corner.
%\newif\if@mainmatter \@mainmattertrue
\renewcommand\frontmatter{%
  \cleardoublepage%
  \@mainmatterfalse%
  \pagenumbering{arabic}%
  %\pagestyle{plain}%
  \fancyhf{}%
    \ifthenelse{\boolean{@bidituftefloat@twoside}}%
    {\fancyhead[LE,RO]{\thepage}}%
    {\fancyhead[RE,RO]{\thepage}}%
}
%%
% The main matter in Tufte's /Beautiful Evidence/ doesn't restart the page
% numbering---it continues where it left off in the front matter.
\renewcommand\mainmatter{%
  \cleardoublepage%
  \@mainmattertrue%
  \fancyhf{}%
  \ifthenelse{\boolean{@bidituftefloat@twoside}}%
      {\renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
      \fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}% book title
      \fancyhead[RO]{\smallcaps{\newlinetospace{\leftmark}}\quad\thepage}}% chapter title
      {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}% book title
}
%%
% The back matter contains appendices, indices, glossaries, endnotes,
% biliographies, list of contributors, illustration credits, etc.
\renewcommand\backmatter{%
  \if@openright%
    \cleardoublepage%
  \else%
    \clearpage%
  \fi%
  \@mainmatterfalse%
}
%%
% Only show the chapter titles in the table of contents
\setcounter{tocdepth}{0}
\AtBeginDocument{%
\IfFileExists{biditufte-book.cfg}
  {\input{biditufte-book.cfg}
   \ClassInfo{biditufte-book}{Loading biditufte-book configuration file \@gobble}}
  {}%
}
%    \end{macrocode}
% \iffalse
%</biditufte-book.cls>
%<*bidipoem.sty>
%\fi
% \section{File \texttt{bidipoem.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidipoem}%
[2019/03/03 v1.0 Environments for typesetting Persian traditional and modern poems]

% Usage:
%
% \Setversedim #1#2 		% define the layout (within a group): 
% #1 = length of both half-verses
% #2 = separation distance = length of a connection, if present
% 	Variant:
% \Setversedim #1[#2]#3 	% for half-verses of unequal length
% #1 = length of first (=right) half-verse
% #2 = length of second (=left) half-verse
% #3 = separation distance = length of a connection, if present
%
% \traditionalhalfverses #1#2		% typeset two separated half-verses
% #1 = text of first (=right) half-verse
% #2 = text of second (=left) half-verse
% 	Variant:
% \traditionalhalfverses #1[#2]#3		% typeset two connected half-verses
% #1 = text of first (=right) half-verse
% #2 = text of connection
% #3 = text of second (=left) half-verse
%
% Alternative (if preferred):
%
% \traditionalconnverses #1#2#3		% = \traditionalhalfverses #1[#2]#3


\newcommand*{\bidipoem@spreadbox}[2]{\hbox to #1{#2}}

% define the layout, verses will be centered

\newdimen \bidipoem@hvlen	\newdimen \bidipoem@hvsep	
\newdimen \bidipoem@hvind	\newdimen \bidipoem@@hvlen

\newcommand*{\Setversedim}[2]{% set lengths of half-verse, [separation]
\bidipoem@hvind \textwidth 
\bidipoem@hvlen #1\relax \advance \bidipoem@hvind -\bidipoem@hvlen 
\ifx [#2\def \bidipoem@next {\bidipoem@set@verseI [}\else
\bidipoem@@hvlen \bidipoem@hvlen \def \bidipoem@next {\bidipoem@set@@verse {#2}}\fi \bidipoem@next }

\def \bidipoem@set@verseI [#1]{% optional parameter
\bidipoem@@hvlen #1\relax \bidipoem@set@@verse }

\newcommand*{\bidipoem@set@@verse}[1]{% separation
\advance \bidipoem@hvind -\bidipoem@@hvlen \bidipoem@hvsep #1\relax 
\advance \bidipoem@hvind -\bidipoem@hvsep  \divide \bidipoem@hvind 2 }

\newcommand*{\traditionalconnverses}[3]{% first half-verse, connection, second half-verse
\ifdim 0pt > \bidipoem@hvind %
\bidipoem@spreadbox \bidipoem@hvlen {#1}\\ \hfill % first block
\else
\noindent \hskip \bidipoem@hvind \relax \bidipoem@spreadbox \bidipoem@hvlen {#1}\fi 
\bidipoem@spreadbox \bidipoem@hvsep {#2}% separator
\bidipoem@spreadbox \bidipoem@@hvlen {#3}% second block
\par }

% macro for two half verses
\newcommand*{\traditionalhalfverses}[2]{% optional parameter?
\ifx [#2\def\bidipoem@half@verses@next{\bidipoem@half@verses {#1}[}%
\else\def\bidipoem@half@verses@next{\bidipoem@half@verses {#1}[\hfill]{#2}}\fi%
\bidipoem@half@verses@next}

\def \bidipoem@half@verses #1[#2]#3{% first[mid]second
\traditionalconnverses {#1}{#2}{#3}}


{\catcode`\^^M=\active % these lines must end with %
  \gdef\traditionalpoem@obeylines{\catcode`\^^M\active \let^^M\traditionalpoem@par}%
  \global\let^^M\traditionalpoem@par} % this is in case ^^M appears in a \write
{\catcode`\^^M=\active % these lines must end with %
  \gdef\modernpoem@obeylines{\catcode`\^^M\active \let^^M\modernpoem@par}%
  \global\let^^M\modernpoem@par} % this is in case ^^M appears in a \write
\def\poemcolsepskip{.1\versewidth plus .1\versewidth minus .05\versewidth}
\def\poemmarginskip{1em plus 1fil minus 1em}
\def\poemextrabaselineskip{0\baselineskip}
\def\poemskip{\medskip}
\newcommand{\bidipoem@openbox}{\leavevmode
  \hbox to.77778em{%
  \hfil\vrule
  \vbox to.675em{\hrule width.6em\vfil\hrule}%
  \vrule\hfil}}
\def\poemblocksep{\quad\hbox{\bidipoem@openbox}}
\newdimen\versewidth
\newtoks\bidipoem@p@ftn
\def\poem@verse#1{%
\ifdim\wd#1>\new@poem@width
\xdef\new@poem@width{\the\wd#1}%
\ifdim\new@poem@width>\poem@width
\xdef\poem@width{\new@poem@width}%
\global\let\poem@needrun\relax
\fi
\fi
\hbox to\poem@width{\unhbox#1}%
\global\bidipoem@p@ftn\expandafter{\expandafter}\the\bidipoem@p@ftn%
}
\def\poem@linebegin{\vadjust{}\hskip\@flushglue\hskip\poemmarginskip\relax}
\def\poem@lineend{\nobreak\hskip\poemmarginskip\hskip\@flushglue\vadjust{}}
\def\poem@lineversesep{%
\nobreak
\hskip\z@ plus 1filll%
\penalty600%
\hskip\poemcolsepskip
\hskip\z@ plus -2filll%
\vadjust{}%
\nobreak
\hskip\z@ plus 1filll%
}
\def\poem@lineparsebegin{%
\halign\bgroup
\global\setbox\verse@i=\hbox{%
\let\@footnotetext\bidipoem@p@ftntext%
\let\@LTRfootnotetext\bidipoem@p@LTRftntext%
\let\@RTLfootnotetext\bidipoem@p@RTLftntext%
\let\@xfootnotenext\bidipoem@p@xftntext%
\let\@xfootnote\bidipoem@p@xfootnote%
\let\@xLTRfootnotenext\bidipoem@p@xLTRftntext%
\let\@xLTRfootnote\bidipoem@p@xLTRfootnote%
\let\@xRTLfootnotenext\bidipoem@p@xRTLftntext%
\let\@xRTLfootnote\bidipoem@p@xRTLfootnote%
\ignorespaces##\unskip}&&
\global\setbox\verse@ii=\hbox{%
\let\@footnotetext\bidipoem@p@ftntext%
\let\@LTRfootnotetext\bidipoem@p@LTRftntext%
\let\@RTLfootnotetext\bidipoem@p@RTLftntext%
\let\@xfootnotenext\bidipoem@p@xftntext%
\let\@xfootnote\bidipoem@p@xfootnote%
\let\@xLTRfootnotenext\bidipoem@p@xLTRftntext%
\let\@xLTRfootnote\bidipoem@p@xLTRfootnote%
\let\@xRTLfootnotenext\bidipoem@p@xRTLftntext%
\let\@xRTLfootnote\bidipoem@p@xRTLfootnote%
\ignorespaces##\unskip}
\cr
}
\def\poem@lineparseend{%
\crcr\egroup
\vskip-\baselineskip
}
\def\traditionalpoem@cr{%
  \cr\poem@line
}
\newbox\verse@i
\newbox\verse@ii
\newif\ifpoem@started

\def\poem@line{%
\poem@lineparseend
\ifdim\wd\verse@i>\z@\global\poem@startedtrue\fi
\ifdim\wd\verse@ii>\z@\global\poem@startedtrue\fi
\ifpoem@started
  \ifdim\wd\verse@ii>\z@\else
  \nopagebreak[3]
  \fi
  \leavevmode
  \poem@linebegin
  \poem@verse\verse@i
  \ifdim\wd\verse@ii>\z@
  \poem@lineversesep
  \poem@verse\verse@ii
  \fi
  \poem@lineend
%  \nopagebreak
  \par
  \vskip\poemextrabaselineskip
\fi
\poem@lineparsebegin
}
\def\@traditionalpoem{%
\stepcounter{poem@no}
        \ifnum\max@poem@no<\number\c@poem@no%
\xdef\poem@width{\z@}%
        \else
\xdef\poem@width{\poem@prop{poem@width}}%
\fi
\xdef\new@poem@width{\z@}%
\global\versewidth=\poem@width
\poemskip\par
\begingroup
\tabskip=\z@
\parskip=\z@
\parindent=\z@
\parfillskip=\z@
\rightskip=\z@
\leftskip=\z@
\widowpenalty=10000% No break between verses of the same line.
\clubpenalty=10000% Same as above.  Not really needed.
\def\newblock{\hfil\poemblocksep\hfil\null}%
\def\traditionalpoem@par{\traditionalpoem@cr}% Redefine \par for possible \obeylines
\def\\{\global\poem@startedtrue\traditionalpoem@cr}%
\global\poem@startedfalse
\csname poem@obeylines\endcsname
\let\poem@obeylines\relax
\poem@lineparsebegin
}
\def\@endtraditionalpoem{%
\cr
\ifdim\wd\verse@i>\z@\poem@line\else\ifdim\wd\verse@ii>\z@\poem@line\else
\noalign{%
\skip0=\poemextrabaselineskip
\vskip-\skip0
\vskip-\baselineskip
}%
\fi\fi
\poem@lineparseend
\endgroup
\par
\vskip\baselineskip
\poemskip
\ifdim\new@poem@width<\poem@width
\global\let\poem@needrun\relax
\fi
        \poem@write@aux{poem@width@\romannumeral\c@poem@no}{\new@poem@width}%
\ifx\AtEndDocument\undefined\poem@finish\fi
\@endparenv
}


\long\def\bidipoem@p@ftntext#1{%
  \edef\@tempx{\the\bidipoem@p@ftn\noexpand\footnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidipoem@p@ftn\expandafter{\@tempx{#1}}}%
\long\def\bidipoem@p@LTRftntext#1{%
  \edef\@tempxi{\the\bidipoem@p@ftn\noexpand\LTRfootnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidipoem@p@ftn\expandafter{\@tempxi{#1}}}%
\long\def\bidipoem@p@RTLftntext#1{%
  \edef\@tempxii{\the\bidipoem@p@ftn\noexpand\RTLfootnotetext[\the\csname c@\@mpfn\endcsname]}%
  \global\bidipoem@p@ftn\expandafter{\@tempxii{#1}}}%

\long\def\bidipoem@p@xftntext[#1]#2{%
  \global\bidipoem@p@ftn\expandafter{\the\bidipoem@p@ftn\footnotetext[#1]{#2}}}

\long\def\bidipoem@p@xLTRftntext[#1]#2{%
  \global\bidipoem@p@ftn\expandafter{\the\bidipoem@p@ftn\LTRfootnotetext[#1]{#2}}}

\long\def\bidipoem@p@xRTLftntext[#1]#2{%
  \global\bidipoem@p@ftn\expandafter{\the\bidipoem@p@ftn\RTLfootnotetext[#1]{#2}}}

\def\bidipoem@p@xfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidipoem@p@xftntext[#1]}

\def\bidipoem@p@xLTRfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidipoem@p@xLTRftntext[#1]}

\def\bidipoem@p@xRTLfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\bidipoem@p@xRTLftntext[#1]}



\newenvironment{traditionalpoem}{\@traditionalpoem}{\@endtraditionalpoem}
\expandafter\def\csname traditionalpoem*\endcsname{\let\poem@obeylines=\traditionalpoem@obeylines\traditionalpoem}
\expandafter\def\csname endtraditionalpoem*\endcsname{\endtraditionalpoem}
\def\poem@finish{%
\poem@write@aux{max@poem@no}{\number\c@poem@no}%
\ifx\poem@needrun\relax
\PackageWarning{bidipoem}{Unjustified poem.  Rerun TeX to get poem right}%
\global\let\poem@needrun\undefined
\fi
}
\ifx\AtEndDocument\undefined\else\AtEndDocument\poem@finish\fi
\newcounter{poem@no}\setcounter{poem@no}{\z@}
\ifx\max@poem@no\undefined
        \def\max@poem@no{0}%
\fi
\newcommand{\poem@prop}[1]{\@nameuse{#1@\romannumeral\c@poem@no}}
\newcommand{\poem@write@aux}[2]{%
        \def\@x{\immediate\write\@auxout{\global\noexpand\@namedef{#1}{#2}}}%
        \@x
}
\def\@modernpoem{%
\par
\begingroup
\parskip=\z@
\parindent=\z@
\def\[{\@settab\@tabplus\ignorespaces}%
\def\]{\@tabminus\ignorespaces}%
\def\newblock{\poemblocksep}%
\let\newpoem@tabcr\@tabcr
\def\modernpoem@par{% Redefine \par for possible \obeylines
  \ifpoem@started\else
    \ifdim\wd\@curline>\z@\global\poem@startedtrue\else
      \@stopfield
      \ifdim\wd\@curfield>\z@\global\poem@startedtrue\fi
      \@contfield
    \fi
  \fi
  \ifpoem@started\newpoem@tabcr\fi}%
\def\@tabcr{\global\poem@startedtrue\newpoem@tabcr}%
\global\poem@startedfalse
\csname poem@obeylines\endcsname
\let\poem@obeylines\relax
\begin{tabbing}%
}
\def\@endmodernpoem{%
\global\poem@startedfalse
\ifdim\wd\@curline>\z@\global\poem@startedtrue\else
  \@stopfield
  \ifdim\wd\@curfield>\z@\global\poem@startedtrue\fi
  \@contfield
\fi
\ifpoem@started\else\let\@stopline\@stopfield\fi
\end{tabbing}%
\endgroup
\par
  \if@noparlist \else
    \ifdim\lastskip >\z@
      \@tempskipa\lastskip \vskip -\lastskip
      \advance\@tempskipa\parskip \advance\@tempskipa -\@outerparskip
      \vskip\@tempskipa
    \fi
    \@endparenv
  \fi
}
\newenvironment{modernpoem}{\@modernpoem}{\@endmodernpoem}
\expandafter\def\csname modernpoem*\endcsname{\let\poem@obeylines=\modernpoem@obeylines\modernpoem}
\expandafter\def\csname endmodernpoem*\endcsname{\endmodernpoem}
\gdef\@startfield{%
\global\setbox\@curfield\hbox\bgroup%
\let\@footnotetext\bidipoem@p@ftntext%
\let\@LTRfootnotetext\bidipoem@p@LTRftntext%
\let\@RTLfootnotetext\bidipoem@p@RTLftntext%
\let\@xfootnotenext\bidipoem@p@xftntext%
\let\@xfootnote\bidipoem@p@xfootnote%
\let\@xLTRfootnotenext\bidipoem@p@xLTRftntext%
\let\@xLTRfootnote\bidipoem@p@xLTRfootnote%
\let\@xRTLfootnotenext\bidipoem@p@xRTLftntext%
\let\@xRTLfootnote\bidipoem@p@xRTLfootnote%
\color@begingroup}
\gdef\@stopfield{%
  \color@endgroup\egroup\global\bidipoem@p@ftn\expandafter{\expandafter}\the\bidipoem@p@ftn}
\gdef\@contfield{%
\global\setbox\@curfield\hbox\bgroup%
\let\@footnotetext\bidipoem@p@ftntext%
\let\@LTRfootnotetext\bidipoem@p@LTRftntext%
\let\@RTLfootnotetext\bidipoem@p@RTLftntext%
\let\@xfootnotenext\bidipoem@p@xftntext%
\let\@xfootnote\bidipoem@p@xfootnote%
\let\@xLTRfootnotenext\bidipoem@p@xLTRftntext%
\let\@xLTRfootnote\bidipoem@p@xLTRfootnote%
\let\@xRTLfootnotenext\bidipoem@p@xRTLftntext%
\let\@xRTLfootnote\bidipoem@p@xRTLfootnote%
\color@begingroup\unhbox\@curfield}
%    \end{macrocode}
% \iffalse
%</bidipoem.sty>
%<*boek3-xetex-bidi.def>
%\fi
% \section{File \texttt{boek3-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{boek3-xetex-bidi.def}[2025/09/30 v0.5 bidi adaptations for boek3 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\@makeschapterhead{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty{-\@highpenalty}%
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\if@oldtoc
\renewcommand*\l@chapter[2]{%
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \penalty\@highpenalty
   \endgroup}
\else
  \renewcommand*\l@chapter{\@regtocline{0}}
\fi
\renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont \abstractname}
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
       \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\renewcommand*\thesection{\thechapter\@SepMark\@arabic\c@section}
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand*\theequation{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi\@arabic\c@equation}
\renewcommand*\thefigure{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@figure}
\renewcommand*\thetable{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@table}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
%    \end{macrocode}
% \iffalse
%</boek3-xetex-bidi.def>
%<*boek-xetex-bidi.def>
%\fi
% \section{File \texttt{boek-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{boek-xetex-bidi.def}[2025/09/30 v0.5 bidi adaptations for boek class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\@makeschapterhead{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty{-\@highpenalty}%
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\if@oldtoc
\renewcommand*\l@chapter[2]{%
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \penalty\@highpenalty
   \endgroup}
\else
  \renewcommand*\l@chapter{\@regtocline{0}}
\fi
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont \abstractname}
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
       \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewcommand*\thesection{\thechapter\@SepMark\@arabic\c@section}
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand*\theequation{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi\@arabic\c@equation}
\renewcommand*\thefigure{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@figure}
\renewcommand*\thetable{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@table}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
%    \end{macrocode}
% \iffalse
%</boek-xetex-bidi.def>
%<*bookest-xetex-bidi.def>
%\fi
% \section{File \texttt{bookest-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{bookest-xetex-bidi.def}[2010/07/25 v0.4 bidi adaptations for bookest class for XeTeX engine]
\def\@makechapterhead#1{%
  \vspace*{20\p@}
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        {\colorA\huge\scshape \@chapapp\space \thechapter}
        \par\nobreak
        \vskip 10\p@
      \fi
    \fi
    \interlinepenalty\@M
  {\colorB\hrule}
  \vskip 15\p@
   \if@RTL\begin{flushleft}\else\begin{flushright}\fi
     {\colorA\Huge \bfseries #1}\par\nobreak
   \if@RTL\end{flushleft}\else\end{flushright}\fi
  \vskip 5\p@
  {\colorB\hrule}
  \vskip 30\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{20\p@}
  {\parindent \z@ \raggedright \normalfont
  {\colorB\hrule}
  \vskip 15\p@
   \begin{center}
     {\colorA\Huge \bfseries #1}\par\nobreak
   \end{center}
  \vskip 5\p@
  {\colorB\hrule}
  \vskip 30\p@
  }}
%    \end{macrocode}
% \iffalse
%</bookest-xetex-bidi.def>
%<*book-xetex-bidi.def>
%\fi
% \section{File \texttt{book-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{book-xetex-bidi.def}[2025/09/30 v1.4 bidi adaptations for standard book class for XeTeX engine]
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \columnseprule \z@
                \columnsep 35\p@
                \twocolumn[\@makeschapterhead{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem}
               {\if@restonecol\onecolumn\else\clearpage\fi}
\IfClassLoadedF{bookest}{%
  \if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi}
\IfPackageLoadedF{tocloft}{%
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
      \hskip -\if@RTL\rightskip\else\leftskip\fi
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
}
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\renewcommand\theequation
  {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand \thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand \thetable
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand \thesection {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}
\renewcommand\backmatter{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \@mainmatterfalse}
\IfPackageLoadedF{natbib}{%
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
      \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
}
%    \end{macrocode}
% \iffalse
%</book-xetex-bidi.def>
%<*breqn-xetex-bidi.def>
%\fi
% \section{File \texttt{breqn-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{breqn-xetex-bidi.def}[2016/09/12 v0.2 bidi adaptations for breqn package for XeTeX engine]
\def\@dmath[#1]{\if@RTL\@RTLfalse\fi%
  \everydisplay\expandafter{\the\everydisplay \display@setup}%
  \if@noskipsec \leavevmode \fi
  \if@inlabel \leavevmode \global\@inlabelfalse \fi
  \if\eq@group\else\eq@prelim\fi
  \setkeys{breqn}{#1}%
  \the\eqstyle
  \eq@setnumber
  \begingroup
  \eq@setup@a
  \eq@startup
}
\def\@dgroup[#1]{\if@RTL\@RTLfalse\fi%
  \let\eq@group\@True \global\let\eq@GRP@first@dmath\@True
  \global\GRP@queue\@emptytoks \global\setbox\GRP@box\box\voidb@x
  \global\let\GRP@label\@empty
  \global\grp@wdL\z@\global\grp@wdR\z@\global\grp@wdT\z@
  \global\grp@linewidth\z@\global\grp@wdNum\z@
  \global\let\grp@eqs@numbered\@False
  \global\let\grp@aligned\@True
  \global\let\grp@shiftnumber\@False
  \eq@prelim
  \setkeys{breqn}{#1}%
  \if\grp@hasNumber \grp@setnumber \fi
}
\def\@dseries[#1]{\if@RTL\@RTLfalse\fi%
  \let\display@setup\dseries@display@setup
  % Question: should this be the default for dseries???
  \global\eq@wdCond\z@
  \@dmath[layout={M},#1]%
  \mathsurround\z@\@@math \penalty\@Mi
  \let\endmath\ends@math
  \def\premath{%
    \ifdim\lastskip<.3em \unskip
    \else\ifnum\lastpenalty<\@M \dquad\fi\fi
}%
  \def\postmath{\unpenalty\eq@addpunct \penalty\intermath@penalty \dquad \@ignoretrue}%
\ignorespaces
}
\def\eqnumform#1{\if@nonlatin\beginR\@RTLtrue\fi(#1\@@italiccorr)\if@nonlatin\endR\fi}
\renewenvironment{dsuspend}{%
  \global\setbox\EQ@box\vbox\bgroup\if@nonlatin\@RTLtrue\fi \@parboxrestore
    \parshape 1 \displayindent \displaywidth\relax
    \hsize=\columnwidth \noindent\ignorespaces
}{%
  \par\egroup
  \global\setbox\GRP@box\vbox{%
    \hbox{\copy\EQ@box\vtop{\unvbox\EQ@box}}%
    \unvbox\GRP@box
  }%
  \global\GRP@queue\@xp{\the\GRP@queue
     \@elt{\let\eq@isIntertext\@True}%
  }%
}
%    \end{macrocode}
% \iffalse
%</breqn-xetex-bidi.def>
%<*cals-xetex-bidi.def>
%\fi
% \section{File \texttt{cals-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{cals-xetex-bidi.def}[2016/11/30 v0.4 bidi adaptations for cals package for XeTeX engine]
\renewcommand\cals@setup@alignment[1]{%
\if c#1\relax \cals@vfillAdd \leftskip \cals@vfillAdd \rightskip \fi
\if l#1\relax \cals@vfillDrop\leftskip \cals@vfillDrop\rightskip \fi
\if r#1\relax \cals@vfillAdd \leftskip \cals@vfillDrop\rightskip \fi
}
\renewcommand\cals@table@alignment{\if@RTLtab r\else l\fi}
\renewenvironment{calstable}[1][\cals@table@alignment]{%
\if@RTLtab\cals@activate@rtl\fi
\let\cals@thead@tokens=\relax
\let\cals@tfoot@tokens=\relax
\let\cals@tbreak@tokens=\relax
\cals@tfoot@height=0pt \relax
\let\cals@last@context=n%
\let\cals@current@context=b%
\parindent=0pt \relax%
\cals@setup@alignment{#1}%
\cals@setpadding{Ag}\cals@setcellprevdepth{Al}\cals@set@tohsize%
%% Alignment inside is independent on center/flushright outside
\parfillskip=0pt plus1fil\relax
\let\cals@borderL=\relax
\let\cals@borderR=\relax
\let\cals@borderT=\relax
\let\cals@borderB=\relax
\setbox\cals@backup@row=\box\voidb@x\relax
\cals@AtBeginTable
}{% End of the table
\cals@tfoot@tokens\lastrule\cals@AtEndTable}
\renewcommand\alignL{%
\if@RTLtab
  \cals@vfillAdd\cals@paddingL
\else
  \cals@vfillDrop\cals@paddingL
\fi
\cals@vfillDrop\cals@paddingR}
\renewcommand\alignR{%
\if@RTLtab
  \cals@vfillDrop\cals@paddingL
\else
  \cals@vfillAdd\cals@paddingL
\fi
\cals@vfillDrop\cals@paddingR}
%    \end{macrocode}
% \iffalse
%</cals-xetex-bidi.def>
%<*caption-xetex-bidi.def>
%\fi
% \section{File \texttt{caption-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{caption-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for caption package for XeTeX engine]
\let\@makecaption\caption@makecaption
%    \end{macrocode}
% \iffalse
%</caption-xetex-bidi.def>
%<*caption3-xetex-bidi.def>
%\fi
% \section{File \texttt{caption3-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{caption3-xetex-bidi.def}[2013/04/01 v0.1 bidi adaptations for caption3 package for XeTeX engine]
\renewcommand*\caption@@par{%
  \parindent\caption@parindent\hangindent\if@RTL-\fi\caption@hangindent}%
%    \end{macrocode}
% \iffalse
%</caption3-xetex-bidi.def>
%<*colortbl-xetex-bidi.def>
%\fi
% \section{File \texttt{colortbl-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{colortbl-xetex-bidi.def}[2012/06/10 v0.2 bidi adaptations for colortbl package for XeTeX engine]
\def\CT@setup{%
  \@tempdimb\col@sep
  \@tempdimc\col@sep
  \def\CT@color{%
    \global\let\CT@do@color\CT@@do@color
    \bidicolor}}
\def\@classz{\@classx
   \@tempcnta \count@
   \prepnext@tok
\expandafter\CT@extract\the\toks\@tempcnta\columncolor!\@nil
   \@addtopreamble{\if@RTLtab\beginL\fi%
    \setbox\z@\hbox\bgroup\bgroup\if@RTLtab\beginR\fi
      \ifcase \@chnum
      \hskip\stretch{.5}\kern\z@
      \d@llarbegin
      \insert@column
      \d@llarend\hskip\stretch{.5}\or
      \d@llarbegin \insert@column \d@llarend \hfill \or
      \hfill\kern\z@ \d@llarbegin \insert@column \d@llarend \or
   $\vcenter
   \@startpbox{\@nextchar}\insert@column \@endpbox $\or
   \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or
   \vbox \@startpbox{\@nextchar}\insert@column \@endpbox
  \fi
 \if@RTLtab\endR\fi\egroup\egroup
\begingroup
  \CT@setup
  \CT@column@color
  \CT@row@color
  \CT@cell@color
  \CT@do@color
\endgroup
        \@tempdima\ht\z@
        \advance\@tempdima\minrowclearance
        \vrule\@height\@tempdima\@width\z@
        \unhbox\z@\if@RTLtab\endL\fi}%
  \prepnext@tok}
%    \end{macrocode}
% \iffalse
%</colortbl-xetex-bidi.def>
%<*color-xetex-bidi.def>
%\fi
% \section{File \texttt{color-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{color-xetex-bidi.def}[2013/04/08 v0.2 bidi adaptations for color package for XeTeX engine]
\long\def\color@b@x#1#2#3{%
 \leavevmode\ifmmode\else\if@RTL\beginL\fi\fi
 \setbox\z@\hbox{\kern\fboxsep{\set@color\if@RTL\beginR\fi#3\if@RTL\endR\fi}\kern\fboxsep}%
 \dimen@\ht\z@\advance\dimen@\fboxsep\ht\z@\dimen@
 \dimen@\dp\z@\advance\dimen@\fboxsep\dp\z@\dimen@
 {#1{#2\color@block{\wd\z@}{\ht\z@}{\dp\z@}%
      \box\z@}}\ifmmode\else\if@RTL\endL\fi\fi}
\def\normalcolor{\let\current@color\default@color\ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\set@color\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi}
\DeclareRobustCommand\color{%
  \ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\@ifnextchar[\@undeclaredcolor\@declaredcolor}
\def\@declaredcolor#1{%
  \@ifundefined{\string\color @#1}%
    {\c@lor@error{`#1'}}%
    {\expandafter\let\expandafter\current@color
     \csname\string\color @#1\endcsname
     \set@color}%
  \ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi\ignorespaces}
\def\@undeclaredcolor[#1]#2{%
  \@ifundefined{color@#1}%
    {\c@lor@error{model `#1'}}%
    {\csname color@#1\endcsname\current@color{#2}%
     \set@color}%
  \ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi\ignorespaces}
\DeclareRobustCommand\bidicolor{%
  \@ifnextchar[\@bidiundeclaredcolor\@bidideclaredcolor}
\def\@bidiundeclaredcolor[#1]#2{%
  \@ifundefined{color@#1}%
    {\c@lor@error{model `#1'}}%
    {\csname color@#1\endcsname\current@color{#2}%
     \set@color}%
  \ignorespaces}
\def\@bidideclaredcolor#1{%
  \@ifundefined{\string\color @#1}%
    {\c@lor@error{`#1'}}%
    {\expandafter\let\expandafter\current@color
     \csname\string\color @#1\endcsname
     \set@color}%
  \ignorespaces}
\def\color@box#1#2{\color@b@x\relax{\bidicolor#1{#2}}}
\def\color@fbox#1#2#3{%
  \color@b@x{\fboxsep\z@\bidicolor#1{#2}\fbox}{\bidicolor#1{#3}}}
\def\color@setgroup{\begingroup\ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\set@color\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi}
%    \end{macrocode}
% \iffalse
%</color-xetex-bidi.def>
%<*combine-xetex-bidi.def>
%\fi
% \section{File \texttt{combine-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{combine-xetex-bidi.def}[2011/09/23 v0.1 bidi adaptations for combine class for XeTeX engine]
\renewcommand{\c@ll@chapsecii}[2]{%
  \if@RTL\advance\rightskip\@tempdima\else\advance\leftskip\@tempdima\fi
  \if@RTL\hskip -\rightskip\else\hskip -\leftskip\fi
  #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
}
\renewcommand{\c@ll@chapseci}{%
  \setlength\@tempdima{0em}%
  \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode
}
\renewenvironment{tocindent}[1]{%
  \hangindent \if@RTL-\fi#1 \hangafter -100\relax}{}
%    \end{macrocode}
% \iffalse
%</combine-xetex-bidi.def>
%<*crop-xetex-bidi.def>
%\fi
% \section{File \texttt{crop-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{crop-xetex-bidi.def}[2025/01/03 v0.3 bidi adaptations for crop package for XeTeX engine]
\IfClassLoadedT{memoir}{\endinput}
\RequirePackage{graphicx}
\renewcommand*\CROP@@ulc{%
   \if@RTLmain%
       \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(-40,0){\circle{10}}
        \put(-30,-5){\line(0,1){10}}
        \put(-35,0){\line(1,0){30}}
        \put(-10,30){\circle{10}}
        \put(-5,30){\line(1,0){10}}
        \put(0,35){\line(0,-1){30}}
    \end{picture}%
   \else%
    \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(-30,0){\circle{10}}
        \put(-30,-5){\line(0,1){10}}
        \put(-35,0){\line(1,0){30}}
        \put(0,30){\circle{10}}
        \put(-5,30){\line(1,0){10}}
        \put(0,35){\line(0,-1){30}}
    \end{picture}%
    \fi%
}
\renewcommand*\CROP@@urc{%
   \if@RTLmain%
       \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(20,0){\circle{10}}
        \put(30,-5){\line(0,1){10}}
        \put(35,0){\line(-1,0){30}}
        \put(-10,30){\circle{10}}
        \put(-5,30){\line(1,0){10}}
        \put(0,35){\line(0,-1){30}}
    \end{picture}%
   \else%
    \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(30,0){\circle{10}}
        \put(30,-5){\line(0,1){10}}
        \put(35,0){\line(-1,0){30}}
        \put(0,30){\circle{10}}
        \put(-5,30){\line(1,0){10}}
        \put(0,35){\line(0,-1){30}}
    \end{picture}%
    \fi%
}
\renewcommand*\CROP@@llc{%
   \if@RTLmain%
       \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(-40,0){\circle{10}}
        \put(-30,-5){\line(0,1){10}}
        \put(-35,0){\line(1,0){30}}
        \put(-10,-30){\circle{10}}
        \put(-5,-30){\line(1,0){10}}
        \put(0,-35){\line(0,1){30}}
    \end{picture}%
   \else%
    \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(-30,0){\circle{10}}
        \put(-30,-5){\line(0,1){10}}
        \put(-35,0){\line(1,0){30}}
        \put(0,-30){\circle{10}}
        \put(-5,-30){\line(1,0){10}}
        \put(0,-35){\line(0,1){30}}
    \end{picture}%
    \fi%
}
\renewcommand*\CROP@@lrc{%
    \if@RTLmain%
        \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(20,0){\circle{10}}
        \put(30,-5){\line(0,1){10}}
        \put(35,0){\line(-1,0){30}}
        \put(-10,-30){\circle{10}}
        \put(-5,-30){\line(1,0){10}}
        \put(0,-35){\line(0,1){30}}
    \end{picture}%
    \else%
    \begin{picture}(0,0)
        \unitlength\p@\thinlines
        \put(30,0){\circle{10}}
        \put(30,-5){\line(0,1){10}}
        \put(35,0){\line(-1,0){30}}
        \put(0,-30){\circle{10}}
        \put(-5,-30){\line(1,0){10}}
        \put(0,-35){\line(0,1){30}}
    \end{picture}%
    \fi%
}
\@ifpackagewith{crop}{cam}{%
\CROP@execopt{cam}%
}{}
%    \end{macrocode}
% \iffalse
%</crop-xetex-bidi.def>
%<*cutwin-xetex-bidi.def>
%\fi
% \section{File \texttt{cutwin-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{cutwin-xetex-bidi.def}[2011/11/12 v0.1 bidi adaptations for cutwin package for XeTeX engine]
\renewcommand*{\c@twcompctr}[2]{%
  \def\c@twfirst{1}
  \loop\advance\c@twwinlines\m@ne
  \setbox\c@twslicea=\vsplit#1 to\baselineskip
  \setbox\c@twsliceb=\vsplit#1 to\baselineskip
  \c@twprune{\c@twslicea}{\c@twlftside}%
  \c@twprune{\c@twsliceb}{\c@twrtside}%
  \ifnum\c@twfirst=\@ne
    \setbox#2=\vbox{\unvbox#2\hbox
    to\hsize{\if@RTL\box\c@twsliceb\else\box\c@twslicea\fi\pageinwindow\hfil\if@RTL\box\c@twslicea\else\box\c@twsliceb\fi}}%
  \else
    \setbox#2=\vbox{\unvbox#2\hbox
    to\hsize{\if@RTL\box\c@twsliceb\else\box\c@twslicea\fi\hfil\if@RTL\box\c@twslicea\else\box\c@twsliceb\fi}}%
  \fi
  \def\c@twfirst{2}
  \ifnum\c@twwinlines>\z@\repeat}
\renewcommand*{\c@twcompoddctr}[2]{%
  \def\c@twrounds{1}
  \def\c@twfirst{1}
  \@for\c@twlspec:=\c@twb\do{%
    \ifnum\c@twrounds=1
      \setbox\c@twslicea=\vsplit#1 to\baselineskip % first of pair
      \c@twprune{\c@twslicea}{\c@twlspec}%
      \def\c@twrounds{2}
    \else
      \setbox\c@twsliceb=\vsplit#1 to\baselineskip % second of pair
      \c@twprune{\c@twsliceb}{\c@twlspec}%
      \ifnum\c@twfirst=1
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\if@RTL\box\c@twsliceb\else\box\c@twslicea\fi\hfil\picinwindow\hfil\if@RTL\box\c@twslicea\else\box\c@twsliceb\fi}}%
        \def\c@twfirst{2}
      \else
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\if@RTL\box\c@twsliceb\else\box\c@twslicea\fi\hfil\if@RTL\box\c@twslicea\else\box\c@twsliceb\fi}}%
      \fi
      \def\c@twrounds{1}
    \fi}}
%    \end{macrocode}
% \iffalse
%</cutwin-xetex-bidi.def>
%<*cuted-xetex-bidi.def>
%\fi
% \section{File \texttt{cuted-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{cuted-xetex-bidi.def}[2022/02/18 v0.7 bidi adaptations for cuted package for XeTeX engine]

\def\RTL@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
       \hskip \columnwidth
       \hfil
       {\normalcolor\vrule \@width\columnseprule}%
       \hfil
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hskip -\textwidth
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}%
       \hskip \columnsep
      \hskip \columnwidth }}%
    \ifvoid\hold@viper
    \else
      \setbox\@outputbox \vbox to\textheight{%
                             \box\hold@viper
                             \box\@outputbox
                             \vss
                             }%
    \fi
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
      \ifvoid\@viper
      \else
        \global\setbox\@viper\vbox{%
                   \vskip-\stripsep
                   \unvbox\@viper
                   }%
        \@viperoutput
      \fi
    \endgroup
  \fi}%

\def\LTR@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hfil
        {\normalcolor\vrule \@width\columnseprule}%
        \hfil
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}}}%
    \ifvoid\hold@viper
    \else
      \setbox\@outputbox \vbox to\textheight{%
                             \box\hold@viper
                             \box\@outputbox
                             \vss
                             }%
    \fi
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
      \ifvoid\@viper
      \else
        \global\setbox\@viper\vbox{%
                   \vskip-\stripsep
                   \unvbox\@viper
                   }%
        \@viperoutput
      \fi
    \endgroup
  \fi}%

\def\@addviper{%
    \@insertfalse
    \def\var@@thecol@num{2}%
    \if@firstcolumn
        \def\var@@thecol@num{1}%
        \@reqcolroom=.5\@pageht
        \ht@viper=\@reqcolroom
        \advance\@reqcolroom by\ht\@viper
        \advance\@reqcolroom by\stripsep
    \else
        \@reqcolroom=\@colht
        \advance\@reqcolroom by\@pageht
        \ht@viper.5\@reqcolroom
        \@reqcolroom=\ht@viper
        \advance\@reqcolroom by\ht\@viper
        \advance\@reqcolroom by\stripsep
        \global\setbox\@holdpg\vbox{%
            \setbox\cuted@@tempbox@a\vbox{%
                \aftergroup\unvbox
                \unvcopy\@leftcolumn
                \unskip\unkern\unpenalty
                \setbox\@tempboxa\lastbox
                \ifdim\dimexpr\ht\@tempboxa+\wd\@tempboxa+\dp\@tempboxa>\z@
                    %% keeps lastbox
                    \aftergroup\@leftcolumn
                \else
                    %% removes lastbox
                    \aftergroup\cuted@@tempbox@a
                \fi
                }%
            \unskip\unkern\unpenalty
            \on@stripcols@break
            \the\At@ViperColsBreak
            \unvbox\@holdpg
            }%
        \global\At@ViperColsBreak{}%
        \ht@viper=.5\ht\@holdpg
        \ifdim\ht@viper>\@colht
            \ht@viper=\@colht
        \fi
    \fi
    %%
    %% calculations for breaking
    %%
    \ifvoid\hold@viper
        \ht@hold@viper=\z@
    \else
        \ht@hold@viper=\ht\hold@viper
    \fi
    \cuted@@tempdim@b\ht@viper
    \set@split@topskip@to\topskip
    \loop
        \xdef\saved@tempdimb{\the\cuted@@tempdim@b}%
        \setbox\cuted@@varbox@a\copy\@holdpg
        \setbox\cuted@@tempbox@a\vsplit\cuted@@varbox@a to\cuted@@tempdim@b
        %% set leftcolumn boxes
        \setbox\cuted@@tempbox@c\vbox{\unvbox\cuted@@tempbox@a}%
        \setbox\cuted@@tempbox@a\vbox to\cuted@@tempdim@b{\unvcopy\cuted@@tempbox@c}%
        \xdef\var@@leftcolumn@badness{\the\badness}%
        %% set rightcolumn boxes
        \setbox\cuted@@varbox@c\vbox{\unvbox\cuted@@varbox@a}%
        \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@b{\unvcopy\cuted@@varbox@c}%
        \xdef\var@@rightcolumn@badness{\the\badness}%
        %% analyzing split goodness
        \cuted@@tempdim@spread=\ht\cuted@@tempbox@c
        \advance\cuted@@tempdim@spread by\dp\cuted@@tempbox@c
        \advance\cuted@@tempdim@spread by-\ht\cuted@@varbox@c
        \advance\cuted@@tempdim@spread by-\dp\cuted@@varbox@c
        \cuted@@wlog@debug{CUTED [-----]%
              ^^JLeft: \the\ht\cuted@@tempbox@c
              +\the\dp\cuted@@tempbox@c\space/\var@@leftcolumn@badness
              ^^JRight: \the\ht\cuted@@varbox@c
              +\the\dp\cuted@@varbox@c\space/\var@@rightcolumn@badness
              ^^JSplit: \the\cuted@@tempdim@b
              ^^JExtra height: \the\cuted@@tempdim@spread
             }%
        \ifnum\var@@leftcolumn@badness<\cuted@@column@badness
            \ifnum\var@@rightcolumn@badness<\cuted@@column@badness
                \cuted@@tempdim@spread=\z@
            \fi
        \fi
        \ifdim\cuted@@tempdim@spread<\z@
            \if@left@column@spread
                \if@right@column@shrink
                    \ifdim\dimexpr\cuted@@tempdim@spread+\pageshrink>\z@
                        \cuted@@tempdim@a=\dimexpr\ht\cuted@@tempbox@c-0.5\cuted@@tempdim@spread\relax
                    \else
                        \cuted@@tempdim@a=-\dimexpr\cuted@@tempdim@spread+.5\pageshrink\relax
                    \fi
                    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@a{\unvcopy\cuted@@tempbox@c}%
                    \ifnum\badness<\cuted@@column@badness
                        \cuted@@tempdim@b=\cuted@@tempdim@a
                        \cuted@@tempdim@spread=\z@
                    \fi
                    \cuted@@wlog@debug{CUTED [leftcolumn badness]: \number\badness\space on \the\cuted@@tempdim@a}%
                    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@a{\unvcopy\cuted@@varbox@c}%
                    \cuted@@wlog@debug{CUTED [rightcolumn badness]: \number\badness\space on \the\cuted@@tempdim@a}%
                \else
                    \setbox\cuted@@varbox@a\vbox to\ht\cuted@@varbox@c{%
                        \unvcopy\cuted@@tempbox@c
                        }%
                    \ifnum\badness<\cuted@@column@badness
                        \@tempdimb=\ht\cuted@@varbox@c
                        \cuted@@tempdim@spread=\z@
                    \fi
                    \cuted@@wlog@debug{CUTED [leftcolumn badness]: \number\badness on \the\ht\cuted@@varbox@c}%
                    \setbox\cuted@@varbox@a\vbox to\ht\cuted@@varbox@c{%
                        \unvcopy\cuted@@varbox@c
                        }%
                    \cuted@@wlog@debug{CUTED [rightcolumn badness]: \number\badness on \the\ht\cuted@@varbox@c}%
                \fi
            \else
                \if@right@column@shrink
                    \ifdim\dimexpr\cuted@@tempdim@spread+\pageshrink<\z@
                    \else
                        \cuted@@tempdim@b=\ht\cuted@@tempbox@c
                        \cuted@@tempdim@spread=\z@
                    \fi
                \fi
            \fi
        \else
            \ifdim\cuted@@tempdim@spread>\z@
                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
                    \cuted@@tempdim@b=\@colht
                    \cuted@@tempdim@spread=\z@
                \fi
            \fi
        \fi
    \ifdim\cuted@@tempdim@spread<\z@
        \advance\cuted@@tempdim@b 1\p@
    \repeat
    \wlog{CUTED [- LAST -]%
          ^^JExtra skip:\the\cuted@@tempdim@spread
          ^^JLeft:\the\ht\cuted@@tempbox@c/\the\dp\cuted@@tempbox@c
          ^^JRight:\the\ht\cuted@@varbox@c/\the\dp\cuted@@varbox@c
          ^^JSplit: \saved@tempdimb
          ^^JOutput:\the\cuted@@tempdim@b
          ^^JPageshrink: \the\pageshrink
          ^^JPagestretch: \the\pagestretch
          ^^J@colht:\the\@colht
          }%
    %%
    %% final construction of the cuted page above strip
    %%
    \setbox\cuted@@tempbox@c\vsplit\@holdpg to\saved@tempdimb
    \setbox\cuted@@tempbox@a\vbox to\cuted@@tempdim@b{%
        \cuted@@tempdim@a=\dimexpr
            \cuted@@tempdim@b-\ht\cuted@@tempbox@c
            \relax
        \cuted@@tempdim@spread=\dp\cuted@@tempbox@c
        \unvbox\cuted@@tempbox@c
        \ifdim\cuted@@tempdim@spread>\dp\strutbox
        \else
            \vskip-\cuted@@tempdim@spread
        \fi
        \prevdepth\z@
        \hrule\@height\cuted@@page@rule width\textwidth
        \vskip-\cuted@@page@rule
        \ifdim\cuted@@tempdim@a>\z@
            \if@left@column@spread
            \else
                \vss
            \fi
        \else
            \ifdim\cuted@@tempdim@a<\z@
                \if@left@column@shrink
                \else
                    \vss
                \fi
            \fi
        \fi
        }%
    \wlog{CUTED [output]: \the\cuted@@tempdim@b
          ^^JCUTED [leftcolumn badness]: \number\badness
         }%
    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@b{%
        \cuted@@tempdim@a=\dimexpr
            \cuted@@tempdim@b-\ht\@holdpg
            \relax
        \unvbox\@holdpg
        \ifdim\cuted@@tempdim@a>\z@
            \if@right@column@spread
            \else
                \vss
            \fi
        \else
            \ifdim\cuted@@tempdim@a<\z@
                \if@right@column@shrink
                \else
                    \vss
                \fi
            \fi
        \fi
        }%
    \wlog{CUTED [rightcolumn badness]: \number\badness}%
    \setbox\cuted@@tempbox@var\vbox{%
        \hb@xt@\textwidth{%
           \if@RTLmain
              \hskip \columnwidth
              \hfil
              {\normalcolor\vrule \@width\columnseprule}%
              \hfil
              \hb@xt@\columnwidth{%
                 \vbox to\ht@viper{\box\cuted@@tempbox@a\vss}%
                 \hss
              }%
              \hskip -\textwidth
              \hb@xt@\columnwidth{%
                 \vbox to\ht@viper{\box\cuted@@varbox@a\vss}%
                 \hss
              }%
              \hskip \columnsep
              \hskip \columnwidth
           \else
              \hb@xt@\columnwidth{%
                 \vbox to\ht@viper{\box\cuted@@tempbox@a\vss}%
                 \hss
              }%
              \hfil
              {\normalcolor\vrule \@width\columnseprule}%
              \hfil
              \hb@xt@\columnwidth{%
                 \vbox to\ht@viper{\box\cuted@@varbox@a\vss}%
                 \hss
              }%
           \fi
            }%
        }%
    %%
    %% finalize cuted page
    %%
    \ifvoid\hold@viper
        \global\setbox\hold@viper\vbox{%
            \unvbox\cuted@@tempbox@var
            \penalty\interlinepenalty
            \vskip\stripsep
            \the\preCutedStrip
            \ifnum\outputpenalty<-\@Mii
                \vskip -\parskip
            \fi
            \outputpenalty\z@
            }%
    \else
        \global\setbox\hold@viper\vbox{%
             \unvbox\hold@viper
             \cuted@@tempbox@var
             \penalty\interlinepenalty
             \vskip\stripsep
             \the\preCutedStrip
             \ifnum\outputpenalty<-\@Mii
                 \vskip -\parskip
             \fi
             \outputpenalty\z@
             }%
    \fi
    \ifdim\@colht>\@reqcolroom
        \global\setbox\hold@viper\vbox{%
             \unvbox\hold@viper
             \box\@viper
             \penalty\interlinepenalty
             \the\postCutedStrip
             \vskip\stripsep
             \ifnum\outputpenalty<-\@Mii
                 \vskip -\parskip
             \fi
             \outputpenalty\z@
             }%
        \@inserttrue
        \global\@firstcolumntrue
        \advance\ht@hold@viper by-\ht\hold@viper
        \global\advance\@colht by\ht@hold@viper
        \ifdim\@colht<2.5\baselineskip
            \@latex@warning@no@line {Optional argument of \noexpand\twocolumn
                                     too tall on page \thepage (\var@@thecol@num column)}%
            \@emptycol
            \if@firstcolumn
            \else
                \@emptycol
            \fi
            \global\@lastvipertrue
        \else
            \global\vsize\@colht
            \global\@colroom\@colht
            \check@floats\cuted@@tempdim@a
            \ifdim\cuted@@tempdim@a>\z@
                \global\advance\@colroom by-\cuted@@tempdim@a
            \fi
            \ifdim\@colroom<\z@
                \global\@colroom1\p@
                \ifdim\cuted@@tempdim@a>\@colht
                    \@latex@warning@no@line{TOP and/or BOT FLOAT's
                        to large on \thepage (\var@@thecol@num column)}%
                \fi
                \@emptycol
                \if@firstcolumn
                \else
                    \@emptycol
                \fi
                \global\@lastvipertrue
            \fi
        \fi
    \fi
    \if@insert
    \else
        \advance\ht@hold@viper by-\ht\hold@viper
        \global\advance\@colht by\ht@hold@viper
        \global\setbox\hold@viper\vbox{%
            \unvbox\hold@viper
            \set@split@topskip@to{\z@ plus2\p@}%
            \vsplit\@viper to\@colht
            \vss
            }%
        \vbox{}%
        \global\@firstcolumnfalse
        \newpage
    \fi
    }
%    \end{macrocode}
% \iffalse
%</cuted-xetex-bidi.def>
%<*cvthemebidicasual.sty>
%\fi
% \section{File \texttt{cvthemebidicasual.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cvthemebidicasual}
\DeclareOption{blue}{}
\newif\if@colourorange\@colourorangefalse
\DeclareOption{orange}{\@colourorangetrue}
\newif\if@colourgreen\@colourgreenfalse
\DeclareOption{green}{\@colourgreentrue}
\newif\if@colourred\@colourredfalse
\DeclareOption{red}{\@colourredtrue}
\newif\if@colourgrey\@colourgreyfalse
\DeclareOption{grey}{\@colourgreytrue}
\DeclareOption*{
  \PackageWarning{cvthemebidicasual}{Unknown option ‘\CurrentOption’}}
\ExecuteOptions{colour}
\ProcessOptions\relax
\renewcommand*{\listitemsymbol}{\textbullet}
\definecolor{firstnamecolor}{rgb}{0.65,0.65,0.65}
\familynamecolour{808080}
\firstnamecolour{A9A9A9}
\quotecolour{696969}
\addresscolour{696969}
\definecolor{sectionrectanglecolor}{rgb}{0.25,0.50,0.75}
\sectiontitlecolour{1E90FF}
\subsectioncolour{4682B4}
\definecolor{rulecolour}{gray}{0.6}
\definecolor{footersymbolcolour}{rgb}{0.25,0.50,0.75}
\definecolor{footersymbolcolor}{rgb}{0.25,0.50,0.75}
\if@colourorange
  \definecolor{sectionrectanglecolor}{rgb}{1.00,0.65,0.20}
  \definecolor{sectionrectanglecolor}{rgb}{1.00,0.65,0.20}
  \sectiontitlecolour{FF8C00}
  \subsectioncolour{FF8C00}
  \definecolor{footersymbolcolour}{rgb}{0.95,0.55,0.15}
  \definecolor{footersymbolcolor}{rgb}{0.95,0.55,0.15}\fi
\if@colourgreen
  \definecolor{sectionrectanglecolor}{rgb}{0.55,0.85,0.35}
  \definecolor{sectionrectanglecolour}{rgb}{0.55,0.85,0.35}
  \sectiontitlecolour{008000}
  \subsectioncolour{008000}
  \definecolor{footersymbolcolour}{rgb}{0.30,0.65,0.15}
  \definecolor{footersymbolcolor}{rgb}{0.30,0.65,0.15}\fi
\if@colourred
  \definecolor{sectionrectanglecolor}{rgb}{1.00,0.30,0.30}
  \definecolor{sectionrectanglecolour}{rgb}{1.00,0.30,0.30}
  \sectiontitlecolour{FF0000}
  \subsectioncolour{FF0000}
  \definecolor{footersymbolcolour}{rgb}{0.95,0.20,0.20}
  \definecolor{footersymbolcolor}{rgb}{0.95,0.20,0.20}\fi
\if@colourgrey
  \definecolor{sectionrectanglecolor}{rgb}{0.75,0.75,0.75}
  \definecolor{sectionrectanglecolour}{rgb}{0.75,0.75,0.75}
  \sectiontitlecolour{808080}
  \subsectioncolour{808080}
  \definecolor{footersymbolcolour}{rgb}{0.35,0.35,0.35}
  \definecolor{footersymbolcolor}{rgb}{0.35,0.35,0.35}\fi
\renewcommand*{\ttdefault}{pcr}
\renewcommand*{\firstnamefont}{\fontsize{38}{40}\mdseries\upshape}
\renewcommand*{\familynamefont}{\firstnamefont}
\renewcommand*{\addressfont}{\normalsize\mdseries\slshape}
\renewcommand*{\quotefont}{\large\slshape}
\renewcommand*{\sectionfont}{\Large\mdseries\upshape}
\renewcommand*{\subsectionfont}{\large\mdseries\upshape}
\renewcommand*{\maketitle}{%
  {%
    \ifthenelse{\isundefined{\@photo}}%
      {}%
      {{\color{firstnamecolor}\framebox{\includegraphics[width=\@photowidth]{\@photo}}}}%
    \hfill%
    \bidi@raggedleft{\firstnamestyle{\@firstname}~\familynamestyle{\@familyname}}\\[-.35em]}%
   {\color{firstnamecolor}\rule{\textwidth}{.25ex}\\[2.5em]}%
  \ifthenelse{\isundefined{\@quote}}%
    {}%
    {\centering{\begin{minipage}{\quotewidth}\centering\quotestyle{\@quote}\end{minipage}}\\[2.5em]}%
  }%
\newif\if@firstfooterelement\@firstfooterelementtrue
\providecommand*{\footersymbol}{}
\renewcommand*{\footersymbol}{%
  \if@firstfooterelement%
  \else%
    { ~~\color{footersymbolcolor}\textbullet~~~}\fi}
\providecommand*{\makefooter}{}
\renewcommand*{\makefooter}{%
  \fancypagestyle{plain}{%
    \fancyfoot[c]{%
      \parbox{0.8\textwidth}{%
      \centering%
      \addressfont\@addresscolour%
      \ifthenelse{\isundefined{\@address}}{}{%
        \addresssymbol~\@address\\%
        \@firstfooterelementfalse}%
      \ifthenelse{\isundefined{\@mobile}}{}{\mobilesymbol~\@mobile\@firstfooterelementfalse}%
      \ifthenelse{\isundefined{\@phone}}{}{\footersymbol\phonesymbol~\@phone\@firstfooterelementfalse}%
      \ifthenelse{\isundefined{\@fax}}{}{\footersymbol\faxsymbol~\@fax\@firstfooterelementfalse}%
      \ifthenelse{\isundefined{\@email}}{}{\footersymbol\emailsymbol~\emaillink{\@email}\@firstfooterelementfalse}%
      \ifthenelse{\isundefined{\@extrainfo}}{}{\footersymbol\@extrainfo\@firstfooterelementfalse}}}%
  }%
  \pagestyle{plain}}
\AtBeginDocument{\makefooter}
%    \end{macrocode}
% \iffalse
%</cvthemebidicasual.sty>
%<*cvthemebidiclassic.sty>
%\fi
% \section{File \texttt{cvthemebidiclassic.sty}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cvthemebidiclassic}
\DeclareOption{blue}{}
\newif\if@colourorange\@colourorangefalse
\DeclareOption{orange}{\@colourorangetrue}
\newif\if@colourgreen\@colourgreenfalse
\DeclareOption{green}{\@colourgreentrue}
\newif\if@colourred\@colourredfalse
\DeclareOption{red}{\@colourredtrue}
\newif\if@colourgrey\@colourgreyfalse
\DeclareOption{grey}{\@colourgreytrue}
\DeclareOption*{
  \PackageWarning{cvthemebidiclassic}{Unknown option ‘\CurrentOption’}}
\ExecuteOptions{colour}
\ProcessOptions\relax
\renewcommand*{\listitemsymbol}{\textbullet}
\firstnamecolour{}
\familynamecolour{}
\titlecolour{808080}
\quotecolour{696969}
\addresscolour{696969}
\definecolor{sectionrectanglecolour}{rgb}{0.25,0.50,0.75}
\definecolor{sectionrectanglecolor}{rgb}{0.25,0.5,0.75}
\sectiontitlecolour{1E90FF}
\subsectioncolour{4682B4}
\if@colourorange
  \addresscolour{FF8C00}
  \definecolor{sectionrectanglecolour}{rgb}{1.00,0.65,0.20}
  \definecolor{sectionrectanglecolor}{rgb}{1,0.65,0.20}
  \sectiontitlecolour{FF8C00}
  \subsectioncolour{FF8C00}\fi
\if@colourgreen
  \addresscolour{008000}
  \definecolor{sectionrectanglecolour}{rgb}{0.55,0.85,0.35}
  \definecolor{sectionrectanglecolor}{rgb}{0.55,0.85,0.35}
  \sectiontitlecolour{008000}
  \subsectioncolour{008000}\fi
\if@colourred
  \addresscolour{FF0000}
  \definecolor{sectionrectanglecolour}{rgb}{1.00,0.30,0.30}
  \definecolor{sectionrectanglecolor}{rgb}{1.00,0.30,0.30}
  \sectiontitlecolour{FF0000}
  \subsectioncolour{FF0000}\fi
\if@colourgrey
  \addresscolour{808080}
  \definecolor{sectionrectanglecolour}{rgb}{0.75,0.75,0.75}
  \definecolor{sectionrectanglecolor}{rgb}{0.75,0.75,0.75}
  \sectiontitlecolour{808080}
  \subsectioncolour{808080}\fi
\renewcommand*{\ttdefault}{pcr}
\renewcommand*{\firstnamefont}{\fontsize{34}{36}\mdseries\upshape}
\renewcommand*{\titlefont}{\LARGE\mdseries\slshape}
\renewcommand*{\addressfont}{\normalsize\mdseries\slshape}
\renewcommand*{\familynamefont}{\firstnamefont}
\renewcommand*{\quotefont}{\large\slshape}
\renewcommand*{\sectionfont}{\Large\mdseries\upshape}
\renewcommand*{\subsectionfont}{\large\mdseries\upshape}
\newlength{\maketitlenamemaxwidth}
\setlength{\maketitlenamemaxwidth}{.525\textwidth}
\newlength{\maketitlenamefullwidth}
\settowidth{\maketitlenamefullwidth}{\firstnamestyle{\@firstname~}\familynamestyle{\@familyname}}
\newlength{\maketitlenamewidth}
\ifnum\maketitlenamemaxwidth<\maketitlenamefullwidth\setlength{\maketitlenamewidth}{\maketitlenamemaxwidth}\else\setlength{\maketitlenamewidth}{\maketitlenamefullwidth}\fi
\newlength{\maketitlepicturewidth}
\setlength{\maketitlepicturewidth}{\@photowidth}
\newlength{\maketitledetailswidth}
\renewcommand*{\recomputethemelengths}{%
  \setlength{\maketitledetailswidth}{\textwidth}%
  \addtolength{\maketitledetailswidth}{-\maketitlenamewidth}%
  \addtolength{\maketitledetailswidth}{-\separatorcolumnwidth}%
  \addtolength{\maketitledetailswidth}{-\maketitlepicturewidth}}
\recomputethemelengths
\newif\if@firstdetailselement\@firstdetailselementtrue
\newcommand*{\maketitledetailsnewline}{
  \if@firstdetailselement%
    \@firstdetailselementfalse%
  \else%
    \\[.2em]\fi}
\renewcommand*{\maketitle}{%
  % name and title
  \begin{minipage}[b]{\maketitlenamewidth}%
    \firstnamestyle{\@firstname~}\familynamestyle{\@familyname}%
    \ifthenelse{\equal{\@title}{}}{}{\\[1.25em]\titlestyle{\@title}}%
  \end{minipage}%
  % optional data
  \begin{minipage}[b]{\maketitledetailswidth}%
    \bidi@raggedleft\addressfont\@addresscolour%
   \ifthenelse{\isundefined{\@address}}{}{%
      \maketitledetailsnewline%
      \addresssymbol~\\\@address}%
    \ifthenelse{\isundefined{\@mobile}}{}{\maketitledetailsnewline\mobilesymbol~\@mobile}%
    \ifthenelse{\isundefined{\@phone}}{}{\maketitledetailsnewline\phonesymbol~\@phone}%
    \ifthenelse{\isundefined{\@fax}}{}{\maketitledetailsnewline\faxsymbol~\@fax}%
    \ifthenelse{\isundefined{\@email}}{}{\maketitledetailsnewline\emailsymbol~\emaillink{\@email}}%
    \ifthenelse{\isundefined{\@extrainfo}}{}{\maketitledetailsnewline\@extrainfo}%
  \end{minipage}%
  % optional photo
  \ifthenelse{\isundefined{\@photo}}%
    {}%
    {\hspace*{\separatorcolumnwidth}\color{firstnamecolor}\framebox{\includegraphics[width=\maketitlepicturewidth]{\@photo}}}\\[3em]%
  % optional quote
  \ifthenelse{\isundefined{\@quote}}%
    {}%
    {\centering{\begin{minipage}{\quotewidth}\centering\quotestyle{\@quote}\end{minipage}}\\[2.5em]}%
  }
%    \end{macrocode}
% \iffalse
%</cvthemebidiclassic.sty>
%<*dblfnote-xetex-bidi.def>
%\fi
% \section{File \texttt{dblfnote-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{dblfnote-xetex-bidi.def}[2012/12/12 v0.3 bidi adaptations for dblfnote package for XeTeX engine]
\let\autofootnoterule\relax
\let\rightfootnoterule\relax
\let\leftfootnoterule\relax
\let\textwidthfootnoterule\relax
\let\LRfootnoterule\relax
\def\footnoterule{\kern-3\p@
  \hrule \@width  \DFNcolumnwidth \kern 2.6\p@}%   
\AtBeginDocument{\let\dfn@latex@footnotetext\@footnotetext
\let\@footnotetext\dfn@footnotetext}
\long\def\dfn@LTRfootnotetext#1{{\setbox\dfn@boxa\vbox{
        \let\insert\dfn@gobble
        \columnwidth\DFNcolumnwidth \hbadness\c@DFNsloppiness
        \def\@makefnmark{\smash{\dfn@makefnmark}}
        \dfn@latex@LTRfootnotetext{#1}\par \boxmaxdepth\dfn@fnmaxdp}%
        \dfn@dima\ht\dfn@boxa \advance\dfn@dima\dp\dfn@boxa
        \ifdim\dfn@dima>\z@\else
                \dfn@dima1sp\relax
                \setbox\dfn@boxa\vbox{\vbox to1sp{\unvbox\dfn@boxa\vfil}}\fi
        \global\setbox\dfn@ins\vbox{\boxmaxdepth\dfn@fnmaxdp
                \ifvoid\dfn@ins\else
                        \unvbox\dfn@ins \allowbreak \nointerlineskip \fi
                \ifdfn@allowcbreak \unvbox \else \box \fi \dfn@boxa}%
        \setbox\dfn@boxa\copy\dfn@ins
        \dfn@split{.5\ht\dfn@boxa}\dfn@boxa\dfn@boxb\dfn@fnmaxdp\footnotesep
        \advance\@tempdima\@tempdimb \@tempdimb\@tempdima
        \advance\@tempdima-\dfn@fnht \global\dfn@fnht\@tempdimb
        \insert\footins{\floatingpenalty\@MM \vbox to\@tempdima{}}%
        \xdef\dfn@list{\dfn@list\@elt{\number\dfn@dima}{\number\@tempdima}}}}
\AtBeginDocument{\let\dfn@latex@LTRfootnotetext\@LTRfootnotetext
\let\@LTRfootnotetext\dfn@LTRfootnotetext}
\long\def\dfn@RTLfootnotetext#1{{\setbox\dfn@boxa\vbox{
        \let\insert\dfn@gobble
        \columnwidth\DFNcolumnwidth \hbadness\c@DFNsloppiness
        \def\@makefnmark{\smash{\dfn@makefnmark}}
        \dfn@latex@RTLfootnotetext{#1}\par \boxmaxdepth\dfn@fnmaxdp}%
        \dfn@dima\ht\dfn@boxa \advance\dfn@dima\dp\dfn@boxa
        \ifdim\dfn@dima>\z@\else
                \dfn@dima1sp\relax
                \setbox\dfn@boxa\vbox{\vbox to1sp{\unvbox\dfn@boxa\vfil}}\fi
        \global\setbox\dfn@ins\vbox{\boxmaxdepth\dfn@fnmaxdp
                \ifvoid\dfn@ins\else
                        \unvbox\dfn@ins \allowbreak \nointerlineskip \fi
                \ifdfn@allowcbreak \unvbox \else \box \fi \dfn@boxa}%
        \setbox\dfn@boxa\copy\dfn@ins
        \dfn@split{.5\ht\dfn@boxa}\dfn@boxa\dfn@boxb\dfn@fnmaxdp\footnotesep
        \advance\@tempdima\@tempdimb \@tempdimb\@tempdima
        \advance\@tempdima-\dfn@fnht \global\dfn@fnht\@tempdimb
        \insert\footins{\floatingpenalty\@MM \vbox to\@tempdima{}}%
        \xdef\dfn@list{\dfn@list\@elt{\number\dfn@dima}{\number\@tempdima}}}}
\AtBeginDocument{\let\dfn@latex@RTLfootnotetext\@RTLfootnotetext
\let\@RTLfootnotetext\dfn@RTLfootnotetext}
\def\dfn@RTLmakecol{{\ifvoid\footins\else
        \dfn@dima\ht\footins
        \@tempcnta\z@ \dfn@countins
        \@tempdima\z@ \let\@elt\dfn@elt@getht
        \dfn@list\@nil
        \ifdim\@tempdima=\z@\else
        \dfn@split\@tempdima\dfn@ins\dfn@boxa\z@\z@
        \global\setbox\dfn@ins\box\dfn@ins
        \@tempswatrue
        \ifdfn@trysingle
                \setbox\dfn@boxb\vbox{\unvcopy\@cclv}\@tempdima\@colroom
                \advance\@tempdima-\ht\dfn@boxb \advance\@tempdima-\dp\dfn@boxb
                \advance\@tempdima-\skip\footins
                \advance\@tempdima-\ht\dfn@boxa
                \ifdim\@tempdima<\z@\else \@tempswafalse
                        \global\setbox\footins\vbox{\boxmaxdepth\dfn@fnmaxdp
                                \footnoterule \unvbox\dfn@boxa}\fi\fi
        \if@tempswa
        \dfn@split{\dfn@dima}\dfn@boxa\dfn@boxb\dfn@fnmaxdp\footnotesep
        \global\setbox\footins\vbox{\hbox{%
                 \hskip \DFNcolumnwidth
                 \hskip\DFNcolumnsep
                \hbox to\DFNcolumnwidth{\vbox to\@tempdima{\footnoterule
                        \unvbox\dfn@boxb\vss}\hss}
                \hskip -\textwidth
                \hbox to\DFNcolumnwidth{\ifvoid\dfn@boxa\else
                        \vbox to\@tempdima{
                                \setbox\@tempboxa\vbox{\footnoterule}
                                \ifdfn@ruleboth \unvbox\@tempboxa
                                \else \@tempdima\ht\@tempboxa
                                        \advance\@tempdima\dp\@tempboxa
                                        \vskip\@tempdima
                                        \prevdepth\dp\@tempboxa \fi
                                \unvbox\dfn@boxa\vss}\fi\hss}
                                 \hskip \DFNcolumnsep
                                 \hskip \DFNcolumnwidth}}\fi\fi
        \global\dfn@fnht\z@
        \ifx\dfn@list\@empty\else
                \let\@elt\dfn@elt@adjust \dfn@dima\z@ \dfn@dimb\z@
                \dfn@list \global\advance\dfn@fnht\dfn@dimb
                \let\@elt\relax
                \ifdim\dfn@dimb>\z@
                        \xdef\dfn@list{\@elt{0}{\number\dfn@dimb}\dfn@list}%
                        \insert\footins{\floatingpenalty\@MM
                                \vbox to\dfn@dimb{}}\fi
                \ifdim\dfn@fnht>\@tempdima
                        \@tempdimb\@tempdima \advance\@tempdimb-\dfn@fnht
                        \global\dfn@fnht\@tempdima
                        \xdef\dfn@list{\dfn@list\@elt{0}{\number\@tempdimb}}%
                        \xdef\dfn@afteroutput{\insert\footins{
                                        \floatingpenalty\@MM
                                        \vbox to\number\@tempdimb sp{}}%
                                \global\let\noexpand\dfn@afteroutput\relax}%
                \fi\fi
        \fi}%
        \let\footnoterule\relax \dfn@latex@makecol
        \let\footnoterule\dfn@footnoterule}
\def\dfn@LTRmakecol{{\ifvoid\footins\else
        \dfn@dima\ht\footins
        \@tempcnta\z@ \dfn@countins
        \@tempdima\z@ \let\@elt\dfn@elt@getht
        \dfn@list\@nil
        \ifdim\@tempdima=\z@\else
        \dfn@split\@tempdima\dfn@ins\dfn@boxa\z@\z@
        \global\setbox\dfn@ins\box\dfn@ins
        \@tempswatrue
        \ifdfn@trysingle
                \setbox\dfn@boxb\vbox{\unvcopy\@cclv}\@tempdima\@colroom
                \advance\@tempdima-\ht\dfn@boxb \advance\@tempdima-\dp\dfn@boxb
                \advance\@tempdima-\skip\footins
                \advance\@tempdima-\ht\dfn@boxa
                \ifdim\@tempdima<\z@\else \@tempswafalse
                        \global\setbox\footins\vbox{\boxmaxdepth\dfn@fnmaxdp
                                \footnoterule \unvbox\dfn@boxa}\fi\fi
        \if@tempswa
        \dfn@split{\dfn@dima}\dfn@boxa\dfn@boxb\dfn@fnmaxdp\footnotesep
        \global\setbox\footins\vbox{\hbox{%
                \hbox to\DFNcolumnwidth{\vbox to\@tempdima{\footnoterule
                        \unvbox\dfn@boxb\vss}\hss}\hskip\DFNcolumnsep
                \hbox to\DFNcolumnwidth{\ifvoid\dfn@boxa\else
                        \vbox to\@tempdima{
                                \setbox\@tempboxa\vbox{\footnoterule}
                                \ifdfn@ruleboth \unvbox\@tempboxa
                                \else \@tempdima\ht\@tempboxa
                                        \advance\@tempdima\dp\@tempboxa
                                        \vskip\@tempdima
                                        \prevdepth\dp\@tempboxa \fi
                                \unvbox\dfn@boxa\vss}\fi\hss}}}\fi\fi
        \global\dfn@fnht\z@
        \ifx\dfn@list\@empty\else
                \let\@elt\dfn@elt@adjust \dfn@dima\z@ \dfn@dimb\z@
                \dfn@list \global\advance\dfn@fnht\dfn@dimb
                \let\@elt\relax
                \ifdim\dfn@dimb>\z@
                        \xdef\dfn@list{\@elt{0}{\number\dfn@dimb}\dfn@list}%
                        \insert\footins{\floatingpenalty\@MM
                                \vbox to\dfn@dimb{}}\fi
                \ifdim\dfn@fnht>\@tempdima
                        \@tempdimb\@tempdima \advance\@tempdimb-\dfn@fnht
                        \global\dfn@fnht\@tempdima
                        \xdef\dfn@list{\dfn@list\@elt{0}{\number\@tempdimb}}%
                        \xdef\dfn@afteroutput{\insert\footins{
                                        \floatingpenalty\@MM
                                        \vbox to\number\@tempdimb sp{}}%
                                \global\let\noexpand\dfn@afteroutput\relax}%
                \fi\fi
        \fi}%
        \let\footnoterule\relax \dfn@latex@makecol
        \let\footnoterule\dfn@footnoterule}
\renewcommand{\dfn@makecol}{\if@RTLmain\dfn@RTLmakecol\else\dfn@LTRmakecol\fi}
\newcommand{\RTLdfnmakecol}{\renewcommand{\dfn@makecol}{\dfn@RTLmakecol}}
\newcommand{\LTRdfnmakecol}{\renewcommand{\dfn@makecol}{\dfn@LTRmakecol}}
\DFNalwaysdouble 
%    \end{macrocode}
% \iffalse
%</dblfnote-xetex-bidi.def>
%<*diagbox-xetex-bidi.def>
%\fi
% \section{File \texttt{diagbox-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{diagbox-xetex-bidi.def}[2017/12/30 v0.2 bidi adaptations for diagbox package for XeTeX engine]
\bidi@patchcmd{\diagbox@double}{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
}{\bidi@@diagbox@double@ii}{}{}
\bidi@patchcmd{\diagbox@double}{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
}{\bidi@@diagbox@double@iii}{}{}
\newcommand*{\bidi@@diagbox@double@ii}{%
  \if@RTL
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepl}}}
  \else
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
  \fi
}
\newcommand*{\bidi@@diagbox@double@iii}{%
  \if@RTL
    \begin{tabular}{@{\hspace{\diagbox@insepr}}>{\diagbox@font}l@{}}
  \else
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
  \fi
}
\bidi@patchcmd{\diagbox@triple@setbox@NW}{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
}{\bidi@@diagbox@triple@setbox@NW@tabular@i@ii}{}{}
\bidi@patchcmd{\diagbox@triple@setbox@NW}{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
}{\bidi@@diagbox@triple@setbox@NW@tabular@i@ii}{}{}
\bidi@patchcmd{\diagbox@triple@setbox@NW}{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
}{\bidi@@diagbox@triple@setbox@NW@tabular@iii}{}{}
\newcommand*{\bidi@@diagbox@triple@setbox@NW@tabular@i@ii}{%
  \if@RTL
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepl}}}
  \else
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
  \fi}
\newcommand*{\bidi@@diagbox@triple@setbox@NW@tabular@iii}{%
  \if@RTL
    \begin{tabular}{@{\hspace{\diagbox@insepr}}>{\diagbox@font}l@{}}
  \else
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
  \fi}
\let\diagbox@triple@setbox@SW\diagbox@triple@setbox@NW
\bidi@patchcmd{\diagbox@triple@setbox@SE}{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}l@{}}%
}{\bidi@@diagbox@triple@setbox@SE@tabular@i}{}{}
\bidi@patchcmd{\diagbox@triple@setbox@SE}{%
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepr}}}%
}{\bidi@@diagbox@triple@setbox@SE@tabular@ii@iii}{}{}
\bidi@patchcmd{\diagbox@triple@setbox@SE}{%
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepr}}}%
}{\bidi@@diagbox@triple@setbox@SE@tabular@ii@iii}{}{}
\newcommand*{\bidi@@diagbox@triple@setbox@SE@tabular@i}{%
  \if@RTL
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepl}}}
  \else
    \begin{tabular}{@{\hspace{\diagbox@insepl}}l@{}}
  \fi
}
\newcommand*{\bidi@@diagbox@triple@setbox@SE@tabular@ii@iii}{%
  \if@RTL
    \begin{tabular}{@{\hspace{\diagbox@insepr}}l@{}}
  \else
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepr}}}
  \fi
}
\let\diagbox@triple@setbox@NE\diagbox@triple@setbox@SE
\bidi@patchcmd{\diagbox@double@pict@SE}{%
  \diagbox@setlinecolor
  \Line(0,\strip@pt\diagbox@ht)(\strip@pt\diagbox@wd,0)%
}{%
  {\diagbox@setlinecolor
  \Line(0,\strip@pt\diagbox@ht)(\strip@pt\diagbox@wd,0)}%
}{}{}
\let\diagbox@double@pict@NW\diagbox@double@pict@SE
\bidi@patchcmd{\diagbox@double@pict@NE}{%
  \diagbox@setlinecolor
  \Line(0,0)(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht)%
}{%
  {\diagbox@setlinecolor
  \Line(0,0)(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht)}%
}{}{}
\let\diagbox@double@pict@SW\diagbox@double@pict@NE
\bidi@patchcmd{\diagbox@triple@pict@NW}{%
  \diagbox@setlinecolor
  \Line(0,\yym)(\x,0)
  \Line(\xm,\y)(\x,0)%
}{%
  {\diagbox@setlinecolor
  \Line(0,\yym)(\x,0)
  \Line(\xm,\y)(\x,0)}%
}{}{}
\bidi@patchcmd{\diagbox@triple@pict@NE}{%
  \diagbox@setlinecolor
  \Line(0,0)(\xxm,\y)
  \Line(0,0)(\x,\yym)%
}{%
  {\diagbox@setlinecolor
  \Line(0,0)(\xxm,\y)
  \Line(0,0)(\x,\yym)}%
}{}{}
\bidi@patchcmd{\diagbox@triple@pict@SW}{%
  \diagbox@setlinecolor
  \Line(0,\ym)(\x,\y)
  \Line(\xm,0)(\x,\y)%
}{%
  {\diagbox@setlinecolor
  \Line(0,\ym)(\x,\y)
  \Line(\xm,0)(\x,\y)}%
}{}{}
\bidi@patchcmd{\diagbox@triple@pict@SE}{%
  \diagbox@setlinecolor
  \Line(0,\y)(\xxm,0)
  \Line(0,\y)(\x,\ym)%
}{%
  {\diagbox@setlinecolor
  \Line(0,\y)(\xxm,0)
  \Line(0,\y)(\x,\ym)}%
}{}{}
%    \end{macrocode}
% \iffalse
%</diagbox-xetex-bidi.def>
%<*draftwatermark-xetex-bidi.def>
%\fi
% \section{File \texttt{draftwatermark-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{draftwatermark-xetex-bidi.def}[2010/07/25 v0.2 bidi adaptations for draftwatermark package for XeTeX engine]
\renewcommand\SetWatermarkText[1]{%
  \def\sc@wm@text{\if@RTLmain\beginR\fi#1\if@RTLmain\endR\fi}}
%    \end{macrocode}
% \iffalse
%</draftwatermark-xetex-bidi.def>
%<*eso-pic-xetex-bidi.def>
%\fi
% \section{File \texttt{eso-pic-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{eso-pic-xetex-bidi.def}[2022/02/18 v0.4 bidi adaptations for eso-pic package for XeTeX engine]
\renewcommand\AtPageLowerLeft[1]{\AtPageUpperLeft{%
  \put(\if@RTLmain\paperwidth\else 0\fi,-\paperheight){#1}}}

\ESO@isMEMOIR{%
  \renewcommand\AtTextUpperLeft[1]{%
    \begingroup
      \ifodd\c@page
        \if@RTLmain
          \ESO@tempdima=\paperwidth
          \advance\ESO@tempdima-\textwidth
          \advance\ESO@tempdima-\spinemargin
        \else
          \ESO@tempdima=\spinemargin
        \fi
      \else
        \if@RTLmain
          \ESO@tempdima=\spinemargin
        \else
          \ESO@tempdima=\paperwidth
          \advance\ESO@tempdima-\textwidth
          \advance\ESO@tempdima-\spinemargin
        \fi
      \fi
      \ESO@tempdimb=-\uppermargin
      \AtPageUpperLeft{%
        \put(\if@RTLmain-\textwidth-\fi\ESO@tempdima,\ESO@tempdimb){#1}%
      }%
    \endgroup
  }
}{%
  \renewcommand\AtTextUpperLeft[1]{%
    \begingroup
      \ESO@tempdima=1in\relax
      \if@twoside
        \ifodd\c@page
          \if@RTLmain
            \advance\ESO@tempdima\evensidemargin
          \else
            \advance\ESO@tempdima\oddsidemargin
          \fi
        \else
          \if@RTLmain
            \advance\ESO@tempdima\oddsidemargin
          \else
            \advance\ESO@tempdima\evensidemargin
          \fi
        \fi
      \else
        \advance\ESO@tempdima\oddsidemargin
      \fi
      \ESO@tempdimb=-1in\relax
      \advance\ESO@tempdimb-\topmargin
      \advance\ESO@tempdimb-\headheight
      \advance\ESO@tempdimb-\headsep
      \AtPageUpperLeft{%
        \put(\if@RTLmain-\textwidth-\fi\ESO@tempdima,\ESO@tempdimb){#1}%
      }%
    \endgroup
  }
}
%    \end{macrocode}
% \iffalse
%</eso-pic-xetex-bidi.def>
%<*empheq-xetex-bidi.def>
%\fi
% \section{File \texttt{empheq-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{empheq-xetex-bidi.def}[2018/01/08 v0.2 bidi adaptations for empheq package for XeTeX engine]
\MHInternalSyntaxOn
\def\EQ_tag_plus_endmark:{%
  \iftagsleft@
    \gdef\maketag@@@##1{%
      \hfuzz\displaywidth
      \if@RTL\makebox[\widthof{##1}][r]{%
        \hbox to \displaywidth{\m@th\normalfont##1\hss
          \raisebox{-\dp\EQ_mathdisplay_box
                    -\depthof{\EQ_outerbox:{}}}
                   {\PotEndMark{\hss}}}}
      \else\makebox[\widthof{##1}][l]{%
        \hbox to \displaywidth{\m@th\normalfont##1\hss
          \raisebox{-\dp\EQ_mathdisplay_box
                    -\depthof{\EQ_outerbox:{}}}
                   {\PotEndMark{\hss}}}}\fi}%
  \MH_else:
    \gdef\maketag@@@##1{%
      \hbox{\m@th\normalfont##1\llap{\hss\PotEndMark{%
        \settoheight{\@tempdima}{\@nameuse{\InTheoType Symbol}}%
        \MH_addtolength:dn \@tempdima
          {\g_EQ_bottomtag_depth_dim+\mintagvsep}
        \setlength{\@tempdimb}
          {\g_EQ_bottomrow_depth_dim+\depthof{\EQ_outerbox:{}}
            +\depthof{\EQ_innerbox:{}}}
        \MH_if_dim:w \@tempdima>\@tempdimb
          \MH_setlength:dn \@tempdima{-\dp\EQ_mathdisplay_box
            -\@tempdima+\g_EQ_bottomrow_depth_dim}
          \addtolength{\@tempdima}{\depthof{\EQ_innerbox:{}}}%
          \def\EQ_next:{\raisebox{\@tempdima}}%
        \MH_else:
          \def\EQ_next:{
            \raisebox{-\dp\EQ_mathdisplay_box
                      -\depthof{\EQ_outerbox:{}}}}%
        \MH_fi:\EQ_next:}}}}%
  \MH_fi:}
\def\EQ_post_process:{%
  \EQ_initialize:
  \EQ_begin_equation:
  \MH_if_boolean:nT {outer_mult}{
    \setkeys{\MT_options_name:}{
      firstline-afterskip=0pt,
      lastline-preskip=0pt,
      multlined-width=0pt,
    }
    \ifodd \l_EQ_alignmentmode_int
      \setkeys{\MT_options_name:}{multlined-pos=b}
    \MH_else:
      \setkeys{\MT_options_name:}{multlined-pos=t}
    \MH_fi:
      \g@addto@macro\EQ_complete_mathdisplay:{
        \begin{MTmultlined}\relax}
  }
  \g@addto@macro\EQ_complete_mathdisplay:\EQ_mathbody:
  \MH_if_boolean:nT {outer_mult}{
    \g@addto@macro\EQ_complete_mathdisplay:{\end{MTmultlined}}
  }
  \EQ_end_equation:
  \edef\EQ_hyperref_link_fint{\number\Hy@linkcounter}
  \savecounters@
  \EQ_typeset_tags:
  \edef\l_EQ_equation_fint{\number\c@equation}
  \restorecounters@
  \Hy@linkcounter=\EQ_hyperref_link_fint
  \settowidth\l_EQ_totalwidth_dim{%
    $\EQ_left_side:\EQ_innerbox:{}\EQ_right_side:$}%
  \MH_if_boolean:nTF {outer_mult}
    { \def\EQ_next:{_mult} }
    { \def\EQ_next:{} }
  \@nameuse{EQ_modify_linewidth_
            \romannumeral\l_EQ_equationtype_int\EQ_next: :}%
  \EQ_typeset_display:
  \@nameuse{EQ_find_displaywidth_
           \romannumeral\l_EQ_equationtype_int\EQ_next: :}
  \MH_addtolength:dn
    \l_EQ_totalwidth_dim{\l_EQ_displaywidth_dim}
  \savebox\EQ_mathdisplay_box[\l_EQ_totalwidth_dim][c]{%
    $\EQ_left_side:
    \EQ_innerbox:{%
      \MH_if_case:w \l_EQ_alignmentmode_int\MH_or:
        \makebox[\l_EQ_displaywidth_dim][c]
          {\usebox{\EQ_mathdisplay_box}}%
      \MH_or:
        \makebox[\l_EQ_displaywidth_dim][c]
          {\usebox{\EQ_mathdisplay_box}}%
      \MH_or:
        \if@RTL\makebox[\l_EQ_displaywidth_dim][r]{%
          \MH_if_num:w \l_EQ_equationtype_int=5 \MH_else:
            \MH_if_num:w \l_EQ_equationtype_int=6 \MH_else:
              \kern-\@mathmargin
            \MH_fi:
          \MH_fi:
          \usebox{\EQ_mathdisplay_box}}%
        \else\makebox[\l_EQ_displaywidth_dim][l]{%
          \MH_if_num:w \l_EQ_equationtype_int=5 \MH_else:
            \MH_if_num:w \l_EQ_equationtype_int=6 \MH_else:
              \kern-\@mathmargin
            \MH_fi:
          \MH_fi:
          \usebox{\EQ_mathdisplay_box}}\fi%
      \MH_or:
        \if@RTL\makebox[\l_EQ_displaywidth_dim][r]{%
          \MH_if_num:w \l_EQ_equationtype_int=5 \MH_else:
            \MH_if_num:w \l_EQ_equationtype_int=6 \MH_else:
              \kern-\@mathmargin
            \MH_fi:
          \MH_fi:
          \usebox{\EQ_mathdisplay_box}}
        \else\makebox[\l_EQ_displaywidth_dim][l]{%
          \MH_if_num:w \l_EQ_equationtype_int=5 \MH_else:
            \MH_if_num:w \l_EQ_equationtype_int=6 \MH_else:
              \kern-\@mathmargin
            \MH_fi:
          \MH_fi:
          \usebox{\EQ_mathdisplay_box}}\fi%
      \MH_fi:}%
    \EQ_right_side:$}%
  \begin{AmSequation*}
  \@nameuse{EQ_place_display_
           \romannumeral\l_EQ_equationtype_int\EQ_next: :}
  \MH_if_dim:w \g_EQ_widesttag_dim>\z@
  \MH_set_boolean_T:n {show_manual_tags}
    \MH_if_case:w \l_EQ_alignmentmode_int
    \MH_or: \if@RTL\EQ_place_tag:N l\else\EQ_place_tag:N r\fi %#1
    \MH_or: \if@RTL\EQ_place_tag:N r\else\EQ_place_tag:N l\fi %#2
    \MH_or: \if@RTL\EQ_place_tag:N l\else\EQ_place_tag:N r\fi %#3
    \MH_or: \if@RTL\EQ_place_tag:N r\else\EQ_place_tag:N l\fi %#4
    \MH_fi:
  \MH_fi:
  \end{AmSequation*}
  \global\c@equation=\l_EQ_equation_fint\relax
}
\AtBeginDocument{%
  \@ifpackageloaded{fancybox}{%
    \@ifpackageloaded{color}{\definecolor{shadowcolor}{rgb}{0,0,0}}%
    {\renewcommand*\textcolor[2]{\normalcolor{#2}}}%
    \renewcommand*\shadowbox{%
      \@ifstar{\MH_set_boolean_T:n {shadowbox_star}
               \VerbBox\EQ_shadowbox:n}
              {\MH_set_boolean_F:n {shadowbox_star}
               \VerbBox\EQ_shadowbox:n}}
    \def\EQ_shadowbox:n #1{%
      \sbox{\z@}{\fbox{#1}}%
      \MH_if_boolean:nTF {shadowbox_star}{
        \MH_setlength:dn \@tempdima{\z@}%
      }{
        \MH_setlength:dn \@tempdima{\dp\z@+\shadowsize}%
      }
      \raisebox{\@tempdima}{%
        \if@RTL\makebox[\z@][r]{%
          \kern\shadowsize \textcolor{shadowcolor}{%
            \rule[-\dp\z@-\shadowsize]{\wd\z@}{\shadowsize}}%
        }%
        \else\makebox[\z@][l]{%
          \kern\shadowsize \textcolor{shadowcolor}{%
            \rule[-\dp\z@-\shadowsize]{\wd\z@}{\shadowsize}}%
        }\fi%
        \usebox\z@\textcolor{shadowcolor}{%
          \rule[-\dp\z@-\shadowsize]{\shadowsize}{\ht\z@+\dp\z@}}}}%
  }{}%
}
\MHInternalSyntaxOff
%    \end{macrocode}
% \iffalse
%</empheq-xetex-bidi.def>
%<*extarticle-xetex-bidi.def>
%\fi
% \section{File \texttt{extarticle-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{extarticle-xetex-bidi.def}[2025/09/30 v0.8 bidi adaptations for extarticle class for XeTeX engine]
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
      \hskip -\if@RTL\rightskip\else\leftskip\fi
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
  \renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty\@secpenalty
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
    \endgroup
  \fi}
\ApplyPatchIfPackageLoaded{nameref}{%
  \bidi@patchcmd\NR@part\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\NR@part' failed}}%
  \bidi@patchcmd\NR@spart\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\NR@spart' failed}}%
}{%
  \bidi@patchcmd\@part\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\@part' failed}}%
  \bidi@patchcmd\@spart\raggedright{%
    \if@RTL\raggedleft\else\raggedright\fi
  }{}{\bidi@warningnoline{Oops! patching `\string\@spart' failed}}%
}
\renewenvironment{thebibliography}[1]
     {\section*{\refname
        \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}}%
         \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
         \bidi@@thebibliography@font@hook%
         \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}  
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
    \if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}%% 
%    \end{macrocode}
% \iffalse
%</extarticle-xetex-bidi.def>
%<*extbook-xetex-bidi.def>
%\fi
% \section{File \texttt{extbook-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{extbook-xetex-bidi.def}[2017/06/09 v0.4 bidi adaptations for extbook class for XeTeX engine]
  \if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\renewcommand\theequation
  {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand \thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand \thetable
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand \thesection {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}

\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}
\renewcommand\backmatter{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \@mainmatterfalse}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname
        \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
%    \end{macrocode}
% \iffalse
%</extbook-xetex-bidi.def>
%<*extletter-xetex-bidi.def>
%\fi
% \section{File \texttt{extletter-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{extletter-xetex-bidi.def}[2025/09/30 v0.3 bidi adaptations for extletter class for XeTeX engine]
\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\if@RTL\raggedright\else\raggedleft\fi\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\if@RTL\raggedright\begin{tabular}{r@{}}\else\raggedleft\begin{tabular}{l@{}}\fi\ignorespaces
      \fromaddress \\*[2\parskip]%
      \@date \end{tabular}\par}%
  \fi
  \vspace{2\parskip}%
  {\if@RTL\raggedleft\else\raggedright\fi \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\renewcommand{\closing}[1]{\par\nobreak\vspace{\parskip}%
  \stopbreaks
  \noindent
  \ifx\@empty\fromaddress\else
  \hspace*{\longindentation}\fi
  \parbox{\indentedwidth}{\if@RTL\raggedleft\else\raggedright\fi
       \ignorespaces #1\\[6\medskipamount]%
       \ifx\@empty\fromsig
           \fromname
       \else \fromsig \fi\strut}%
   \par}
\renewcommand\left@footnoterule{%
  \kern-\p@
  \hrule \@width .4\columnwidth
  \kern .6\p@}
\renewcommand\right@footnoterule{%
  \kern-\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern .6\p@}
%    \end{macrocode}
% \iffalse
%</extletter-xetex-bidi.def>
%<*extrafootnotefeatures-xetex-bidi.def>
%\fi
% \section{File \texttt{extrafootnotefeatures-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{extrafootnotefeatures-xetex-bidi.def}[2025/09/13 v2.8 bidi extra footnote features for XeTeX engine]
\newdimen\bidi@columnwidth
\def\bidi@floathook{%
  \bidi@columnwidth\columnwidth
}
\newcommand*{\@bidi@before@Hy@hyperfootnotes}{%
\if@bidi@csundef{ifHy@hyperfootnotes}{}{%
\if@bidi@csundef{HLTR@@LTRfootnotetext}{}{%
\ifHy@hyperfootnotes
  \let\@@H@@footnotetext\@footnotetext
  \let\@@HLTR@@LTRfootnotetext\@LTRfootnotetext
  \let\@@HRTL@@RTLfootnotetext\@RTLfootnotetext
  \let\@@H@@mpfootnotetext\@mpfootnotetext
  \let\@@HLTR@@mpLTRfootnotetext\@mpLTRfootnotetext
  \let\@@HRTL@@mpRTLfootnotetext\@mpRTLfootnotetext
\fi
}%
}%
}
\newcommand*{\@bidi@after@Hy@hyperfootnotes}{%
\if@bidi@csundef{ifHy@hyperfootnotes}{}{%
\if@bidi@csundef{HLTR@@LTRfootnotetext}{}{%
\ifHy@hyperfootnotes
  \let\H@@footnotetext\@footnotetext
  \let\@footnotetext\@@H@@footnotetext
  \let\HLTR@@LTRfootnotetext\@LTRfootnotetext
  \let\@LTRfootnotetext\@@HLTR@@LTRfootnotetext
  \let\HRTL@@RTLfootnotetext\@RTLfootnotetext
  \let\@RTLfootnotetext\@@HRTL@@RTLfootnotetext
  \let\H@@mpfootnotetext\@mpfootnotetext
  \let\@mpfootnotetext\@@H@@mpfootnotetext
  \let\HLTR@@mpLTRfootnotetext\@mpLTRfootnotetext
  \let\@mpLTRfootnotetext\@@HLTR@@mpLTRfootnotetext
  \let\HRTL@@mpRTLfootnotetext\@mpRTLfootnotetext
  \let\@mpRTLfootnotetext\@@HRTL@@mpRTLfootnotetext
\fi
}%
}%
}
\let\autofootnoterule\relax
\let\rightfootnoterule\relax
\let\leftfootnoterule\relax
\let\textwidthfootnoterule\relax
\let\LRfootnoterule\relax
\def\footnoterule{\kern-3\p@
  \hrule \@width \columnwidth \kern 2.6\p@}
\newcommand{\@preamnormalfmt}{%
  \parindent 1em%
  \noindent
} 
\newcommand{\@normalfootfmt}[1]{%
  \@preamnormalfmt
  \footfootmark
  \rule\z@\footnotesep\ignorespaces{\foottextfont #1}%
  \@finalstrut\strutbox
}
\newcommand{\@normalRTLfootfmt}[1]{%
  \@preamnormalfmt
  \RTLfootfootmark
  \rule\z@\footnotesep\ignorespaces{\RTLfoottextfont #1}%
  \@finalstrut\strutbox
}
\newcommand{\@normalLTRfootfmt}[1]{%
  \@preamnormalfmt
  \LTRfootfootmark
  \rule\z@\footnotesep\ignorespaces{\LTRfoottextfont #1}%
  \@finalstrut\strutbox
}
\renewcommand{\@footnotetext}[1]{%
    \insert\footins{%
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font
    \foottextfont
    \@preamfntext
    \hsize\columnwidth
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \@normalfootfmt{#1}%
    \color@endgroup}%    
      \m@mmf@prepare}
\renewcommand{\@RTLfootnotetext}[1]{%
    \insert\footins{%
    \@RTLtrue%
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font
    \RTLfoottextfont
    \@preamfntext
    \hsize\columnwidth
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \@normalRTLfootfmt{#1}%
    \color@endgroup}%    
      \m@mmf@prepare}
\renewcommand{\@LTRfootnotetext}[1]{%
    \insert\footins{%
    \@RTLfalse%
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font
    \LTRfoottextfont
    \@preamfntext
    \hsize\columnwidth
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \@normalLTRfootfmt{#1}%
    \color@endgroup}%    
      \m@mmf@prepare}
\renewcommand{\@mpfootnotetext}[1]{%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font%
    \foottextfont \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@normalfootfmt{#1}%
  \color@endgroup}}
\renewcommand{\@mpLTRfootnotetext}[1]{%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font%
    \LTRfoottextfont \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@normalLTRfootfmt{#1}%
  \color@endgroup}}
\renewcommand{\@mpRTLfootnotetext}[1]{%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font%
    \RTLfoottextfont \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@normalRTLfootfmt{#1}%
  \color@endgroup}}
\let\m@mold@footnotetext\@footnotetext
\let\m@mold@LTRfootnotetext\@LTRfootnotetext
\let\m@mold@RTLfootnotetext\@RTLfootnotetext
\let\m@mold@mpfootnotetext\@mpfootnotetext
\let\m@mold@mpLTRfootnotetext\@mpLTRfootnotetext
\let\m@mold@mpRTLfootnotetext\@mpRTLfootnotetext
\bidi@ensure@newcommand{\normalfootnotes}{%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\m@mold@footnotetext
  \let\@LTRfootnotetext\m@mold@LTRfootnotetext
  \let\@RTLfootnotetext\m@mold@RTLfootnotetext
  \let\@mpfootnotetext\m@mold@mpfootnotetext
  \let\@mpLTRfootnotetext\m@mold@mpLTRfootnotetext
  \let\@mpRTLfootnotetext\m@mold@mpRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\IfClassLoadedT{memoir}{\let\plainfootnotes\normalfootnotes}
\bidi@ensure@newcommand*{\setSingleSpace}[1]{%
  \def\m@m@singlespace{#1}%
  \def\m@m@footnote@spacing{#1}%
  \def\m@m@float@spacing{#1} %
}
\setSingleSpace{1}
\bidi@ensure@newcommand*{\multiplefootnotemarker}{3sp}
\bidi@ensure@newcommand*{\m@mmf@prepare}{%
  \kern-\multiplefootnotemarker
  \kern\multiplefootnotemarker\relax}
\bidi@ensure@newlength{\footmarkwidth}
\bidi@ensure@newcommand*{\footmarkstyle}[1]{\def\footscript##1{#1}}
\bidi@ensure@newcommand*{\LTRfootmarkstyle}[1]{\def\LTRfootscript##1{#1}}
\bidi@ensure@newcommand*{\RTLfootmarkstyle}[1]{\def\RTLfootscript##1{#1}}
\bidi@ensure@newcommand{\footfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\footscript{\@thefnmark}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\footscript{\@thefnmark}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\footscript{\@thefnmark}}%
    \fi
  \fi}
\bidi@ensure@newcommand{\LTRfootfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\LTRfootscript{\@thefnmark}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\LTRfootscript{\@thefnmark}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\LTRfootscript{\@thefnmark}}%
    \fi
  \fi}
\bidi@ensure@newcommand{\RTLfootfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\RTLfootscript{\@thefnmark}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\RTLfootscript{\@thefnmark}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\RTLfootscript{\@thefnmark}}%
    \fi
  \fi}
\footmarkstyle{\textsuperscript{#1}}
\LTRfootmarkstyle{\textsuperscript{#1}}
\RTLfootmarkstyle{\textsuperscript{#1}}
\newcommand*{\bidi@normal@footmarkwidth}{%
  \setlength{\footmarkwidth}{1em plus.3em minus.3em}%
}
\newcommand*{\bidi@star@footmarkwidth}{%
  \setlength{\footmarkwidth}{0em plus.3em minus.3em}%
}
\bidi@normal@footmarkwidth
\bidi@ensure@newcommand{\m@mdoextrafeet}{\extrafeetins}
\bidi@ensure@newcommand*{\extrafeetins}{%
  \bidi@joinfootnotes\footinsv@r\@footstartv@r\@footgroupv@r
  \bidi@joinfootnotes\footinsv@l\@footstartv@l\@LTRfootgroupv@l
  \bidi@joinfootnotes\@bidi@copyins@{}{\unvbox\@bidi@copyins@}%
    \extrafeetinshook}
\bidi@ensure@newcommand{\extrafeetinshook}{}
\bidi@ensure@newcommand{\foottextfont}{\footnotesize}
\bidi@ensure@newcommand{\LTRfoottextfont}{\footnotesize}
\bidi@ensure@newcommand{\RTLfoottextfont}{\footnotesize}
\bidi@ensure@newlength{\footinsdim}
  \setlength{\footinsdim}{8in}   % standard for \dimen\footins
\bidi@ensure@newcommand{\@preamfntext}{%
  \interlinepenalty\interfootnotelinepenalty
  \floatingpenalty \@MM
  \splittopskip=\footnotesep
  \splitmaxdepth=\dp\strutbox
  \@parboxrestore}
\def\bidi@ifmulticol#1#2{\@tempswafalse
  \ifnum\col@number>\@ne
    \ifnum\count\footins>1999 \@tempswatrue \fi
  \fi
  \if@tempswa #1\else #2\fi
}
\def\bidi@joinfootnotes#1#2#3{%
  \ifvoid#1
  \else
    \@tempskipa\skip#1%
    \bidi@ifmulticol{\divide\@tempskipa\col@number}{}%
    \edef\bidi@footskip{\vskip\the\@tempskipa\relax}%
    \bidi@removexfootskip
    \ifvoid\footins
      \global\setbox\footins\vbox{#2#3}%
    \else
      \global\setbox\footins\vbox{%
         \unvbox\footins
         \bidi@footskip
         #2#3%
       }%
    \fi
  \fi
}
\def\bidi@joinmpfootnotes#1#2#3{%
  \ifvoid#1
  \else
    \@tempskipa\skip#1%
    \bidi@ifmulticol{\divide\@tempskipa\col@number}{}%
    \edef\bidi@footskip{\vskip\the\@tempskipa\relax}%
    \bidi@removexfootskip
    \ifvoid\@mpfootins
      \global\setbox\@mpfootins\vbox{#2#3}%
    \else
      \global\setbox\@mpfootins\vbox{%
         \unvbox\@mpfootins
         \bidi@footskip
         #2#3%
       }%
    \fi
  \fi
}
\bidi@ensure@newcommand{\m@mdoextrafeetmini}{%
  \extrafeetminihook}
\bidi@ensure@newcommand{\extrafeetendmini}{%
\bidi@joinmpfootnotes\@mpfootinsv@r\@footstartv@r\mp@footgroupv@r
  \bidi@joinmpfootnotes\@mpfootinsv@l\@footstartv@l\mp@LTRfootgroupv@l
  \extrafeetendminihook}
\bidi@ensure@newcommand{\extrafeetendminihook}{}
\bidi@ensure@newcommand{\m@mdoextrafeetendmini}{\extrafeetendmini}
\def\endminipage{%
  \par
  \unskip
  \m@mdoextrafeetendmini
  \ifvoid\@mpfootins
  \else
    \vskip\skip\@mpfootins
    \normalcolor
    \footnoterule
    \unvbox\@mpfootins
  \fi
  \@minipagefalse
  \color@endgroup
  \egroup
  \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}}
\bidi@ensure@newcommand{\m@make@footstart}[1]{%
  \@namedef{@footstart#1}{%
    \leftskip=\z@
    \rightskip=\z@
    \parindent=\z@
  }%
}
\newinsert\footinsv@r
\skip\footinsv@r\skip\footins
\count\footinsv@r=1000 % no magnifcation
\dimen\footinsv@r=\footinsdim
\m@make@footstart{v@r}
\newinsert\footinsv@l
\skip\footinsv@l\skip\footins
\count\footinsv@l=1000 % no magnifcation
\dimen\footinsv@l=\footinsdim
\m@make@footstart{v@l}
\bidi@ensure@newcommand{\@footgroupv@r}{}
\newinsert\@mpfootinsv@r
\skip\@mpfootinsv@r\skip\@mpfootins
\newinsert\@mpfootinsv@l
\skip\@mpfootinsv@l\skip\@mpfootins
\bidi@ensure@newcommand{\mp@footgroupv@r}{}
\newcount\m@m@k \newdimen\m@m@h
\bidi@ensure@newcommand*{\m@mrigidbalance}[3]{\setbox0=\box#1 \m@m@k=#2 \m@m@h=#3
  \@@line{\beginR\splittopskip=\m@m@h \vbadness=\@M \hfilneg
  \valign{##\vfill\cr\m@mdosplits}\endR}}
\newcommand*{\bidi@LTRrigidbalance}[3]{\setbox0=\box#1 \m@m@k=#2 \m@m@h=#3
  \@@line{\beginL\splittopskip=\m@m@h \vbadness=\@M \hfilneg
  \valign{##\vfill\cr\m@mdosplits}\endL}}
\bidi@ensure@newcommand*{\m@mdosplits}{\ifnum\m@m@k>0 \noalign{\hfil}\m@msplitoff
  \global\advance\m@m@k-1\cr\m@mdosplits\fi}
\bidi@ensure@newcommand*{\m@msplitoff}{\dimen0=\ht0
  \divide\dimen0 by\m@m@k \advance\dimen0 by\m@m@h
  \setbox2 \vsplit0 to \dimen0
  \unvbox2 }
\bidi@ensure@newcommand{\twocolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@twocolfootnotetext
  \let\@LTRfootnotetext\@twocolLTRfootnotetext
  \let\@RTLfootnotetext\@twocolRTLfootnotetext
  \dimen\footinsv@r=2\footinsdim
  \count\footinsv@r=500\relax
  \m@make@twocol@footgroup{v@r}%
  \let\@footgroupv@r\@twocol@footgroupv@r
  \dimen\footinsv@l=2\footinsdim
  \count\footinsv@l=500\relax
  \bidi@make@twocol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@twocol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mptwocolfootnotetext
  \let\@mpLTRfootnotetext\@mptwocolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mptwocolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mptwocol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mptwocol@footgroupv@r
  \bidi@make@mptwocol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mptwocol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@twocolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@twocolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@twocolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamtwofmt}{%
  \hsize .45\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@twocolfootfmt}[1]{%
  \@preamtwofmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@twocolLTRfootfmt}[1]{%
  \@preamtwofmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@twocolRTLfootfmt}[1]{%
  \@preamtwofmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mptwocolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mptwocolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mptwocolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@twocol@footgroup}[1]{%
  \@namedef{@twocol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{\tw@}{\splittopskip}}}}
\newcommand{\bidi@make@twocol@LTRfootgroup}[1]{%
  \@namedef{@twocol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{\tw@}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mptwocol@footgroup}[1]{%
\@namedef{@mptwocol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{\tw@}{\splittopskip}}}}
\newcommand{\bidi@make@mptwocol@LTRfootgroup}[1]{%
\@namedef{@mptwocol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{\tw@}{\splittopskip}}}}
\bidi@ensure@newcommand{\threecolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@threecolfootnotetext
  \let\@LTRfootnotetext\@threecolLTRfootnotetext
  \let\@RTLfootnotetext\@threecolRTLfootnotetext
  \dimen\footinsv@r=3\footinsdim
  \count\footinsv@r=333\relax
  \m@make@threecol@footgroup{v@r}%
  \let\@footgroupv@r\@threecol@footgroupv@r
  \dimen\footinsv@l=3\footinsdim
  \count\footinsv@l=333\relax
  \bidi@make@threecol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@threecol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpthreecolfootnotetext
  \let\@mpLTRfootnotetext\@mpthreecolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpthreecolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpthreecol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpthreecol@footgroupv@r
  \bidi@make@mpthreecol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpthreecol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@threecolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\@threecolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolLTRfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\@threecolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolRTLfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\@preamthreefmt}{%
  \hsize .3\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@threecolfootfmt}[1]{%
  \@preamthreefmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@threecolLTRfootfmt}[1]{%
  \@preamthreefmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@threecolRTLfootfmt}[1]{%
  \@preamthreefmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpthreecolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi  
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\@mpthreecolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolLTRfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\@mpthreecolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@threecolRTLfootfmt{#1}%
  \color@endgroup}\m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@threecol@footgroup}[1]{%
\@namedef{@threecol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
 \hsize\bidi@columnwidth
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{footins#1}}{\thr@@}{\splittopskip}}}}
\newcommand{\bidi@make@threecol@LTRfootgroup}[1]{%
\@namedef{@threecol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
 \hsize\bidi@columnwidth
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{footins#1}}{\thr@@}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpthreecol@footgroup}[1]{%
\@namedef{@mpthreecol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{\thr@@}{\splittopskip}}}}
\newcommand{\bidi@make@mpthreecol@LTRfootgroup}[1]{%
\@namedef{@mpthreecol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{\thr@@}{\splittopskip}}}}
\bidi@ensure@newcommand{\fourcolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@fourcolfootnotetext
  \let\@LTRfootnotetext\@fourcolLTRfootnotetext
  \let\@RTLfootnotetext\@fourcolRTLfootnotetext
  \dimen\footinsv@r=4\footinsdim
  \count\footinsv@r=250\relax
  \m@make@fourcol@footgroup{v@r}%
  \let\@footgroupv@r\@fourcol@footgroupv@r
  \dimen\footinsv@l=4\footinsdim
  \count\footinsv@l=250\relax
  \bidi@make@fourcol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@fourcol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpfourcolfootnotetext
  \let\@mpLTRfootnotetext\@mpfourcolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpfourcolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpfourcol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpfourcol@footgroupv@r
  \bidi@make@mpfourcol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpfourcol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@fourcolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@fourcolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@fourcolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamfourfmt}{%
  \hsize .25\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@fourcolfootfmt}[1]{%
  \@preamfourfmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@fourcolLTRfootfmt}[1]{%
  \@preamfourfmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@fourcolRTLfootfmt}[1]{%
  \@preamfourfmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpfourcolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpfourcolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpfourcolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fourcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@fourcol@footgroup}[1]{%
  \@namedef{@fourcol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{4}{\splittopskip}}}}
\newcommand{\bidi@make@fourcol@LTRfootgroup}[1]{%
  \@namedef{@fourcol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{4}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpfourcol@footgroup}[1]{%
\@namedef{@mpfourcol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{4}{\splittopskip}}}}
\newcommand{\bidi@make@mpfourcol@LTRfootgroup}[1]{%
\@namedef{@mpfourcol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{4}{\splittopskip}}}}
\bidi@ensure@newcommand{\fivecolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@fivecolfootnotetext
  \let\@LTRfootnotetext\@fivecolLTRfootnotetext
  \let\@RTLfootnotetext\@fivecolRTLfootnotetext
  \dimen\footinsv@r=5\footinsdim
  \count\footinsv@r=200\relax
  \m@make@fivecol@footgroup{v@r}%
  \let\@footgroupv@r\@fivecol@footgroupv@r
  \dimen\footinsv@l=5\footinsdim
  \count\footinsv@l=200\relax
  \bidi@make@fivecol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@fivecol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpfivecolfootnotetext
  \let\@mpLTRfootnotetext\@mpfivecolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpfivecolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpfivecol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpfivecol@footgroupv@r
  \bidi@make@mpfivecol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpfivecol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@fivecolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@fivecolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@fivecolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamfivefmt}{%
  \hsize .2\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@fivecolfootfmt}[1]{%
  \@preamfivefmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@fivecolLTRfootfmt}[1]{%
  \@preamfivefmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@fivecolRTLfootfmt}[1]{%
  \@preamfivefmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpfivecolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpfivecolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpfivecolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@fivecolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@fivecol@footgroup}[1]{%
  \@namedef{@fivecol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{5}{\splittopskip}}}}
\newcommand{\bidi@make@fivecol@LTRfootgroup}[1]{%
  \@namedef{@fivecol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{5}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpfivecol@footgroup}[1]{%
\@namedef{@mpfivecol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{5}{\splittopskip}}}}
\newcommand{\bidi@make@mpfivecol@LTRfootgroup}[1]{%
\@namedef{@mpfivecol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{5}{\splittopskip}}}}
\bidi@ensure@newcommand{\sixcolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@sixcolfootnotetext
  \let\@LTRfootnotetext\@sixcolLTRfootnotetext
  \let\@RTLfootnotetext\@sixcolRTLfootnotetext
  \dimen\footinsv@r=6\footinsdim
  \count\footinsv@r=166\relax
  \m@make@sixcol@footgroup{v@r}%
  \let\@footgroupv@r\@sixcol@footgroupv@r
  \dimen\footinsv@l=6\footinsdim
  \count\footinsv@l=166\relax
  \bidi@make@sixcol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@sixcol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpsixcolfootnotetext
  \let\@mpLTRfootnotetext\@mpsixcolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpsixcolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpsixcol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpsixcol@footgroupv@r
  \bidi@make@mpsixcol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpsixcol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@sixcolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@sixcolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@sixcolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamsixfmt}{%
  \hsize .16\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@sixcolfootfmt}[1]{%
  \@preamsixfmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@sixcolLTRfootfmt}[1]{%
  \@preamsixfmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@sixcolRTLfootfmt}[1]{%
  \@preamsixfmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpsixcolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpsixcolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpsixcolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sixcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@sixcol@footgroup}[1]{%
  \@namedef{@sixcol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{6}{\splittopskip}}}}
\newcommand{\bidi@make@sixcol@LTRfootgroup}[1]{%
  \@namedef{@sixcol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{6}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpsixcol@footgroup}[1]{%
\@namedef{@mpsixcol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{6}{\splittopskip}}}}
\newcommand{\bidi@make@mpsixcol@LTRfootgroup}[1]{%
\@namedef{@mpsixcol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{6}{\splittopskip}}}}
\bidi@ensure@newcommand{\sevencolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@sevencolfootnotetext
  \let\@LTRfootnotetext\@sevencolLTRfootnotetext
  \let\@RTLfootnotetext\@sevencolRTLfootnotetext
  \dimen\footinsv@r=7\footinsdim
  \count\footinsv@r=142\relax
  \m@make@sevencol@footgroup{v@r}%
  \let\@footgroupv@r\@sevencol@footgroupv@r
  \dimen\footinsv@l=7\footinsdim
  \count\footinsv@l=142\relax
  \bidi@make@sevencol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@sevencol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpsevencolfootnotetext
  \let\@mpLTRfootnotetext\@mpsevencolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpsevencolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpsevencol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpsevencol@footgroupv@r
  \bidi@make@mpsevencol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpsevencol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
} 
\bidi@ensure@newcommand{\@sevencolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@sevencolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@sevencolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamsevenfmt}{%
  \hsize .142\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@sevencolfootfmt}[1]{%
  \@preamsevenfmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@sevencolLTRfootfmt}[1]{%
  \@preamsevenfmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@sevencolRTLfootfmt}[1]{%
  \@preamsevenfmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpsevencolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
     \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpsevencolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpsevencolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@sevencolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@sevencol@footgroup}[1]{%
  \@namedef{@sevencol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{7}{\splittopskip}}}}
\newcommand{\bidi@make@sevencol@LTRfootgroup}[1]{%
  \@namedef{@sevencol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{7}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpsevencol@footgroup}[1]{%
\@namedef{@mpsevencol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{7}{\splittopskip}}}}
\newcommand{\bidi@make@mpsevencol@LTRfootgroup}[1]{%
\@namedef{@mpsevencol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{7}{\splittopskip}}}}
\bidi@ensure@newcommand{\eightcolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@eightcolfootnotetext
  \let\@LTRfootnotetext\@eightcolLTRfootnotetext
  \let\@RTLfootnotetext\@eightcolRTLfootnotetext
  \dimen\footinsv@r=8\footinsdim
  \count\footinsv@r=125\relax
  \m@make@eightcol@footgroup{v@r}%
  \let\@footgroupv@r\@eightcol@footgroupv@r
  \dimen\footinsv@l=8\footinsdim
  \count\footinsv@l=125\relax
  \bidi@make@eightcol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@eightcol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpeightcolfootnotetext
  \let\@mpLTRfootnotetext\@mpeightcolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpeightcolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpeightcol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpeightcol@footgroupv@r
  \bidi@make@mpeightcol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpeightcol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@eightcolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@eightcolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@eightcolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preameightfmt}{%
  \hsize .125\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@eightcolfootfmt}[1]{%
  \@preameightfmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@eightcolLTRfootfmt}[1]{%
  \@preameightfmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@eightcolRTLfootfmt}[1]{%
  \@preameightfmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpeightcolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpeightcolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpeightcolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@eightcolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@eightcol@footgroup}[1]{%
  \@namedef{@eightcol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{8}{\splittopskip}}}}
\newcommand{\bidi@make@eightcol@LTRfootgroup}[1]{%
  \@namedef{@eightcol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{8}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpeightcol@footgroup}[1]{%
\@namedef{@mpeightcol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{8}{\splittopskip}}}}
\newcommand{\bidi@make@mpeightcol@LTRfootgroup}[1]{%
\@namedef{@mpeightcol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{8}{\splittopskip}}}}
\bidi@ensure@newcommand{\ninecolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@ninecolfootnotetext
  \let\@LTRfootnotetext\@ninecolLTRfootnotetext
  \let\@RTLfootnotetext\@ninecolRTLfootnotetext
  \dimen\footinsv@r=9\footinsdim
  \count\footinsv@r=111\relax
  \m@make@ninecol@footgroup{v@r}%
  \let\@footgroupv@r\@ninecol@footgroupv@r
  \dimen\footinsv@l=9\footinsdim
  \count\footinsv@l=111\relax
  \bidi@make@ninecol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@ninecol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mpninecolfootnotetext
  \let\@mpLTRfootnotetext\@mpninecolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpninecolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mpninecol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mpninecol@footgroupv@r
  \bidi@make@mpninecol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mpninecol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}  
\bidi@ensure@newcommand{\@ninecolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@ninecolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@ninecolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamninefmt}{%
  \hsize .1\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@ninecolfootfmt}[1]{%
  \@preamninefmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@ninecolLTRfootfmt}[1]{%
  \@preamninefmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@ninecolRTLfootfmt}[1]{%
  \@preamninefmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mpninecolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpninecolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mpninecolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@ninecolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@ninecol@footgroup}[1]{%
  \@namedef{@ninecol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{9}{\splittopskip}}}}
\newcommand{\bidi@make@ninecol@LTRfootgroup}[1]{%
  \@namedef{@ninecol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{9}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mpninecol@footgroup}[1]{%
\@namedef{@mpninecol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{9}{\splittopskip}}}}
\newcommand{\bidi@make@mpninecol@LTRfootgroup}[1]{%
\@namedef{@mpninecol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{9}{\splittopskip}}}}
\bidi@ensure@newcommand{\tencolumnfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@tencolfootnotetext
  \let\@LTRfootnotetext\@tencolLTRfootnotetext
  \let\@RTLfootnotetext\@tencolRTLfootnotetext
  \dimen\footinsv@r=10\footinsdim
  \count\footinsv@r=100\relax
  \m@make@tencol@footgroup{v@r}%
  \let\@footgroupv@r\@tencol@footgroupv@r
  \dimen\footinsv@l=10\footinsdim
  \count\footinsv@l=100\relax
  \bidi@make@tencol@LTRfootgroup{v@l}%
  \let\@LTRfootgroupv@l\@tencol@LTRfootgroupv@l
  \let\@mpfootnotetext\@mptencolfootnotetext
  \let\@mpLTRfootnotetext\@mptencolLTRfootnotetext
  \let\@mpRTLfootnotetext\@mptencolRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mptencol@footgroup{v@r}%
  \let\mp@footgroupv@r\@mptencol@footgroupv@r
  \bidi@make@mptencol@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mptencol@LTRfootgroupv@l
  \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@tencolfootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
{\if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@tencolLTRfootnotetext}[1]{\insert\footinsv@l{\@RTLfalse%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@tencolRTLfootnotetext}[1]{\insert\footinsv@r{\@RTLtrue%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@preamtenfmt}{%
  \hsize .1\hsize
  \parindent=\z@
  \tolerance=5000\relax
  \leavevmode}
\bidi@ensure@newcommand{\@tencolfootfmt}[1]{%
  \@preamtenfmt
  {\footfootmark\strut {\foottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@tencolLTRfootfmt}[1]{%
  \@preamtenfmt
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@tencolRTLfootfmt}[1]{%
  \@preamtenfmt
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\strut\par}\allowbreak}
\bidi@ensure@newcommand{\@mptencolfootnotetext}[1]{%
  \global\setbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mptencolLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
    \unvbox\@mpfootinsv@l
    \@RTLfalse
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolLTRfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\@mptencolRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
    \unvbox\@mpfootinsv@r
    \@RTLtrue
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
    \@tencolRTLfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@tencol@footgroup}[1]{%
  \@namedef{@tencol@footgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \m@mrigidbalance{\@nameuse{footins#1}}{10}{\splittopskip}}}}
\newcommand{\bidi@make@tencol@LTRfootgroup}[1]{%
  \@namedef{@tencol@LTRfootgroup#1}{{%
   \def\baselinestretch{\m@m@footnote@spacing}%
   \hsize\bidi@columnwidth
    \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
     \bidi@LTRrigidbalance{\@nameuse{footins#1}}{10}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@make@mptencol@footgroup}[1]{%
\@namedef{@mptencol@footgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \m@mrigidbalance{\@nameuse{@mpfootins#1}}{10}{\splittopskip}}}}
\newcommand{\bidi@make@mptencol@LTRfootgroup}[1]{%
\@namedef{@mptencol@LTRfootgroup#1}{{%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1} \splittopskip=\ht\strutbox
  \bidi@LTRrigidbalance{\@nameuse{@mpfootins#1}}{10}{\splittopskip}}}}
\bidi@ensure@newcommand{\m@munvxh}[1]{%
  \setbox0=\vbox{\unvbox#1%
    \global\setbox1=\lastbox}%
  \unhbox1
  \unskip
  \unskip
  \unpenalty
  \hskip\m@mipn@skip}
\bidi@ensure@newcommand{\m@mungebox}{%
  \setbox0=\hbox{\m@munvxh0}%
  \dp0=\z@
  \ht0=\footfudgefactor\wd0
  \box0
  \penalty0}
\newskip\m@mipn@skip
\bidi@ensure@newcommand*{\m@minterparanoteglue}[1]{%
  {\foottextfont\global\m@mipn@skip=#1\relax}}
\m@minterparanoteglue{1em plus.3em minus.3em}
\bidi@ensure@newcommand*{\m@mmakehboxofhboxes}{%
 \setbox0=\hbox{}%
  \loop
    \unpenalty
    \setbox2=\lastbox
  \ifhbox2
    \setbox0=\hbox{\box2\unhbox0}
  \repeat}
\bidi@ensure@newcommand*{\m@mremovehboxes}{\setbox0=\lastbox
  \ifhbox0{\m@mremovehboxes}\unhbox0 \fi}
\newcommand*\AddExtraParaSkip[1]{%
    \def\bidi@xparaskip{\advance\@tempdima#1\relax}%
}
\let\bidi@xparaskip\relax
\@onlypreamble\AddExtraParaSkip
\@onlypreamble\bidi@xparaskip
\def\bidi@startparafootskip#1{%
  \global\advance\skip#1\bidi@paraskip
}
\@onlypreamble\bidi@startparafootskip
\bidi@ensure@newcommand{\paragraphfootnotes}{%
  \@namedef{foottextfontv@r}{\foottextfont}%  % [RS]
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%
  \@bidi@before@Hy@hyperfootnotes
  \let\@footnotetext\@parafootnotetext
  \let\@LTRfootnotetext\@paraLTRfootnotetext
  \let\@RTLfootnotetext\@paraRTLfootnotetext
  \dimen\footinsv@r=\footinsdim
  \count\footinsv@r=1000\relax
  \let\bidi@removexfootskip\bidi@removexparafootskip
  \m@make@para@footgroup{v@r}%
  \m@make@para@footstart{v@r}%
  \let\@footgroupv@r\@para@footgroupv@r
  \let\@footstartv@r\@para@footstartv@r
  \dimen\footinsv@l=\footinsdim
  \count\footinsv@l=1000\relax
  \bidi@make@para@LTRfootgroup{v@l}%
  \m@make@para@footstart{v@l}%
  \let\@LTRfootgroupv@l\@para@LTRfootgroupv@l
  \let\@footstartv@l\@para@footstartv@l
  \let\@mpfootnotetext\@mpparafootnotetext
  \let\@mpLTRfootnotetext\@mpparaLTRfootnotetext
  \let\@mpRTLfootnotetext\@mpparaRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \m@make@mppara@footgroup{v@r}%
  \bidi@make@mppara@LTRfootgroup{v@l}%
  \let\mp@footgroupv@r\@mppara@footgroupv@r
  \let\mp@LTRfootgroupv@l\@mppara@LTRfootgroupv@l
  \g@addto@macro\bidi@floathook{%
    \begingroup
      \foottextfont \@tempdima\normalbaselineskip
      \multiply \@tempdima \@cclvi
      \@tempdimb \columnwidth
      \divide \@tempdimb \@cclvi
      \divide \@tempdima \@tempdimb
      \xdef\footfudgefactor{\strip@pt\@tempdima}%
    \endgroup
  }
  \AtBeginDocument{%
    \begingroup
      \foottextfont
      \@tempdima\footnotesep
      \advance\@tempdima -\ht\strutbox
      \ifdim\@tempdima<\z@ \@tempdima\z@ \fi
      \advance\@tempdima.5\normalbaselineskip
      \bidi@xparaskip 
      \xdef\bidi@paraskip{\the\@tempdima\relax}%
    \endgroup
    \bidi@startparafootskip\footinsv@r
    \bidi@startparafootskip\footinsv@l
  }
   \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\newcommand{\normalRTLparaLTRfootnotes}{%
  \@namedef{foottextfontv@l}{\LTRfoottextfont}%  
  \@bidi@before@Hy@hyperfootnotes
  \if@RTL@footnote
    \let\@footnotetext\m@mold@footnotetext
  \else
    \let\@footnotetext\@parafootnotetext
  \fi
  \let\@LTRfootnotetext\@paraLTRfootnotetext
  \let\@RTLfootnotetext\m@mold@RTLfootnotetext
  \dimen\footinsv@l=\footinsdim
  \count\footinsv@l=1000\relax
  \let\bidi@removexfootskip\bidi@removexparafootskip
  \bidi@make@para@LTRfootgroup{v@l}%
  \m@make@para@footstart{v@l}%
  \let\@LTRfootgroupv@l\@para@LTRfootgroupv@l
  \let\@footstartv@l\@para@footstartv@l
  \if@RTL@footnote
    \let\@mpfootnotetext\m@mold@mpfootnotetext
  \else
    \let\@mpfootnotetext\@mpparafootnotetext
  \fi
  \let\@mpLTRfootnotetext\@mpparaLTRfootnotetext
  \let\@mpRTLfootnotetext\m@mold@mpRTLfootnotetext
  \@bidi@after@Hy@hyperfootnotes
  \bidi@make@mppara@LTRfootgroup{v@l}%
  \let\mp@LTRfootgroupv@l\@mppara@LTRfootgroupv@l
  \g@addto@macro\bidi@floathook{%
    \begingroup
      \LTRfoottextfont \@tempdima\normalbaselineskip
      \multiply \@tempdima \@cclvi
      \@tempdimb \columnwidth
      \divide \@tempdimb \@cclvi
      \divide \@tempdima \@tempdimb
      \xdef\footfudgefactor{\strip@pt\@tempdima}%
    \endgroup
  }
  \AtBeginDocument{%
    \begingroup
      \LTRfoottextfont
      \@tempdima\footnotesep
      \advance\@tempdima -\ht\strutbox
      \ifdim\@tempdima<\z@ \@tempdima\z@ \fi
      \advance\@tempdima.5\normalbaselineskip
      \bidi@xparaskip 
      \xdef\bidi@paraskip{\the\@tempdima\relax}%
    \endgroup
    \bidi@startparafootskip\footinsv@l
  }
   \@ifstar\bidi@star@footmarkwidth\bidi@normal@footmarkwidth
}
\bidi@ensure@newcommand{\@parafootnotetext}[1]{\insert
  \if@RTL@footnote
    \footinsv@r
  \else
    \footinsv@l
  \fi
  {%
  \let\bidi@RTL@everypar\@empty%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \setbox0=\vbox{\hsize=\maxdimen
    \color@begingroup
      \noindent \@parafootfmt{#1}%
    \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\@paraLTRfootnotetext}[1]{\insert\footinsv@l{%
 \let\bidi@RTL@everypar\@empty%
 \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\LTRfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \setbox0=\vbox{\hsize=\maxdimen
    \color@begingroup
      \noindent \@paraLTRfootfmt{#1}%
    \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\@paraRTLfootnotetext}[1]{\insert\footinsv@r{%
  \let\bidi@RTL@everypar\@empty%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \reset@font\RTLfoottextfont
  \@preamfntext
  \protected@edef\@currentlabel{%
    \csname p@footnote\endcsname\@thefnmark}%
  \setbox0=\vbox{\hsize=\maxdimen
    \color@begingroup
      \noindent \@paraRTLfootfmt{#1}%
    \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\@parafootfmt}[1]{%
  \parindent=\z@
  \parfillskip=0pt \@plus 1fil
  {\footfootmark\strut {\foottextfont #1}\penalty-10}}
\bidi@ensure@newcommand{\@paraLTRfootfmt}[1]{%
  \parindent=\z@
  \parfillskip=0pt \@plus 1fil
  {\LTRfootfootmark\strut {\LTRfoottextfont #1}\penalty-10}}
\bidi@ensure@newcommand{\@paraRTLfootfmt}[1]{%
  \parindent=\z@
  \parfillskip=0pt \@plus 1fil
  {\RTLfootfootmark\strut {\RTLfoottextfont #1}\penalty-10}}
\bidi@ensure@newcommand{\@mpparafootnotetext}[1]{%
  \global\setbox
  \if@RTL@footnote
    \@mpfootinsv@r
  \else
    \@mpfootinsv@l
  \fi
  \vbox{%
    \unvbox
    \if@RTL@footnote
      \@mpfootinsv@r
    \else
      \@mpfootinsv@l
    \fi
    \let\bidi@RTL@everypar\@empty
    \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\foottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
    \setbox0=\vbox{\hsize=\maxdimen
      \color@begingroup
      \noindent \@parafootfmt{#1}%
      \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\@mpparaLTRfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@l\vbox{%
   \unvbox\@mpfootinsv@l
   \let\bidi@RTL@everypar\@empty
   \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\LTRfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
    \setbox0=\vbox{\hsize=\maxdimen
      \color@begingroup
      \noindent \@paraLTRfootfmt{#1}%
      \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\@mpparaRTLfootnotetext}[1]{%
  \global\setbox\@mpfootinsv@r\vbox{%
  \unvbox\@mpfootinsv@r
   \let\bidi@RTL@everypar\@empty
   \def\baselinestretch{\m@m@footnote@spacing}%
    \reset@font\RTLfoottextfont
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
    \setbox0=\vbox{\hsize=\maxdimen
      \color@begingroup
      \noindent \@paraRTLfootfmt{#1}%
      \color@endgroup}%
  \m@mungebox}\m@mmf@prepare}
\bidi@ensure@newcommand{\m@make@para@footgroup}[1]{%
\@namedef{@para@footgroup#1}{%
  \unvbox\@nameuse{footins#1}
  \@RTLtrue
  \m@mmakehboxofhboxes
  \setbox0=\hbox{\unhbox0 \m@mremovehboxes}%
  \hsize\bidi@columnwidth
  \@parboxrestore
  \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1}%
  \noindent\unhbox0\par}}
\bidi@ensure@newcommand{\bidi@make@para@LTRfootgroup}[1]{%
\@namedef{@para@LTRfootgroup#1}{%
  \unvbox\@nameuse{footins#1}
  \@RTLfalse
  \m@mmakehboxofhboxes
  \setbox0=\hbox{\unhbox0 \m@mremovehboxes}%
  \hsize\bidi@columnwidth
  \@parboxrestore
  \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1}%
  \noindent\unhbox0\par}}
\newcommand{\bidi@removexparafootskip}{%
  \advance\@tempskipa -\bidi@paraskip
  \edef\bidi@footskip{\vskip\the\@tempskipa\relax}%
}
\let\bidi@removexfootskip\relax
\bidi@ensure@newcommand{\m@make@mppara@footgroup}[1]{%
\@namedef{@mppara@footgroup#1}{%
  \unvbox\@nameuse{@mpfootins#1}
  \@RTLtrue
  \m@mmakehboxofhboxes
  \setbox0=\hbox{\unhbox0 \m@mremovehboxes}%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1}%
  \noindent\unhbox0\par}}
\bidi@ensure@newcommand{\bidi@make@mppara@LTRfootgroup}[1]{%
\@namedef{@mppara@LTRfootgroup#1}{%
  \unvbox\@nameuse{@mpfootins#1}
  \@RTLfalse
  \m@mmakehboxofhboxes
  \setbox0=\hbox{\unhbox0 \m@mremovehboxes}%
  \def\baselinestretch{\m@m@footnote@spacing}%
  \@nameuse{foottextfont#1}%
  \noindent\unhbox0\par}}
\bidi@ensure@newcommand{\m@make@para@footstart}[1]{%
\@namedef{@para@footstart#1}{%
  \leftskip=\z@
  \rightskip=\z@
  \parindent=\z@
  }%
}
\bidi@ensure@newcommand*{\m@m@makecolfloats}{%
  \xdef\@freelist{\@freelist\@midlist}%
  \global\let\@midlist\@empty
  \@combinefloats}
\bidi@ensure@newcommand*{\m@m@makecoltext}{%
  \ifvbox\@kludgeins
    \@makespecialcolbox
  \else
    \setbox\@outputbox \vbox to\@colht{%
      \@texttop
      \dimen@ \dp\@outputbox
      \unvbox \@outputbox
      \vskip -\dimen@
      \@textbottom}%
  \fi}
\bidi@ensure@newcommand*{\m@m@makecolintro}{}
\bidi@ensure@newcommand*{\m@mopfootnote}{\setbox\@outputbox \vbox{%
  \boxmaxdepth\@maxdepth
  \@tempdima\dp\@cclv
  \unvbox\@cclv
  \vskip-\@tempdima
  \bidi@mopfn@bottom
  \vskip \skip\footins
  \color@begingroup
    \normalcolor
    \footnoterule
    \unvbox \footins
  \color@endgroup
  }%
}
\newcommand*{\bidi@mopfootnotebf}{%
  \setbox\@outputbox \vbox{%
  \boxmaxdepth\@maxdepth
  \unvbox\@outputbox
  \bidi@mopfn@bottom
  \vskip\skip\footins
  \color@begingroup
    \normalcolor
    \footnoterule
    \unvbox \footins
  \color@endgroup
  }%
}
\gdef\mem@makecol{%
  \m@m@makecolintro
  \m@mdoextrafeet
  \ifvoid\footins
    \setbox\@outputbox \box\@cclv
  \else
    \m@mopfootnote
  \fi
  \m@m@makecolfloats
  \m@m@makecoltext
  \global \maxdepth \@maxdepth}
\gdef\bidi@makecolbf{%
  \m@m@makecolintro
  \m@mdoextrafeet
  \setbox\@outputbox \box\@cclv
  \m@m@makecolfloats
  \ifvoid\footins
  \else
    \bidi@mopfootnotebf
  \fi
  \m@m@makecoltext
  \global \maxdepth \@maxdepth}
\newcommand{\FeetAboveFloat}{\gdef\@makecol{\mem@makecol}}
\newcommand{\FeetBelowFloat}{\gdef\@makecol{\bidi@makecolbf}}
\newcommand\FeetAtBottom{\def\bidi@mopfn@bottom{\vfill\relax}}
\newcommand\FeetBelowRagged{\let\bidi@mopfn@bottom\relax}
\FeetAboveFloat
\FeetBelowRagged
\def\bidi@reinserts#1{\ifvoid#1\else
    \ifnum\count\@currbox>\z@
      \advance\@pageht \ht#1%
      \advance\@pageht \skip#1%
      \advance\@pageht \dp#1%
    \fi
    \insert#1{\unvbox#1}%
  \fi
}
\def\bidi@init@multi@footins#1{%
    \multiply\count#1\col@number
    \multiply\skip#1\col@number
}
\def\bidi@reinsert@footnotes#1{\ifvoid#1\else
         \insert#1{}\fi}
\AtBeginDocument{%
  \bidi@preto\@doclearpage\m@mdoextrafeet
  \g@addto@macro\@reinserts{%
    \bidi@reinserts\footinsv@r
    \bidi@reinserts\footinsv@l
  }
  \bidi@floathook
  \g@addto@macro\@floatplacement{%
    \bidi@ifmulticol{}{\bidi@floathook}%
  }%
  \if@bidi@csundef{multi@column@out}{%
    \@onlypreamble\bidi@init@multi@footins
    \let\bidi@ifmulticol\@secondoftwo
  }{%
    \bidi@preto\multi@column@out\m@mdoextrafeet
    \g@addto@macro\init@mult@footins{%
      \bidi@init@multi@footins\footinsv@r
      \bidi@init@multi@footins\footinsv@l
    }%
    \g@addto@macro\reinsert@footnotes{%
      \bidi@reinsert@footnotes\footinsv@r
      \bidi@reinsert@footnotes\footinsv@l
    }%
  }%
}
%    \end{macrocode}
% \iffalse
%</extrafootnotefeatures-xetex-bidi.def>
%<*extreport-xetex-bidi.def>
%\fi
% \section{File \texttt{extreport-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{extreport-xetex-bidi.def}[2025/09/30 v0.4 bidi adaptations for extreport class for XeTeX engine]
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
      \hskip -\if@RTL\rightskip\else\leftskip\fi
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname
        \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
  \if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
\renewcommand\thesection      {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand\theequation{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi\@arabic\c@equation}
\renewcommand\thefigure{%
  \ifnum \c@chapter>\z@\thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand\thetable{%
  \ifnum \c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@table}
%    \end{macrocode}
% \iffalse
%</extreport-xetex-bidi.def>
%<*fancybox-xetex-bidi.def>
%\fi
% \section{File \texttt{fancybox-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{fancybox-xetex-bidi.def}[2013/05/01 v0.1 bidi adaptations for fancybox package for XeTeX engine]
\def\fancy@@oval#1#2#3{%
  \boxmaxdepth \maxdimen
  \@ovttrue \@ovbtrue \@ovltrue \@ovrtrue
  \@tfor\@tempa :=#3\do{\csname @ov\@tempa false\endcsname}%
  \@ovxx#1\relax
  \advance\@ovxx-\@wholewidth
  \@ovyy#2\relax
  \advance\@ovyy-\@wholewidth
  \@tempdimb \ifdim \@ovyy >\@ovxx \@ovxx\else \@ovyy \fi
  \advance\@tempdimb-2\p@
  \ifdim\@tempdimb>\the@cornersize\relax
    \@tempdimb=\the@cornersize
  \fi
  \@getcirc\@tempdimb
  \@ovro\ht\@tempboxa \@ovri\dp\@tempboxa
  \@ovdx\@ovxx \advance\@ovdx-\@tempdima \divide\@ovdx \tw@
  \@ovdy\@ovyy \advance\@ovdy-\@tempdima \divide\@ovdy \tw@
  \@circlefnt
  \setbox\@tempboxa\hbox{\beginL%
    \if@ovr \@ovvert32\kern -\@tempdima \fi
    \if@ovl \kern \@ovxx \@ovvert01\kern -\@tempdima \kern -\@ovxx \fi
    \if@ovt \@ovhorz \kern -\@ovxx \fi
    \if@ovb \raise \@ovyy \@ovhorz \fi\endL}%
  \advance\@ovdx\@ovro
  \advance\@ovdy\@ovro
  \advance\@ovxx\@wholewidth
  \wd\@tempboxa=\@ovxx
  \dp\@tempboxa=\z@}
%    \end{macrocode}
% \iffalse
%</fancybox-xetex-bidi.def>
%<*fancyhdr-xetex-bidi.def>
%\fi
% \section{File \texttt{fancyhdr-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{fancyhdr-xetex-bidi.def}[2025/09/03 v1.0 bidi adaptations for fancyhdr package for XeTeX engine]

\let\f@nch@everypar\everypar

\def\f@nch@parbox@align@hl{\def\f@nch@align@@h{\bidi@raggedright}}
\def\f@nch@parbox@align@hr{\def\f@nch@align@@h{\bidi@raggedleft}}

%    \end{macrocode}
% \iffalse
%</fancyhdr-xetex-bidi.def>
%<*fix2col-xetex-bidi.def>
%\fi
% \section{File \texttt{fix2col-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{fix2col-xetex-bidi.def}[2017/05/06 v0.4 bidi adaptations for fix2col package for XeTeX engine]
\def\RTL@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
    \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
\else  \global\@firstcolumntrue
\setbox\@outputbox \vbox {\hbox to\textwidth {%
\hskip \columnwidth
\hfil \vrule width\columnseprule \hfil
\hbox to\columnwidth {%
\bidi@firstcolumn@status@write%
\box\@leftcolumn \hss}%
\hskip -\textwidth
\hbox to\columnwidth{%
\bidi@lastcolumn@status@write%
\box\@outputbox \hss}%
\hskip \columnsep
\hskip \columnwidth }}%
\@combinedblfloats \@setmarks \@outputpage
\begingroup \@dblfloatplacement \@startdblcolumn
\@whilesw\if@fcolmade \fi
{\@outputpage \@startdblcolumn }\endgroup
\fi}
\def\LTR@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
    \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else 
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hfil
        \vrule \@width\columnseprule
        \hfil
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}}}%
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage\@startdblcolumn}%
    \endgroup
  \fi}
%    \end{macrocode}
% \iffalse
%</fix2col-xetex-bidi.def>
%<*fleqn-xetex-bidi.def>
%\fi
% \section{File \texttt{fleqn-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{fleqn-xetex-bidi.def}[2024/12/07 v0.2 bidi adaptations for fleqn tag for XeTeX engine]
\DeclareRobustCommand\[{\relax
                \ifmmode\@badmath
                \else
                  \begin{trivlist}%
                    \@beginparpenalty\predisplaypenalty
                    \@endparpenalty\postdisplaypenalty
                    \item[]\leavevmode
                    \hb@xt@\linewidth\bgroup \beginL$\m@th\displaystyle %$
                      \hskip\mathindent\bgroup
                \fi}
\DeclareRobustCommand\]{\relax
                \ifmmode
                      \egroup $\hfil% $
                    \endL\egroup
                  \end{trivlist}%
                \else \@badmath
                \fi}
\renewenvironment{equation}%
    {\@beginparpenalty\predisplaypenalty
     \@endparpenalty\postdisplaypenalty
     \refstepcounter{equation}%
     \trivlist \item[]\leavevmode
       \hb@xt@\linewidth\bgroup\beginL $\m@th% $
         \displaystyle
         \hskip\mathindent}%
        {$\hfil % $
         \displaywidth\linewidth\hbox{\@eqnnum}%
       \endL\egroup
     \endtrivlist}
%    \end{macrocode}
% \iffalse
%</fleqn-xetex-bidi.def>
%<*float-xetex-bidi.def>
%\fi
% \section{File \texttt{float-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{float-xetex-bidi.def}[2013/04/04 v0.2 bidi adaptations for float package for XeTeX engine]
\renewcommand\floatc@plain[2]{\setbox\@tempboxa\hbox{{\@fs@cfont #1:} #2}%
  \ifdim\wd\@tempboxa>\hsize {\@fs@cfont #1:} #2\par
    \else\hbox to\hsize{\if@RTL\beginR\fi\hfil\box\@tempboxa\hfil\if@RTL\endR\fi}\fi}
\def\float@newx#1[#2]{\@ifundefined{c@#1}{\newcounter{#1}[#2]%
    \expandafter\edef\csname the#1\endcsname{%
      \expandafter\noexpand\csname
        the#2\endcsname\@SepMark\noexpand\arabic{#1}}}%
    {\PackageWarning{float}{Can't redefine counter variable for #1.}}}
%    \end{macrocode}
% \iffalse
%</float-xetex-bidi.def>
%<*floatrow-xetex-bidi.def>
%\fi
% \section{File \texttt{floatrow-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{floatrow-xetex-bidi.def}[2025/01/03 v0.2 bidi adaptations for floatrow package for XeTeX engine]
\RequirePackage{color}
\renewcommand\flnew@within[1]{\@addtoreset{\FB@captype}{#1}%
  \expandafter\edef\csname the\FB@captype\endcsname{%
      \expandafter\noexpand\csname
        the#1\endcsname\@SepMark\noexpand\arabic{\FB@captype}}}
%    \end{macrocode}
% \iffalse
%</floatrow-xetex-bidi.def>
%<*flowfram-xetex-bidi.def>
%\fi
% \section{File \texttt{flowfram-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{flowfram-xetex-bidi.def}[2025/01/03 v0.6 bidi adaptations for flowfram package for XeTeX engine]
\def\@outputdblcol{%
\@nxtcol=\c@thisframe
\c@curpg=\c@page
\@g@tnextcol{\@nxtcol}%
\if@ff@nwpg % next flow frame starts on new page
  \global\@firstcolumntrue
  \@setcolbox\c@thisframe
  \if@specialpage
    \global\@specialpagefalse
    \@nameuse{ps@\@specialstyle}\relax
  \fi
  \if@twoside
    \ifodd\count\z@
      \let\@thehead\@oddhead
      \let\@thefoot\@oddfoot
    \else
      \let\@thehead\@evenhead
      \let\@thefoot\@evenfoot
    \fi
  \else
    \let\@thehead\@oddhead
    \let\@thefoot\@oddfoot
  \fi
  \@begindvi
  \@dodynamicthehead\@dodynamicthefoot
  \vbadness=\@M
  \setbox\@outputbox\vbox{\hbox to \textwidth{\@ff@do@allframes}}%
  \@combinedblfloats
  \@outputpage
\advance\c@curpg by -\c@page\relax
  \whiledo{\c@curpg>0}{\advance\c@curpg by -1\relax
  \setbox\@outputbox\vbox{\hbox to \textwidth{\@ff@do@allframes}}%
\@outputpage}
  \begingroup
    \@dblfloatplacement
    \@startdblcolumn
    \@whilesw \if@fcolmade \fi
       {\@outputpage \@startdblcolumn }\endgroup
  \@resetst@tics
  \@resetdyn@mics
\else % still on same page, save contents of box255
  \global\@firstcolumnfalse
  \@setcolbox\c@thisframe
\fi
\global\c@thisframe=\@nxtcol
\@setcol{\c@thisframe}\relax
\global\@colht\vsize
}
\def\@outputpage{%
\begingroup
  \let\protect\noexpand
  \@resetactivechars
  \global\let\@@if@newlist\if@newlist
  \global\@newlistfalse\@parboxrestore
  \global\let\bidi@BeforeOutputPageShipOut\@firstofone
  \bidi@beforeoutputpageshipouthook
  \shipout\vbox{\set@typeset@protect
    \aftergroup
    \endgroup
    \aftergroup
    \set@typeset@protect
    \reset@font\normalsize
    \bidi@font@@outputpage
    \normalsfcodes
    \let\label\@gobble
    \let\index\@gobble
    \let\glossary\@gobble
    \baselineskip\z@skip
    \lineskip\z@skip
    \lineskiplimit\z@
    \vskip\topmargin\moveright\@themargin
    \vbox{%
      \global\let\bidi@BeforeHeader\@firstofone
      \bidi@beforeheaderhook
      \vskip\headheight
      \vskip\headsep
      \global\let\bidi@BeforeOutputBoxOutputPage\@firstofone
      \bidi@beforeoutputboxoutputpagehook
      \box\@outputbox
      \global\let\bidi@AfterOutputBoxOutputPage\@firstofone
      \bidi@afteroutputboxoutputpagehook
    }}%
  \global\let\bidi@AfterOutputPageShipOut\@firstofone
  \bidi@afteroutputpageshipouthook
  \global\let\if@newlist\@@if@newlist
  \stepcounter{page}%
  \setcounter{displayedframe}{0}%
  \let\firstmark\botmark
  \global\let\bidi@AtEndOutputPage\@firstofone
  \bidi@atendoutputpagehook
  }


\newcommand*\bidi@s@tfftextcol{\ifthenelse{\equal{\ff@txtcol}{}}{}{%
\expandafter\bidicolor\ff@txtcol}}

\newcommand{\bidi@ff@box}[3]{{\@ffbackground{\vbox to#2
{\hb@xt@ #1{\hss{\bidi@s@tfftextcol #3}\hss}\vss\kern\z@}}}}


\renewcommand*{\@docolbox}[1]{%
\edef\ff@frametype{%
\csname @ff@frametype@\romannumeral#1\endcsname}%
\edef\ff@col{\csname @ff@col@\romannumeral#1\endcsname}%
\edef\ff@txtcol{\csname @ff@txtcol@\romannumeral#1\endcsname}%
\edef\ff@backcol{\csname @ff@backcol@\romannumeral#1\endcsname}%
\@ff@setoffset{#1}%
\rotateframe{\csname @ff@angle@\romannumeral#1\endcsname}{%
\ifthenelse{\boolean{columnframe\romannumeral#1}}{%
\@ff@fbox{\csname colwidth\romannumeral#1\endcsname}%
{\csname colheight\romannumeral#1\endcsname}{%
\expandafter\box\csname column\romannumeral#1\endcsname}{%
\csname\ff@frametype\endcsname}%
}{%
\bidi@ff@box{\csname colwidth\romannumeral#1\endcsname}%
{\csname colheight\romannumeral#1\endcsname}{%
\expandafter\box\csname column\romannumeral#1\endcsname}%
}}}
\IfClassLoadedT{book}{%
\renewcommand\theequation
  {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand \thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand \thetable
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand \thesection {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}}
\IfClassLoadedT{report}{%
\renewcommand\theequation
  {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand \thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand \thetable
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand \thesection {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}}
\renewcommand{\rotateframe}[2]{\if@ttb@rotate
\rotatebox{#1}{\if@RTL\beginL\fi#2\if@RTL\endL\fi}%
\else
#2\relax
\fi}
%    \end{macrocode}
% \iffalse
%</flowfram-xetex-bidi.def>
%<*fnpct-xetex-bidi.def>
%\fi
% \section{File \texttt{fnpct-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{fnpct-xetex-bidi.def}[2025/09/12 v0.2 bidi adaptations for fnpct package for XeTeX engine]
\ExplSyntaxOn
    \@ifclassloaded{beamer}
      {
        \AdaptNote \footnote{d<>o+m} [\beamer@mpfn]
          {
            \IfNoValueTF{#1}
              {\IfNoValueTF{#2}{#NOTE{#3}}{#NOTE[#2]{#3}}}
              {\IfNoValueTF{#2}{#NOTE<#1>{#3}}{#NOTE<#1>[#2]{#3}}}
          }
        \AdaptNote \RTLfootnote{d<>o+m} [\beamer@mpfn]
          {
            \IfNoValueTF{#1}
              {\IfNoValueTF{#2}{#NOTE{#3}}{#NOTE[#2]{#3}}}
              {\IfNoValueTF{#2}{#NOTE<#1>{#3}}{#NOTE<#1>[#2]{#3}}}
          }
        \AdaptNote \LTRfootnote{d<>o+m} [\beamer@mpfn]
          {
            \IfNoValueTF{#1}
              {\IfNoValueTF{#2}{#NOTE{#3}}{#NOTE[#2]{#3}}}
              {\IfNoValueTF{#2}{#NOTE<#1>{#3}}{#NOTE<#1>[#2]{#3}}}
          }
      }
      {
        \AdaptNote  \RTLfootnote {o+m} [\@mpfn]
          { \IfNoValueTF {#1} {#NOTE{#2}} {#NOTE[#1]{#2}} }
        \AdaptNote  \LTRfootnote {o+m} [\@mpfn]
          { \IfNoValueTF {#1} {#NOTE{#2}} {#NOTE[#1]{#2}} }
      }
\ExplSyntaxOff
%    \end{macrocode}
% \iffalse
%</fnpct-xetex-bidi.def>
%<*footnote-xetex-bidi.def>
%\fi
% \section{File \texttt{footnote-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{footnote-xetex-bidi.def}[2025/09/30 v1.6 bidi footnote macros for XeTeX engine]
\if@RTLmain\@RTL@footnotetrue\else\@RTL@footnotefalse\fi
\newif\ifbidi@autofootnoterule
\def\bidi@mpfootnoterule{\footnoterule}
\newcounter{footdir@label}
\renewcommand*{\thefootdir@label}{footdir@\the\value{footdir@label}}
\newcommand*{\footdir@write}{%
  \stepcounter{footdir@label}%
  \zref@labelbyprops{\thefootdir@label}{abspage}%
}
\newcommand*{\debugfootnotedirection}{\footdir@debugtrue}
\newtoks\footdir@toks
\newcommand*{\footdir@debug}[1]{%
  \iffootdir@debug
    \typeout{[footdir] #1}%
  \fi
}
%\@ifpackagelater{zref-abspage}{2012/10/27}{%
%  \newcommand*{\footdir@LeftRightElse}{%
%    \ltx@ifundefined{footdir@\the\value{zabspage}}{%
%      \footdir@debug{abspage \the\value{zabspage}: else}%
%      \ltx@thirdofthree
%    }{%
%      \if\csname footdir@\the\value{zabspage}\endcsname L%
%        \footdir@debug{abspage \the\value{zabspage}: left}%
%        \expandafter\ltx@firstofthree
%      \else
%        \footdir@debug{abspage \the\value{zabspage}: right}%
%        \expandafter\ltx@secondofthree
%      \fi
%    }%
%  }%
%}{%
  \providecommand*{\c@zabspage}{\c@abspage}%
  \newcommand*{\footdir@LeftRightElse}{%
    \footdir@write
    \zifrefundefined{\thefootdir@label}{%
      \footdir@debug{abspage ??: else}%  
      \ltx@thirdofthree
    }{%
      \edef\footdir@abspage{%
        \zref@extractdefault{\thefootdir@label}{abspage}{0}%
      }%
      \ltx@ifundefined{footdir@\footdir@abspage}{%
        \footdir@debug{\footdir@abspage: else}%   
        \ltx@thirdofthree
      }{%
        \if\csname footdir@\footdir@abspage\endcsname L%
          \footdir@debug{\footdir@abspage: left}%
          \expandafter\ltx@firstofthree
        \else
          \footdir@debug{\footdir@abspage: right}%
          \expandafter\ltx@secondofthree
        \fi
      }%   
    }%     
  }%       
%}          
\newcommand*{\footdir@fntext}[1]{%
  \zifrefundefined{\thefootdir@label}{%
  }{%
    \edef\footdir@name{%
      footdir@\zref@extractdefault{\thefootdir@label}{abspage}{0}%
    }%
    \@ifundefined{\footdir@name}{%
      \expandafter\gdef\csname\footdir@name\endcsname{#1}%
    }{}%
  }%
}  

\newcommand*{\footdir@temp}[3]{%
  \@ifdefinable{#1}{%
    \let#1#2%
    \renewcommand{#2}[1]{%
      \footdir@write
      \footdir@fntext{#3}%
      \stepcounter{footdir@label}%
      \footdir@fntext{#3}%
      \footdir@toks{##1}% 
      \footdir@toks\expandafter{%
        \the\expandafter\footdir@toks
        \expandafter
        \zref@labelbyprops\expandafter{\thefootdir@label}{abspage}%
      }%
      \expandafter#1\expandafter{\the\footdir@toks}%
    }%
  }%  
} 

\def\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\def\left@footnoterule{\kern-3\p@
  \hrule \@width .4\columnwidth \kern 2.6\p@} 
\def\textwidth@footnoterule{\kern-3\p@
  \hrule \@width \columnwidth \kern 2.6\p@}
\def\leftfootnoterule{%
\bidi@autofootnoterulefalse
\def\footnoterule{\left@footnoterule}}
\let\LRfootnoterule=\leftfootnoterule
\def\rightfootnoterule{%
\bidi@autofootnoterulefalse
\def\footnoterule{\right@footnoterule}}
\def\textwidthfootnoterule{%
\bidi@autofootnoterulefalse
\def\footnoterule{\textwidth@footnoterule}}



\def\auto@footnoterule{%
\footdir@LeftRightElse%
\left@footnoterule%  
\right@footnoterule% 
\left@footnoterule%
}  



\def\autofootnoterule{%
\bidi@autofootnoteruletrue%
\def\footnoterule{\auto@footnoterule}%
}

\newcommand*{\SplitFootnoteRule}{%
  \gdef\split@prev{0}
  \let\pagefootnoterule\footnoterule
  \let\mpfootnoterule\footnoterule
  \def\splitfootnoterule{\kern-3\p@ \hrule \kern2.6\p@}
  \def\footnoterule{\relax
    \ifx \@listdepth\@mplistdepth
      \mpfootnoterule
    \else
      \ifnum\split@prev=\z@
        \pagefootnoterule
      \else
        \splitfootnoterule
      \fi
      \xdef\split@prev{\the\insertpenalties}%
    \fi
  }%
}




\def\RTLfootnote{\@ifnextchar[\@xRTLfootnote{\stepcounter\@mpfn
     \protected@xdef\@thefnmark{\thempfn}%
     \@footnotemark\@RTLfootnotetext}}
\def\@xRTLfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\@RTLfootnotetext}
\def\LTRfootnote{\@ifnextchar[\@xLTRfootnote{\stepcounter\@mpfn
     \protected@xdef\@thefnmark{\thempfn}%
     \@footnotemark\@LTRfootnotetext}}
\def\@xLTRfootnote[#1]{%
   \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\@LTRfootnotetext}


\def\setfootnoteRL{\@RTL@footnotetrue}
\def\unsetfootnoteRL{\@RTL@footnotefalse}
\def\setfootnoteLR{\unsetfootnoteRL}

\newcommand*{\bidi@@footnotetext@font}{\footnotesize}
\newcommand*{\bidi@@LTRfootnotetext@font}{\footnotesize}
\newcommand*{\bidi@@RTLfootnotetext@font}{\footnotesize}

\long\def\@footnotetext#1{\insert\footins{%
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi%
    \reset@font%
    \bidi@@footnotetext@font% \reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark
    }%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}%


\long\def\@RTLfootnotetext#1{\insert\footins{%
    \@RTLtrue%
    \reset@font%
    \bidi@@RTLfootnotetext@font% \reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark
    }%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}%

\long\def\@LTRfootnotetext#1{\insert\footins{%
    \@RTLfalse%
    \reset@font%
    \bidi@@LTRfootnotetext@font% \reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark
    }%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}%

\AtBeginDocument{%
\if@RTL@footnote    
  \newcommand*{\bidi@footdir@footnote}{R}   
\else
  \newcommand*{\bidi@footdir@footnote}{L}
\fi%
}

\footdir@temp\footdir@ORG@bidi@footnotetext\@footnotetext{\bidi@footdir@footnote}%    
\footdir@temp\footdir@ORG@bidi@RTLfootnotetext\@RTLfootnotetext{R}%
\footdir@temp\footdir@ORG@bidi@LTRfootnotetext\@LTRfootnotetext{L}%

\long\def\@mpRTLfootnotetext#1{%
  \ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\global\let\bidi@mpfootnoterule\right@footnoterule\fi\fi%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \@RTLtrue
    \reset@font%
    \bidi@@RTLfootnotetext@font% \reset@font\footnotesize
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}
\long\def\@mpLTRfootnotetext#1{%
 \ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\global\let\bidi@mpfootnoterule\left@footnoterule\fi\fi%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \@RTLfalse
    \reset@font%
    \bidi@@LTRfootnotetext@font% \reset@font\footnotesize
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}
\long\def\@mpfootnotetext#1{%
 \ifbidi@autofootnoterule\ifnum\c@mpfootnote=\@ne\if@RTL@footnote\global\let\bidi@mpfootnoterule\right@footnoterule\else\global\let\bidi@mpfootnoterule\left@footnoterule\fi\fi\fi%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \if@RTL@footnote\@RTLtrue\else\@RTLfalse\fi
    \reset@font%
    \bidi@@footnotetext@font% \reset@font\footnotesize
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}
\def\@iiiminipage#1#2[#3]#4{%
  \leavevmode
  \@pboxswfalse
  \if@hboxRconstruct\@bidi@list@minipage@parbox@not@nobtrue\fi
  \if@RTL\if#1t\@bidi@list@minipage@parboxtrue\else\if#1b\@bidi@list@minipage@parboxtrue\fi\fi\fi
  \setlength\@tempdima{#4}%
  \def\@mpargs{{#1}{#2}[#3]{#4}}%
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \let\@footnotetext\@mpfootnotetext
      \let\@LTRfootnotetext\@mpLTRfootnotetext
      \let\@RTLfootnotetext\@mpRTLfootnotetext
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \@minipagerestore
      \@setminipage}
\def\endminipage{%
    \par
    \unskip
    \ifvoid\@mpfootins\else
      \vskip\skip\@mpfootins
      \normalcolor
      \bidi@mpfootnoterule
      \unvbox\@mpfootins
    \fi
    \@minipagefalse   %% added 24 May 89
  \color@endgroup
  \egroup
  \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}}
\def\LTRthanks#1{\footnotemark
    \protected@xdef\@thanks{\@thanks
        \protect\LTRfootnotetext[\the\c@footnote]{#1}}%
}
\def\LTRfootnotetext{%
     \@ifnextchar [\@xLTRfootnotenext
       {\protected@xdef\@thefnmark{\thempfn}%
    \@LTRfootnotetext}}
\def\@xLTRfootnotenext[#1]{%
  \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
  \endgroup
  \@LTRfootnotetext}
\def\RTLthanks#1{\footnotemark
    \protected@xdef\@thanks{\@thanks
        \protect\RTLfootnotetext[\the\c@footnote]{#1}}%
}
\let\@thanks\@empty
\def\RTLfootnotetext{%
     \@ifnextchar [\@xRTLfootnotenext
       {\protected@xdef\@thefnmark{\thempfn}%
    \@RTLfootnotetext}}
\def\@xRTLfootnotenext[#1]{%
  \begingroup
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
  \endgroup
  \@RTLfootnotetext}
\leftfootnoterule
%    \end{macrocode}
% \iffalse
%</footnote-xetex-bidi.def>
%<*footnotebackref-xetex-bidi.def>
%\fi
% \section{File \texttt{footnotebackref-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{footnotebackref-xetex-bidi.def}[2022/02/18 v0.1 bidi adaptations for footnotebackref package for XeTeX engine]
\LetLtxMacro{\BHFN@OldLTRFootnote}{\LTRfootnote}
\LetLtxMacro{\BHFN@OldRTLFootnote}{\RTLfootnote}

\renewcommand*\LTRfootnote{%
    \refstepcounter{BackrefHyperFootnoteCounter}%
    \edef\BackrefFootnoteTag{bhfn:\theBackrefHyperFootnoteCounter}%
    \label{\BackrefFootnoteTag}%
    \@ifnextchar[\Backref@OptLTRHyperFootnote\Backref@HyperLTRFootnote}
    
\renewcommand*\RTLfootnote{%
    \refstepcounter{BackrefHyperFootnoteCounter}%
    \edef\BackrefFootnoteTag{bhfn:\theBackrefHyperFootnoteCounter}%
    \label{\BackrefFootnoteTag}%
    \@ifnextchar[\Backref@OptRTLHyperFootnote\Backref@HyperRTLFootnote}
\newcommand\Backref@HyperLTRFootnote[1]{%
    \BHFN@OldLTRFootnote{\Backref@HyperSymbol#1}}
    
\newcommand\Backref@HyperRTLFootnote[1]{%
    \BHFN@OldRTLFootnote{\Backref@HyperSymbol#1}}
    
\newcommand\Backref@OptHyperLTRFootnote[2][\empty]{%
    \BHFN@OldLTRFootnote[#1]{\Backref@HyperSymbol#2}}
    
\newcommand\Backref@OptHyperRTLFootnote[2][\empty]{%
    \BHFN@OldRTLFootnote[#1]{\Backref@HyperSymbol#2}}
    
\bidi@AfterFile{extrafootnotefeatures-xetex-bidi.def}{%
\ifFootnoteBackref@numberlinked
\renewcommand{\footfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\footscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\footscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\footscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \fi
  \fi}
\renewcommand{\LTRfootfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\LTRfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\LTRfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\LTRfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \fi
  \fi}
\renewcommand{\RTLfootfootmark}{%
  \ifdim\footmarkwidth < \z@
    \llap{\hb@xt@ -\footmarkwidth{%
            \hss\normalfont\RTLfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
          \hspace*{-\footmarkwidth}}%
  \else
    \ifdim\footmarkwidth = \z@
      {\normalfont\RTLfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \else
      \hb@xt@\footmarkwidth{\hss\normalfont\RTLfootscript{\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}%
    \fi
  \fi}
\fi
}
%    \end{macrocode}
% \iffalse
%</footnotebackref-xetex-bidi.def>
%<*framed-xetex-bidi.def>
%\fi
% \section{File \texttt{framed-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{framed-xetex-bidi.def}[2012/06/05 v0.3 bidi adaptations for framed package for XeTeX engine]
\renewcommand\TitleBarFrame[3][]{\begingroup
  \ifx\delimiter#1\delimiter
    \let\TF@conlab\@empty
  \else
    \def\TF@conlab{% continuation label
     \nointerlineskip
     \smash{\rlap{\kern\wd\@tempboxa\kern\fboxrule\kern\fboxsep #1}}}%
  \fi
  %\let\TF@savecolor\current@color
  \textcolor{TFFrameColor}{%
  \CustomFBox
    {\TF@Title{#2}}{\TF@conlab}%
    \fboxrule\fboxrule\fboxrule\fboxrule
    %{\let\current@color\TF@savecolor\set@color #3}%
    {\normalcolor #3}%
  }\endgroup
}
\renewenvironment{titled-frame}[1]{%
  \def\FrameCommand{\fboxsep8pt\fboxrule2pt
     \TitleBarFrame{\textbf{#1}}}%
  \def\FirstFrameCommand{\fboxsep8pt\fboxrule2pt
     \TitleBarFrame[$\if@RTL\blacktriangleleft\else\blacktriangleright\fi$]{\textbf{#1}}}%
  \def\MidFrameCommand{\fboxsep8pt\fboxrule2pt
     \TitleBarFrame[$\if@RTL\blacktriangleleft\else\blacktriangleright\fi$]{\textbf{#1\ (cont)}}}%
  \def\LastFrameCommand{\fboxsep8pt\fboxrule2pt
     \TitleBarFrame{\textbf{#1\ (cont)}}}%
  \MakeFramed{\advance\hsize-20pt \FrameRestore}}%
%  note: 8 + 2 + 8 + 2 = 20.  Don't use \width because the frame title
%  could interfere with the width measurement.
 {\endMakeFramed}
\chardef\FrameRestore=\catcode`\| % for debug
\catcode`\|=\catcode`\% % (debug: insert space after backslash)
\def\fb@put@frame#1#2{\relax
 \ifdim\pagegoal=\maxdimen \pagegoal\vsize \fi
|   \message{=============== Entering putframe ====================^^J
|     \pagegoal=\the\pagegoal,  \pagetotal=\the\pagetotal. }%
 \ifinner
   \fb@putboxa#1%
   \fb@afterframe
 \else
  \dimen@\pagegoal \advance\dimen@-\pagetotal % natural space left on page
  \ifdim\dimen@<2\baselineskip % Too little room on page
|   \message{Page has only \the\dimen@\space room left; eject. }%
    \eject \fb@adjheight \fb@put@frame#1#2%
  \else % there's appreciable room left on the page
     \fb@sizeofframe#1%
|    \message{\string\pagetotal=\the\pagetotal,
|        \string\pagegoal=\the\pagegoal,
|        \string\pagestretch=\the\pagestretch,
|        \string\pageshrink=\the\pageshrink,
|        \string\fb@frh=\the\fb@frh. \space}
|    \message{^^JBox of size \the\ht\@tempboxa\space}%
     \begingroup % temporarily set \dimen@ to be...
     \advance\dimen@.8\pageshrink  % maximum space available on page
     \advance\dimen@-\fb@frh\relax % max space available for frame's contents
%%% LOOKS SUBTRACTED AND ADDED, SO DOUBLE ACCOUNTING!
     \expandafter\endgroup
     % expand \ifdim, then restore \dimen@ to real room left on page
     \ifdim\dimen@>\ht\@tempboxa % whole box does fit
|       \message{fits in \the\dimen@. }%
        % ToDo: Change this to use vsplit anyway to capture the marks
        % MERGE THIS WITH THE else CLAUSE!!!
        \fb@putboxa#1%
        \fb@afterframe
     \else % box must be split
|       \message{must be split to fit in \the\dimen@. }%
        % update frame measurement to use \FirstFrameCommand or \MidFrameCommand
        \fb@sizeofframe#2%
        \setbox\@tempboxa\vbox{% simulate frame and flexiblity of the page:
           \vskip \fb@frh \@plus\pagestretch \@minus.8\pageshrink
           \kern137sp\kern-137sp\penalty-30
           \unvbox\@tempboxa}%
        \edef\fb@resto@set{\boxmaxdepth\the\boxmaxdepth 
                           \splittopskip\the\splittopskip}%
        \boxmaxdepth\z@ \splittopskip\z@
|      \message{^^JPadded box of size \the\ht\@tempboxa\space split to \the\dimen@}%
        % Split box here
        \setbox\tw@\vsplit\@tempboxa to\dimen@
|       \toks99\expandafter{\splitfirstmark}%
|       \toks98\expandafter{\splitbotmark}%
|       \message{Marks are: \the\toks99, \the\toks98. }%
        \setbox\tw@\vbox{\unvbox\tw@}% natural-sized
|       \message{Natural height of split box is \the\ht\tw@, leaving 
|          \the\ht\@tempboxa\space remainder. }%
        % If the split-to size > (\vsize-\topskip), then set box to full size.
        \begingroup
        \advance\dimen@\topskip
        \expandafter\endgroup
        \ifdim\dimen@>\pagegoal
|         \message{Frame is big -- Use up the full column. }%
          \dimen@ii\pagegoal
          \advance\dimen@ii -\topskip
          \advance\dimen@ii \FrameHeightAdjust\relax
        \else  % suspect this is implemented incorrectly:
          % If the split-to size > feasible room_on_page, rebox it smaller.
          \advance\dimen@.8\pageshrink
          \ifdim\ht\tw@>\dimen@
|           \message{Box too tall; rebox it to \the\dimen@. }%
            \dimen@ii\dimen@
          \else % use natural size
            \dimen@ii\ht\tw@
          \fi
        \fi
        % Re-box contents to desired size \dimen@ii
        \advance\dimen@ii -\fb@frh
        \setbox\tw@\vbox to\dimen@ii \bgroup
        % remove simulated frame and page flexibility:
        \vskip -\fb@frh \@plus-\pagestretch \@minus-.8\pageshrink
        \unvbox\tw@ \unpenalty\unpenalty
        \ifdim\lastkern=-137sp % whole box went to next page
|          \message{box split at beginning! }%
           % need work here???
           \egroup \fb@resto@set \eject % (\vskip for frame size was discarded) 
           \fb@adjheight
           \fb@put@frame#1#2% INSERTED ???
        \else % Got material split off at the head
           \egroup \fb@resto@set
           \ifvoid\@tempboxa % it all fit after all
|             \message{box split at end! }%
              \setbox\@tempboxa\box\tw@
              \fb@putboxa#1%
              \fb@afterframe
           \else % it really did split
|             \message{box split as expected. Its reboxed height is \the\ht\tw@. }%
              \ifdim\wd\tw@>\z@
                \wd\tw@\wd\@tempboxa
                \centerline{#2{\hboxL{\box\tw@}}}%  ??? \centerline bad idea
              \else
|               \message{Zero width means likely blank. Don't frame it (guess)}%
                \box\tw@
              \fi
              \hrule \@height\z@ \@width\hsize
              \eject
              \fb@adjheight
              \fb@put@frame\LastFrameCommand\MidFrameCommand
  \fi\fi\fi\fi\fi
}
\def\fb@putboxa#1{%
  \ifvoid\@tempboxa
    \PackageWarning{framed}{Boxa is void -- discard it. }%
  \else
|   \message{Frame and place boxa. }%
|   %{\showoutput\showbox\@tempboxa}%
    \centerline{#1{\hboxL{\box\@tempboxa}}}%
  \fi
}
\catcode`\|=\FrameRestore
\def\FrameRestore{%
   \let\if@nobreak\iffalse
   \let\if@noskipsec\iffalse
   \let\-\@dischyph
   \let\'\@acci\let\`\@accii\let\=\@acciii
   %  \message{FrameRestore:
   %    \@totalleftmargin=\the \@totalleftmargin,
   %    \rightmargin=\the\rightmargin, 
   %    \@listdepth=\the\@listdepth.  }%
   % Test if we are in a list (or list-like paragraph)
   \ifnum \ifdim\@totalleftmargin>\z@ 1\fi  
          \ifdim\rightmargin>\z@ 1\fi
          \ifnum\@listdepth>\z@ 1\fi 0>\z@
     %     \message{In a list: \linewidth=\the\linewidth, \@totalleftmargin=\the\@totalleftmargin,
     %       \parshape=\the\parshape, \columnwidth=\the\columnwidth, \hsize=\the\hsize, 
     %       \labelwidth=\the\labelwidth. }%
     \@setminipage % snug fit around the item
     % Now try to propageate changes of width from \hsize to list parameters.
     % This is deficient, but a more advanced way to indicate modification to text 
     % dimensions is not (yet) provided; in particular, no separate left/right
     % adjustment.
     \advance\linewidth-\columnwidth \advance\linewidth\hsize
     \parshape\@ne \@totalleftmargin \linewidth
   \else % Not in list
     \linewidth=\hsize
     %\message{No list, set \string\linewidth=\the\hsize. }%
   \fi
   \sloppy
}
%    \end{macrocode}
% \iffalse
%</framed-xetex-bidi.def>
%<*ftnright-xetex-bidi.def>
%\fi
% \section{File \texttt{ftnright-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{ftnright-xetex-bidi.def}[2018/09/29 v0.6 bidi adaptations for ftnright package for XeTeX engine]

\def\prepare@bidi@copyins{%
  \global\bidi@rcol@copyinsskip\skip\@bidi@copyins@
  \global\skip\@bidi@copyins@\z@
  \global\count\@bidi@copyins@\z@
  \global\dimen\@bidi@copyins@\textheight}

\newskip\bidi@rcol@copyinsskip

\def\LTR@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \global\count\footins\@m
    \global\skip\footins\rcol@footinsskip
    \global\count\@bidi@copyins@\@m
    \global\skip\@bidi@copyins@\bidi@rcol@copyinsskip
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
   \preparefootins
   \prepare@bidi@copyins
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hfil
        {\normalcolor\vrule \@width\columnseprule}%
        \hfil
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}}}%
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
    \endgroup
  \fi}%

\def\RTL@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \global\count\footins\@m
    \global\skip\footins\rcol@footinsskip
    \global\count\@bidi@copyins@\@m
    \global\skip\@bidi@copyins@\bidi@rcol@copyinsskip
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
   \preparefootins
   \prepare@bidi@copyins
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
       \hskip \columnwidth
       \hfil
       {\normalcolor\vrule \@width\columnseprule}%
       \hfil
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hskip -\textwidth
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}%
       \hskip \columnsep
      \hskip \columnwidth }}%
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
    \endgroup
  \fi}%

\def\@startcolumn{%
 \ifx\@deferlist\@empty
   \global\@fcolmadefalse
   \global\@colroom\@colht
 \else
   \ifvoid\footins\else
     \ftn@amount\ht\footins
     \advance\ftn@amount\dp\footins
     \advance\ftn@amount\skip\footins
   \fi
   \ifvoid\@bidi@copyins@\else
     \bidi@copyins@amount\ht\@bidi@copyins@
     \advance\bidi@copyins@amount\dp\@bidi@copyins@
     \advance\bidi@copyins@amount\skip\@bidi@copyins@
   \fi
   \global\advance\@colht-\ftn@amount
   \global\advance\@colht-\bidi@copyins@amount
   \global\@colroom\@colht
   \@xstartcol
   \global\advance\@colht\ftn@amount
   \global\advance\@colroom\ftn@amount
   \global\advance\@colht\bidi@copyins@amount
   \global\advance\@colroom\bidi@copyins@amount
 \fi
 \if@fcolmade
  \setbox\@cclv\box\@outputbox
  \@makecol
 \else
   \ifvoid\footins\else
     \insert\footins{\unvbox\footins}\fi
   \ifvoid\@bidi@copyins@\else
     \insert\@bidi@copyins@{\unvbox\@bidi@copyins@}\fi
 \fi}

\newdimen\bidi@copyins@amount

\def\@makecol{\if@firstcolumn
  \setbox\@outputbox\box\@cclv
  \if@twocolumn \else
    \ifvoid\footins \else
      \@latexerr{ftnright package
                 used in one-column mode}%
   {The ftnright package was designed to
    work with LaTeX's standard^^Jtwocolumn
    option. It does *not* work with the
    multicol package.^^JSo please specify
    `twocolumn' in the
    \noexpand\documentclass command.}%
      \shipout\box\footins \fi
    \ifvoid\@bidi@copyins@ \else
      \@latexerr{ftnright package
                 used in one-column mode}%
   {The ftnright package was designed to
    work with LaTeX's standard^^Jtwocolumn
    option. It does *not* work with the
    multicol package.^^JSo please specify
    `twocolumn' in the
    \noexpand\documentclass command.}%
      \shipout\box\@bidi@copyins@ \fi\fi
  \ifnum\insertpenalties>\z@
      \@latexerr{ftnright package
                 scrambled footnotes}%
    {There is too much footnote material in
     the first column  and ftnright^^Jis
     unable to cope with this.^^JYou need
     to reduce the amount to get a properly
     formatted page.}%
  \fi
 \else
  \ifvoid\footins
    \ifvoid\@bidi@copyins@
      \setbox\@outputbox\box\@cclv
    \else
      \setbox\@outputbox\vbox
        {\ifvoid\@cclv \else
           \unvbox\@cclv
           \vskip \skip\@bidi@copyins@
         \fi
           \color@begingroup
           \normalcolor
           \unvbox \@bidi@copyins@
           \color@endgroup}%
    \fi
  \else
    \setbox\@outputbox\vbox
      {\ifvoid\@cclv \else
        \unvbox\@cclv
        \vskip\skip\footins\fi
        \color@begingroup
        \normalcolor
        \footnoterule\unvbox\footins
        \color@endgroup
        \ifvoid\@bidi@copyins@
        \else
          \vskip \skip\@bidi@copyins@
          \color@begingroup
          \normalcolor
          \unvbox \@bidi@copyins@
          \color@endgroup
        \fi
      }%
  \fi
 \fi
  \xdef\@freelist{\@freelist\@midlist}%
  \global \let \@midlist \@empty
  \@combinefloats
  \ifvbox\@kludgeins
    \@makespecialcolbox
  \else
   \setbox\@outputbox\vbox to\@colht
     {\boxmaxdepth\maxdepth
      \@texttop
      \@tempdima\dp\@outputbox
      \unvbox\@outputbox
      \vskip-\@tempdima
      \@textbottom}%
  \fi
  \global\maxdepth\@maxdepth}

\let\leftfootnoterule\@empty
\let\rightfootnoterule\@empty
\let\textwidthfootnoterule\@empty
\let\autofootnoterule\@empty
\let\footnoterule\@empty
\long\def\@makefntext#1{\parindent 1em
   \noindent\hbox to 2em{}%
   \llap{\@thefnmark\hbox{.}\,\,}#1}
   
\setlength{\skip\@bidi@copyins@}
          {10pt plus 5pt minus 3pt}
\AtBeginDocument{\prepare@bidi@copyins}   
%    \end{macrocode}
% \iffalse
%</ftnright-xetex-bidi.def>
%<*graphicx-xetex-bidi.def>
%\fi
% \section{File \texttt{graphicx-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{graphicx-xetex-bidi.def}[2017/06/17 v0.5 bidi adaptations for graphicx package for XeTeX engine]
\def\Grot@box@std#1#2{\ifmmode\else\if@RTL\beginL\fi\fi%
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{\ifmmode\if@RTL\beginR\fi#2\if@RTL\endR\fi\else\if@RTL\beginR\fi#2\if@RTL\endR\fi\fi}}%
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box\ifmmode\else\if@RTL\endL\fi\fi}
\long\def\Grot@box@kv[#1]#2#3{\ifmmode\else\if@RTL\beginL\fi\fi%
  \@begin@tempboxa\hbox{\ifmmode\if@RTL\beginR\fi#3\if@RTL\endR\fi\else\if@RTL\beginR\fi#3\if@RTL\endR\fi\fi}%
    \Grot@x\width \divide\Grot@x\tw@
    \Grot@y\height \advance\Grot@y-\depth \divide\Grot@y\tw@
    \setkeys{Grot}{#1}%
    \setbox\z@\box\@tempboxa
    \Grot@setangle{#2}%
    \Grot@box\ifmmode\else\if@RTL\endL\fi\fi
  \@end@tempboxa}
\long\def\Gscale@box#1[#2]#3{\ifmmode\else\if@RTL\beginL\fi\fi%
  \leavevmode
  \def\Gscale@x{#1}\def\Gscale@y{#2}%
  \setbox\z@\hbox{{#3}}%
  \setbox\tw@\hbox{\Gscale@start\rlap{\copy\z@}\Gscale@end}%
  \ifdim#2\p@<\z@
    \ht\tw@-#2\dp\z@
    \dp\tw@-#2\ht\z@
  \else
    \ht\tw@#2\ht\z@
    \dp\tw@#2\dp\z@
  \fi
  \ifdim#1\p@<\z@
    \hb@xt@-#1\wd\z@{\kern-#1\wd\z@\box\tw@\hss}%
  \else
    \wd\tw@#1\wd\z@
    \box\tw@
  \fi\ifmmode\else\if@RTL\endL\fi\fi}
\def\Gin@iii[#1,#2][#3,#4]#5{%
  \begingroup
  \ifmmode\else\if@RTL\beginL\fi\fi
  \Gin@bboxtrue
  \Gin@defaultbp\Gin@llx{#1}%
  \Gin@defaultbp\Gin@lly{#2}%
  \Gin@defaultbp\Gin@urx{#3}%
  \Gin@defaultbp\Gin@ury{#4}%
  \Ginclude@graphics{#5}%
  \ifmmode\else\if@RTL\endL\fi\fi
  \endgroup}
\def\Gin@ii[#1]#2{%
    \def\@tempa{[}\def\@tempb{#2}%
    \ifx\@tempa\@tempb
      \def\@tempa{\Gin@iii[#1][}%
      \expandafter\@tempa
    \else
     \begingroup
       \ifmmode\else\if@RTL\beginL\fi\fi
       \@tempswafalse
       \toks@{\Ginclude@graphics{#2}}%
       \setkeys{Gin}{#1}%
       \Gin@esetsize
       \the\toks@
       \ifmmode\else\if@RTL\endL\fi\fi
     \endgroup
     \fi}
\def\reflectbox{\bidiGscale@box-1[1]}
\long\def\bidiGscale@box#1[#2]#3{\ifmmode\else\if@RTL\beginL\fi\fi%
  \leavevmode
  \def\Gscale@x{#1}\def\Gscale@y{#2}%
  \setbox\z@\hbox{{\ifmmode\if@RTL\beginR\fi#3\if@RTL\endR\fi\else\if@RTL\beginR\fi#3\if@RTL\endR\fi\fi}}%
  \setbox\tw@\hbox{\Gscale@start\rlap{\copy\z@}\Gscale@end}%
  \ifdim#2\p@<\z@
    \ht\tw@-#2\dp\z@
    \dp\tw@-#2\ht\z@
  \else
    \ht\tw@#2\ht\z@
    \dp\tw@#2\dp\z@
  \fi
  \ifdim#1\p@<\z@
    \hb@xt@-#1\wd\z@{\kern-#1\wd\z@\box\tw@\hss}%
  \else
    \wd\tw@#1\wd\z@
    \box\tw@
  \fi\ifmmode\else\if@RTL\endL\fi\fi}
\def\scalebox#1{%
  \@ifnextchar[{\bidiGscale@box{#1}}{\bidiGscale@box{#1}[#1]}}
\def\resizebox{%
  \leavevmode
  \@ifstar{\bidiGscale@@box\totalheight}{\bidiGscale@@box\height}}
\def\bidiGscale@@box#1#2#3{%
  \let\@tempa\Gin@exclamation
  \expandafter\def\expandafter\@tempb\expandafter{\string#2}%
  \expandafter\def\expandafter\@tempc\expandafter{\string#3}%
  \ifx\@tempb\@tempa
    \ifx\@tempc\@tempa
      \toks@{\mbox}%
    \else
      \toks@{\bidiGscale@box@dd{#3}#1}%
    \fi
  \else
    \ifx\@tempc\@tempa
      \toks@{\bidiGscale@box@dd{#2}\width}%
    \else
      \toks@{\bidiGscale@box@dddd{#2}\width{#3}#1}%
    \fi
  \fi
  \the\toks@}
\long\def\bidiGscale@box@dd#1#2#3{%
  \@begin@tempboxa\hbox{\ifmmode\if@RTL\beginR\fi#3\if@RTL\endR\fi\else\if@RTL\beginR\fi#3\if@RTL\endR\fi\fi}%
    \setlength\@tempdima{#1}%
    \setlength\@tempdimb{#2}%
    \Gscale@div\@tempa\@tempdima\@tempdimb
    \Gscale@box\@tempa[\@tempa]{\box\@tempboxa}%
  \@end@tempboxa}
\long\def\bidiGscale@box@dddd#1#2#3#4#5{%
  \@begin@tempboxa\hbox{\ifmmode\if@RTL\beginR\fi#5\if@RTL\endR\fi\else\if@RTL\beginR\fi#5\if@RTL\endR\fi\fi}%
    \setlength\@tempdima{#1}%
    \setlength\@tempdimb{#2}%
    \Gscale@div\@tempa\@tempdima\@tempdimb
    \setlength\@tempdima{#3}%
    \setlength\@tempdimb{#4}%
    \Gscale@div\@tempb\@tempdima\@tempdimb
    \ifGin@iso
      \ifdim\@tempa\p@>\@tempb\p@
        \let\@tempa\@tempb
      \else
        \let\@tempb\@tempa
      \fi
    \fi
    \Gscale@box\@tempa[\@tempb]{\box\@tempboxa}%
  \@end@tempboxa}
%    \end{macrocode}
% \iffalse
%</graphicx-xetex-bidi.def>
%<*geometry-xetex-bidi.def>
%\fi
% \section{File \texttt{geometry-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{geometry-xetex-bidi.def}[2017/01/14 v0.2 bidi adaptations for geometry package for XeTeX engine]
\renewcommand*{\Gm@vrules@mpi}{%
\if@RTLmain%
        \hb@xt@\@tempdima{\hskip-\marginparwidth\hskip-\marginparsep
        \llap{\Gm@vrule}\ignorespaces
        \hskip \marginparwidth\rlap{\Gm@vrule}\hskip \marginparsep
        \llap{\Gm@vrule}\hskip\textwidth\rlap{\Gm@vrule}\hss}%
    \else%
  \hb@xt@\@tempdima{\llap{\Gm@vrule}\ignorespaces
  \hskip \textwidth\Gm@vrule\hskip \marginparsep
  \llap{\Gm@vrule}\hfil\Gm@vrule}\fi}%
\renewcommand*{\Gm@vrules@mpii}{%
\if@RTLmain%
  \hb@xt@\@tempdima{\llap{\Gm@vrule}\ignorespaces
  \hskip \textwidth\Gm@vrule\hskip \marginparsep
  \llap{\Gm@vrule}\hfil\Gm@vrule}%
\else%
  \hb@xt@\@tempdima{\hskip-\marginparwidth\hskip-\marginparsep
  \llap{\Gm@vrule}\ignorespaces
  \hskip \marginparwidth\rlap{\Gm@vrule}\hskip \marginparsep
  \llap{\Gm@vrule}\hskip\textwidth\rlap{\Gm@vrule}\hss}\fi}%
\bidi@patchcmd{\Gm@pageframes}{%
     \ifodd\count\z@
       \let\@themargin\oddsidemargin
     \else
       \let\@themargin\evensidemargin
     \fi
}{%
     \ifodd\count\z@
       \if@RTLmain
         \let\@themargin\evensidemargin
       \else
         \let\@themargin\oddsidemargin
       \fi
     \else
       \if@RTLmain
         \let\@themargin\oddsidemargin
       \else
         \let\@themargin\evensidemargin
       \fi
     \fi
}{}{}
%    \end{macrocode}
% \iffalse
%</geometry-xetex-bidi.def>
%<*hgeneric-testphase-xetex-bidi.def>
%\fi
% \section{File \texttt{hgeneric-testphase-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{hgeneric-testphase-xetex-bidi.def}[2025/09/26 v0.3 bidi adaptations for generic Hyperref driver for the LaTeX PDF management bundle for XeTeX engine]
\ExplSyntaxOn
\bidi@undef\hyper@linkstart
\bidi@undef\hyper@linkend
\cs_new_protected:Npn \hyper@linkstart #1 #2 %#1 context, #2=destination name
  {
    \bool_if:NT \l__hyp_annot_GoTo_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \Hy@VerboseLinkStart{#1}{#2}% only for debug
            \group_begin:
            \tl_set:Nn \l_hyp_current_dest_name_tl {#2}
            \socket_use:nnn{hyp/link/GoTo/Contents}{#2}{}
            \hook_use:n {hyp/link/#1}
            \ifmmode\else\beginL\fi
            \__hyp_link_goto_begin:nw {#2}
          }
          {
            \group_begin:
          }
      }
  }

\cs_new_protected:Npn \hyper@linkend
  {
    \bool_if:NT \l__hyp_annot_GoTo_bool
      {
        \__hyp_check_link_nesting:TF
          {
            \__hyp_link_goto_end:
            \ifmmode\else\endL\fi
            \group_end:
            \Hy@VerboseLinkStop
          }
          {
            \group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
  }
\AtBeginDocument{%
\bidi@undef\hyper@link
\bidi@undef\hyper@linkfile
\bidi@undef\hyper@linkurl
\bidi@undef\hyper@linknamed
\cs_new_protected:Npn \hyper@link #1 #2 #3 %#1 context, #2=destination name, #3 content
  {
    \bool_if:NTF \l__hyp_annot_GoTo_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \Hy@VerboseLinkStart{#1}{#2}
            \group_begin:
            \tl_set:Nn \l_hyp_current_dest_name_tl {#2}
            \socket_use:nnn{hyp/link/GoTo/Contents}{#2}{#3}
            \hook_use:n {hyp/link/#1}
            \ifmmode\else\beginL\fi
            \__hyp_link_goto_begin:nw {#2}\ifmmode\else\if@RTL\beginR\fi\fi#3\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
            \__hyp_link_goto_end:
            \ifmmode\else\endL\fi
            \group_end:
            \Hy@VerboseLinkStop
          }
          {
            \group_begin: #3\group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#3}}
  }
\cs_new_protected:Npn \hyper@linkfile #1 #2 #3 % link text, filename, destname
  {
   \bool_if:NTF \l__hyp_annot_GoToR_bool
     {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \group_begin:
            \tl_set:Ne \l__hyp_filename_tmpa_tl { \text_expand:n { #2 } }
            \exp_args:Ne
              \pdf_object_if_exist:nF { __hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl }
                {
                  \pdfdict_put:nne { l_pdffile/Filespec}{Subtype}{\pdf_name_from_unicode_e:n {application/pdf}}
                  \pdffile_embed_file:noe
                    {}
                    {\l__hyp_filename_tmpa_tl }
                    {__hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl }
                }
            \pdfdict_put:nne
               {l_hyp/annot/A/GoToR}
               {F}
               {\pdf_object_ref:e {__hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl}}
            \__hyp_text_pdfstring:nnN
              { #3 }
              { \l__hyp_text_enc_dest_print_tl }
              \l__hyp_dest_name_tmpa_tl
            \socket_use:nn{hyp/link/GoToR/Contents}{#2}
            \tl_if_blank:eTF {#3}
              {
                \pdfdict_put:nne {l_hyp/annot/A/GoToR}{D}
                  {
                   [
                     \int_eval:n
                      { \int_max:nn {0}{ 0\l__hyp_href_pdf_page_tl - 1 }}
                     /\l__hyp_dest_pdfremotestartview_tl
                   ]
                  }
              }
              {
                \pdfdict_put:nno {l_hyp/annot/A/GoToR}{D}{\l__hyp_dest_name_tmpa_tl}
              }
            \mode_leave_vertical:
            \pdf_object_unnamed_write:ne{dict}{\pdfdict_use:n {l_hyp/annot/A/GoToR}}
            \pdfannot_dict_put:nne {link/GoToR}{A}{\pdf_object_ref_last:}
            \ifmmode\else\beginL\fi
            \pdfannot_link:nnn %expansion??
              { GoToR }
              {
              }
              {
               \let\protect\relax
                \ifmmode\else\if@RTL\beginR\fi\fi#1\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
                \Hy@VerboseLinkStop %where is the start??
              }
            \ifmmode\else\endL\fi
            \group_end:
          }
          {
            \group_begin: #1 \group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
     }
     {{\let\protect\relax#1}}
  }
\cs_new_protected:Npn \hyper@linkurl #1 #2  %#1:link text #2: URI,
  {
    \bool_if:NTF \l__hyp_annot_URI_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
           \group_begin:
            \__hyp_text_pdfstring:eoN
              { #2}
              { \l__hyp_text_enc_uri_print_tl }
              \l__hyp_uri_tmpa_tl
            \pdfdict_put:nno{l_hyp/annot/A/URI}{URI}{\l__hyp_uri_tmpa_tl}
            \bool_if:NT \l__hyp_href_url_ismap_bool
              {
               \pdfdict_put:nnn{l_hyp/annot/A/URI}{IsMap}{true}
              }
            \socket_use:nn{hyp/link/URI/Contents}{#2}
            \cs_set_eq:NN \# \c_hash_str
            \cs_set_eq:NN \% \c_percent_str
            \Hy@safe@activestrue
            \mode_leave_vertical:
            \pdfannot_dict_put:nne {link/URI}{A}{<<\pdfdict_use:n {l_hyp/annot/A/URI}>>}
            \ifmmode\else\beginL\fi
            \pdfannot_link:nen { URI }
              {
              }
              {
                \let\protect\relax
                \ifmmode\else\if@RTL\beginR\fi\fi#1\ifmmode\else\if@RTL\endR\fi\fi
                \Hy@xspace@end
                \Hy@VerboseLinkStop %where is the start??
              }
            \ifmmode\else\endL\fi
            \group_end:
           }
           {
             \group_begin: #1 \group_end:
           }
         \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#1}}
  }
\RenewDocumentCommand \Acrobatmenu { m m }
  {
    \hyper@linknamed {#1} {#2}
  }
\cs_new_protected:Npn \hyper@linknamed #1 #2 %#1 action, #2 link text
  {
    \bool_if:NTF \l__hyp_annot_Named_bool
      {
         \int_gincr:N\g__hyp_linknestlevel_int
         \__hyp_check_link_nesting:TF
          {
            \group_begin:
            \pdfmeta_standard_verify:nnTF {named_actions}{#1}
              {
                \mode_leave_vertical:
                \pdfdict_put:nne {l_hyp/annot/A/Named}{N}
                  {\pdf_name_from_unicode_e:n{#1}}
                \pdfannot_dict_put:nne {link/Named}{A}{<<\pdfdict_use:n {l_hyp/annot/A/Named}>>}
                \ifmmode\else\beginL\fi
                \pdfannot_link:nnn { Named }
                 {
   %                /A
   %                  <<
   %                    \pdfdict_use:n { l_hyp/annot/A/Named }
   %                  >>
                 }
                 {
                   \ifmmode\else\if@RTL\beginR\fi\fi#2\ifmmode\else\if@RTL\endR\fi
                   \Hy@xspace@end
                   \Hy@VerboseLinkStop
                 }
                 \ifmmode\else\endL\fi
              }
              {
                \msg_warning:nnn { hyp } { pdfa-no-named-action }{#1}
                #2
              }
           \group_end:
          }
          { \group_begin: #2 \group_end: }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#2}}
  }
}
\bidi@patchcmd\@TextField{%
  \pdfannot_box:nnnn
}{%
  \if@RTL
    \hskip\Fld@width
  \fi
  \pdfannot_box:nnnn
}{}{}
\bidi@patchcmd\@TextField{%
  \MakeTextField{\Fld@width}{\Fld@height}
}{%
  \if@RTL
    \hskip-\Fld@width
  \fi
  \MakeTextField{\Fld@width}{\Fld@height}
}{}{}
\ExplSyntaxOff
%    \end{macrocode}
% \iffalse
%</hgeneric-testphase-xetex-bidi.def>
%<*hvfloat-xetex-bidi.def>
%\fi
% \section{File \texttt{hvfloat-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{hvfloat-xetex-bidi.def}[2012/04/18 v0.2 bidi adaptations for hvfloat package for XeTeX engine]
\def\do@@hvFloat[#1]#2#3{%
	\def\hv@shortCap{#1}
	\def\hv@longCap{#2}
	\def\hv@label{#3}
%\newcommand*{\hvFloat}[5][]{%
% [#1}: keyvalues
% #2: type  figure | table | ...
% #3: float contents
% [#4]: short caption
% #5: caption
% #6: label
% \setDefaults%
% \def\@tempa{#1}%
% \ifx\@tempa\empty\else\setkeys{hvSet}{#1}\fi% set options, only when not empty
  \def\@tempa{90}%
  \ifx\hvSet@rotAngle\@tempa \setlength{\hvMaxCapWidth}{\textheight}
  \else                      \setlength{\hvMaxCapWidth}{\linewidth}
  \fi
%
% First we save the object in \hvObjectBox
%
  \ifx\hvSet@objectAngle\hv@Zero % rotate the object?
    \savebox{\hvObjectBox}{\ifhv@useOBox\usebox{\hvOBox}\else\hv@floatObject\fi}
  \else
    \savebox{\hvObjectBox}{%
    \rotatebox{\hvSet@objectAngle}{%
    \ifhv@useOBox\usebox{\hvOBox}\else\hv@floatObject\fi}}
  \fi
  \setlength{\hvObjectWidth}{\wd\hvObjectBox}
%
% Now we save the caption with its defined \hvCapWidth
%
  \ifx\hvSet@capWidth\hv@Width\setlength{\hvCapWidth}{\hvObjectWidth}
  \else
    \ifx\hvSet@capWidth\hv@Height\setlength{\hvCapWidth}{\ht\hvObjectBox}
    \else
      \setlength{\hvCapWidth}{\hvObjectWidth}
      \ifx\hvSet@capPos\hv@Left\addtolength{\hvMaxCapWidth}{-\hvObjectWidth}\fi
      \ifx\hvSet@capPos\hv@Right\addtolength{\hvMaxCapWidth}{-\hvObjectWidth}\fi
      \ifdim\hvSet@capWidth\columnwidth<\hvMaxCapWidth
	\setlength{\hvCapWidth}{\hvSet@capWidth\columnwidth}
      \else
	\setlength{\hvCapWidth}{\hvMaxCapWidth}
      \fi
    \fi
  \fi
%
% now we have the object and the caption with the right
% rotated angles saved in boxes
%
  \def\fps@figure{\hvSet@floatPos}
  \ifhv@nonFloat\begingroup%	Start the nonfloat part
  \else         \begin{\hv@floatType}%		Start the floating environment
  \fi%
  \saveCaptionSkip% we put this space ourselve
  \ifx\hvSet@capAngle\hv@Width % need rotation?
    \sbox{\hvCaptionBox}{%
      \begin{minipage}[b]{\hvCapWidth}% minipage, to get hyphenation
        \ifhv@nonFloat%
	  \ifhv@onlyText#2%
  	  \else%
	    \ifx\hv@floatType\hv@figure
	      \ifx\relax#1\relax \figcaption{#2}\else\figcaption[#1]{#2}\fi
	    \else
	      \ifx\relax#1\relax \tabcaption{#2}\else\tabcaption[#1]{#2}\fi%
	    \fi
	  \fi
	\else\ifx\relax\hv@shortCap\relax\caption{#2}\else\caption[#1]{#2}\fi%
	\fi%
	\label{#3}%
      \end{minipage}%
    }%
  \else%
    \sbox{\hvCaptionBox}{%
      \rotatebox{\hvSet@capAngle}{%
      \begin{minipage}[b]{\hvCapWidth}% minipage, to get hyphenation
	\ifhv@nonFloat%
  	  \ifhv@onlyText#2%
  	  \else%
	    \ifx\hv@floatType\hv@figure 
	      \ifx\relax#1\relax \figcaption{#2}\else\figcaption[#1]{#2}\fi
	    \else
	      \ifx\relax#1\relax \tabcaption{#2}\else\tabcaption[#1]{#2}\fi%
	    \fi
	  \fi
	\else\ifx\relax\hv@shortCap\relax\caption{#2}\else\caption[#1]{#2}\fi%
        \fi%
        \label{#3}%
      \end{minipage}%
      }%
    }%
  \fi%
%%
  \restoreCaptionSkip% save old values
  \ifx\hvSet@objectPos\hv@Right\bidi@raggedleft%
  \else%
    \ifx\hvSet@objectPos\hv@Center
      \ifhv@nonFloat\hspace*{\fill}\else\centering\fi%
    \fi%
  \fi%
%
% to rotate object and caption together, we save all in another box
% the caption comes first, if its on the left or the top
%
  \savebox{\@tempboxa}{%
  \ifx\hvSet@capPos\hv@Left  %  caption on left side
\if@RTL%
\ifx\hvSet@capVPos\hv@Center%
							\ifhv@fbox
								\fbox{\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}}
							\else
								\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}
							\fi%
							\hspace{\hvSet@floatCapSep pt}%
							\ifhv@fbox
								\fbox{\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}}%
							\else
								\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}
							\fi%
						\else%
							\ifx\hvSet@capVPos\hv@Top
								\ifhv@fbox
									\fbox{\raisebox{-\height}{\usebox{\hvObjectBox}}}%
								\else
									\raisebox{-\height}{\usebox{\hvObjectBox}}%
								\fi%
								\hspace{\hvSet@floatCapSep pt}%
								\ifhv@fbox
									\fbox{\raisebox{-\height}{\usebox{\hvCaptionBox}}}%
								\else
									\raisebox{-\height}{\usebox{\hvCaptionBox}}%
								\fi
							\else
								\ifhv@fbox
									\fbox{\usebox{\hvObjectBox}}%
								\else
									\usebox{\hvObjectBox}%
								\fi
								\hspace{\hvSet@floatCapSep pt}%
								\ifhv@fbox
									\fbox{\usebox{\hvCaptionBox}}%
								\else
									\usebox{\hvCaptionBox}%
								\fi%
							\fi%
\fi%
\else% not RTL
    \ifx\hvSet@capVPos\hv@Center%
      \ifhv@fbox\fbox{\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}}%
      \else     \parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}%
      \fi%
    \hspace{\hvSet@floatCapSep pt}% capfloatsep
    \ifhv@fbox\fbox{\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}}
    \else     \parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}
    \fi%
  \else%
    \ifx\hvSet@capVPos\hv@Top % caption at top
      \ifhv@fbox\fbox{\raisebox{-\height}{\usebox{\hvCaptionBox}}}%
      \else     \raisebox{-\height}{\usebox{\hvCaptionBox}}%
      \fi
      \hspace{\hvSet@floatCapSep pt}% capfloatsep
      \ifhv@fbox\fbox{\raisebox{-\height}{\usebox{\hvObjectBox}}}%
      \else     \raisebox{-\height}{\usebox{\hvObjectBox}}%
      \fi%
    \else% caption on bottom
      \ifhv@fbox\fbox{\usebox{\hvCaptionBox}}
                \else\usebox{\hvCaptionBox}
      \fi%
      \hspace{\hvSet@floatCapSep pt}%
      \ifhv@fbox\fbox{\usebox{\hvObjectBox}}
      \else     \usebox{\hvObjectBox}
      \fi%
    \fi%
\fi% end of RTL
  \fi%
  \else
				\ifx\hvSet@capPos\hv@Top
					\ifdim\wd\hvCaptionBox>\wd\hvObjectBox
						\begin{minipage}{\wd\hvCaptionBox}
					\else
						\begin{minipage}{\wd\hvObjectBox}
					\fi
					\centering
					\ifhv@fbox
						\fbox{\usebox{\hvCaptionBox}}\\[\hvBelowCaptionSkip]
						\fbox{\usebox{\hvObjectBox}}
					\else
						\usebox{\hvCaptionBox}\\[\hvBelowCaptionSkip]
						\usebox{\hvObjectBox}
					\fi%
					\end{minipage}
				\else
					\ifx\hvSet@capPos\hv@Bottom
						\ifdim\wd\hvCaptionBox>\wd\hvObjectBox
							\begin{minipage}{\wd\hvCaptionBox}
						\else
							\begin{minipage}{\wd\hvObjectBox}
						\fi
						\centering
						\ifhv@fbox
							\fbox{\usebox{\hvObjectBox}}\\[\hvAboveCaptionSkip]
							\fbox{\usebox{\hvCaptionBox}}
						\else
							\usebox{\hvObjectBox}\\[\hvAboveCaptionSkip]
							\usebox{\hvCaptionBox}
						\fi%
						\end{minipage}
					\else% the last option: put the caption on the right
\if@RTL%
    \ifx\hvSet@capVPos\hv@Center%
      \ifhv@fbox\fbox{\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}}%
      \else     \parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}%
      \fi%
    \hspace{\hvSet@floatCapSep pt}% capfloatsep
    \ifhv@fbox\fbox{\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}}
    \else     \parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}
    \fi%
  \else%
    \ifx\hvSet@capVPos\hv@Top % caption at top
      \ifhv@fbox\fbox{\raisebox{-\height}{\usebox{\hvCaptionBox}}}%
      \else     \raisebox{-\height}{\usebox{\hvCaptionBox}}%
      \fi
      \hspace{\hvSet@floatCapSep pt}% capfloatsep
      \ifhv@fbox\fbox{\raisebox{-\height}{\usebox{\hvObjectBox}}}%
      \else     \raisebox{-\height}{\usebox{\hvObjectBox}}%
      \fi%
    \else% caption on bottom
      \ifhv@fbox\fbox{\usebox{\hvCaptionBox}}
                \else\usebox{\hvCaptionBox}
      \fi%
      \hspace{\hvSet@floatCapSep pt}%
      \ifhv@fbox\fbox{\usebox{\hvObjectBox}}
      \else     \usebox{\hvObjectBox}
      \fi%
    \fi%
  \fi%
\else% not RTL
						\ifx\hvSet@capVPos\hv@Center%
							\ifhv@fbox
								\fbox{\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}}
							\else
								\parbox{\wd\hvObjectBox}{\usebox{\hvObjectBox}}
							\fi%
							\hspace{\hvSet@floatCapSep pt}%
							\ifhv@fbox
								\fbox{\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}}%
							\else
								\parbox{\wd\hvCaptionBox}{\usebox{\hvCaptionBox}}
							\fi%
						\else%
							\ifx\hvSet@capVPos\hv@Top
								\ifhv@fbox
									\fbox{\raisebox{-\height}{\usebox{\hvObjectBox}}}%
								\else
									\raisebox{-\height}{\usebox{\hvObjectBox}}%
								\fi%
								\hspace{\hvSet@floatCapSep pt}%
								\ifhv@fbox
									\fbox{\raisebox{-\height}{\usebox{\hvCaptionBox}}}%
								\else
									\raisebox{-\height}{\usebox{\hvCaptionBox}}%
								\fi
							\else
								\ifhv@fbox
									\fbox{\usebox{\hvObjectBox}}%
								\else
									\usebox{\hvObjectBox}%
								\fi
								\hspace{\hvSet@floatCapSep pt}%
								\ifhv@fbox
									\fbox{\usebox{\hvCaptionBox}}%
								\else
									\usebox{\hvCaptionBox}%
								\fi%
							\fi%
						\fi
\fi% end of RTL
					\fi
				\fi
			\fi
		}% End savebox Object and caption
%
% now we rotate the object and caption, if needed
%
		\ifx\hvSet@rotAngle\hv@Zero
			\usebox{\@tempboxa}
		\else
			\rotatebox{\hvSet@rotAngle}{\usebox{\@tempboxa}}
		\fi
	\ifhv@nonFloat
		\ifx\hvSet@objectPos\hv@Center
			\ifhv@nonFloat
				\hspace{\fill}
			\fi
		\fi
		\endgroup%	End the nonfloat part
	\else
		\end{\hv@floatType}%	End the floating environment
	\fi
}
%    \end{macrocode}
% \iffalse
%</hvfloat-xetex-bidi.def>
%<*hyperref-xetex-bidi.def>
%\fi
% \section{File \texttt{hyperref-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{hyperref-xetex-bidi.def}[2025/01/05 v1.4 bidi adaptations for hyperref package for XeTeX engine]
\AtBeginDocument{%
\def\contentsline#1#2#3#4{%
  \ifx\\#4\\%
    \csname l@#1\endcsname{#2}{#3}%
  \else
    \ifcase\Hy@linktoc % none
      \csname l@#1\endcsname{#2}{#3}%
    \or % section
      \csname l@#1\endcsname{%
        \hyper@linkstart{link}{#4}{\if@RTL\beginR\fi#2\if@RTL\endR\fi}\hyper@linkend
      }{#3}%
    \or % page
      \csname l@#1\endcsname{{#2}}{%
        \hyper@linkstart{link}{#4}{#3}\hyper@linkend
      }%
    \else % all
      \csname l@#1\endcsname{%
        \hyper@linkstart{link}{#4}{\if@RTL\beginR\fi#2\if@RTL\endR\fi}\hyper@linkend
      }{%
        \hyper@linkstart{link}{#4}{#3}\hyper@linkend
      }%
    \fi
  \fi
}
\ifHy@hyperfootnotes
   \let\H@@footnotetext\@footnotetext
   \let\HRTL@@RTLfootnotetext\@RTLfootnotetext
   \let\HLTR@@LTRfootnotetext\@LTRfootnotetext
    \def\@xfootnotenext[#1]{%
    \begingroup
      \csname c@\@mpfn\endcsname #1\relax
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
    \ifx\@footnotetext\@mpfootnotetext
      \expandafter\H@@mpfootnotetext
    \else
      \expandafter\H@@footnotetext
    \fi
  }%
    \def\@xRTLfootnotenext[#1]{%
    \begingroup
      \csname c@\@mpfn\endcsname #1\relax
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
    \ifx\@RTLfootnotetext\@mpRTLfootnotetext
      \expandafter\HRTL@@mpRTLfootnotetext
    \else
      \expandafter\HRTL@@RTLfootnotetext
    \fi
  }%
    \def\@xLTRfootnotenext[#1]{%
    \begingroup
      \csname c@\@mpfn\endcsname #1\relax
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
    \ifx\@LTRfootnotetext\@mpLTRfootnotetext
      \expandafter\HLTR@@mpLTRfootnotetext
    \else
      \expandafter\HLTR@@LTRfootnotetext
    \fi
  }%
    \def\@xfootnotemark[#1]{%
    \begingroup
      \c@footnote #1\relax
      \unrestored@protected@xdef\@thefnmark{\thefootnote}%
    \endgroup
    \H@@footnotemark
  }%
  \let\H@@mpfootnotetext\@mpfootnotetext
  \let\HRTL@@mpRTLfootnotetext\@mpRTLfootnotetext
  \let\HLTR@@mpLTRfootnotetext\@mpLTRfootnotetext
    \long\def\@mpfootnotetext#1{%
    \H@@mpfootnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }#1%
      \fi
    }%
  }%
  \long\def\@mpRTLfootnotetext#1{%
    \HRTL@@mpRTLfootnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }#1%
      \fi
    }%
  }%
    \long\def\@mpLTRfootnotetext#1{%
    \HLTR@@mpLTRfootnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }#1%
      \fi
    }%
  }%
    \long\def\@footnotetext#1{%
    \H@@footnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }%
        \let\@currentHlabel\Hy@footnote@currentHlabel
        \let\@currentHref\Hy@footnote@currentHref
        \let\@currentlabelname\@empty
        #1%
      \fi
    }%
  }%
    \long\def\@RTLfootnotetext#1{%
    \HRTL@@RTLfootnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }%
        \let\@currentHlabel\Hy@footnote@currentHlabel
        \let\@currentHref\Hy@footnote@currentHref
        \let\@currentlabelname\@empty
        #1%
      \fi
    }%
  }%
    \long\def\@LTRfootnotetext#1{%
    \HLTR@@LTRfootnotetext{%
      \ifHy@nesting
        \hyper@@anchor{\Hy@footnote@currentHref}{#1}%
      \else
        \Hy@raisedlink{%
          \hyper@@anchor{\Hy@footnote@currentHref}{\relax}%
        }%
        \let\@currentHlabel\Hy@footnote@currentHlabel
        \let\@currentHref\Hy@footnote@currentHref
        \let\@currentlabelname\@empty
        #1%
      \fi
    }%
  }%
    \ApplyPatchCodeToPackage{tabularx}{%
    \let\HyOrg@TX@endtabularx\TX@endtabularx
    \def\Hy@tabularx@hook{%
      \let\@footnotetext\H@@footnotetext
      \let\@LTRfootnotetext\HLTR@@LTRfootnotetext
      \let\@RTLfootnotetext\HRTL@@RTLfootnotetext
      \let\@footnotemark\H@@footnotemark
      \let\@mpfootnotetext\H@@mpfootnotetext
      \let\@mpLTRfootnotetext\HLTR@@mpLTRfootnotetext
      \let\@mpRTLfootnotetext\HRTL@@mpRTLfootnotetext
    }%
    \begingroup
      \toks@\expandafter{\TX@endtabularx}%
      \xdef\Hy@gtemp{%
        \noexpand\Hy@tabularx@hook
        \the\toks@
      }%
    \endgroup
    \let\TX@endtabularx\Hy@gtemp
  }%
    \ApplyPatchCodeToPackage{longtable}{%
    \CheckCommand{\LT@p@LTRftntext}[1]{%
      \edef\@tempa{%
        \the\LT@p@ftn
        \noexpand\LTRfootnotetext[\the\c@footnote]%
      }%
      \global\LT@p@ftn\expandafter{\@tempa{#1}}%
    }%
    \long\def\LT@p@LTRftntext#1{%
      \edef\@tempa{%
        \the\LT@p@ftn
        \begingroup
          \noexpand\c@footnote=\the\c@footnote\relax
          \noexpand\protected@xdef\noexpand\@thefnmark{%
            \noexpand\thempfn
          }%
          \noexpand\Hy@LT@LTRfootnotetext{%
            \Hy@footnote@currentHref
          }%
      }%
      \global\LT@p@ftn\expandafter{%
          \@tempa{#1}%
        \endgroup
      }%
    }%
    \long\def\Hy@LT@LTRfootnotetext#1#2{%
     \HLTR@@LTRfootnotetext{%
        \ifHy@nesting
          \hyper@@anchor{#1}{#2}%
        \else
          \Hy@raisedlink{%
            \hyper@@anchor{#1}{\relax}%
          }%
          \def\@currentHref{#1}%
          \let\@currentlabelname\@empty
          #2%
        \fi
      }%
    }%
    \CheckCommand{\LT@p@RTLftntext}[1]{%
      \edef\@tempa{%
        \the\LT@p@ftn
        \noexpand\RTLfootnotetext[\the\c@footnote]%
      }%
      \global\LT@p@ftn\expandafter{\@tempa{#1}}%
    }%
    \long\def\LT@p@RTLftntext#1{%
      \edef\@tempa{%
        \the\LT@p@ftn
        \begingroup
          \noexpand\c@footnote=\the\c@footnote\relax
          \noexpand\protected@xdef\noexpand\@thefnmark{%
            \noexpand\thempfn
          }%
          \noexpand\Hy@LT@RTLfootnotetext{%
            \Hy@footnote@currentHref
          }%
      }%
      \global\LT@p@ftn\expandafter{%
          \@tempa{#1}%
        \endgroup
      }%
    }%
    \long\def\Hy@LT@RTLfootnotetext#1#2{%
     \HRTL@@RTLfootnotetext{%
        \ifHy@nesting
          \hyper@@anchor{#1}{#2}%
        \else
          \Hy@raisedlink{%
            \hyper@@anchor{#1}{\relax}%
          }%
          \def\@currentHref{#1}%
          \let\@currentlabelname\@empty
          #2%
        \fi
      }%
    }%
  }%
    \ApplyPatchCodeToPackage{bidipoem}{%
    \long\def\bidipoem@p@ftntext#1{%
      \edef\@tempx{%
        \the\bidipoem@p@ftn
        \begingroup
          \noexpand\csname c@\@mpfn\endcsname=\the\csname c@\@mpfn\endcsname\relax
          \noexpand\protected@xdef\noexpand\@thefnmark{%
            \noexpand\thempfn
          }%
          \noexpand\Hy@bidipoem@footnotetext{%
            \Hy@footnote@currentHref
          }%
      }%
      \global\bidipoem@p@ftn\expandafter{%
          \@tempx{#1}%
        \endgroup
      }%
    }%
    \long\def\Hy@bidipoem@footnotetext#1#2{%
      \H@@footnotetext{%
        \ifHy@nesting
          \hyper@@anchor{#1}{#2}%
        \else
          \Hy@raisedlink{%
            \hyper@@anchor{#1}{\relax}%
          }%
          \def\@currentHref{#1}%
          \let\@currentlabelname\@empty
          #2%
        \fi
      }%
    }%
        \long\def\bidipoem@p@LTRftntext#1{%
      \edef\@tempxi{%
        \the\bidipoem@p@ftn
        \begingroup
          \noexpand\csname c@\@mpfn\endcsname=\the\csname c@\@mpfn\endcsname\relax
          \noexpand\protected@xdef\noexpand\@thefnmark{%
            \noexpand\thempfn
          }%
          \noexpand\Hy@bidipoem@LTRfootnotetext{%
            \Hy@footnote@currentHref
          }%
      }%
      \global\bidipoem@p@ftn\expandafter{%
          \@tempxi{#1}%
        \endgroup
      }%
    }%
    \long\def\Hy@bidipoem@LTRfootnotetext#1#2{%
      \HLTR@@LTRfootnotetext{%
        \ifHy@nesting
          \hyper@@anchor{#1}{#2}%
        \else
          \Hy@raisedlink{%
            \hyper@@anchor{#1}{\relax}%
          }%
          \def\@currentHref{#1}%
          \let\@currentlabelname\@empty
          #2%
        \fi
      }%
    }%
        \long\def\bidipoem@p@RTLftntext#1{%
      \edef\@tempxii{%
        \the\bidipoem@p@ftn
        \begingroup
          \noexpand\csname c@\@mpfn\endcsname=\the\csname c@\@mpfn\endcsname\relax
          \noexpand\protected@xdef\noexpand\@thefnmark{%
            \noexpand\thempfn
          }%
          \noexpand\Hy@bidipoem@RTLfootnotetext{%
            \Hy@footnote@currentHref
          }%
      }%
      \global\bidipoem@p@ftn\expandafter{%
          \@tempxii{#1}%
        \endgroup
      }%
    }%
    \long\def\Hy@bidipoem@RTLfootnotetext#1#2{%
      \HRTL@@RTLfootnotetext{%
        \ifHy@nesting
          \hyper@@anchor{#1}{#2}%
        \else
          \Hy@raisedlink{%
            \hyper@@anchor{#1}{\relax}%
          }%
          \def\@currentHref{#1}%
          \let\@currentlabelname\@empty
          #2%
        \fi
      }%
    }%
  }%
  \let\HyOrg@maketitle\maketitle
  \def\maketitle{%
    \let\Hy@saved@footnotemark\@footnotemark
    \let\Hy@saved@footnotetext\@footnotetext
    \let\HyRTL@saved@RTLfootnotetext\@RTLfootnotetext
    \let\HyLTR@saved@LTRfootnotetext\@LTRfootnotetext
    \let\@footnotemark\H@@footnotemark
    \let\@footnotetext\H@@footnotetext
    \let\@RTLfootnotetext\HRTL@@RTLfootnotetext
    \let\@LTRfootnotetext\HLTR@@LTRfootnotetext
    \@ifnextchar[\Hy@maketitle@optarg{% ]
      \HyOrg@maketitle
      \Hy@maketitle@end
    }%
  }%
  \def\Hy@maketitle@optarg[#1]{%
    \HyOrg@maketitle[{#1}]%
    \Hy@maketitle@end
  }%
  \def\Hy@maketitle@end{%
    \ifx\@footnotemark\H@@footnotemark
      \let\@footnotemark\Hy@saved@footnotemark
    \fi
    \ifx\@footnotetext\H@@footnotetext
      \let\@footnotetext\Hy@saved@footnotetext
    \fi
    \ifx\@RTLfootnotetext\HRTL@@RTLfootnotetext
      \let\@RTLfootnotetext\HyRTL@saved@RTLfootnotetext
    \fi
    \ifx\@LTRfootnotetext\HLTR@@LTRfootnotetext
      \let\@LTRfootnotetext\HyLTR@saved@LTRfootnotetext
    \fi
  }%
  \def\realfootnote{%
    \@ifnextchar[\@xfootnote{%
      \stepcounter{\@mpfn}%
      \protected@xdef\@thefnmark{\thempfn}%
      \H@@footnotemark\H@@footnotetext
    }%
  }%
\fi
\def\Hy@BeginAnnot#1{%
  \ifmmode\else\beginL\fi%
  \global\advance\c@Hy@AnnotLevel\@ne
  \ifnum\c@Hy@AnnotLevel=\@ne
    #1%
  \fi
}
\def\Hy@EndAnnot{%
  \ifnum\c@Hy@AnnotLevel=\@ne
    \Hy@endcolorlink
    \@pdfm@mark{eann}%
  \fi
  \global\advance\c@Hy@AnnotLevel\m@ne
  \ifmmode\else\endL\fi%
}
\def\hyper@link#1#2#3{%
  \hyper@linkstart{#1}{#2}\ifmmode\else\if@RTL\beginR\fi\fi#3\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end\hyper@linkend
}
\def\hyper@linkfile#1#2#3{%
  \leavevmode
  \Hy@BeginAnnot{%
    \def\Hy@pstringF{#2}%
    \Hy@CleanupFile\Hy@pstringF
    \Hy@pstringdef\Hy@pstringF\Hy@pstringF
    \Hy@pstringdef\Hy@pstringD{#3}%
    \Hy@MakeRemoteAction
    \@pdfm@mark{%
      bann<<%
        /Type/Annot%
        /Subtype/Link%
        \ifHy@pdfa /F 4\fi
        \Hy@setpdfborder
        \ifx\@filebordercolor\relax
        \else
          /C[\@filebordercolor]%
        \fi
        /A<<%
          /S/GoToR%
          /F(\Hy@pstringF)%
          /D%
          \ifx\\#3\\%
            [\Hy@href@page\@pdfremotestartview]%
          \else
            (\Hy@pstringD)%
          \fi
          \Hy@SetNewWindow
          \Hy@href@nextactionraw
        >>%
      >>%
    }%
    \Hy@colorlink\@filecolor
  }%
  \ifmmode\else\if@RTL\beginR\fi\fi#1\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
  \Hy@EndAnnot
}
\def\@hyper@launch run:#1\\#2#3{% filename, anchor text linkname
  \leavevmode
  \Hy@BeginAnnot{%
    \Hy@pstringdef\Hy@pstringF{#1}%
    \Hy@pstringdef\Hy@pstringP{#3}%
    \@pdfm@mark{%
      bann<<%
        /Type/Annot%
        /Subtype/Link%
        \ifHy@pdfa /F 4\fi
        \Hy@setpdfborder
        \ifx\@runbordercolor\relax
        \else
          /C[\@runbordercolor]%
        \fi
        /A<<%
          /F(\Hy@pstringF)%
          /S/Launch%
          \Hy@SetNewWindow
          \ifx\\#3\\%
          \else
            /Win<</P(\Hy@pstringP)/F(\Hy@pstringF)>>%
          \fi
          \Hy@href@nextactionraw
        >>%
      >>%
    }%
    \Hy@colorlink\@runcolor
  }%
  \ifmmode\else\if@RTL\beginR\fi\fi#2\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
  \Hy@EndAnnot
}
\def\hyper@linkurl#1#2{%
  \leavevmode
  \Hy@BeginAnnot{%
    \Hy@pstringdef\Hy@pstringURI{#2}%
    \@pdfm@mark{%
      bann<<%
        /Type/Annot%
        /Subtype/Link%
        \ifHy@pdfa /F 4\fi
        \Hy@setpdfborder
        \ifx\@urlbordercolor\relax
        \else
          /C[\@urlbordercolor]%
        \fi
        /A<<%
          /S/URI%
          /URI(\Hy@pstringURI)%
          \ifHy@href@ismap
            /IsMap true%
          \fi
          \Hy@href@nextactionraw
        >>%
      >>%
    }%
    \Hy@colorlink\@urlcolor
  }%
  \ifmmode\else\if@RTL\beginR\fi\fi#1\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
  \Hy@EndAnnot
}
\def\Acrobatmenu#1#2{%
  \Hy@Acrobatmenu{#1}{#2}{%
    \Hy@BeginAnnot{%
      \EdefEscapeName\Hy@temp@menu{#1}%
      \@pdfm@mark{%
        bann<<%
          /Type/Annot%
          /Subtype/Link%
          \ifHy@pdfa /F 4\fi
          \Hy@setpdfborder
          \ifx\@menubordercolor\relax
          \else
            /C[\@menubordercolor]%
          \fi
          /A<<%
            /S/Named%
            /N/\Hy@temp@menu
            \Hy@href@nextactionraw
          >>%
        >>%
      }%
      \Hy@colorlink\@menucolor
    }%
    \ifmmode\else\if@RTL\beginR\fi\fi#2\ifmmode\else\if@RTL\endR\fi\fi\Hy@xspace@end
    \Hy@EndAnnot
  }%
}
\def\hyper@natlinkstart#1{%
  \Hy@backout{#1}%
  \hyper@linkstart{cite}{cite.#1}\if@RTL\beginR\fi%
  \def\hyper@nat@current{#1}%
}
\def\hyper@natlinkend{%
  \if@RTL\endR\fi\hyper@linkend
}
\def\hyper@natlinkbreak#1#2{%
  \if@RTL\endR\fi\hyper@linkend#1\hyper@linkstart{cite}{cite.#2}\if@RTL\beginR\fi%
}%
}
\pdfstringdefDisableCommands{%
\let\LRE\@firstofone
\let\LR\@firstofone
\let\RLE\@firstofone
\let\RL\@firstofone
\def\XeTeX{Xe\TeX}%
\def\XeLaTeX{Xe\LaTeX}%
}
\bidi@patchcmd\@TextField{%
  \@pdfm@mark
}{%
  \if@RTL
    \hskip\Fld@width
  \fi
  \@pdfm@mark
}{}{}
\bidi@patchcmd\@TextField{%
  \unhbox
}{%
  \if@RTL
    \hskip-\Fld@width
  \fi
  \unhbox
}{}{}
\bidi@patchcmd\@@Radio{%
  \@pdfm@mark
}{%
  \if@RTL
    \hskip\Fld@width
  \fi
  \@pdfm@mark
}{}{}
\bidi@patchcmd\@@Radio{%
  \unhcopy
}{%
  \if@RTL
    \hskip-\Fld@width
  \fi
  \unhcopy
}{}{}
\bidi@patchcmd\@Submit{%
  \@pdfm@mark
}{%
  \if@RTL
    \null
    \hskip\wd\pdfm@box
  \fi
  \@pdfm@mark
}{}{}
\bidi@patchcmd\@Submit{%
  \unhbox
}{%
  \if@RTL
    \hskip-\wd\pdfm@box
  \fi
  \unhbox
}{}{}
\bidi@patchcmd\@Reset{%
  \@pdfm@mark
}{%
  \if@RTL
    \null
    \hskip\wd\pdfm@box
  \fi
  \@pdfm@mark
}{}{}
\bidi@patchcmd\@Reset{%
  \unhbox
}{%
  \if@RTL
    \hskip-\wd\pdfm@box
  \fi
  \unhbox
}{}{}
%    \end{macrocode}
% \iffalse
%</hyperref-xetex-bidi.def>
%<*imsproc-xetex-bidi.def>
%\fi
% \section{File \texttt{imsproc-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{imsproc-xetex-bidi.def}[2025/09/30 v0.2 bidi adaptations for imsproc class for XeTeX engine]
\newenvironment{thebibliography}[1]{%
  \@bibtitlestyle
  \normalfont\bibliofont\labelsep .5em\relax
  \renewcommand\theenumiv{\arabic{enumiv}}\let\p@enumiv\@empty
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook
  \list{\@biblabel{\theenumiv}}{\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth \advance\leftmargin\labelsep
    \usecounter{enumiv}}%
  \sloppy \clubpenalty\@M \widowpenalty\clubpenalty
  \sfcode`\.=\@m
}{%
  \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
  \endlist
}

\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
  \columnseprule\z@ \columnsep 35\p@
  \@indextitlestyle
  \thispagestyle{plain}%
  \let\item\@idxitem
  \parindent\z@  \parskip\z@\@plus.3\p@\relax
  \if@RTL\raggedleft\else\raggedright\fi
  \hyphenpenalty\@M
  \footnotesize}
\def\@idxitem{\par\hangindent \if@RTL-\fi2em}
\def\subitem{\par\hangindent \if@RTL-\fi2em\hspace*{1em}}
\def\subsubitem{\par\hangindent \if@RTL-\fi3em\hspace*{2em}}

\def\right@footnoterule{%
  \kern-.4\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-5pc\relax \hrulefill }
  \kern11\p@\kern-\footnotesep} 
\def\left@footnoterule{\kern-.4\p@
        \hrule\@width 5pc\kern11\p@\kern-\footnotesep}
\def\@makefnmark{%
  \leavevmode
  \raise.9ex\hbox{\fontsize\sf@size\z@\normalfont\@thefnmark}%
}

\def\part{\@startsection{part}{0}%
  \z@{\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\bfseries\if@RTL\raggedleft\else\raggedright\fi}}
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \if@RTL\rightskip\else\leftskip\fi#3\relax \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima\relax
    \if@RTL\leftskip\else\rightskip\fi\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima #6\nobreak\relax
    \hfil\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
\renewcommand\thesubsection    {\thesection\@SepMark\arabic{subsection}}
\renewcommand\thesubsubsection {\thesubsection \@SepMark\arabic{subsubsection}}
\renewcommand\theparagraph     {\thesubsubsection\@SepMark\arabic{paragraph}}
\renewcommand\thesubparagraph  {\theparagraph\@SepMark\arabic{subparagraph}}
\def\maketitle{\par
  \@topnum\z@ % this prevents figures from falling at the top of page 1
  \@setcopyright
  \thispagestyle{firstpage}% this sets first page specifications
  \uppercasenonmath\shorttitle
  \ifx\@empty\shortauthors \let\shortauthors\shorttitle
  \else \andify\shortauthors
  \fi
  \@maketitle@hook
  \begingroup
  \@maketitle
  \toks@\@xp{\shortauthors}\@temptokena\@xp{\shorttitle}%
  \toks4{\def\\{ \ignorespaces}}% defend against questionable usage
  \edef\@tempa{%
    \@nx\markboth{\the\toks4
      \@nx\MakeUppercase{\the\toks@}}{\the\@temptokena}}%
  \@tempa
  \endgroup
  \c@footnote\z@
  \@cleartopmattertags
}
%    \end{macrocode}
% \iffalse
%</imsproc-xetex-bidi.def>
%<*leqno-xetex-bidi.def>
%\fi
% \section{File \texttt{leqno-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{leqno-xetex-bidi.def}[2018/01/07 v0.2 bidi adaptations for leqno tag for XeTeX engine]
\renewcommand\@eqnnum{\hb@xt@.01\p@{}%
                      \rlap{\hskip -\displaywidth
                        {\normalfont\normalcolor\if@RTL\beginR\fi(\theequation)\if@RTL\endR\fi}}}
%    \end{macrocode}
% \iffalse
%</leqno-xetex-bidi.def>
%<*letter-xetex-bidi.def>
%\fi
% \section{File \texttt{letter-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{letter-xetex-bidi.def}[2025/09/30 v0.4 bidi adaptations for standard letter class for XeTeX engine]
\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\if@RTL\raggedright\else\raggedleft\fi\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\if@RTL\raggedright\else\raggedleft\fi\if@RTL\begin{tabular}{r@{}}\else\begin{tabular}{l@{}}\fi\ignorespaces
      \fromaddress \\*[2\parskip]%
      \@date \end{tabular}\par}%
  \fi
  \vspace{2\parskip}%
  {\if@RTL\raggedleft\else\raggedright\fi \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\renewcommand\left@footnoterule{%
  \kern-\p@
  \hrule \@width .4\columnwidth
  \kern .6\p@}
\renewcommand\right@footnoterule{%
  \kern-\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern .6\p@}
%    \end{macrocode}
% \iffalse
%</letter-xetex-bidi.def>
%<*lettrine-xetex-bidi.def>
%\fi
% \section{File \texttt{lettrine-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{lettrine-xetex-bidi.def}[2024/12/08 v0.9 bidi adaptations for lettrine package for XeTeX engine]
\RemoveFromHook{begindocument}[lettrine]
\AtBeginDocument[lettrine]{%
  \if\DefaultOptionsFile\relax
  \else
    \InputIfFileExists{\DefaultOptionsFile}%
      {}%
      {\PackageWarning{lettrine.sty}%
         {File \DefaultOptionsFile\space not found}%
      }%
  \fi
  \let\ifL@RTL\if@RTL
}
%    \end{macrocode}
% \iffalse
%</lettrine-xetex-bidi.def>
%<*lineno-xetex-bidi.def>
%\fi
% \section{File \texttt{lineno-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{lineno-xetex-bidi.def}[2024/12/07 v0.3 bidi adaptations for lineno package for XeTeX engine]
\bidi@patchcmd{\MakeLineNo}{%
  \hb@xt@\z@{\makeLineNumber}%
}{%
  \hboxL to \z@{\makeLineNumber}%
}{}{}

\bidi@patchcmd{\makeLineNumberLeft}{\LineNumber}{%
  \if@RTL
    \hb@xt@\linenumberwidth{\LineNumber\hss}%
  \else
    \LineNumber
  \fi
}{}{}

\bidi@patchcmd{\makeLineNumberRight}{%
  \hb@xt@\linenumberwidth{\hss\LineNumber}%
}{%
  \if@RTL
    \LineNumber
  \else
    \hb@xt@\linenumberwidth{\hss\LineNumber}%
  \fi
}{}{}

\bidi@AfterPreamble{%
  \if@RTLmain
    \rightlinenumbers*
  \else
    \leftlinenumbers*
  \fi
  \@ifpackagewith{lineno}{left}{%
    \leftlinenumbers*
  }{}
  \@ifpackagewith{lineno}{right}{%
    \rightlinenumbers*
  }{}
  \@ifpackagewith{lineno}{switch}{%
    \if@RTLmain
      \switchlinenumbers*%
    \else
      \switchlinenumbers
    \fi
  }{}
  \@ifpackagewith{lineno}{switch*}{%
    \if@RTLmain
      \switchlinenumbers
    \else
      \switchlinenumbers*%
    \fi
  }{}
}

%    \end{macrocode}
% \iffalse
%</lineno-xetex-bidi.def>
%<*listings-xetex-bidi.def>
%\fi
% \section{File \texttt{listings-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{listings-xetex-bidi.def}[2025/01/03 v1.6 bidi adaptations for listings package for XeTeX engine]
\lst@Key{captiondirection}{textdirection}{%
    \lstKV@SwitchCases{#1}%
    {textdirection:\\%
     RTL:\chardef\bidi@lst@caption@direction\@ne\\%
     LTR:\chardef\bidi@lst@caption@direction\z@%
    }{\PackageError{Listings}{direction #1 unknown}\@ehc}}
    
\lst@Key{captionscript}{textscript}{%
    \lstKV@SwitchCases{#1}%
    {textscript:\\%
     latin:\chardef\bidi@lst@caption@script\@ne\\%
     nonlatin:\chardef\bidi@lst@caption@script\z@%
    }{\PackageError{Listings}{direction #1 unknown}\@ehc}}
    
\newcommand*{\bidi@lst@ensure@caption@direction}[2]{%
   \@ifundefined{bidi@lst@caption@direction}{}{%
    \ifnum\bidi@lst@caption@direction=\z@%
        #1%
    \else%
         \ifnum\bidi@lst@caption@direction=\@ne%
             #2%
         \fi%
     \fi%
}}

\newcommand*{\bidi@lst@ensure@caption@script}[2]{%
   \@ifundefined{bidi@lst@caption@script}{}{%
    \ifnum\bidi@lst@caption@script=\z@%
        #1%
    \else%
         \ifnum\bidi@lst@caption@script=\@ne%
             #2%
         \fi%
     \fi%
}}

\long\def\@bidi@lst@makecaption#1#2{%
   \bidi@lst@ensure@caption@script{\@nonlatintrue}{\@nonlatinfalse}%
   \vskip\abovecaptionskip
   \bidi@lst@ensure@caption@direction{\@RTLfalse}{\@RTLtrue}%
   \sbox\@tempboxa{%
   \bidi@lst@ensure@caption@direction{\beginL}{\beginR}%
   #1: #2%
   \bidi@lst@ensure@caption@direction{\endL}{\endR}%
   }%
   \ifdim \wd\@tempboxa >\hsize
     #1: #2\par
   \else
     \global \@minipagefalse
     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
   \fi
   \vskip\belowcaptionskip}%
\def\lst@makecaption{\@bidi@lst@makecaption}
\def\lst@maketitle{\@bidi@lst@makecaption\lst@title@dropdelim}
\bidi@AtEndPreamble{%
\bidi@patchcmd{\lst@MakeCaption}{%
    \ifx #1t%
        \ifx\lst@@caption\@empty\expandafter\lst@HRefStepCounter \else
                                \expandafter\refstepcounter
        \fi {lstlisting}%
}{%
    \ifx #1t%
       \bidi@lst@ensure@caption@direction{\@RTLfalse}{\@RTLtrue}%
        \ifx\lst@@caption\@empty\expandafter\lst@HRefStepCounter \else
                                \expandafter\refstepcounter
        \fi {lstlisting}%
        \bidi@lst@ensure@caption@direction{\@RTLfalse}{\@RTLfalse}%
}{}{}%
\bidi@patchcmd{\lst@MakeCaption}{%
                \addcontentsline{lol}{lstlisting}%
                    {\protect\numberline{\thelstlisting}\lst@@caption}%
}{%
\begingroup%
               \bidi@lst@ensure@caption@direction{\@RTLfalse}{\@RTLtrue}%
                \addcontentsline{lol}{lstlisting}%
                    {\protect\numberline{\thelstlisting}\lst@@caption}%
\endgroup%
}{}{}%
}
\ApplyPatchIfPackageLoaded{caption}{%
  \AtBeginCaption{%
  \bidi@lst@ensure@caption@script{\@nonlatintrue}{\@nonlatinfalse}%
  \bidi@lst@ensure@caption@direction{\@RTLfalse}{\@RTLtrue}%
}
  \let\@bidi@lst@makecaption\caption@makecaption%
  \def\lst@makecaption{\caption@starfalse\@bidi@lst@makecaption}%
  \def\lst@maketitle{\caption@startrue\@bidi@lst@makecaption\@empty}%
}{%
\AtBeginDocument{%
\@ifundefined{captionlabelfalse}{}{%
  \def\lst@maketitle{\captionlabelfalse\@bidi@lst@makecaption\@empty}}%
\@ifundefined{caption@startrue}{}{%
  \def\lst@maketitle{\caption@startrue\@bidi@lst@makecaption\@empty}}%
}%
}
\AtBeginDocument{
  \@ifundefined{thechapter}{\let\lst@ifnumberbychapter\iffalse}{}
  \lst@ifnumberbychapter
      \gdef\thelstlisting%
           {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@lstlisting}
  \else
      \gdef\thelstlisting{\@arabic\c@lstlisting}
  \fi}
%    \end{macrocode}
% \iffalse
%</listings-xetex-bidi.def>
%<*longtable-xetex-bidi.def>
%\fi
% \section{File \texttt{longtable-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{longtable-xetex-bidi.def}[2025/01/05 v0.8 bidi adaptations for longtable package for XeTeX engine]
\ExplSyntaxOn
\def\LT@array[#1]#2{%
  \UseTaggingSocket{tbl/init}
  \tl_if_empty:eTF { \LTcaptype }
    {
      \tl_gset:Ne \@currentHref {LT@tables.\theHLT@tables}
    }
    {
      \@kernel@refstepcounter{\LTcaptype}\stepcounter{LT@tables}
      \tl_gset:Ne \@currentHref {\LTcaptype.\cs_if_exist_use:c {theH\LTcaptype}}
    }
  \tbl_gzero_row_count:
  \UseTaggingSocket{tbl/longtable/init}
  \if l#1%
    \if@RTLtab\LTleft\fill \LTright\z@\else\LTleft\z@ \LTright\fill\fi
  \else\if r#1%
    \if@RTLtab\LTleft\z@ \LTright\fill\else\LTleft\fill \LTright\z@\fi
  \else\if c#1%
    \LTleft\fill \LTright\fill
  \fi\fi\fi
  \let\LT@mcol\multicolumn
  \let\LT@@tabarray\@tabarray
  \let\LT@@hl\hline
  \def\@tabarray{%
    \let\hline\LT@@hl
    \LT@@tabarray}%
  \let\\\LT@tabularcr
  \let\tabularnewline\\%
  \def\newpage{\noalign{\break}}%
  \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
  \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
  \let\hline\LT@hline \let\kill\LT@kill\let\caption\LT@caption
  \@tempdima\ht\strutbox
  \let\@endpbox\LT@endpbox
  \ifx\extrarowheight\@undefined
    \let\@acol\@tabacol
    \let\@classz\@tabclassz \let\@classiv\@tabclassiv
    \def\@startpbox{\vtop\LT@startpbox}%
    \let\@@startpbox\@startpbox
    \let\@@endpbox\@endpbox
    \let\LT@LL@FM@cr\@tabularcr
  \else
    \advance\@tempdima\extrarowheight
    \col@sep\tabcolsep
    \let\@startpbox\LT@startpbox\let\LT@LL@FM@cr\@arraycr
  \fi
  \setbox\@arstrutbox\hbox{\vrule
    \@height \arraystretch \@tempdima
    \@depth \arraystretch \dp \strutbox
    \@width \z@}%
  \let\@sharp##\let\protect\relax
   \begingroup
    \@mkpream{#2}%
    \tbl_count_table_cols:
    \xdef\LT@bchunk{%
      \tbl_inbetween_rows:
       \global\advance\c@LT@chunks\@ne
       \global\LT@rows\z@\setbox\z@\vbox\bgroup
       \LT@setprevdepth
       \tabskip\LTleft \noexpand\halign to\hsize\bgroup
       \tabskip\z@ \@arstrut
       \UseTaggingSocket{tbl/row/begin}%
       \tbl_init_cell_data_for_row:
       \@preamble \tabskip\LTright \cr}%
  \endgroup
  \expandafter\LT@nofcols\LT@bchunk&\LT@nofcols
  \LT@make@row
  \m@th\let\par\@empty
  \everycr{%
    \noalign{%
      \__tbl_trace:n {--longtable-->~chunk~row:~ \the\LT@rows \space
                   row:~ \the\g__tbl_row_int   \space
                   column:~ \the\g__tbl_col_int
      }
      \tbl_if_row_was_started:T
          {
            \UseTaggingSocket{tbl/row/end}
            \tbl_inbetween_rows:
          }
      \int_compare:nNnT \LT@rows < \LTchunksize
         { \tbl_gincr_row_count: }   % next is row about to start
    }%
  }%
  \lineskip\z@\baselineskip\z@
  \LT@bchunk}
\ExplSyntaxOff
\def\LT@makecaption#1#2#3{%
  \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
    \reset@font
    \sbox\@tempboxa{\if@RTL\beginR\fi#1{#2: }#3\if@RTL\endR\fi}%
    \ifdim\wd\@tempboxa>\hsize
      #1{#2: }#3%
    \else
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
    \endgraf\vskip\baselineskip}%
  \hss}}}
\ApplyPatchCodeToPackage{caption}{%
  \renewcommand\LT@makecaption[3]{%
    \caption@LT@make{%
      \caption@LT@settype\LTcaptype
      \caption@LT@setup
      \caption@setautoposition{\ifcase\LT@rows t\else b\fi}%
      \caption@startrue#1\caption@starfalse
      \caption@prepare@stepcounter\LTcaptype
      \caption@begin\LTcaptype
        \caption@normalsize
        \vskip-\ht\strutbox
        \caption@ifdefined\FBifcaptop{%
          \let\caption@belowskip\@empty}{}%
        \caption@make@above
        \caption@@make{#2}{#3}\endgraf
        \caption@make@below
      \caption@end}}%
}
\def\LT@startpbox#1{%
  \bgroup
    \color@begingroup
    \let\@footnotetext\LT@p@ftntext
    \let\@LTRfootnotetext\LT@p@LTRftntext
    \let\@RTLfootnotetext\LT@p@RTLftntext
    \setlength\hsize{#1}%
    \@arrayparboxrestore
    \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
    }
\long\def\LT@p@LTRftntext#1{%
  \edef\@tempa{\the\LT@p@ftn\noexpand\LTRfootnotetext[\the\c@footnote]}%
  \global\LT@p@ftn\expandafter{\@tempa{#1}}}%
\long\def\LT@p@RTLftntext#1{%
  \edef\@tempa{\the\LT@p@ftn\noexpand\RTLfootnotetext[\the\c@footnote]}%
  \global\LT@p@ftn\expandafter{\@tempa{#1}}}%
\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@\ht\LT@foot
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
          \@makecol
          \@outputpage
          \global\vsize\@colroom
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
        \if@RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi
          \unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi
          \UseTaggingSocket{tbl/longtable/foot}
        \if@RTLtab\egroup\endR\egroup\fi
    \fi
  \else
    \setbox\@cclv\vbox{%
      \if@RTLtab\hbox\bgroup\beginR\vbox\bgroup\fi
        \unvbox\@cclv\copy\LT@foot\vss
      \if@RTLtab\egroup\endR\egroup\fi
    }%
    \UseTaggingSocket{tbl/longtable/foot}
    \@makecol
    \@outputpage
      \global\vsize\@colroom
    \copy\LT@head\nobreak
  \fi}
%    \end{macrocode}
% \iffalse
%</longtable-xetex-bidi.def>
%<*lscape-xetex-bidi.def>
%\fi
% \section{File \texttt{lscape-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{lscape-xetex-bidi.def}[2025/01/03 v0.3 bidi adaptations for lscape package for XeTeX engine]
\RequirePackage{graphicx}
\bidi@patchcmd{\LS@rot}{\rotatebox{90}{\box\@outputbox}}{%
  \if@RTL
    \rotatebox[origin=br]{-90}{\box\@outputbox}%
  \else
    \rotatebox{90}{\box\@outputbox}%
  \fi
}{}{}

\g@addto@macro{\landscape}{%
  \if@bidi@csdef{bidi@columnwidth}{%
    \bidi@columnwidth\columnwidth
  }{}%
  \let\bidi@left@footnoterule\left@footnoterule
  \let\bidi@right@footnoterule\right@footnoterule
  \def\left@footnoterule{%
    \if@RTL
      \bidi@right@footnoterule
    \else
      \bidi@left@footnoterule
    \fi
  }%
  \def\right@footnoterule{%
    \if@RTL
      \bidi@left@footnoterule
    \else
      \bidi@right@footnoterule
    \fi
  }%
}
%    \end{macrocode}
% \iffalse
%</lscape-xetex-bidi.def>
%<*mathtools-xetex-bidi.def>
%\fi
% \section{File \texttt{mathtools-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{mathtools-xetex-bidi.def}[2025/01/03 v0.2 bidi adaptations for mathtools package for XeTeX engine]
\RequirePackage{graphicx}
\MHInternalSyntaxOn
\def\MT_define_tagform:nwnn #1[#2]#3#4{
  \@namedef{MT_tagform_#1:n}##1
    {\maketag@@@{\if@nonlatin\beginR\fi#3\kern\z@\ignorespaces#2{##1}\unskip\@@italiccorr#4\if@nonlatin\endR\fi}}
}
\renewtagform{default}{(}{)}
\MHInternalSyntaxOff
%    \end{macrocode}
% \iffalse
%</mathtools-xetex-bidi.def>
%<*mdframed-xetex-bidi.def>
%\fi
% \section{File \texttt{mdframed-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{mdframed-xetex-bidi.def}[2013/09/22 v0.4 bidi adaptations for mdframed package for XeTeX engine]
\newif\if@bidi@mdf@RTL
\def\mdf@lrbox#1{%
  \mdf@patchamsthm%patch amsthm
   \if@RTL\@bidi@mdf@RTLtrue\fi%
   \@RTLfalse%
 \setbox#1\vbox\bgroup%
   \color@begingroup%
    \if@bidi@mdf@RTL\@RTLtrue\fi%
     \mdf@horizontalmargin@equation%
     \columnwidth=\hsize%
     \textwidth=\hsize%
     \let\if@nobreak\iffalse%
     \let\if@noskipsec\iffalse%
     \let\par\@@par%
     \let\-\@dischyph%
     \let\'\@acci\let\`\@accii\let\=\@acciii%
     \parindent\z@ \parskip\z@skip%
     \linewidth\hsize%
     \@totalleftmargin\z@%
     \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip%
     \parfillskip\@flushglue \lineskip\normallineskip%
     \baselineskip\normalbaselineskip%
%%  \sloppy%
     \let\\\@normalcr%
     \mdf@par@local%New feature to restore parskip/parindent local in save box
     \ifbool{mdf@suppressfirstparskip}{\vspace*{-\parskip}}{}%
     \@afterindentfalse%
    %\@afterheading%
}
\renewrobustcmd\mdfframedtitleenv[1]{%
    \mdf@lrbox{\mdf@frametitlebox}%
     \mdf@frametitlealignment%
       \leavevmode{\color{\mdf@frametitlefontcolor}%
           \normalfont\mdf@frametitlefont{#1}
       \ifbool{mdf@ignorelastdescenders}%
         {%
          \par\strut\par
          \unskip\unskip\setbox0=\lastbox
          \vspace*{\dimexpr\ht\strutbox-\baselineskip\relax}%
         }{}}%
    \par\unskip\ifvmode\nointerlineskip\hrule \@height\z@ \@width\hsize\fi%%
    \endmdf@lrbox\relax%
   \mdf@ignorevbadness%
   \setbox\mdf@frametitlebox=\vbox{\unvbox\mdf@frametitlebox}%
   \mdfframetitleboxwidth=\wd\mdf@frametitlebox\relax%
   \mdfframetitleboxheight=\ht\mdf@frametitlebox\relax%
   \mdfframetitleboxdepth=\dp\mdf@frametitlebox\relax%
   \mdfframetitleboxtotalheight=\dimexpr
                                  \ht\mdf@frametitlebox
                                  +\dp\mdf@frametitlebox%
                                  +\mdf@frametitleaboveskip@length
                                  +\mdf@frametitlebelowskip@length
                                \relax%
}

\renewrobustcmd*\mdf@footnoteoutput{%
     \ifvoid\@mpfootins\else%
          \nobreak%
          \vskip\mdf@footenotedistance@length%
          \normalcolor%
          \bidi@mpfootnoterule%
          \unvbox\@mpfootins%
     \fi%
}


\renewrobustcmd*\mdf@footnoteinput{%
   \def\@mpfn{mpfootnote}%
   \def\thempfn{\thempfootnote}%
   \c@mpfootnote\z@%
   \let\@footnotetext\@mpfootnotetext%
    \let\@LTRfootnotetext\@mpLTRfootnotetext%
    \let\@RTLfootnotetext\@mpRTLfootnotetext%
}
%    \end{macrocode}
% \iffalse
%</mdframed-xetex-bidi.def>
%<*media9-xetex-bidi.def>
%\fi
% \section{File \texttt{media9-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{media9-xetex-bidi.def}[2025/01/03 v0.1 bidi adaptations for media9 package for XeTeX engine]
\RequirePackage{bidi-media9}
%    \end{macrocode}
% \iffalse
%</media9-xetex-bidi.def>
%<*bidi-media9.sty>
%\fi
% \section{File \texttt{bidi-media9.sty}}
%    \begin{macrocode}
\ProvidesExplPackage{bidi-media9}{2022/02/18}{0.4}
{bidi fixes for media9 package for the XeTeX engine}

\keys_define:nn{media9/mbtn}{
  draft .code:n = {},
  final .code:n = {},

  tooltip .tl_gset_x:N = \g_mix_tooltip_tl,
  tooltip .value_required:n = {true},

  overface .code:n = {
    \sbox\l_mix_poster_box{
      \bool_if:NTF\g_pbs_lscape_bool{\rotatebox{90}{#1}}{\if@RTL\beginR\fi#1\if@RTL\endR\fi}}
    \mix_pdfxform:n{\l_mix_poster_box}
    \tl_gset:Nx\g_mix_overbtn_tl{\mix_pdflastxform:}
  },
  overface .value_required:n = {true},

  downface .code:n = {
    \sbox\l_mix_poster_box{
      \bool_if:NTF\g_pbs_lscape_bool{\rotatebox{90}{#1}}{\if@RTL\beginR\fi#1\if@RTL\endR\fi}}
    \mix_pdfxform:n{\l_mix_poster_box}
    \tl_gset:Nx\g_mix_downbtn_tl{\mix_pdflastxform:}
  },
  downface .value_required:n = {true},

  3Dgotoview .code:n = {
    \tl_set:Nx\l_tmpa_tl{#1}              %extract ref
    \regex_replace_once:nnN{([^:]+):??.*}{\1}\l_tmpa_tl
    \tl_trim_spaces:N\l_tmpa_tl
    \tl_if_exist:cTF{ann@\l_tmpa_tl}{
      \str_if_eq:eeF{\tl_use:c{ann@\l_tmpa_tl}}{draft}{
        \tl_set:Nx\l_tmpb_tl{#1}          %extract idx
        \regex_replace_once:nnN{[^:]+:?}{}\l_tmpb_tl
        \tl_trim_spaces:N\l_tmpb_tl
        \tl_if_blank:VF\l_tmpb_tl{
          \regex_match:nVTF{^[DFLNP]$}\l_tmpb_tl{
            \tl_set:Nx\l_mix_vidx_tl{/\l_tmpb_tl}
          }{
            \regex_match:nVTF{^\d+$}\l_tmpb_tl{
              \tl_set:Nx\l_mix_vidx_tl{~\l_tmpb_tl}
            }{
              \regex_replace_once:nnN{^\(\s*}{}\l_tmpb_tl
              \regex_replace_once:nnN{\s*\)$}{}\l_tmpb_tl
              \tl_set:Nx\l_mix_vidx_tl{~(\l_tmpb_tl)}
            }
          }
        }
        \mix_pdfobj:nnn{}{dict}{
          /S/JavaScript/JS~(
            if(typeof(annotRM)=='undefined'){annotRM=new~Array();}
            if(typeof(annotRM['\l_tmpa_tl'])=='undefined'){
              annotRM['\l_tmpa_tl']=
                this.getAnnotRichMedia(\tl_use:c{page@\l_tmpa_tl},'\l_tmpa_tl');
            }
            annotRM['\l_tmpa_tl'].activated=true;
          )
          \tl_if_blank:VF\l_tmpb_tl{
            /Next~<<
              /S/GoTo3DView
              /TA~\tl_use:c{ann@\l_tmpa_tl}
              /V\l_mix_vidx_tl
            >>
          }
        }
        \tl_gput_right:Nx\g_mix_btnactions_tl{~\mix_pdflastobj:}
      }
    }{
      \msg_warning:nnx{media9}{undefined~reference}{\l_tmpa_tl}
      \cs_if_exist:NF\g_mix_refundefwarned_tl{
        \tl_new:N\g_mix_refundefwarned_tl
        \AtEndDocument{\msg_warning:nn{media9}{undefined~references}}
      }
    }
  },
  3Dgotoview .value_required:n = {true},

  mediacommand .code:n = {
    \tl_set:Nx\l_tmpa_tl{#1}
    \regex_replace_once:nnN{([^:]+):??.*}{\1}\l_tmpa_tl %extract ref
    \tl_trim_spaces:N\l_tmpa_tl
    \tl_if_exist:cTF{ann@\l_tmpa_tl}{
      \str_if_eq:eeF{\tl_use:c{ann@\l_tmpa_tl}}{draft}{
        \tl_set:Nx\l_tmpb_tl{#1}
        \regex_replace_once:nnN{[^:]+\:?}{}\l_tmpb_tl
        \tl_trim_spaces:N\l_tmpb_tl
        \regex_replace_all:nnN{^\{|\}$}{}\l_tmpb_tl
        \tl_set:Nx\l_mix_cmd_tl{
          \exp_after:wN\mix_separate_cmd_from_actn:w\l_tmpb_tl[]\q_stop}
        \tl_trim_spaces:N\l_mix_cmd_tl
        \tl_set:Nx\l_mix_arg_tl{
          \exp_after:wN\mix_separate_arg_from_actn:w\l_tmpb_tl[]\q_stop}
        \tl_trim_spaces:N\l_mix_arg_tl
        \mix_pdfobj:nnn{}{dict}{
          /S/JavaScript/JS~(
            if(typeof(annotRM)=='undefined'){annotRM=new~Array();}
            if(typeof(annotRM['\l_tmpa_tl'])=='undefined'){
              annotRM['\l_tmpa_tl']=
                this.getAnnotRichMedia(\tl_use:c{page@\l_tmpa_tl},'\l_tmpa_tl');
            }
            annotRM['\l_tmpa_tl'].activated=true;
          )
          \tl_if_blank:VF\l_mix_cmd_tl{
            /Next~<<
              /S/RichMediaExecute
              /TA~\tl_use:c{ann@\l_tmpa_tl}
              /TI~\tl_use:c{main@\l_tmpa_tl}
              /CMD~<<
                /C~(\l_mix_cmd_tl)
                \tl_if_blank:VF\l_mix_arg_tl{
                  /A~[\l_mix_arg_tl]
                }
              >>
            >>
          }
        }
        \tl_gput_right:Nx\g_mix_btnactions_tl{~\mix_pdflastobj:}
      }
    }{
      \msg_warning:nnx{media9}{undefined~reference}{\l_tmpa_tl}
      \cs_if_exist:NF\g_mix_refundefwarned_tl{
        \tl_new:N\g_mix_refundefwarned_tl
        \AtEndDocument{\msg_warning:nn{media9}{undefined~references}}
      }
    }
  },
  mediacommand .value_required:n = {true},

  jsaction .code:n = {
    \tl_set:Nx\l_tmpa_tl{#1}
    \regex_match:nVTF{^[^\{:]+:.*$}\l_tmpa_tl{
      \regex_replace_once:nnN{([^:]+):??.*}{\1}\l_tmpa_tl %extract ref
      \tl_trim_spaces:N\l_tmpa_tl
    }{\tl_clear:N\l_tmpa_tl}
    \tl_set:Nx\l_tmpb_tl{#1}
    \tl_if_blank:VF\l_tmpa_tl{
      \tl_if_exist:cF{ann@\l_tmpa_tl}{
        \msg_warning:nnx{media9}{undefined~reference}{\l_tmpa_tl}
        \cs_if_exist:NF\g_mix_refundefwarned_tl{
          \tl_new:N\g_mix_refundefwarned_tl
          \AtEndDocument{\msg_warning:nn{media9}{undefined~references}}
        }
      }
      \regex_replace_once:nnN{[^:]+\:}{}\l_tmpb_tl
    }
    \tl_set:Nx\l_tmpb_tl{\exp_after:wN\use:n\l_tmpb_tl}
    \tl_trim_spaces:N\l_tmpb_tl
    \tl_if_blank:VF\l_tmpb_tl{
    \mix_pdfobj:nnn{}{dict}{
      /S/JavaScript/JS~(
        try{\l_tmpb_tl}catch(e){console.show();console.println(e)})}}
    \bool_lazy_and:nnT{
      \tl_if_exist_p:c{ann@\l_tmpa_tl}
    }{
      !\str_if_eq_p:ee{\tl_use:c{ann@\l_tmpa_tl}}{draft}
    }{
      \mix_pdfobj:nnn{}{dict}{
        /S/JavaScript/JS~(
          if(typeof(annotRM)=='undefined'){annotRM=new~Array();}
          if(typeof(annotRM['\l_tmpa_tl'])=='undefined'){
            annotRM['\l_tmpa_tl']=
              this.getAnnotRichMedia(\tl_use:c{page@\l_tmpa_tl},'\l_tmpa_tl');
          }
          annotRM['\l_tmpa_tl'].activated=true;
        )
        \tl_if_blank:VF\l_tmpb_tl{/Next~\mix_pdflastobj:}
      }
    }
    \bool_if:nT{
      \bool_lazy_and_p:nn{
        \tl_if_exist_p:c{ann@\l_tmpa_tl}
      }{
        !\str_if_eq_p:ee{\tl_use:c{ann@\l_tmpa_tl}}{draft}
      }
      || !\tl_if_blank_p:V\l_tmpb_tl
    }{
      \tl_gput_right:Nx\g_mix_btnactions_tl{~\mix_pdflastobj:}
    }
  },
  jsaction .value_required:n = {true},

  unknown .code:n = {
    \msg_error:nnx{media9}{unknown~option}{\l_keys_key_tl}
  }
}

\RenewDocumentCommand\includemedia{O{}mm}{%#1 options, #2 text/image #3 media file
  \mix_uriend:
  \group_begin:
  \mix_beginLTR:
  \mode_leave_vertical:
  %empty stream as appearance dummy
  \cs_if_exist:NF\g_mix_appearance_tl{
    \hbox_set:Nn\l_mix_poster_box{\phantom{\rule{1pt}{1pt}}}
    \mix_pdfxform:n{\l_mix_poster_box}
    \tl_gset:Nx\g_mix_appearance_tl{\mix_pdflastxform:}
  }
  \mix_reset:
  \mix_uribegin: %treat URI characters correctly
  \keys_set:nn{media9/user}{#1}
  \mix_uriend:
  \tl_greplace_all:Nnn\g_mix_flashvars_tl{~&}{&}
  \tl_greplace_all:Nnn\g_mix_flashvars_tl{&~}{&}
  \tl_greplace_all:Nnn\g_mix_flashvars_tl{~=}{=}
  \tl_greplace_all:Nnn\g_mix_flashvars_tl{=~}{=}
  \tl_gtrim_spaces:N\g_mix_flashvars_tl

  \cs_if_exist:NT\Ginput@path{\cs_set_eq:NN\input@path\Ginput@path}

  %\hbox_set:Nn\l_mix_poster_box{\group_begin:#2\group_end:}
  %\hbox_set:Nn\l_mix_poster_box{#2}
  \sbox\l_mix_poster_box{\if@RTL\beginR\fi#2\if@RTL\endR\fi}
  \mix_scale:n{\l_mix_poster_box}
  \bool_if:nT{
    \dim_compare_p:n{\g_mix_tt_tl=\c_zero_dim}||
    \dim_compare_p:n{\g_mix_wd_tl=\c_zero_dim}
  }{
    \tl_gset:Nn\g_mix_usrpbtn_tl{none}
  }
  \bool_if:NTF\g_mix_usrdraft_bool{
    \tl_if_empty:NF\g_mix_usrlabel_tl{
      \mix_keytoaux_now:nn{ann@\g_mix_usrlabel_tl}{draft}
    }
    \tl_if_blank:oTF{#2}{
      \mix_uribegin: %treat URI characters correctly
      \mix_draftbox:n{\tl_to_str:n{#3}}
      \mix_uriend:
    }{
      \hbox_to_wd:nn{\g_mix_wd_tl}{
        \vrule~width~\c_zero_dim~height~\g_mix_ht_tl~depth~\g_mix_dp_tl
        \box_use:N\l_mix_poster_box\hss
      }
    }
  }{
    \bool_if:nF{\str_if_eq_p:Vn\g_mix_usrpbtn_tl{none}}{
      %attach script that switches off play button overlay upon activation
      \mix_pdfobj:nnn{}{stream}{
        {}{
          var~ocgs=host.getOCGs(host.pageNum);
          for(var~i=0;i<ocgs.length;i++){
            if(ocgs[i].name=='MediaPlayButton\int_use:N\g_mix_rmcnt_int'){
              ocgs[i].state=false;
            }
          }
        }
      }
      \mix_pdfobj:nnn{}{dict}{
        /Type/Filespec/EF~<</F~\mix_pdflastobj:>>/F~(btnoff)%/UF~(btnoff)
      }
      \tl_gset:Nx\g_mix_assets_tl{(btnoff)~\mix_pdflastobj:}
      \tl_set:Nx\l_mix_scripts_tl{~\mix_pdflastobj:~}
      %enforce plain playbutton overlay for XeTeX
      \sys_if_engine_xetex:T{\tl_gset:Nn\g_mix_usrpbtn_tl{plain}}
    }
    %embed main asset
    \mix_uribegin:
    \mix_embedasset:n{#3}
    \bool_if:nTF{
      \str_if_eq_p:Vn\l_mix_ext_tl{prc}||\str_if_eq_p:Vn\l_mix_ext_tl{u3d}
    }{
      \bool_gset_true:N\g_mix_iiid_bool
      \tl_gset:Nn\g_mix_mainassetsub_tl{3D}
    }{
      \str_case_e:nnF{\l_mix_base_tl}{
        {APlayer}{\tl_gset:Nn\g_mix_mainassetsub_tl{Sound}}
        {AudioPlayer}{\tl_gset:Nn\g_mix_mainassetsub_tl{Sound}}
        {VPlayer}{\tl_gset:Nn\g_mix_mainassetsub_tl{Video}}
        {VideoPlayer}{\tl_gset:Nn\g_mix_mainassetsub_tl{Video}}
        {StrobeMediaPlayback}{\tl_gset:Nn\g_mix_mainassetsub_tl{Video}}
      }{\tl_gset:Nn\g_mix_mainassetsub_tl{Flash}}
    }
    \tl_gset:Nx\g_mix_mainasset_tl{~\g_mix_lastasset_tl}
    \mix_uriend:
    %secondary assets (added by addresource)
    \seq_map_function:NN\g_mix_res_seq\mix_embedasset:n
    \seq_map_inline:Nn\g_mix_script_seq{
      \mix_embedasset:n{##1}
      \tl_put_right:Nx\l_mix_scripts_tl{~\g_mix_lastasset_tl}
    }
    %attach 3D calculation script
    \bool_if:nT{\g_mix_iiid_bool && \g_mix_iiidcalc_bool}{
      \mix_embedasset:n{3Dmenu.js}
      \tl_put_left:Nx\l_mix_scripts_tl{\g_mix_lastasset_tl~}
    }
    %create 3D views from file (option 3Dviews)
    \bool_if:nT{\g_mix_iiid_bool && !(\tl_if_blank_p:V\g_mix_vfile_tl)}{
      \tl_set:Nn\l_mix_level_tl{-1}
      \int_zero:N\l_mix_viewcnt_int
      \int_zero:N\l_mix_lineno_int

      \ior_open:Nn\l_mix_vfile_stream{\g_mix_vfile_tl}
      \ior_map_inline:Nn\l_mix_vfile_stream{
        \int_incr:N\l_mix_lineno_int
        \keys_set:nn{media9/views}{##1} %process input line
      }
      \ior_close:N\l_mix_vfile_stream
    }
    \bool_if:nT{ %create default 3D view if required
      \g_mix_iiid_bool &&
      (\g_mix_opt_iiidview_bool || \tl_if_blank_p:V\l_mix_iiidviewarray_tl)
    }{
      \tl_set_eq:NN\l_mix_bg_tl\g_mix_opt_bg_tl
      \tl_set_eq:NN\l_mix_ls_tl\g_mix_opt_ls_tl
      \tl_set_eq:NN\l_mix_rm_tl\g_mix_opt_rm_tl
      \tl_set_eq:NN\l_mix_psob_tl\g_mix_opt_psob_tl
      \tl_set_eq:NN\l_mix_coo_tl\g_mix_opt_coo_tl
      \tl_set_eq:NN\l_mix_ctoc_tl\g_mix_opt_ctoc_tl
      \tl_set_eq:NN\l_mix_ciiw_tl\g_mix_opt_ciiw_tl

      \fp_set_eq:NN\l_mix_roo_fp\g_mix_opt_roo_fp
      \fp_set_eq:NN\l_mix_aac_fp\g_mix_opt_aac_fp
      \fp_set_eq:NN\l_mix_oscale_fp\g_mix_opt_oscale_fp
      \fp_set_eq:NN\l_mix_roll_fp\g_mix_opt_roll_fp

      \bool_set_eq:NN\l_mix_ciiw_bool\g_mix_opt_ciiw_bool
      \bool_set_eq:NN\l_mix_iiidortho_bool\g_mix_opt_iiidortho_bool
      \tl_clear:N\l_mix_naarray_tl

      \bool_if:NF\l_mix_ciiw_bool{
        \tl_set:Nx\l_mix_args_tl{\l_mix_coo_tl\space\l_mix_ctoc_tl\space}
        \exp_after:wN\mix_calc_ciiw:w\l_mix_args_tl\q_stop
      }

      \tl_clear:N\l_mix_naarray_tl
      \tl_clear:N\l_mix_saarray_tl
      \tl_set_eq:NN\l_mix_nr_tl\g_mix_nrdflt_tl

      \mix_view:n{Default}
      \tl_set:Nx\l_mix_dfltview_tl{\mix_pdflastobj:}

    }
    \mix_pdfobj:nnn{}{dict}{
      /Type/RichMediaInstance
      /Subtype/\g_mix_mainassetsub_tl
      /Asset~\g_mix_mainasset_tl
      \bool_if:NF\g_mix_iiid_bool{
        /Params~<<
          /Binding\str_if_eq:VnTF\g_mix_transp_tl{true}{
            /Foreground
          }{
            /Background
          }
          \tl_if_blank:VF\g_mix_flashvars_tl{
            /FlashVars~(\g_mix_flashvars_tl)
          }
        >>
      }
    }
    \tl_if_empty:NF\g_mix_usrlabel_tl{
      \mix_keytoaux_now:nn{main@\g_mix_usrlabel_tl}{\mix_pdflastobj:}
    }
    \mix_pdfobj:nnn{}{dict}{
      /Type/RichMediaConfiguration
      /Subtype/\g_mix_mainassetsub_tl
      /Instances~[\mix_pdflastobj:]
    }
    \mix_pdfobj:nnn{}{dict}{
      /Type/RichMediaContent
      /Assets~<</Names~[\g_mix_assets_tl]>>
      /Configurations~[\mix_pdflastobj:]
      \bool_if:nT{
        \g_mix_iiid_bool && !(\tl_if_empty_p:V\l_mix_iiidviewarray_tl)
      }{
        /Views~[\l_mix_iiidviewarray_tl]
      }
    }
    \tl_set:Nx\l_mix_content_tl{\mix_pdflastobj:}
    \bool_if:nT{
      \g_mix_iiid_bool && \str_if_eq_p:Vn\g_mix_playtpe_tl{Oscillating}
    }{
      \tl_gset:Nx\g_mix_playcnt_tl{\int_eval:n{\g_mix_playcnt_tl*2}}
    }
    %determine floating window size
    \bool_if:NT\g_mix_opt_windowed_bool{
      \exp_after:wN\mix_parse_winsizearg:w\g_mix_winsize_tl\q_stop
    }
    \mix_pdfobj:nnn{}{dict}{
      /Activation~<<
        /Condition\g_mix_act_tl
        \bool_if:nT{
          \g_mix_iiid_bool &&
          !(\str_if_eq_p:Vn\g_mix_playtpe_tl{None})
        }{%seems to work only with 3D content
          /Animation~<<
            /Subtype/\g_mix_playtpe_tl
            /PlayCount~\g_mix_playcnt_tl
            /Speed~\g_mix_playspd_tl
          >>
        }
        \bool_if:nT{
          \g_mix_iiid_bool && (
            \g_mix_opt_iiidview_bool || \tl_if_blank_p:V\l_mix_iiidviewarray_tl
          )
        }{/View~\l_mix_dfltview_tl}
        /Presentation~<<
          /Transparent~\g_mix_transp_tl
          \bool_if:NTF\g_mix_opt_windowed_bool{
            /Style/Windowed
            /Window~<<
              /Width~<</Default~\tl_mix_fltwd>>
              /Height~<</Default~\tl_mix_fltht>>
              /Position~<<
                /HOffset~0/VOffset~0
                \str_case_e:nnF{\g_mix_winpos_tl}{
                  {tl}{/VAlign/Near/HAlign/Near}
                  {cl}{/VAlign/Center/HAlign/Near}
                  {bl}{/VAlign/Far/HAlign/Near}
                  {bc}{/VAlign/Far/HAlign/Center}
                  {br}{/VAlign/Far/HAlign/Far}
                  {cr}{/VAlign/Center/HAlign/Far}
                  {tr}{/VAlign/Near/HAlign/Far}
                  {tc}{/VAlign/Near/HAlign/Center}
                }{/HAlign/Center/VAlign/Center}
              >>
            >>
          }{
            /Style/Embedded
          }
          \bool_if:NTF\g_mix_iiid_bool{
            /Toolbar~\g_mix_tools_tl
            /NavigationPane~\g_mix_nav_tl
          }{
            /PassContextClick~\g_mix_contextclick_tl
          }
        >>
        \tl_if_blank:VF\l_mix_scripts_tl{/Scripts~[\l_mix_scripts_tl]}
      >>
      /Deactivation~<</Condition\g_mix_deact_tl>>
    }
    \tl_set:Nx\l_mix_settings_tl{\mix_pdflastobj:}
    \tl_if_empty:NF\g_mix_usrlabel_tl{
      \tl_gset_eq:NN\g_mix_label_tl\g_mix_usrlabel_tl
    }
    % #1:width, #2:height, #3:depth, #4:content (key-value)
    \mix_pdfannot:nnnn{\g_mix_wd_tl}{\g_mix_ht_tl}{\g_mix_dp_tl}{
      /Subtype/RichMedia
      /F~4
      /BS~<</W~0/S/S>>
      /Contents~(media~embedded~by~media9~[\g_mix_version_tl~(\g_mix_date_tl)])
      /NM~(\g_mix_label_tl)
      /AP~<</N~\g_mix_appearance_tl>>
      /RichMediaSettings~\l_mix_settings_tl
      /RichMediaContent~\l_mix_content_tl
    }
    \tl_if_empty:NF\g_mix_usrlabel_tl{
      \mix_keytoaux_now:nn{ann@\g_mix_usrlabel_tl}{\mix_pdflastann:}
      \mix_keytoaux_shipout:nn{page@\g_mix_usrlabel_tl}{
        \noexpand\the\g@mix@page@int}
    }
    \mix_pdfobj:nnn{}{dict}{
      /S/JavaScript/JS~(
        try{
          if(typeof(annotRM)=='undefined'){annotRM=new~Array();}
          if(typeof(annotRM['\g_mix_label_tl'])=='undefined'){
            annotRM['\g_mix_label_tl']=
              this.getAnnotRichMedia(this.pageNum,'\g_mix_label_tl');
          }
          \str_if_eq:eeF{\g_mix_usrpbtn_tl}{none}{
            if(typeof(ocgBtn\int_use:N\g_mix_rmcnt_int)=='undefined'){
              var~ocgs=this.getOCGs(this.pageNum);
              for(var~i=0;i<ocgs.length;i++){
                if(ocgs[i].name=='MediaPlayButton\int_use:N\g_mix_rmcnt_int'){
                   var~ocgBtn\int_use:N\g_mix_rmcnt_int=ocgs[i];
                }
              }
            }
            if(
              !annotRM['\g_mix_label_tl'].activated&&(
                app.viewerType=='Reader'||
                app.viewerType=='Exchange'||
                app.viewerType=='Exchange-Pro'
              )&&app.viewerVersion>=9
            ){
              ocgBtn\int_use:N\g_mix_rmcnt_int.state=true;
            }
          }
        }catch(e){}
        this.dirty=false;
      )
    }
    \mix_pdfannot:nnnn{0pt}{0pt}{0pt}{
      /Subtype/Widget
      /FT/Btn/Ff~65537/F~2
      /BS~<</W~0>>
      /T~(fd@\g_mix_label_tl)
      /AA~<</PO~\mix_pdflastobj:~/PV~\mix_pdflastobj:>>
    }
    \mix_appendtofields:n{\mix_pdflastann:}
    \hbox_overlap_right:n{\box_use:N\l_mix_poster_box}
    \str_if_eq:eeTF{\g_mix_usrpbtn_tl}{none}{
      \hbox_to_wd:nn{\g_mix_wd_tl}{
        \vrule~width~\c_zero_dim~height~\g_mix_ht_tl~depth~\g_mix_dp_tl\hss
      }
    }{%insert play button overlay
      \mix_insert_btnocg: %create OCG
      \cs_gset_eq:Nc\mix_pbtn:NN{g@mix@pbtn@\g_mix_usrpbtn_tl @tl}
      \group_begin:
      \cs_if_exist:NT\textdir{\textdir TLT}
        \sbox\l_mix_pbtn_box{\mix_pbtn:NN\g_mix_wd_tl\g_mix_tt_tl}
        \box_move_down:nn{\g_mix_dp_tl}{
          \hbox_to_wd:nn{\g_mix_wd_tl}{
            \vbox_to_ht:nn{\g_mix_tt_tl}{
              \vss
              \ocgbase_oc_bdc:n{\g_mix_btnocg_tl}
              \box_use:N\l_mix_pbtn_box
              \ocgbase_oc_emc:
            }
          }
        }
      \group_end:
    }
    \int_gincr:N\g_mix_rmcnt_int
  }
  \mix_endLTR:
  \group_end:
}
\tl_set_eq:NN\l_mix_includemedia_tl\includemedia
\tl_set:Nn\includemedia{\mix_uribegin:\l_mix_includemedia_tl}

\RenewDocumentCommand\mediabutton{O{}m}{%#1 options, #2 normal button text
  \mix_uriend:
  \group_begin:
  \mix_beginLTR:
  \mode_leave_vertical:
  %reset various variables
  \tl_gclear:N\g_mix_overbtn_tl
  \tl_gclear:N\g_mix_downbtn_tl
  \tl_gclear:N\g_mix_btnactions_tl
  \tl_gclear:N\g_mix_tooltip_tl
  %process options
  \bool_gset_eq:NN\g_mix_btndraft_bool\g_mix_pkgdraft_bool
  \mix_uribegin: %treat URI characters correctly
  \keys_set:nn{media9/mbtndraft}{#1} %detect draft/final on first pass
  \bool_if:NF\g_mix_btndraft_bool{\keys_set:nn{media9/mbtn}{#1}}
  \mix_uriend:
  %normal button appearance
  %\hbox_set:Nn\l_mix_poster_box{#2}
  \sbox\l_mix_poster_box{\if@RTL\beginR\fi#2\if@RTL\endR\fi}
  \tl_set:Nx\width {\dim_use:N\box_wd:N\l_mix_poster_box}
  \tl_set:Nx\height{\dim_use:N\box_ht:N\l_mix_poster_box}
  \tl_set:Nx\depth {\dim_use:N\box_dp:N\l_mix_poster_box}
  \bool_if:NTF\g_mix_btndraft_bool{\box_use:N\l_mix_poster_box}{
    \sbox\l_mix_poster_box{\bool_if:NTF\g_pbs_lscape_bool{\rotatebox{90}{
      \box_use:N\l_mix_poster_box}}{\box_use:N\l_mix_poster_box}}
    \mix_pdfxform:n{\l_mix_poster_box}
    \tl_set:Nx\g_mix_normalbtn_tl{\mix_pdflastxform:}
    %insert widget annotation
    \mix_pdfannot:nnnn{\width}{\height}{\depth}{
      /Subtype/Widget
      /T~(mbtn@\int_use:N\g_mix_mbtncnt_int)
      \tl_if_empty:NF\g_mix_tooltip_tl{/TU~(\g_mix_tooltip_tl)}
      /FT/Btn/Ff~65536
      \tl_if_empty:NTF\g_mix_downbtn_tl{/H/I}{/H/P}
      /AP~<<
        /N~\g_mix_normalbtn_tl
        \tl_if_empty:NF\g_mix_overbtn_tl{/R~\g_mix_overbtn_tl}
        \tl_if_empty:NF\g_mix_downbtn_tl{/D~\g_mix_downbtn_tl}
      >>
      /MK~<<
        /TP~1~/IF~<</S/A/FB~true/A~[0.0~0.0]>>
        /I~\g_mix_normalbtn_tl
        \tl_if_empty:NF\g_mix_overbtn_tl{/RI~\g_mix_overbtn_tl}
        \tl_if_empty:NF\g_mix_downbtn_tl{/IX~\g_mix_downbtn_tl}
      >>
      /A~<<
        /S/JavaScript/JS~(app.focusRect=false;)
        %sequence of actions to perform
        \tl_if_empty:NF\g_mix_btnactions_tl{/Next~[\g_mix_btnactions_tl]}
      >>
    }
    \mix_appendtofields:n{\mix_pdflastann:}
    \hbox_to_wd:nn{\width}{
      \vrule~width~\c_zero_dim~height~\height~depth~\depth\hss
    }
    \int_gincr:N\g_mix_mbtncnt_int
  }
  \mix_endLTR:
  \group_end:
}
\tl_set_eq:NN\l_mix_mediabutton_tl\mediabutton
\tl_set:Nn\mediabutton{\mix_uribegin:\l_mix_mediabutton_tl}

%    \end{macrocode}
% \iffalse
%</bidi-media9.sty>
%<*memoir-xetex-bidi.def>
%\fi
% \section{File \texttt{memoir-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{memoir-xetex-bidi.def}[2025/01/03 v0.7 bidi adaptations for memoir class for XeTeX engine]
\renewcommand{\keepthetitle}{%
  \@bsmtitlempty
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\and\relax
  \global\let\andnext\relax
  \global\let\@thanks\@empty
  \global\let\@title\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty}
\renewcommand{\maketitle}{\par
  \begingroup
    \@bsmarkseries
    \def\@makefnmark{\@textsuperscript{%
       \normalfont\@bsthanksheadpre \tamark \@bsthanksheadpost}}%
    \long\def\@makefntext##1{\makethanksmark ##1}
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \ifdim\pagetotal>\z@
        \newpage
      \fi
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{title}\@thanks
  \endgroup
  \@bscontmark  %  \setcounter{footnote}{0}%
  }
\renewcommand*{\memRTLleftskip}{\if@RTL\rightskip\else\leftskip\fi}
\renewcommand*{\memRTLrightskip}{\if@RTL\leftskip\else\rightskip\fi}
\renewcommand*{\memRTLvleftskip}{\if@RTL\vrightskip\else\vleftskip\fi}
\renewcommand*{\memRTLvrightskip}{\if@RTL\vleftskip\else\vrightskip\fi}
\renewcommand*{\memRTLraggedright}{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*{\memRTLraggedleft}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand*{\thesection}{\thechapter\@SepMark\@arabic\c@section}
\renewcommand*{\thesubsection}{%
              \thesection\@SepMark\@arabic\c@subsection}
\renewcommand*{\thesubsubsection}{%
              \thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*{\theparagraph}{%
              \thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*{\thesubparagraph}{%
              \theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand{\setthesection}{\thechapter\@SepMark\Alph{section}}
\renewcommand{\theequation}{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand{\thefigure}{\thechapter\@SepMark\@arabic\c@figure}
\renewcommand{\thetable}{\thechapter\@SepMark\@arabic\c@table}
\ifartopt
  \chapterstyle{article}
  \counterwithout{figure}{chapter}
  \counterwithout{table}{chapter}
  \counterwithout{footnote}{chapter}
  \counterwithout{equation}{chapter}
  \renewcommand{\chaptername}{}
  \renewcommand{\maketitlehookb}{%
    \vskip -1.5\topsep\vskip -1.5\partopsep}
  \renewcommand{\maketitlehookc}{%
    \vskip -1.5\topsep\vskip -1.5\partopsep}
\fi
\long\def\@makecaption#1#2{\let\@memtempa\relax
  \ifdim\prevdepth>-99\p@ \vskip\abovecaptionskip
  \else \def\@memtempa{\vbox to\topskip{}}\fi
  \let\@contfnote\footnote \renewcommand{\footnote}[2][]{}
  \let\@contfmark\footnotemark \renewcommand{\footnotemark}[1][]{}
  \sbox\@tempboxa{\@contnfont #1\@contdelim \@conttfont #2\@contfinal}
  \let\footnote\@contfnote
  \let\footnotemark\@contfmark
  \ifdim\wd\@tempboxa<\linewidth \centering \fi
  \if@contcw
    \centering
    \parbox{\@contcwidth}{%
    \ifdim\wd\@tempboxa<\@contcwidth \centering \fi
  \fi
  \ifdim\wd\@tempboxa<\linewidth
    \@contpre
    {\@contnfont #1\@contdelim}\@memtempa
    {\@contcshortstyle \@conttfont #2\@contfinal\par}
  \else
    \if@conthang
      \sbox\@tempboxa{\@contnfont #1\@contdelim}
      \@contpre%
      {\@contcstyle\hangindent=\wd\@tempboxa
       \noindent\box\@tempboxa\@memtempa \@conttfont #2\@contfinal\par}
    \else
      \if@contindent
        \@contpre%
        {\@contnfont #1\@contdelim}\@memtempa
        {\@contcstyle\hangindent=\@contindw
                     \hangafter=\@ne\@conttfont #2\@contfinal\par}% <- v1.4
      \else
        \@contpre%
        {\@contnfont #1\@contdelim}\@memtempa
        {\@contcstyle \@conttfont #2\@contfinal\par}
      \fi
    \fi
  \fi
  \@contpost
  \if@contcw
    \par
    }  % end of the \parbox
  \fi
  \vskip\belowcaptionskip}
\ApplyPatchCodeToPackage{caption}{%
\AtBeginPackage{caption}{
\ClassWarningNoLine{memoir}{%
  You are using the caption package with the memoir \MessageBreak
  class. This may cause unexpected or inconsistent \MessageBreak
  results if you use any of memoir's captioning facilities}

\long\def\@makecaption##1##2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{\if@RTL\beginR\fi##1: ##2\if@RTL\endR\fi}%
  \ifdim \wd\@tempboxa >\hsize
    \if@RTL\beginR\fi##1: ##2\if@RTL\endR\fi\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

\def\caption{%
   \ifx\@captype\@undefined
     \@latex@error{\noexpand\caption outside float}\@ehd
     \expandafter\@gobble
   \else
     \refstepcounter\@captype
     \expandafter\@firstofone
   \fi
   {\@dblarg{\@caption\@captype}}%
}

\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
    \normalsize
    \@makecaption{\csname fnum@##1\endcsname}{\ignorespaces ##3}\par
  \endgroup}
}}
\renewenvironment{thebibliography}[1]{%
  \bibsection
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook%
  \begin{bibitemlist}{#1}}{\end{bibitemlist}\postbibhook}
%    \end{macrocode}
% \iffalse
%</memoir-xetex-bidi.def>
%<*midfloat-xetex-bidi.def>
%\fi
% \section{File \texttt{midfloat-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{midfloat-xetex-bidi.def}[2017/05/06 v0.4 bidi adaptations for midfloat package for XeTeX engine]
\def\RTL@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
    \global\c@colht\@colht\global\c@addvipersep\z@
    \ifnum\juo@sk>0
        \remove@strip\juo@sar
        \global\@colht\the\juo@pr
        \ifdim\right@cor>\z@
                \global\advance\@colht by\right@cor
        \fi
        \global\advance\@colht by\cor@height
        \global\cor@height=0pt
    \fi
    \global \setbox\@rightcolumn \vbox{}%
  \else
    \ifdim\c@colht>\@colht
            \@tempdima\@colht
            \ifdim\@colht>\z@
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vbox to\@tempdima{%
                                \vskip\c@addvipersep\unvbox\@outputbox}%
                        \vskip\stripsep
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \global\c@addvipersep\m@addvipersep
            \else
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \fi
            \ifnum\juo@sk>0
                \remove@strip\juo@sar
                \global\@colht\the\juo@pr
                \global\advance\@colht by -\ht\@rightcolumn
                \global\advance\@colht by\cor@height
                \global\cor@height=0pt
            \else
                \global\advance\c@colht by-\ht\@rightcolumn
                \global\@colht\c@colht
            \fi
   \else 
   \global\@firstcolumntrue
    \global\setbox\@outputbox\vbox to\ht\@leftcolumn{%
                        \unvbox\@rightcolumn
                        \vskip\c@addvipersep
                        \unvbox\@outputbox
                        }%
    \setbox\@outputbox \vbox {%
                         \hb@xt@\textwidth {%
                          \hskip \columnwidth
                          \hfil
                           \vrule \@width\columnseprule
                           \hfil
                           \hb@xt@\columnwidth {%
                             \bidi@firstcolumn@status@write%
                             \box\@leftcolumn \hss}%
                           \hskip-\textwidth
                           \hb@xt@\columnwidth {%
                             \bidi@lastcolumn@status@write%
                             \box\@outputbox \hss}%
                           \hskip\columnwidth
                           \hskip\columnsep}%
                              }%
    \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
    \global\juo@sk=0\global\juo@sar={}%
    \global\cor@height\z@\global\c@addvipersep\z@
    \fi
  \fi
}


\def\LTR@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
    \global\c@colht\@colht\global\c@addvipersep\z@
    \ifnum\juo@sk>0
        \remove@strip\juo@sar
        \global\@colht\the\juo@pr
        \ifdim\right@cor>\z@
                \global\advance\@colht by\right@cor
        \fi
        \global\advance\@colht by\cor@height
        \global\cor@height=0pt
    \fi
    \global \setbox\@rightcolumn \vbox{}%
  \else
    \ifdim\c@colht>\@colht
            \@tempdima\@colht
            \ifdim\@colht>\z@
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vbox to\@tempdima{%
                                \vskip\c@addvipersep\unvbox\@outputbox}%
                        \vskip\stripsep
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \global\c@addvipersep\m@addvipersep
            \else
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \fi
            \ifnum\juo@sk>0
                \remove@strip\juo@sar
                \global\@colht\the\juo@pr
                \global\advance\@colht by -\ht\@rightcolumn
                \global\advance\@colht by\cor@height
                \global\cor@height=0pt
            \else
                \global\advance\c@colht by-\ht\@rightcolumn
                \global\@colht\c@colht
            \fi
  \else 
   \global\@firstcolumntrue
    \global\setbox\@outputbox\vbox to\ht\@leftcolumn{%
                        \unvbox\@rightcolumn
                        \vskip\c@addvipersep
                        \unvbox\@outputbox
                        }%
    \setbox\@outputbox \vbox {%
                         \hb@xt@\textwidth {%
                           \hb@xt@\columnwidth {%
                             \bidi@firstcolumn@status@write%
                             \box\@leftcolumn \hss}%
                           \hfil
                           \vrule \@width\columnseprule
                           \hfil
                           \hb@xt@\columnwidth {%
                             \bidi@lastcolumn@status@write%
                             \box\@outputbox \hss}%
                                             }%
                              }%
    \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
    \global\juo@sk=0\global\juo@sar={}%
    \global\cor@height\z@\global\c@addvipersep\z@
    \fi
  \fi
}


\def\@strip[#1/#2]{\global\@tempdima=#1\global\@tempdimb=#2%
  \global \setbox\@viper\vbox\bgroup\if@RTLmain\moveleft\dimexpr(\columnwidth+\columnsep)\fi\vbox\bgroup%
        \hsize\textwidth
        \@parboxrestore
        \col@number \@ne
        \vrule height\topskip width0pt depth0pt
}

\def\endstrip{%
        \egroup\egroup
        \if@firstcolumn
                \ifdim\pagetotal>\z@
                        \vskip\stripsep
                        \global\ht@strip\pagegoal
                        \global\advance\ht@strip by-\pagetotal
                        \global\advance\ht@strip by-\stripsep
                        \global\advance\ht@strip by-\ht\@viper
                        \global\advance\ht@strip by-\stripsep
                        \global\juo@ht=\ht\@viper
                \else
                        \global\ht@strip\z@
                \fi
                \ifdim\ht@strip>\z@
                  \unvbox\@viper
                  \vskip\stripsep
                  \add@strip{\the\pagetotal}{\the\juo@ht}{\the\@tempdima}{\the\@tempdimb}%
                  \global\advance\juo@sk by1
                \else
                  \@latex@error{Strip needs more place!}\@ehc
                  \if@vihproof
                    \framebox[\columnwidth]{??? Strip ???}%
                  \fi
                \fi
        \else
          \@latex@error{Strip is used only on left column!}\@ehc
          \if@vihproof
            \framebox[\columnwidth]{??? Strip ???}%
          \fi
        \fi
}
%    \end{macrocode}
% \iffalse
%</midfloat-xetex-bidi.def>
%<*minitoc-xetex-bidi.def>
%\fi
% \section{File \texttt{minitoc-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{minitoc-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for minitoc package for XeTeX engine]
\def\@undottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth\relax \else
  \vskip \z@ plus.2\p@
  {\if@RTL\rightskip\else\leftskip\fi #2\relax \if@RTL\leftskip\else\rightskip\fi \@tocrmarg \parfillskip -\if@RTL\leftskip\else\rightskip\fi
   \parindent #2\relax\@afterindenttrue
   \interlinepenalty\@M
   \leavevmode
   \@tempdima #3\relax \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \hbox{}%
   \hskip -\if@RTL\rightskip\else\leftskip\fi
    #4\nobreak\hfill \nobreak
           \null\par}%
  \fi}
\def\@Undottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth\relax \else
    \vskip \z@ \@plus.2\p@
    {\if@RTL\rightskip\else\leftskip\fi #2\relax \if@RTL\leftskip\else\rightskip\fi \@tocrmarg \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\coffeefont #4}\nobreak \nobreak\null
    \par}%
  \fi}
\def\@Undottedtoclinep#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth\relax \else
    \vskip \z@ \@plus.2\p@
    {\if@RTL\rightskip\else\leftskip\fi #2\relax \if@RTL\leftskip\else\rightskip\fi \@tocrmarg \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {#4}\nobreak \hfill \nobreak\null
     \hb@xt@\@pnumwidth{{\hfil\normalfont \normalcolor #5}}%
    \par}%
  \fi}
%    \end{macrocode}
% \iffalse
%</minitoc-xetex-bidi.def>
%<*multicol-xetex-bidi.def>
%\fi
% \section{File \texttt{multicol-xetex-bidi.def}}
%    \begin{macrocode}
\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  
    }{}{}%
  }{}%
}
  
  
%    \end{macrocode}
% \iffalse
%</multicol-xetex-bidi.def>
%<*multienum-xetex-bidi.def>
%\fi
% \section{File \texttt{multienum-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{multienum-xetex-bidi.def}[2011/04/16 v0.1 bidi adaptations for multienum package for XeTeX engine]
\renewcommand{\itemx}[1]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep%
\parbox[t]{\remainx}{\bidi@raggedright #1}\par}%\smallskip
\renewcommand{\itemxx}[2]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{.5\remainxx}{\bidi@raggedright #1}\hfill\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.5\remainxx}{\bidi@raggedright #2}\smallskip}
\renewcommand{\itemxxx}[3]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep%
\parbox[t]{.3333\remainxxx}{\bidi@raggedright #1}\hfill\parbox[t]%
{\labelwidth}{\hfill {\labelname}}\hskip\labelsep%
\parbox[t]{0.3333\remainxxx}{\bidi@raggedright #2}\hfill\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep%
\parbox[t]{0.3333\remainxxx}{\bidi@raggedright #3}\par}%\smallskip
\renewcommand{\itemxxxx}[4]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{.25\remainxxxx}{\bidi@raggedright #1}\hfill\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #2}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #3}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #4}\smallskip}
\renewcommand{\itemxxxxx}[5]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.2\remainxxxxx}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.2\remainxxxxx}{\bidi@raggedright #2}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.2\remainxxxxx}{\bidi@raggedright #3}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.2\remainxxxxx}{\bidi@raggedright #4}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.2\remainxxxxx}{\bidi@raggedright #5}\smallskip}
\renewcommand{\itemxox}[2]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{\remainxox}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.3333\remainxxx}{\bidi@raggedright #2}\smallskip}
\renewcommand{\itemxxo}[2]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.3333\remainxxx}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{\remainxox}{\bidi@raggedright #2}\smallskip}
\renewcommand{\itemxoxx}[3]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{\remainxoxx}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #2}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #3}\smallskip}
\renewcommand{\itemxxox}[3]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{.25\remainxxxx}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{\remainxoxx}{\bidi@raggedright #2}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{0.25\remainxxxx}{\bidi@raggedright #3}\smallskip}
\renewcommand{\itemxxxo}[3]{\parbox[t]%
{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{.25\remainxxxx}{\bidi@raggedright #1}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{.25\remainxxxx}{\bidi@raggedright #2}\hfill%
\parbox[t]{\labelwidth}{\hfill{\labelname}}\hskip\labelsep
\parbox[t]{\remainxoxx}{\bidi@raggedright #3}\smallskip}
%    \end{macrocode}
% \iffalse
%</multienum-xetex-bidi.def>
%<*natbib-xetex-bidi.def>
%\fi
% \section{File \texttt{natbib-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{natbib-xetex-bidi.def}[2017/06/09 v0.2 bidi adaptations for natbib package for XeTeX engine]
\renewenvironment{thebibliography}[1]{%
 \bibsection
 \parindent\z@
 \bibpreamble
 \bibfont
 \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
 \bidi@@thebibliography@font@hook%
 \list{\@biblabel{\the\c@NAT@ctr}}{\@bibsetup{#1}\global\c@NAT@ctr\z@}%
 \ifNAT@openbib
   \renewcommand\newblock{\par}%
 \else
   \renewcommand\newblock{\hskip .11em \@plus.33em \@minus.07em}%
 \fi
 \sloppy\clubpenalty4000\widowpenalty4000
 \sfcode`\.\@m
 \let\NAT@bibitem@first@sw\@firstoftwo
    \let\citeN\cite \let\shortcite\cite
    \let\citeasnoun\cite
}{%
 \bibitem@fin
 \bibpostamble
 \def\@noitemerr{%
  \PackageWarning{natbib}{Empty `thebibliography' environment}%
 }%
 \endlist
 \bibcleanup
}%
%    \end{macrocode}
% \iffalse
%</natbib-xetex-bidi.def>
%<*newfloat-xetex-bidi.def>
%\fi
% \section{File \texttt{newfloat-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{newfloat-xetex-bidi.def}[2013/05/22 v0.1 bidi adaptations for newfloat package for XeTeX engine]
\renewcommand*\newfloat@setwithin[2]{%
  \ifcsname c@chapter\endcsname
    \@removefromreset{#1}{chapter}%
  \fi
  \@removefromreset{#1}{section}%
  \edef\@tempa{#2}%
  \ifx\@tempa\@empty
    \def\@tempa{none}%
  \fi
  \def\@tempb{none}%
  \ifx\@tempa\@tempb
    \ifcsname c@chapter\endcsname
      \@chapterlistsgap@off{#1}%
    \fi
    \newfloat@@setwithin{#1}{}{}%
  \else
    \def\@tempb{chapter}%
    \ifx\@tempa\@tempb
      \@addtoreset{#1}{chapter}%
      \@chapterlistsgap@on{#1}%
      \newfloat@@setwithin{#1}{\ifnum\c@chapter>\z@ \thechapter\@SepMark\fi}{\theHchapter\@SepMark}%
    \else
      \def\@tempb{section}%
      \ifx\@tempa\@tempb
        \@addtoreset{#1}{section}%
        \ifcsname c@chapter\endcsname
          \@addtoreset{#1}{chapter}%
          \@chapterlistsgap@on{#1}%
          \newfloat@@setwithin{#1}{\thesection\@SepMark}{\theHsection\@SepMark}%
        \else
          \newfloat@@setwithin{#1}{\ifnum\c@section>\z@ \thesection\@SepMark\fi}{\theHsection\@SepMark}%
        \fi
      \else
        \newfloat@Error{Invalid value `#2' for option `within'}%
      \fi
    \fi
  \fi}
%    \end{macrocode}
% \iffalse
%</newfloat-xetex-bidi.def>
%<*nicematrix-xetex-bidi.def>
%\fi
% \section{File \texttt{nicematrix-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{nicematrix-xetex-bidi.def}[2024/12/15 v0.3 bidi adaptations for nicematrix package for XeTeX engine]
\ExplSyntaxOn
\bidi@patchcmd{\__nicematrix_array:n}{\@tabarray}{%
  \bool_if:NF \l__nicematrix_tabular_bool \@RTLtabfalse
  \@tabarray
}{}{}
\ExplSyntaxOff

%    \end{macrocode}
% \iffalse
%</nicematrix-xetex-bidi.def>
%<*ntheorem-xetex-bidi.def>
%\fi
% \section{File \texttt{ntheorem-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{ntheorem-xetex-bidi.def}[2025/10/28 v0.2 bidi adaptations for ntheorem package for XeTeX engine]
\gdef\@thm#1#2#3{%
   \if@thmmarks
     \stepcounter{end\InTheoType ctr}%
   \fi
   \renewcommand{\InTheoType}{#1}%
   \if@thmmarks
     \stepcounter{curr#1ctr}%
     \setcounter{end#1ctr}{0}%
   \fi
   \refstepcounter{#2}%
   \theorem@prework
   \thm@topsepadd \theorempostskipamount   % cf. latex.ltx: \@trivlist
   \ifvmode \advance\thm@topsepadd\partopsep\fi
   \trivlist
   \@topsep \theorempreskipamount
   \@topsepadd \thm@topsepadd        % used by \@endparenv
   \advance\linewidth -\theorem@indent
   \advance\@totalleftmargin \theorem@indent
  \if@RTL\parshape \@ne 0pt \linewidth\else  \parshape \@ne \@totalleftmargin \linewidth\fi
   \@ifnextchar[{\@ythm{#1}{#2}{#3}}{\@xthm{#1}{#2}{#3}}}
   
\gdef\@xnthm#1#2[#3]{%
  \ifthm@tempif
     \expandafter\@ifundefined{c@#1}%
        {\@definecounter{#1}}{}%
     \@newctr{#1}[#3]%
     \expandafter\xdef\csname the#1\endcsname{%
       \expandafter\noexpand\csname the#3\endcsname \@thmcountersep
%          {\noexpand\csname\the\theoremnumbering\endcsname{#1}}}%
          \noexpand\csname\the\theoremnumbering\endcsname{#1}}%
     \expandafter\gdef\csname mkheader@#1\endcsname
       {\csname setparms@#1\endcsname
        \@thm{#1}{#1}{#2}}%
     \global\@namedef{end#1}{\@endtheorem}\fi}
%    \end{macrocode}
% \iffalse
%</ntheorem-xetex-bidi.def>
%<*ntheorem-hyper-xetex-bidi.def>
%\fi
% \section{File \texttt{ntheorem-hyper-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{ntheorem-hyper-xetex-bidi.def}[2012/05/01 v0.1 bidi adaptations for ntheorem-hyper package for XeTeX engine]
\gdef\@thm#1#2#3{%
   \if@thmmarks
     \stepcounter{end\InTheoType ctr}%
   \fi
   \renewcommand{\InTheoType}{#1}%
   \if@thmmarks
     \stepcounter{curr#1ctr}%
     \setcounter{end#1ctr}{0}%
   \fi
   \refstepcounter{#2}%
   \thm@topsepadd \theorempostskipamount   % cf. latex.ltx: \@trivlist
   \ifvmode \advance\thm@topsepadd\partopsep\fi
   \trivlist
   \@topsep \theorempreskipamount
   \@topsepadd \thm@topsepadd        % used by \@endparenv
   \advance\linewidth -\theorem@indent
   \advance\@totalleftmargin \theorem@indent
   \if@RTL\parshape \@ne 0pt \linewidth\else  \parshape \@ne \@totalleftmargin \linewidth\fi
   \@ifnextchar[{\@ythm{#1}{#2}{#3}}{\@xthm{#1}{#2}{#3}}}
%    \end{macrocode}
% \iffalse
%</ntheorem-hyper-xetex-bidi.def>
%<*overpic-xetex-bidi.def>
%\fi
% \section{File \texttt{overpic-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{overpic-xetex-bidi.def}[2015/12/07 v0.1 bidi adaptations for overpic package for XeTeX engine]
\renewenvironment{overpic}[2][]{%
  \sbox{\z@}{\includegraphics[#1]{#2}}%
  \settodepth{\@tempcnta}{\usebox{\z@}}%
  \settoheight{\@tempcntb}{\usebox{\z@}}%
  \advance\@tempcntb\@tempcnta%
  \settowidth{\@tempcnta}{\usebox{\z@}}%
  \setlength{\@tempdima}{\unitlength}%
  \count@=\z@\Gin@gridfalse\setkeys{Gin}{#1}% 
%
  \OVP@calc%
%  
  \begin{picture}(\@tempcnta,\@tempcntb)%
    \if@RTL\else\put(0,0){\makebox(0,0)[bl]{\usebox{\z@}}}%
    \ifGin@grid%
      \put(0,0){\normalfont\fontsize\@viipt\@viiipt\selectfont%
        \grid(\@tempcnta,\@tempcntb)(\count@,\count@)[0,0]}%
    \fi\fi%  
    % reset the graphics parameter
    \let\Gin@outer@scalex\relax
    \let\Gin@outer@scaley\relax
    \let\Gin@angle\relax
    \let\Gin@ewidth\Gin@exclamation
    \let\Gin@eheight\Gin@ewidth
    \def\Gin@scalex{1}
    \let\Gin@scaley\Gin@exclamation
}{% 
    \if@RTL\ifGin@grid%
      \put(0,0){\normalfont\fontsize\@viipt\@viiipt\selectfont%
        \grid(\@tempcnta,\@tempcntb)(\count@,\count@)[0,0]}%
    \fi%
    \put(0,0){\makebox(0,0)[bl]{\usebox{\z@}}}\fi%
  \end{picture}%
}%
%    \end{macrocode}
% \iffalse
%</overpic-xetex-bidi.def>
%<*pdfbase-xetex-bidi.def>
%\fi
% \section{File \texttt{pdfbase-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{pdfbase-xetex-bidi.def}[2022/02/18 v0.4 bidi adaptations for pdfbase package for XeTeX engine]
\ExplSyntaxOn
\cs_set_eq:NN\pbs_outputpage_orig:\@outputpage
\cs_set_nopar:Npn\@outputpage{
  \int_gincr:N\g_pbs_page_int
  \box_if_vertical:cTF{@outputbox}{
    \bool_set_true:N\l_pbs_is_vertical_bool
  }{
    \bool_set_false:N\l_pbs_is_vertical_bool
  }
  \hbox_set:Nn\@outputbox{
    %begin of page
    \hbox_overlap_right:n{\seq_map_inline:Nn\g_pbs_bop_seq{##1}}
    \box_use_drop:N\@outputbox
    %end of page
    \hbox_overlap_right:n{\seq_map_inline:Nn\g_pbs_eop_seq{##1}}
  }
  \bool_if:NT\l_pbs_is_vertical_bool{
    \vbox_set:Nn\@outputbox{\box_use_drop:N\@outputbox}
  }
  \pbs_outputpage_orig:
}
\ExplSyntaxOff
%    \end{macrocode}
% \iffalse
%</pdfbase-xetex-bidi.def>
%<*pdflscape-xetex-bidi.def>
%\fi
% \section{File \texttt{pdflscape-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{pdflscape-xetex-bidi.def}[2022/02/18 v0.1 bidi adaptations for pdflscape package for XeTeX engine]
\bidi@patchcmd{\landscape}{\PLS@Rotate{90}}{%
  \if@RTL
    \PLS@Rotate{-90}%
  \else
    \PLS@Rotate{90}%
  \fi
}{}{}
%    \end{macrocode}
% \iffalse
%</pdflscape-xetex-bidi.def>
%<*pgfcorescopes.code-xetex-bidi.def>
%\fi
% \section{File \texttt{pgfcorescopes.code-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{pgfcorescopes.code-xetex-bidi.def}[2015/11/14 v0.1 bidi adaptations for pgf package for XeTeX engine]
\def\pgfpicture{%
  \begingroup%
   \ifmmode\else\@RTLfalse\beginL\fi%
    \pgfpicturetrue%
    \global\advance\pgf@picture@serial@count by1\relax%
    \edef\pgfpictureid{pgfid\the\pgf@picture@serial@count}%
    \let\pgf@nodecallback=\pgfutil@gobble%
    \pgf@picmaxx=-16000pt\relax%
    \pgf@picminx=16000pt\relax%
    \pgf@picmaxy=-16000pt\relax%
    \pgf@picminy=16000pt\relax%
    \pgf@relevantforpicturesizetrue%
    \pgf@resetpathsizes%
    \pgfutil@ifnextchar\bgroup\pgf@oldpicture\pgf@picture}
\def\endpgfpicture{%
              \ifpgfrememberpicturepositiononpage%
                \hbox to0pt{\pgfsys@markposition{\pgfpictureid}}%
              \fi%    
              % ok, now let's position the box
              \ifdim\pgf@picmaxx=-16000pt\relax%
                % empty picture. make size 0.  
                \global\pgf@picmaxx=0pt\relax%
                \global\pgf@picminx=0pt\relax%
                \global\pgf@picmaxy=0pt\relax%
                \global\pgf@picminy=0pt\relax%
              \fi%
              % Shift baseline outside:
              \pgf@relevantforpicturesizefalse%
              \pgf@process{\pgf@baseline}%
              \xdef\pgf@shift@baseline{\the\pgf@y}%
              % 
              \pgf@process{\pgf@trimleft}%
              \global\advance\pgf@x by-\pgf@picminx
              % prepare \hskip\pgf@trimleft@final.
              % note that \pgf@trimleft@final is also queried
              % by the pgf image externalization.
              \xdef\pgf@trimleft@final{-\the\pgf@x}%
              % 
              \pgf@process{\pgf@trimright}%
              \global\advance\pgf@x by-\pgf@picmaxx
              % prepare \hskip\pgf@trimright@final.
              % note that \pgf@trimright@final is also queried
              % by the pgf image externalization.
              \xdef\pgf@trimright@final{\the\pgf@x}%
        %
        \pgf@remember@layerlist@globally
            \endgroup%
            \hss%
          \egroup%
      \pgf@restore@layerlist@from@global
          \pgf@insertlayers%
        \endgroup%    
        \pgfsys@discardpath%
        \endgroup%
      \pgfsys@endscope%
    \pgfsys@endpicture%
    \endgroup%
    \hss
  \egroup%
  \pgfsys@typesetpicturebox\pgfpic%
  \ifmmode\else\endL\fi%
  \endgroup%
}
%    \end{macrocode}
% \iffalse
%</pgfcorescopes.code-xetex-bidi.def>
%<*pgfsys-xetex-bidi.def>
%\fi
% \section{File \texttt{pgfsys-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{pgfsys-xetex-bidi.def}[2025/01/05 v0.1 bidi adaptations for pgfsys package for XeTeX engine]
\def\pgfsys@shadingoutsidepgfpicture#1{%
  \beginL#1\endL%
}


%    \end{macrocode}
% \iffalse
%</pgfsys-xetex-bidi.def>
%<*picinpar-xetex-bidi.def>
%\fi
% \section{File \texttt{picinpar-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{picinpar-xetex-bidi.def}[2013/04/08 v0.2 bidi adaptations for picinpar package for XeTeX engine]
\long\def\@makewincaption#1#2{%
   \setbox\@tempboxa\hbox{\footnotesize{\bf #1:\enspace}{#2}}%
   \ifdim\wd\@tempboxa>\picwd
      {\footnotesize{\bf #1:\enspace}{#2\par}}
   \else
      \hbox to\picwd{\if@RTL\beginR\fi\hfil\box\@tempboxa\hfil\if@RTL\endR\fi}
   \fi}
\def\endwindow{%
    \global\tcd=\tcdsav
    \egroup\vskip\parskip\parshape=0 % reset parshape; end \box\rawtext
    \vbadness=10000
    \splittopskip=0pt
%
% Typeset the lines above the window
%
\ifnum\tcd>0\setbox\holder=\vsplit\rawtext to \tcd\baselineskip
\tcn=\tcd
\loop\advance\tcn -1
\setbox\fslice=\vsplit\holder to\baselineskip
\prune\fslice\linewidth
\topheight=0pt
\ifnum\dp\fslice>\dp\wstrutbox
       \advance\topheight-\dp\fslice
       \advance\topheight\dp\wstrutbox
       \advance\topheight\ilg\fi
\hbox to\linewidth{\box\fslice}
\vskip-\topheight
\ifdim\ht\holder>0pt\repeat
\fi
%
% Now we build the boxes beside the window
%
\global\topheight=\tcl\baselineskip
\ifnum\cumpartcl>0\global\tcl=\cumtcl
      \global\topheight=\vpic
\fi
\ifnum\bl>0 \ifnum\br>0 \multiply\topheight by 2\fi\fi
\ifnum\bl>0\setbox\holder=\vsplit\rawtext to\topheight
\else\ifnum\br>0\setbox\holder=\vsplit\rawtext to\topheight\fi\fi
\tcn=\tcl \na=0 \nb=0
\ifnum\bl>0 \ifnum\br>0 \multiply\tcn by 2\fi\fi
\ifnum\bl>0\na=\tcn\ifnum\br>0\divide\na by 2\fi\fi
\ifnum\br>0\nb=\tcn\ifnum\bl>0\divide\nb by 2\fi\fi
\ifnum\na=0\ifnum\nb=0
      \setbox\waslice=\vbox to\vpic{\vss}
      \setbox\wbslice=\vbox to\vpic{\vss}
      \bl=1\br=1
      \vskip\ilg
\fi\fi
%
% both sides
%
\ifnum\na>0 \ifnum\nb>0
\loop\advance\nb -1
\advance\na -1
\if@RTL%
\setbox\bslice=\vsplit\holder to\baselineskip
\prune\bslice\rtside
\setbox\wbslice=\vbox{\unvbox\wbslice\hbox
to\rtside{\box\bslice\hfil}}
\setbox\aslice=\vsplit\holder to\baselineskip
\prune\aslice\lftside
\setbox\waslice=\vbox{\unvbox\waslice\hbox
to\lftside{\box\aslice\hfil}}
\else%
\setbox\aslice=\vsplit\holder to\baselineskip
\prune\aslice\lftside
\setbox\waslice=\vbox{\unvbox\waslice\hbox
to\lftside{\box\aslice\hfil}}
\setbox\bslice=\vsplit\holder to\baselineskip
\prune\bslice\rtside
\setbox\wbslice=\vbox{\unvbox\wbslice\hbox
to\rtside{\box\bslice\hfil}}
\fi%
\ifnum\nb>0\repeat
\fi\fi
%
% only text on the left side
%
\ifnum\na>0
    \loop\advance\na -1
    \setbox\aslice=\vsplit\holder to\baselineskip
    \prune\aslice\lftside
    \setbox\waslice=\vbox{\unvbox\waslice\hbox
    to\lftside{\box\aslice\hfil}}
    \ifdim\ht\holder>0pt\repeat
\fi
%
% only text on the right side
%
\ifnum\nb>0
    \loop\advance\nb -1
    \setbox\bslice=\vsplit\holder to\baselineskip
    \prune\bslice\rtside
    \setbox\wbslice=\vbox{\unvbox\wbslice\hbox
    to\rtside{\box\bslice\hfil}}
    \ifdim\ht\holder>0pt\repeat
\fi
%
% fixing the dimensions of the window part
%
\ifnum\bl=0\topheight=\ht\wbslice
\else\ifnum\br=0\topheight=\ht\waslice
      \else\ifdim\ht\waslice>\ht\wbslice\topheight=\ht\waslice
            \else\topheight=\ht\wbslice\fi\fi\fi
%
% ship out the window material to the main vertical list
%
\ifnum\bl>0 \ifnum\br>0 \ifdim\ht\wbslice<\topheight
\setbox\wbslice=\vbox to\topheight{\box\wbslice\vfill}
\fi\fi\fi
\setbox\windowbox=\vbox{\hbox to\linewidth{%
\ifnum\bl>0\box\waslice\hfill\fi%
\vbox to\topheight{\hrule width\picwd height0pt depth0pt\vskip0pt%
\vfill\unvbox\picbox%
\ifnum\picwd>0\vfill\fi%
\vss}\ifnum\br>0\hfill\vbox{\box\wbslice}\fi}}%
\unvbox\windowbox%
\loop
 \setbox\bslice=\vsplit\rawtext to\baselineskip
 \prune\bslice\linewidth
 \setbox\wbslice=\vbox{\hbox to\linewidth{\box\bslice\hfil}}
 \unvbox\wbslice
 \ifdim\ht\rawtext>0pt
\repeat
}% FINITO
%    \end{macrocode}
% \iffalse
%</picinpar-xetex-bidi.def>
%<*plain-xetex-bidi.def>
%\fi
% \section{File \texttt{plain-xetex-bidi.def}}
%    \begin{macrocode}
\def\TeXXeTOn{\TeXXeTstate=1 }
\def\TeXXeTOff{\TeXXeTstate=0 }
\TeXXeTOn
\def\usebox#1{\leavevmode\copy #1\relax}
\def\bidi@RTL@everypar{{\setbox\z@\lastbox\if@RTL\beginR\else\beginL\fi\ifvoid\z@\else\usebox\z@\fi}}
   \let\bidi@o@everypar=\everypar
   \newtoks\bidi@n@everypar
   \bidi@n@everypar\expandafter{\the\bidi@o@everypar}
   \bidi@o@everypar{\bidi@RTL@everypar\the\bidi@n@everypar}
   \let\everypar=\bidi@n@everypar
\def\moreLRE{\bracetext \aftergroup\endL \beginL\@RTLfalse}
\def\moreRLE{\bracetext \aftergroup\endR \beginR\@RTLtrue}
\protected\def\hboxR{\hbox\bgroup
 \everyhbox{%
  \aftergroup\egroup
  \everyhbox{}%
  \beginR
  \@hboxRconstructtrue
  \bgroup
  \aftergroup\endR
  \aftergroup\egroup
 }\hbox}
\protected\def\hboxL{\hbox\bgroup
 \everyhbox{%
  \aftergroup\egroup
  \everyhbox{}%
  \beginL
  \@hboxRconstructfalse
  \bgroup
  \aftergroup\endL
  \aftergroup\egroup
 }\hbox}
\protected\def\vboxR{\vbox\bgroup
 \everyvbox{%
  \aftergroup\egroup
  \everyvbox{}%
  \@RTLtrue
  \bgroup
  \aftergroup\egroup
 }\vbox}
\protected\def\vboxL{\vbox\bgroup
 \everyvbox{%
  \aftergroup\egroup
  \everyvbox{}%
  \@RTLfalse
  \bgroup
  \aftergroup\egroup
 }\vbox}
\def\LTR{\par\@RTLfalse\@RTL@footnotefalse\hsize\linewidth\parshape\z@}
\def\endLTR{\par}
\def\RTL{\par\@RTLtrue\@RTL@footnotetrue\hsize\linewidth\parshape\z@}
\def\endRTL{\par}
\def\setRTL{\@RTLtrue\@RTL@footnotetrue}
\def\setLTR{\@RTLfalse\@RTL@footnotefalse}
\let\unsetRTL=\setLTR
\let\unsetLTR=\setRTL
\let\LR=\LRE
\let\RL=\RLE
\def\@ensure@RTL#1{\if@RTL#1\else\RLE{#1}\fi}
\def\@ensure@LTR#1{\if@RTL\LRE{#1}\else#1\fi}
\let\@ensure@RL=\@ensure@RTL
\let\@ensure@LR=\@ensure@LTR
\def\@ensure@dir#1{\if@RTL\RLE{#1}\else{#1}\fi}
\let\@ensure@maindir=\@ensure@dir
\def\@@RTL{RTL}
\def\@@LTR{LTR}
\def\save@dir{\if@RTL\gdef\saved@@dir{RTL}\else\gdef\saved@@dir{LTR}\fi}
\def\reset@dir{\ifx\saved@@dir\@@RTL\setRTL\else\ifx\saved@@dir\@@LTR\setLTR\else\relax\fi\fi}
\let\@@TeX\TeX
\def\TeX{\@ensure@LTR{\@@TeX}}
\def\pagecontents{\ifvoid\topins\else\unvbox\topins\fi
  \dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
  \ifvoid\footins\else % footnote info is present
    \vskip\skip\footins
    \footnoterule
    \unvbox\footins\fi
  \ifr@ggedbottom \kern-\dimen@ \vfil \fi
  \ifvoid\@bidi@copyins@
  \else
    \vskip\skip\@bidi@copyins@
    \unvbox\@bidi@copyins@
  \fi
}
\long\def\bidi@reflect@box#1{%
  \leavevmode
  \setbox\z@\hbox{{#1}}%
  \setbox\tw@\hbox{\special{x:gsave}\special{x:scale -1 1}\rlap{\copy\z@}\special{x:grestore}}%
  \hbox to \wd\z@{\kern\wd\z@\box\tw@\hss}%
}
\def\XeTeX{\LR{\leavevmode$\smash{\hbox{X\lower.5ex
  \hbox{\kern-.125em\bidi@reflect@box{E}}\kern-.1667em \TeX}}$}}
\let\setRL=\setRTL
\let\setLR=\setLTR
\let\unsetRL=\setLTR
\let\bidi@saved@eqno=\eqno
\let\bidi@saved@leqno=\leqno
\def\eqno{\ifnum\predisplaydirection<\z@ \bidi@saved@leqno \else \bidi@saved@eqno \fi}
\def\leqno{\ifnum\predisplaydirection<\z@ \bidi@saved@eqno \else \bidi@saved@leqno \fi}
\def\centerline#1{\line{\hss\if@RTL\beginR\fi#1\if@RTL\endR\fi\hss}}
\def\leftline#1{\line{\if@RTL\beginR\fi#1\if@RTL\endR\fi\hss}}
\def\rightline#1{\line{\hss\if@RTL\beginR\fi#1\if@RTL\endR\fi}}
%    \end{macrocode}
% \iffalse
%</plain-xetex-bidi.def>
%<*pstricks-xetex-bidi.def>
%\fi
% \section{File \texttt{pstricks-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{pstricks-xetex-bidi.def}[2025/01/08 v0.7 bidi adaptations for pstricks package for XeTeX engine]
\bidi@patchcmd\pspicture\begingroup{%
  \begingroup
    \ifmmode
    \else
      \@RTLfalse
      \beginL
    \fi
}{}{\bidi@warningnoline{Oops! patching `\string\pspicture' failed}}

\bidi@patchcmd\endpspicture{%
  \endgroup
  \psset[pstricks]{shift=0}% reset value
}{%
  \ifmmode
  \else
    \endL
  \fi
  \endgroup
  \psset[pstricks]{shift=0}% reset value
}{}{\bidi@warningnoline{Oops! patching `\string\endpspicture' failed}}

\bidi@patchcmd\@@scalebox{%
  \special{x: bscale \pst@tempc \pst@tempd}%
  \hbox to \z@{\box\pst@hbox\hss}%
  \special{x: escale}%
}{%
  \if@RTL
    \special{x: escale}%
  \else
    \special{x: bscale \pst@tempc \pst@tempd}%
  \fi
  \hbox to \z@{\box\pst@hbox\hss}%
  \if@RTL
    \special{x: bscale \pst@tempc \pst@tempd}%
  \else
    \special{x: escale}%
  \fi
}{}{\bidi@warningnoline{Oops! patching `\string\@@scalebox' failed}}
\let\ps@@scalebox\@@scalebox

%    \end{macrocode}
% \iffalse
%</pstricks-xetex-bidi.def>
%<*quotchap-xetex-bidi.def>
%\fi
% \section{File \texttt{quotchap-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{quotchap-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for quotchap package for XeTeX engine]
\renewcommand{\qauthor}[1]{%
  \par\smallskip
  {\if@RTL\raggedright\else\raggedleft\fi\upshape #1\qquad\hbox{}\par}\bigskip}
\renewcommand{\@makechapterhead}[1]{\chapterheadstartvskip%
  {\size@chapter{\sectfont\if@RTL\raggedright\else\raggedleft\fi
      {\chapnumfont
        \ifnum \c@secnumdepth >\m@ne%
        \if@mainmatter\thechapter%
        \fi\fi
        \par\nobreak}%
      {\if@RTL\raggedright\else\raggedleft\fi\advance\if@RTL\rightmargin\else\leftmargin\fi10em\interlinepenalty\@M #1\par}}
    \nobreak\chapterheadendvskip}}
\renewcommand*{\@iprintcites}{%
  \vbox to\z@{\leavevmode\copy\@quotebox\vss}
  \global\let\@printcites\relax}
%    \end{macrocode}
% \iffalse
%</quotchap-xetex-bidi.def>
%<*ragged2e-xetex-bidi.def>
%\fi
% \section{File \texttt{ragged2e-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{ragged2e-xetex-bidi.def}[2018/10/17 v0.3 bidi adaptations for ragged2e package for XeTeX engine]
\renewcommand{\Centering}{%
   \ifx\\\@raggedtwoe@savedcr
      \let\\\@centercr
   \fi
   \let\@gnewline\@raggedtwoe@gnewline
   \if@RTL\rightskip\else\leftskip\fi\CenteringLeftskip
   \@rightskip\CenteringRightskip
   \if@RTL\leftskip\else\rightskip\fi\@rightskip
   \parfillskip\CenteringParfillskip
   \parindent\CenteringParindent
   \@raggedtwoe@spaceskiptrue
   \@raggedtwoe@everyselectfont
   }
\renewcommand{\RaggedLeft}{%
   \ifx\\\@raggedtwoe@savedcr
      \let\\\@centercr
   \fi
   \let\@gnewline\@raggedtwoe@gnewline
   \if@RTL\rightskip\else\leftskip\fi\RaggedLeftLeftskip
   \@rightskip\RaggedLeftRightskip
   \if@RTL\leftskip\else\rightskip\fi\@rightskip
   \parfillskip\RaggedLeftParfillskip
   \parindent\RaggedLeftParindent
   \@raggedtwoe@spaceskiptrue
   \@raggedtwoe@everyselectfont
   }
\renewcommand{\RaggedRight}{%
   \ifx\\\@raggedtwoe@savedcr
      \let\\\@centercr
   \fi
   \let\@gnewline\@raggedtwoe@gnewline
   \if@RTL\rightskip\else\leftskip\fi\RaggedRightLeftskip
   \@rightskip\RaggedRightRightskip
   \if@RTL\leftskip\else\rightskip\fi\@rightskip
   \parfillskip\RaggedRightParfillskip
   \parindent\RaggedRightParindent
   \@raggedtwoe@spaceskiptrue
   \@raggedtwoe@everyselectfont
   }
\renewcommand{\justifying}{%
   \let\\\@raggedtwoe@savedcr
   \let\@gnewline\@raggedtwoe@saved@gnewline
   \if@RTL\rightskip\else\leftskip\fi\z@
   \@rightskip\z@
   \if@RTL\leftskip\else\rightskip\fi\@rightskip
   \parfillskip\JustifyingParfillskip
   \parindent\JustifyingParindent
   \@raggedtwoe@spaceskipfalse
   \@raggedtwoe@everyselectfont
   }
\def\@raggedtwoe@raggedrightboxes@opt{%
  \renewcommand{\@arrayparboxrestore}{%
    \let\if@nobreak\iffalse
    \let\if@noskipsec\iffalse
    \let\par\@@par
    \let\-\@dischyph
    \let\'\@acci\let\`\@accii\let\=\@acciii
    \parskip\z@skip
    \everypar{}%
    \linewidth\hsize
    \@totalleftmargin\z@
    \if@RTL
      \RaggedLeft
    \else
      \RaggedRight
    \fi
    \lineskip\normallineskip
    \baselineskip\normalbaselineskip
    \sloppy}%
  \let\@raggedtwoe@raggedrightboxes@opt\relax
  }
\def\@raggedtwoe@document@opt{%
  \AtBeginDocument{\@raggedtwoe@abdhook}%
  \@raggedtwoe@raggedrightboxes@opt
  \@raggedtwoe@footmisctrue
  \let\@raggedtwoe@document@opt\relax
  }
\def\@raggedtwoe@abdhook{%
  \PackageInfo{ragged2e}{ABD: executing `\string\RaggedLeft' for
    right to left documents and `\string\RaggedRight' for left
    to right documents}%
  \if@RTL
    \RaggedLeft
  \else
    \RaggedRight
  \fi
  \@ifundefined{@tocrmarg}{}{\edef\@tocrmarg{\@tocrmarg plus 2em}}%
  \let\@raggedtwoe@abdhook\relax
  }
\@ifpackagewith{ragged2e}{raggedrightboxes}{%
  \@raggedtwoe@raggedrightboxes@opt
}{}
\@ifpackagewith{ragged2e}{document}{%
  \@raggedtwoe@document@opt
}{}
\let\origin@RaggedLeft=\RaggedLeft
\let\origin@RaggedRight=\RaggedRight
\def\RaggedLeft{\if@RTL\origin@RaggedRight\else\origin@RaggedLeft\fi}
\def\RaggedRight{\if@RTL\origin@RaggedLeft\else\origin@RaggedRight\fi}
%    \end{macrocode}
% \iffalse
%</ragged2e-xetex-bidi.def>
%<*rapport1-xetex-bidi.def>
%\fi
% \section{File \texttt{rapport1-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{rapport1-xetex-bidi.def}[2025/09/30 v0.5 bidi adaptations for rapport1 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\@makeschapterhead{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\if@titlepage
  \renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont\abstractname}%
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\else
  \renewenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \bgroup\if@RTL\leftskip\else\rightskip\fi=\unitindent
        \section*{\small\SectFont\abstractname}%
        \noindent\ignorespaces
      \fi}
      {\if@twocolumn\else\par\egroup\fi}
\fi
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty{-\@highpenalty}%
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\if@oldtoc
\renewcommand*\l@chapter[2]{%
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \penalty\@highpenalty
   \endgroup}
\else
  \renewcommand*\l@chapter{\@regtocline{0}}
\fi
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
       \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewcommand*\thesection{\thechapter\@SepMark\@arabic\c@section}
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand*\theequation{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi\@arabic\c@equation}
\renewcommand*\thefigure{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@figure}
\renewcommand*\thetable{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@table}
\if@titlepage
\renewcommand*\TitleFont{\rmfamily}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\uc@nothanks#1\thanks{\uppercase{#1}\futurelet\@tempa\uc@tx}
\def\uc@authornothanks#1\and{\uc@nothanks#1\thanks\relax
    \futurelet\@tempa\uc@ax}
\def\uc@ax{%
  \ifx\@tempa\relax
  \else
    \\ \andname \\ \expandafter\uc@authornothanks
  \fi}
\def\uc@tx{\ifx\@tempa\relax
    \else \expandafter\uc@ty \fi}
\def\uc@ty#1{\thanks{#1}\uc@nothanks}
\else
\renewcommand*\maketitle{\par
  \begingroup
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext{\@xmakefntext{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
    \let \footnote \thanks
    {\LARGE \TitleFont \@title \par}%
    \vskip 1.5em%
    {\large \TitleFont
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \TitleFont \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
%    \end{macrocode}
% \iffalse
%</rapport1-xetex-bidi.def>
%<*rapport3-xetex-bidi.def>
%\fi
% \section{File \texttt{rapport3-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{rapport3-xetex-bidi.def}[2025/09/30 v0.7 bidi adaptations for rapport3 class for XeTeX engine]
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \columnseprule \z@
  \columnsep 35\p@
  \twocolumn[\@makeschapterhead{\indexname}]%
  \@mkboth{\MakeUppercase{\indexname}}{\MakeUppercase{\indexname}}%
  \thispagestyle{plain}\parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem
  }{%
  \if@restonecol\onecolumn\else\clearpage\fi}
\if@titlepage
\renewcommand*\TitleFont{\rmfamily}
\renewcommand*\maketitle{%
  \begin{titlepage}%
    \let\footnotesize\small
    \let\right@footnoterule\relax
    \let\left@footnoterule\relax
    \let\textwidth@footnoterule\relax
    \let \footnote \thanks
    \let \LTRfootnote \LTRthanks
    \let \RTLfootnote \RTLthanks
    \long\def\@makefntext##1{\parindent\z@
         \def\labelitemi{\textendash}\@revlabeltrue
         \leavevmode\@textsuperscript{\@thefnmark}\kern1em\relax ##1}
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \if@compatibility\setcounter{page}{0}\fi
    \null\vfil
    \vskip 60\p@
    \begin{center}%
      \TitleFont
      {\LARGE \def\\{\penalty -\@M}
        \if@allcaps
          \expandafter\uc@nothanks\@title\thanks\relax
        \else
          \@title
        \fi\par}%
      \vskip 3em%
      {\large
        \lineskip .75em \parindent\z@
        \begin{tabular}[t]{c}%
          \if@allcaps
            \expandafter\uc@authornothanks\@author\and\relax
          \else
            \@author
          \fi
        \end{tabular}\par}%
      \vskip 1.5em%
      {\large
        \if@allcaps
          \uppercase\expandafter{\@date}%
        \else
          \@date
        \fi\par}%
      \end{center}\par
    \@thanks
    \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\uc@nothanks#1\thanks{\uppercase{#1}\futurelet\@tempa\uc@tx}
\def\uc@authornothanks#1\and{\uc@nothanks#1\thanks\relax
    \futurelet\@tempa\uc@ax}
\def\uc@ax{%
  \ifx\@tempa\relax
  \else
    \\ \andname \\ \expandafter\uc@authornothanks
  \fi}
\def\uc@tx{\ifx\@tempa\relax
    \else \expandafter\uc@ty \fi}
\def\uc@ty#1{\thanks{#1}\uc@nothanks}
\else
\renewcommand*\maketitle{\par
  \begingroup
    \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext{\@xmakefntext{%
      \@textsuperscript{\normalfont\@thefnmark}}}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@title\@empty
  \global\let\@date\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
\if@titlecentered
  \begin{center}%
    \let \footnote \thanks
    \let \LTRfootnote \LTRthanks
    \let \RTLfootnote \RTLthanks
    {\LARGE \TitleFont \@title \par}%
    \vskip 1.5em%
    {\large \TitleFont
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \TitleFont \@date}%
  \end{center}%
 \else
     {\LARGE \TitleFont \head@style \@title \par} \vskip 1.5em
     {\large \TitleFont \lineskip .5em \tabcolsep\z@
             \def\and{%%% \begin{tabular} has already started
                      \end{tabular}\hskip 1em plus .17fil
                      \if@RTL\begin{tabular}[t]{r}\else\begin{tabular}[t]{l}\fi}%% \end{tabular} will come
             \if@RTL\begin{tabular}[t]{r}\else\begin{tabular}[t]{l}\fi\@author\end{tabular}\par}
     \vskip 1em {\large \TitleFont \@date}
 \fi
  \par
  \vskip 1.5em}
\fi
\renewcommand*\@regtocline[3]{%
  \ifnum #1>\c@tocdepth
  \else
    \vskip\z@\@plus.2\p@
    {\hangindent\z@ \@afterindenttrue \interlinepenalty\@M
     \if@RTL\rightskip\else\leftskip\fi\unitindent
     \if@RTL\leftskip\else\rightskip\fi\unitindent\@plus 1fil
     \parfillskip\z@
     \@tempdima\unitindent
     \parindent\z@
     \leavevmode
     \hbox{}\hskip -\if@RTL\rightskip\else\leftskip\fi\relax#2\nobreak
     \hskip 1em \nobreak{\slshape #3}\par
     }%
  \fi}
\if@oldtoc
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \setlength\@tempdima{3em}%
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
        \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
        \nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\else
   \renewcommand*\l@part{%
     \ifnum \c@tocdepth >-2\relax
     \addpenalty{-\@highpenalty}%
     \addvspace{2.25em \@plus \p@}%
     \@regtocline{0}%
   \fi}
\fi
\if@oldtoc
\renewcommand*\l@chapter[2]{%
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \penalty\@highpenalty
   \endgroup}
\else
  \renewcommand*\l@chapter{\@regtocline{0}}
\fi
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
\if@titlepage
  \renewenvironment{abstract}{%
      \titlepage
      \null\vfil
      \section*{\SectFont\abstractname}%
      \noindent\ignorespaces}
     {\par\vfil\null\endtitlepage}
\else
  \renewenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \bgroup\if@RTL\leftskip\else\rightskip\fi=\unitindent
        \section*{\small\SectFont\abstractname}%
        \noindent\ignorespaces
      \fi}
      {\if@twocolumn\else\par\egroup\fi}
\fi
\renewcommand*\thesection{\thechapter\@SepMark\@arabic\c@section}
\renewcommand*\thesubsection{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*\thesubsubsection{\thesubsection\@SepMark\@arabic\c@subsubsection}
\renewcommand*\theparagraph{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*\thesubparagraph{\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewcommand*\thefigure{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@figure}
\renewcommand*\thetable{%
  \ifnum\c@chapter>\z@\thechapter\@SepMark\fi\@arabic\c@table}
\renewcommand*\theequation{%
  \ifnum \c@chapter>\z@ \thechapter\@SepMark\fi\@arabic\c@equation}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
       \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand*\theenumiv{\@arabic\c@enumiv}}%
      \sloppy\clubpenalty4000\widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\renewcommand*\left@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \hrule\@width\unitindent
  \kern.4\baselineskip
}
\renewcommand*\right@footnoterule{%
  \kern-3\p@
  \kern.5\baselineskip
  \nointerlineskip
  \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\unitindent\relax \hrulefill }
  \kern.4\baselineskip}
\renewcommand*\head@style{%
    \interlinepenalty \@M
    \hyphenpenalty=\@M \exhyphenpenalty=\@M
    \if@RTL\leftskip\else\rightskip\fi=0cm plus .7\hsize\relax}
%    \end{macrocode}
% \iffalse
%</rapport3-xetex-bidi.def>
%<*refrep-xetex-bidi.def>
%\fi
% \section{File \texttt{refrep-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{refrep-xetex-bidi.def}[2025/09/30 v0.6 bidi adaptations for refrep class for XeTeX engine]
\if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let\footnote\thanks
  \let\LTRfootnote\LTRthanks
  \let\RTLfootnote\RTLthanks
  \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
  \def\@makefnmark%
      {\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
  \long\def\@makefntext##1{%
       \@setpar{\@@par
          \@tempdima = \hsize
          \advance\@tempdima -1em
          \parshape \@ne 1em \@tempdima}%
       \par\parindent 1em \noindent
       \hb@xt@\z@{\hss\@textsuperscript{\normalfont\@thefnmark}\,}##1}
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  }
\else
  \renewcommand\maketitle{\par
    \begingroup
      \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
      \def\@makefnmark%
          {\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
      \long\def\@makefntext##1{%
         \@setpar{\@@par
            \@tempdima = \hsize
            \advance\@tempdima -1em
            \parshape \@ne 1em \@tempdima}%
         \par\parindent 1em \noindent
         \hb@xt@\z@{\hss\@textsuperscript{\normalfont\@thefnmark}\,}##1}
      \if@twocolumn
        \ifnum \col@number=\@ne
          \@maketitle
        \else
          \twocolumn[\@maketitle]%
        \fi
      \else
        \newpage
        \global\@topnum\z@   % Prevents figures from going at top of page.
        \@maketitle
      \fi
      \thispagestyle{empty}\@thanks
    \endgroup
    \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
  \def\@maketitle{%
    \newpage
    \null
    \longthickrule\vskip1.5em%
    \let \footnote \thanks
    \let \LTRfootnote \LTRthanks
    \let \RTLfootnote \RTLthanks
    {\secshape \parskip\z@ \parindent\z@
    \Large\bfseries \@title \par}%
    \vskip1.5em\longthickrule\vskip1.5em%
    {\normalsize
      \lineskip .5em%
      \begin{flushright}%
        {\slshape\@author\par}
        \vskip 1em%
        {\@date}%
      \end{flushright}\par}%
    \vskip 1.5em}
\fi
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hbox to\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
      \endgroup
  \fi}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
    \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
    \parfillskip -\@pnumwidth
    \leavevmode \bfseries
    \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
    \hskip -\if@RTL\rightskip\else\leftskip\fi
    #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \penalty\@highpenalty
   \endgroup
  \fi}
\renewcommand\secshape{\if@RTL\rightskip\else\leftskip\fi=-\leftmarginwidth%
                     \if@RTL\leftskip\else\rightskip\fi=\@flushglue%
                     \hyphenpenalty=2000}
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern 2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\renewcommand\theequation
{\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand\thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand\thetable%
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand\thesection       {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection    {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection {\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph     {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph  {\theparagraph\@SepMark\@arabic\c@subparagraph}
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname
         \@mkboth{\bibname}{\bibname}}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
            \sloppy
            \clubpenalty4000
            \@clubpenalty \clubpenalty
            \widowpenalty4000%
      \sfcode`\.=\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
%    \end{macrocode}
% \iffalse
%</refrep-xetex-bidi.def>
%<*report-xetex-bidi.def>
%\fi
% \section{File \texttt{report-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{report-xetex-bidi.def}[2025/09/30 v1.1 bidi adaptations for standard report class for XeTeX engine]
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \columnseprule \z@
                \columnsep 35\p@
                \twocolumn[\@makeschapterhead{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem}
               {\if@restonecol\onecolumn\else\clearpage\fi}
  \if@titlepage
  \renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\right@footnoterule\relax
  \let\left@footnoterule\relax
  \let\textwidth@footnoterule\relax
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\else
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\LTRthanks\relax
  \global\let\RTLthanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
  \let \LTRfootnote \LTRthanks
  \let \RTLfootnote \RTLthanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\fi
\IfPackageLoadedF{tocloft}{%
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \if@RTL\leftskip\else\rightskip\fi \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima
      \hskip -\if@RTL\rightskip\else\leftskip\fi
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
}
\renewcommand\left@footnoterule{%
  \kern-3\p@
  \hrule\@width.4\columnwidth
  \kern2.6\p@}
\renewcommand\right@footnoterule{%
  \kern-3\p@
  \nointerlineskip
  \hbox to \columnwidth{\hskip .6\columnwidth \hrulefill }
  \kern2.6\p@}
\renewcommand\theequation
  {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@equation}
\renewcommand \thefigure
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@figure}
\renewcommand \thetable
     {\ifnum \c@chapter>\z@ \thechapter\@SepMark\fi \@arabic\c@table}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand \thesection {\thechapter\@SepMark\@arabic\c@section}
\renewcommand\thesubsection   {\thesection\@SepMark\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection \@SepMark\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand\thesubparagraph {\theparagraph\@SepMark\@arabic\c@subparagraph}
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \if@RTL\raggedleft\else\raggedright\fi
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}
\IfPackageLoadedF{natbib}{%
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
      \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
      \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
      \bidi@@thebibliography@font@hook%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
}
%    \end{macrocode}
% \iffalse
%</report-xetex-bidi.def>
%<*rotating-xetex-bidi.def>
%\fi
% \section{File \texttt{rotating-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{rotating-xetex-bidi.def}[2013/05/22 v0.2 bidi adaptations for rotating package for XeTeX engine]
\def\end@rotfloat{%
   \end{minipage}\end{lrbox}%
   \stepcounter{r@tfl@t}%
   \rot@label{RF\ther@tfl@t}%
   \rot@pageref{RF\ther@tfl@t}{\R@@page}%
   \edef\@tempa{Adding sideways \@captype\space on page \R@@page\space}
   \rot@mess@toks\expandafter{\@tempa}
   \wd\rot@float@box\z@
   \ht\rot@float@box\z@
   \dp\rot@float@box\z@
   \vboxL to \textheight{%
    \setkeys{Grot}{units=360}%
    \if@rot@twoside
    \else
      \let\R@@page\rot@LR
    \fi
    \ifthenelse{\isodd{\R@@page}}{%
      \if@rot@twoside
        \rot@mess@toks\expandafter{\the\rot@mess@toks (right hand page)}%
      \fi
      \vfill
      \@@line{%
        \hskip\rotFPtop
        \rotatebox{90}{\box\rot@float@box}%
        \hskip\rotFPbot
      }%
    }{%
      \if@rot@twoside
        \rot@mess@toks\expandafter{\the\rot@mess@toks (left hand page)}%
      \fi
      \@@line{%
        \hskip\rotFPbot
        \rotatebox{-90}{\box\rot@float@box}%
        \hskip\rotFPtop
      }%
      \vfill
    }%
    \rot@message{\the\rot@mess@toks}
  }%
  \end@float
}
\let\endsidewaysfigure\end@rotfloat
\let\endsidewaystable\end@rotfloat
\def\end@rotdblfloat{%
  \end{minipage}\end{lrbox}%
  \stepcounter{r@tfl@t}%
  \rot@label{RF\ther@tfl@t}%
  \rot@pageref{RF\ther@tfl@t}{\R@@page}%
  \edef\@tempa{Adding sideways \@captype\space on page \R@@page\space}
  \rot@mess@toks\expandafter{\@tempa}
  \@tempdima\ht\rot@float@box
  \advance\@tempdima by \dp\rot@float@box
  \wd\rot@float@box\z@
  \ht\rot@float@box\z@
  \dp\rot@float@box\z@
  \vboxL to \textheight{%
    \setkeys{Grot}{units=360}%
    \if@rot@twoside
    \else
      \let\R@@page\rot@LR
    \fi
    \ifthenelse{\isodd{\R@@page}}{%
      \ifrot@messages
        \if@rot@twoside
  \rot@mess@toks\expandafter{\the\rot@mess@toks (right hand page)}%
\fi
      \fi
      \vfill
      \@@line{%
        \hskip\rotFPtop
        \rotatebox{90}{\box\rot@float@box}%
        \hskip\rotFPbot
      }%
    }{%
      \ifrot@messages
        \if@rot@twoside
  \rot@mess@toks\expandafter{\the\rot@mess@toks (left hand page)}%
\fi
      \fi%
      \@@line{%
        \hskip\rotFPbot
        \rotatebox{-90}{\box\rot@float@box}%
        \hskip\rotFPtop
      }%
      \vfill
    }%
    \rot@message{\the\rot@mess@toks}%
  }%
  \end@dblfloat
}
\def\turn#1{%
  \Grot@setangle{#1}%
  \setbox\z@\color@hbox\ifmmode\if@RTL\beginR\fi\else\if@RTL\beginR\fi\fi\ignorespaces}
\def\endturn{%
  \ifmmode\if@RTL\endR\fi\else\if@RTL\endR\fi\fi
  \unskip\color@endbox
  \Grot@x\z@
  \Grot@y\z@
  \ifmmode\else\if@RTL\beginL\fi\fi\Grot@box\ifmmode\else\if@RTL\endL\fi\fi
}
\def\rotate#1{%
  \Grot@setangle{#1}%
  \setbox\z@\color@hbox\ifmmode\if@RTL\beginR\fi\else\if@RTL\beginR\fi\fi\ignorespaces}
\def\endrotate{%
 \ifmmode\if@RTL\endR\fi\else\if@RTL\endR\fi\fi
  \unskip\color@endbox
  \Grot@x\z@
  \Grot@y\z@
  \wd0\z@\dp0\z@\ht0\z@
  \ifmmode\else\if@RTL\beginL\fi\fi\Grot@box\ifmmode\else\if@RTL\endL\fi\fi
}
\def\turnbox#1#2{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{\ifmmode\if@RTL\beginR\fi\else\if@RTL\beginR\fi\fi#2\ifmmode\if@RTL\endR\fi\else\if@RTL\endR\fi\fi}}%
  \Grot@x\z@\Grot@y\z@
  \wd0\z@\dp0\z@\ht0\z@
  \ifmmode\else\if@RTL\beginL\fi\fi\Grot@box\ifmmode\else\if@RTL\endL\fi\fi
}
\def\sideways{%
  \Grot@setangle{90}%
  \setbox\z@\color@hbox\ifmmode\if@RTL\beginR\fi\else\if@RTL\beginR\fi\fi\ignorespaces}
\def\endsideways{%
 \ifmmode\if@RTL\endR\fi\else\if@RTL\endR\fi\fi
  \unskip\color@endbox
  \Grot@x\z@
  \Grot@y\z@
  \ifmmode\else\if@RTL\beginL\fi\fi\Grot@box\ifmmode\else\if@RTL\endL\fi\fi
}
%    \end{macrocode}
% \iffalse
%</rotating-xetex-bidi.def>
%<*scrartcl-xetex-bidi.def>
%\fi
% \section{File \texttt{scrartcl-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{scrartcl-xetex-bidi.def}[2025/09/30 v1.5 bidi adaptations for scrartcl class for XeTeX engine]
\newcommand{\scr@saved@LTRfootnotetext}{}
\newcommand{\scr@saved@RTLfootnotetext}{}
\let\scr@saved@footnotetext\@footnotetext
\let\scr@saved@LTRfootnotetext\@LTRfootnotetext
\let\scr@saved@RTLfootnotetext\@RTLfootnotetext
\renewcommand{\@footnotetext}[1]{%
  \scr@saved@footnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@LTRfootnotetext}[1]{%
  \scr@saved@LTRfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@RTLfootnotetext}[1]{%
  \scr@saved@RTLfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand\deffootnote[4][]{%
  \expandafter\ifnum\scr@v@is@ge{3.22}\relax
    \long\def\@makefntext##1{%
      \ExecuteDoHook{footnote/text/begin}%
      \raggedfootnote
      \if@RTL
        \rightskip
      \else
        \leftskip 
      \fi 
      #2
      \l@addto@macro\@trivlist{%
        \ifnum\@listdepth=\@ne
          \if@RTL
            \advance\rightmargin #2\relax
          \else
            \advance\leftmargin #2\relax
          \fi
        \fi
      }%
      \parindent #3\noindent
      \IfArgIsEmpty{#1}{}{%
        \hskip \dimexpr #1-#2\relax
      }%
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
      \ExecuteDoHook{footnote/text/end}%
    }%
  \else
    \ClassInfo{\KOMAClassName}{%
      Using old \string\@makefntext\space due to compatibility
      level\MessageBreak
      less than 3.22}%
    \long\def\@makefntext##1{%
      \setlength{\@tempdimc}{#3}%
      \def\@tempa{#1}\ifx\@tempa\@empty
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#2}%
          \if@RTL
            \parshape \@ne \z@ \@tempdima
          \else
            \parshape \@ne #2 \@tempdima
          \fi}%
      \else
        \addtolength{\@tempdimc}{#2}%
        \addtolength{\@tempdimc}{-#1}%
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#1}%
          \@tempdimb = \hsize
          \addtolength{\@tempdimb}{-#2}%
           \if@RTL
             \parshape \tw@ \z@ \@tempdima \z@ \@tempdimb
           \else
             \parshape \tw@ #1 \@tempdima #2 \@tempdimb
           \fi
        }%
      \fi
      \par
      \parindent\@tempdimc\noindent
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
    }%
  \fi
  \def\@@makefnmark{\hbox{\ftnm@font{#4}}}%
}
\deffootnote[1em]{1.5em}{1em}{\textsuperscript{\thefootnotemark}}
\renewcommand*\left@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  {\usekomafont{footnoterule}{%
      \hrule \@height\ftn@rule@height \@width\ftn@rule@width}}%
  \kern 2.6\p@}
\renewcommand*\right@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  \nointerlineskip
  {\usekomafont{footnoterule}{%
      \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\ftn@rule@width\relax  \leavevmode\leaders\hrule\@height\ftn@rule@height\hfill\kern\z@}}}%
  \kern 2.6\p@} 
\renewcommand*\maketitle[1][1]{%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
  \else
    \def\and{%
      \end{tabular}%
      \hskip 1em \@plus.17fil%
      \begin{tabular}[t]{c}%
    }%
  \fi
  \if@titlepage
    \begin{titlepage}
      \setcounter{page}{%
        #1%
      }%
      \if@titlepageiscoverpage
        \edef\titlepage@restore{%
          \noexpand\endgroup
          \noexpand\global\noexpand\@colht\the\@colht
          \noexpand\global\noexpand\@colroom\the\@colroom
          \noexpand\global\vsize\the\vsize
          \noexpand\global\noexpand\@titlepageiscoverpagefalse
          \noexpand\let\noexpand\titlepage@restore\noexpand\relax
        }%
        \begingroup
        \topmargin=\dimexpr \coverpagetopmargin-1in\relax
        \oddsidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \evensidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \textwidth=\dimexpr
        \paperwidth-\coverpageleftmargin-\coverpagerightmargin\relax
        \textheight=\dimexpr
        \paperheight-\coverpagetopmargin-\coverpagebottommargin\relax
        \headheight=0pt
        \headsep=0pt
        \footskip=\baselineskip
        \@colht=\textheight
        \@colroom=\textheight
        \vsize=\textheight
        \columnwidth=\textwidth
        \hsize=\columnwidth
        \linewidth=\hsize
      \else
        \let\titlepage@restore\relax
      \fi
      \let\footnotesize\small
      \let\right@footnoterule\relax
      \let\left@footnoterule\relax
      \let\textwidth@footnoterule\relax
      \let\footnote\thanks
      \let\LTRfootnote\LTRthanks
      \let\RTLfootnote\RTLthanks
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \ifx\@extratitle\@empty
        \ifx\@frontispiece\@empty
        \else
          \if@twoside\mbox{}\next@tpage\fi
          \noindent\@frontispiece\next@tdpage
        \fi
      \else
        \noindent\@extratitle
        \ifx\@frontispiece\@empty
        \else
          \next@tpage
          \noindent\@frontispiece
        \fi
        \next@tdpage
      \fi
      \setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
      \ifx\@titlehead\@empty \else
        \begin{minipage}[t]{\textwidth}%
          \usekomafont{titlehead}{\@titlehead\par}%
        \end{minipage}\par
      \fi
      \null\vfill
      \begin{center}
        \ifx\@subject\@empty \else
          {\usekomafont{subject}{\@subject\par}}%
          \vskip 3em
        \fi
        {\usekomafont{title}{\huge \@title\par}}%
        \vskip 1em
        {\ifx\@subtitle\@empty\else\usekomafont{subtitle}{\@subtitle\par}\fi}%
        \vskip 2em
        {%
          \usekomafont{author}{%
            \lineskip 0.75em
            \begin{tabular}[t]{c}
              \@author
            \end{tabular}\par
          }%
        }%
        \vskip 1.5em
        {\usekomafont{date}{\@date \par}}%
        \vskip \z@ \@plus3fill
        {\usekomafont{publishers}{\@publishers \par}}%
        \vskip 3em
      \end{center}\par
      \@thanks\global\let\@thanks\@empty
      \vfill\null
      \if@twoside
        \@tempswatrue
        \expandafter\ifnum \@nameuse{scr@v@3.12}>\scr@compatibility\relax
        \else
          \ifx\@uppertitleback\@empty\ifx\@lowertitleback\@empty
            \@tempswafalse
          \fi\fi
        \fi
        \if@tempswa
          \next@tpage
          \begin{minipage}[t]{\textwidth}
            \@uppertitleback
          \end{minipage}\par
          \vfill
          \begin{minipage}[b]{\textwidth}
            \@lowertitleback
          \end{minipage}\par
          \@thanks\global\let\@thanks\@empty
        \fi
      \else
        \ifx\@uppertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\uppertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
        \ifx\@lowertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\lowertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
      \fi
      \ifx\@dedication\@empty
      \else
        \next@tdpage\null\vfill
        {\centering\usekomafont{dedication}{\@dedication \par}}%
        \vskip \z@ \@plus3fill
        \@thanks\global\let\@thanks\@empty
        \cleardoubleemptypage
      \fi
      \ifx\titlepage@restore\relax\else\clearpage\titlepage@restore\fi
    \end{titlepage}
  \else
    \par
    \@tempcnta=%
    #1%
    \relax\ifnum\@tempcnta=1\else
      \ClassWarning{\KOMAClassName}{%
        Optional argument of \string\maketitle\space ignored\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@uppertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\uppertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@lowertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\lowertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \begingroup
      \let\titlepage@restore\relax
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \next@tdpage
      \if@twocolumn
        \ifnum \col@number=\@ne
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \@makeextratitle
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \@makefrontispiece
            \next@tdpage
          \fi
          \@maketitle
        \else
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \twocolumn[\@makeextratitle]%
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \twocolumn[\@makefrontispiece]%
            \next@tdpage
          \fi
          \twocolumn[\@maketitle]%
        \fi
      \else
        \ifx\@extratitle\@empty
          \ifx\@frontispiece\@empty\else \mbox{}\fi
        \else
          \@makeextratitle
        \fi
        \ifx\@frontispiece\@empty
          \ifx\@extratitle\@empty\else\next@tdpage\fi
        \else
          \next@tpage
          \@makefrontispiece
          \next@tdpage
        \fi
        \@maketitle
      \fi
      \ifx\titlepagestyle\@empty\else\thispagestyle{\titlepagestyle}\fi
      \@thanks\global\let\@thanks\@empty
    \endgroup
  \fi
  \setcounter{footnote}{0}%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
    \let\thanks\relax
    \let\LTRthanks\relax
    \let\RTLthanks\relax
    \let\maketitle\relax
    \let\@maketitle\relax
    \global\let\@thanks\@empty
    \global\let\@author\@empty
    \global\let\@date\@empty
    \global\let\@title\@empty
    \global\let\@subtitle\@empty
    \global\let\@extratitle\@empty
    \global\let\@frontispiece\@empty
    \global\let\@titlehead\@empty
    \global\let\@subject\@empty
    \global\let\@publishers\@empty
    \global\let\@uppertitleback\@empty
    \global\let\@lowertitleback\@empty
    \global\let\@dedication\@empty
    \global\let\author\relax
    \global\let\title\relax
    \global\let\extratitle\relax
    \global\let\titlehead\relax
    \global\let\subject\relax
    \global\let\publishers\relax
    \global\let\uppertitleback\relax
    \global\let\lowertitleback\relax
    \global\let\dedication\relax
    \global\let\date\relax
  \fi
  \global\let\and\relax
}%
\def\raggedsection{\if@RTL\raggedleft\else\raggedright\fi}
\def\raggedpart{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*\autodot{\if@altsecnumformat\@SepMark\fi}
\renewcommand*{\thesubsection}{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*{\thesubsubsection}{%
  \thesubsection\@SepMark\@arabic\c@subsubsection
}
\renewcommand*{\theparagraph}{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*{\thesubparagraph}{%
  \theparagraph\@SepMark\@arabic\c@subparagraph
}
\renewenvironment{thebibliography}[1]{%
  \if@bib@break@
    \bib@beginhook
  \else
    \bib@heading
    \ifx\bibpreamble\relax\else\ifx\bibpreamble\@empty\else
        \noindent\bibpreamble\par\nobreak
    \fi\fi
    \bib@beginhook
    \bib@before@hook
  \fi
  \renewcommand{\BreakBibliography}[1]{%
    \@bib@break
    \end{thebibliography}%
    \begingroup ##1\endgroup
    \begin{thebibliography}{#1}
  }%
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook%
  \list{%
    \@biblabel{\@arabic\c@enumiv}%
  }{%
    \settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \if@bib@break@
      \edef\@tempa{%
        \noexpand\usecounter{enumiv}%
        \noexpand\setcounter{enumiv}{\the\c@enumiv}%
      }\@tempa
      \no@bib@break
    \else
      \usecounter{enumiv}%
    \fi
    \let\p@enumiv\@empty
    \renewcommand*\theenumiv{\@arabic\c@enumiv}%
  }%
  \sloppy\clubpenalty4000 \widowpenalty4000
  \sfcode`\.=\@m
}{%
  \if@bib@break@
    \def\@noitemerr{%
      \@latex@warning{%
        \string\BreakBibliography\space at begin of `thebibliography'
        environment\MessageBreak
        or following \string\BreakBibliography}%
    }%
  \else
    \def\@noitemerr{%
      \@latex@warning{%
        Empty `thebibliography' environment or
        \string\BreakBibliography\MessageBreak
        before end of `thebibliography' environment}%
    }%
  \fi
  \endlist
  \if@bib@break@
  \else
    \bib@after@hook
    \let\bib@before@hook\@empty
    \let\bib@after@hook\@empty
  \fi
  \bib@endhook
}
\renewcommand*{\raggeddictum}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand*{\raggeddictumtext}{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*{\raggeddictumauthor}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand\marginline[1]{%
  \marginpar[\if@RTL\raggedright\else\raggedleft\fi{#1}]{\if@RTL\raggedleft\else\raggedright\fi #1}%
}
\renewcommand{\@@makecaption}[3]{%
  \cap@margin
  \begingroup
    \ifonelinecaptions
      \def\stepcounter##1{\advance\value{##1}\@ne}%
      \let\refstepcounter\stepcounter
      \let\label\@gobble
      \let\@footnotetext=\@gobble
      \let\@LTRfootnotetext=\@gobble
      \let\@RTLfootnotetext=\@gobble
      \let\hypertarget\@gobbletwo
      \edef\@xnewline{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xnewline}%
      }%
      \edef\@xcentercr{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xcentercr}%
      }%
      \settowidth{\@tempdima}{\scr@@makesinglelinecaption{#1}{#2}{#3}}%
      \ifdim\@tempdima>\cap@width
        \aftergroup\scr@makemultilinecaption
      \else
        \aftergroup\scr@makesinglelinecaption
      \fi
    \else
      \aftergroup\scr@makemultilinecaption
    \fi
  \endgroup
  {#1}{#2}{#3}%
}
\renewcommand{\scr@makesinglelinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \if@RTL
          \beginR
        \fi
        \scr@@makesinglelinecaption{#1}{#2}{#3}%
        \if@RTL
          \endR
        \fi
        \cap@right
      }\par\kern\dp\strutbox%
    }%
  }\kern-\dp\strutbox
}
\renewcommand{\@makecaption}[2]{%
  \if@captionabove
    \vskip\belowcaptionskip
  \else
    \vskip\abovecaptionskip
  \fi
  \@@makecaption\@firstofone{#1}{#2}%
  \if@captionabove
    \vskip\abovecaptionskip
  \else
    \vskip\belowcaptionskip
  \fi
}

\renewcommand{\scr@@makesinglelinecaption}[3]{%
    {\usekomafont{caption}{\strut\ignorespaces
      #1{{\usekomafont{captionlabel}{#2\captionformat}}}%
      \ignorespaces #3\unskip}}%
}

\renewcommand{\scr@makemultilinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \vbox{\hsize\cap@width\linewidth\hsize
          \scr@ifundefinedorrelax{@captype}{%
            \ClassWarning{\KOMAClassName}{%
              `\string\caption' outside float.\MessageBreak
              Seems you are using `\string\caption' outside a
              float.\MessageBreak
              Maybe you are using a package that uses
              `\string\@makecaption'\MessageBreak
              without setting `\string\@captype' before.\MessageBreak
              Because I cannot detect the caption type, I'm using\MessageBreak
              the empty one.%
            }%
            \let\@captype\@empty
          }{}%
          \scr@ifundefinedorrelax{ragged\@captype caption}{\raggedcaption}{%
            \@nameuse{ragged\@captype caption}%
          }%
          \ifdofullc@p
            \@hangfrom{%
              \strut
              \scr@smashdp{%
                #1{%
                  \usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }%
              }%
            }%
            {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
          \else
            \ifdim\cap@indent<\z@
              \strut
              #1{%
                {\usekomafont{caption}{%
                  \usekomafont{captionlabel}{#2\captionformat}%
                }%
              }\par}%
              \noindent{{\usekomafont{caption}{%
                  \hspace*{-\cap@indent}#3\scr@endstrut
              }}\par}%
            \else
              \if@capbreak
                \strut
                #1{%
                  {\usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }\par}%
                \noindent\@hangfrom{\hspace*{\cap@indent}}%
                {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
              \else
                \@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}%
                {%
                  \hspace{-\cap@indent}%
                  \scr@smashdp{%
                    #1{\usekomafont{caption}{%
                        \usekomafont{captionlabel}{#2\captionformat}%
                      }%
                    }%
                  }%
                  {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
                }%
              \fi
            \fi
          \fi
        }%
        \cap@right
      }\par\kern\dp\strutbox
    }%
  }\kern-\dp\strutbox
}

\bidi@AfterFile{longtable-xetex-bidi.def}{%
  \if@komalongtable
    \renewcommand{\LT@makecaption}[3]{%
      \LT@mcol\LT@cols c{%
        \hbox to\z@{\hss\parbox[t]\linewidth{%
            \if@captionabove\else\vskip\belowcaptionskip\fi
            \@@makecaption{#1}{#2}{#3}%
            \endgraf
            \if@captionabove\vskip\abovecaptionskip\fi
          }%
          \hss
        }%
      }%
    }%
    \renewcommand*{\scr@LT@array}{}%
    \let\scr@LT@array=\LT@array
    \renewcommand*{\LT@array}{%
      \def\@captype{table}%
      \@ifundefined{LTcaptype}{}{%
        \Ifstr{\LTcaptype}{}{}{\let\@captype\LTcaptype}%
      }%
      \csname tocbasic_if_caption_above:TF\endcsname
        {\@captionabovetrue}{\@captionabovefalse}%
      \def\captionabove{\noalign{\global\@captionabovetrue}%
        \LT@caption}%
      \def\captionbelow{\noalign{\global\@captionabovefalse}%
        \LT@caption}%
      \scr@LT@array
    }%
    \ClassInfo{\KOMAClassName}{%
      longtable captions redefined%
    }%
  \fi
}

\CloneTOCEntryStyle{tocline}{part}
\TOCEntryStyleStartInitCode{part}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\hfill}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname[1]{\usekomafont{partentry}{##1}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
    {\usekomafont{partentry}{\usekomafont{partentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{2.25em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{section}
\TOCEntryStyleStartInitCode{section}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{%
    \if@sectionentrywithdots
      {\usekomafont{sectionentrydots}{\TOCLineLeaderFill}}\relax
    \else
      \hfill
    \fi
  }%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname{\usekomafont{sectionentry}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{{\usekomafont{sectionentry}{\usekomafont{sectionentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{1.0em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{subsection}
\TOCEntryStyleStartInitCode{subsection}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\TOCLineLeaderFill\relax}%
      \expandafter\renewcommand%
      \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
        {\normalfont\normalcolor ##1}}%
}

\CloneTOCEntryStyle{subsection}{default}

\DeclareSectionCommand[%
  style=section,%
  level=1,%
  indent=\z@,%
  beforeskip=-3.5ex \@plus -1ex \@minus -.2ex,%
  afterskip=2.3ex \@plus.2ex,%
  tocstyle=section,%
  tocindent=0pt,%
  tocnumwidth=1.5em%
]{section}
\DeclareSectionCommand[%
  style=part,%
  level=\z@,%
  tocstyle=part,%
  toclevel=\m@ne,%
  tocindent=\z@,%
  tocnumwidth=2em%
]{part}
\DeclareSectionCommand[%
  style=section,%
  level=2,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=subsection,%
  tocindent=1.5em,%
  tocnumwidth=2.3em%
]{subsection}
\DeclareSectionCommand[%
  style=section,%
  level=3,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=subsection,%
  tocindent=3.8em,%
  tocnumwidth=3.2em%
]{subsubsection}
\DeclareSectionCommand[%
  style=section,%
  level=4,%
  indent=\z@,%
  beforeskip=3.25ex \@plus1ex \@minus.2ex,%
  afterskip=-1em,%
  tocstyle=subsection,%
  tocindentfollows=subsubsection,%
  tocindent=7.0em,%
  tocnumwidth=4.1em%
]{paragraph}
\DeclareSectionCommand[%
  style=section,%
  level=5,%
  indent=\scr@parindent,%
  beforeskip=3.25ex \@plus1ex \@minus .2ex,%
  afterskip=-1em,%
  tocstyle=subsection,%
  tocindent=10em,%
  tocnumwidth=5em%
]{subparagraph}
%    \end{macrocode}
% \iffalse
%</scrartcl-xetex-bidi.def>
%<*scrbook-xetex-bidi.def>
%\fi
% \section{File \texttt{scrbook-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{scrbook-xetex-bidi.def}[2025/09/30 v1.5 bidi adaptations for scrbook class for XeTeX engine]
\newcommand{\scr@saved@LTRfootnotetext}{}
\newcommand{\scr@saved@RTLfootnotetext}{}
\let\scr@saved@footnotetext\@footnotetext
\let\scr@saved@LTRfootnotetext\@LTRfootnotetext
\let\scr@saved@RTLfootnotetext\@RTLfootnotetext
\renewcommand{\@footnotetext}[1]{%
  \scr@saved@footnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@LTRfootnotetext}[1]{%
  \scr@saved@LTRfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@RTLfootnotetext}[1]{%
  \scr@saved@RTLfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand\deffootnote[4][]{%
  \expandafter\ifnum\scr@v@is@ge{3.22}\relax
    \long\def\@makefntext##1{%
      \ExecuteDoHook{footnote/text/begin}%
      \raggedfootnote
      \if@RTL
        \rightskip
      \else
        \leftskip
      \fi
      #2
      \l@addto@macro\@trivlist{%
        \ifnum\@listdepth=\@ne\advance
          \if@RTL
            \rightmargin #2\relax
          \else
            \leftmargin #2\relax
          \fi
        \fi
      }%
      \parindent #3\noindent
      \IfArgIsEmpty{#1}{}{%
        \hskip \dimexpr #1-#2\relax
      }%
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
      \ExecuteDoHook{footnote/text/end}%
    }%
  \else
    \ClassInfo{\KOMAClassName}{%
      Using old \string\@makefntext\space due to compatibility
      level\MessageBreak
      less than 3.22}%
    \long\def\@makefntext##1{%
      \setlength{\@tempdimc}{#3}%
      \def\@tempa{#1}\ifx\@tempa\@empty
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#2}%
          \if@RTL
            \parshape \@ne \z@ \@tempdima
          \else
            \parshape \@ne #2 \@tempdima
          \fi
          }%
      \else
        \addtolength{\@tempdimc}{#2}%
        \addtolength{\@tempdimc}{-#1}%
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#1}%
          \@tempdimb = \hsize
          \addtolength{\@tempdimb}{-#2}%
          \if@RTL
            \parshape \tw@ \z@ \@tempdima \z@ \@tempdimb
          \else
            \parshape \tw@ #1 \@tempdima #2 \@tempdimb
          \fi
        }%
      \fi
      \par
      \parindent\@tempdimc\noindent
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
    }%
  \fi
  \def\@@makefnmark{\hbox{\ftnm@font{#4}}}%
}
\deffootnote[1em]{1.5em}{1em}{\textsuperscript{\thefootnotemark}}
\renewcommand*\left@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  {\usekomafont{footnoterule}{%
      \hrule \@height\ftn@rule@height \@width\ftn@rule@width}}%
  \kern 2.6\p@}
\renewcommand*\right@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  \nointerlineskip
  {\usekomafont{footnoterule}{%
      \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\ftn@rule@width\relax  \leavevmode\leaders\hrule\@height\ftn@rule@height\hfill\kern\z@}}}%
  \kern 2.6\p@} 
\renewcommand*\maketitle[1][1]{%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
  \else
    \def\and{%
      \end{tabular}%
      \hskip 1em \@plus.17fil%
      \begin{tabular}[t]{c}%
    }%
  \fi
  \if@titlepage
    \begin{titlepage}
      \setcounter{page}{%
        #1%
      }%
      \if@titlepageiscoverpage
        \edef\titlepage@restore{%
          \noexpand\endgroup
          \noexpand\global\noexpand\@colht\the\@colht
          \noexpand\global\noexpand\@colroom\the\@colroom
          \noexpand\global\vsize\the\vsize
          \noexpand\global\noexpand\@titlepageiscoverpagefalse
          \noexpand\let\noexpand\titlepage@restore\noexpand\relax
        }%
        \begingroup
        \topmargin=\dimexpr \coverpagetopmargin-1in\relax
        \oddsidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \evensidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \textwidth=\dimexpr
        \paperwidth-\coverpageleftmargin-\coverpagerightmargin\relax
        \textheight=\dimexpr
        \paperheight-\coverpagetopmargin-\coverpagebottommargin\relax
        \headheight=0pt
        \headsep=0pt
        \footskip=\baselineskip
        \@colht=\textheight
        \@colroom=\textheight
        \vsize=\textheight
        \columnwidth=\textwidth
        \hsize=\columnwidth
        \linewidth=\hsize
      \else
        \let\titlepage@restore\relax
      \fi
      \let\footnotesize\small
      \let\right@footnoterule\relax
      \let\left@footnoterule\relax
      \let\textwidth@footnoterule\relax
      \let\footnote\thanks
      \let\LTRfootnote\LTRthanks
      \let\RTLfootnote\RTLthanks
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \ifx\@extratitle\@empty
        \ifx\@frontispiece\@empty
        \else
          \if@twoside\mbox{}\next@tpage\fi
          \noindent\@frontispiece\next@tdpage
        \fi
      \else
        \noindent\@extratitle
        \ifx\@frontispiece\@empty
        \else
          \next@tpage
          \noindent\@frontispiece
        \fi
        \next@tdpage
      \fi
      \setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
      \ifx\@titlehead\@empty \else
        \begin{minipage}[t]{\textwidth}%
          \usekomafont{titlehead}{\@titlehead\par}%
        \end{minipage}\par
      \fi
      \null\vfill
      \begin{center}
        \ifx\@subject\@empty \else
          {\usekomafont{subject}{\@subject\par}}%
          \vskip 3em
        \fi
        {\usekomafont{title}{\huge \@title\par}}%
        \vskip 1em
        {\ifx\@subtitle\@empty\else\usekomafont{subtitle}{\@subtitle\par}\fi}%
        \vskip 2em
        {%
          \usekomafont{author}{%
            \lineskip 0.75em
            \begin{tabular}[t]{c}
              \@author
            \end{tabular}\par
          }%
        }%
        \vskip 1.5em
        {\usekomafont{date}{\@date \par}}%
        \vskip \z@ \@plus3fill
        {\usekomafont{publishers}{\@publishers \par}}%
        \vskip 3em
      \end{center}\par
      \@thanks\global\let\@thanks\@empty
      \vfill\null
      \if@twoside
        \@tempswatrue
        \expandafter\ifnum \@nameuse{scr@v@3.12}>\scr@compatibility\relax
        \else
          \ifx\@uppertitleback\@empty\ifx\@lowertitleback\@empty
            \@tempswafalse
          \fi\fi
        \fi
        \if@tempswa
          \next@tpage
          \begin{minipage}[t]{\textwidth}
            \@uppertitleback
          \end{minipage}\par
          \vfill
          \begin{minipage}[b]{\textwidth}
            \@lowertitleback
          \end{minipage}\par
          \@thanks\global\let\@thanks\@empty
        \fi
      \else
        \ifx\@uppertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\uppertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
        \ifx\@lowertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\lowertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
      \fi
      \ifx\@dedication\@empty
      \else
        \next@tdpage\null\vfill
        {\centering\usekomafont{dedication}{\@dedication \par}}%
        \vskip \z@ \@plus3fill
        \@thanks\global\let\@thanks\@empty
        \cleardoubleemptypage
      \fi
      \ifx\titlepage@restore\relax\else\clearpage\titlepage@restore\fi
    \end{titlepage}
  \else
    \par
    \@tempcnta=%
    #1%
    \relax\ifnum\@tempcnta=1\else
      \ClassWarning{\KOMAClassName}{%
        Optional argument of \string\maketitle\space ignored\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@uppertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\uppertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@lowertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\lowertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \begingroup
      \let\titlepage@restore\relax
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \next@tdpage
      \if@twocolumn
        \ifnum \col@number=\@ne
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \@makeextratitle
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \@makefrontispiece
            \next@tdpage
          \fi
          \@maketitle
        \else
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \twocolumn[\@makeextratitle]%
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \twocolumn[\@makefrontispiece]%
            \next@tdpage
          \fi
          \twocolumn[\@maketitle]%
        \fi
      \else
        \ifx\@extratitle\@empty
          \ifx\@frontispiece\@empty\else \mbox{}\fi
        \else
          \@makeextratitle
        \fi
        \ifx\@frontispiece\@empty
          \ifx\@extratitle\@empty\else\next@tdpage\fi
        \else
          \next@tpage
          \@makefrontispiece
          \next@tdpage
        \fi
        \@maketitle
      \fi
      \ifx\titlepagestyle\@empty\else\thispagestyle{\titlepagestyle}\fi
      \@thanks\global\let\@thanks\@empty
    \endgroup
  \fi
  \setcounter{footnote}{0}%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
    \let\thanks\relax
    \let\LTRthanks\relax
    \let\RTLthanks\relax
    \let\maketitle\relax
    \let\@maketitle\relax
    \global\let\@thanks\@empty
    \global\let\@author\@empty
    \global\let\@date\@empty
    \global\let\@title\@empty
    \global\let\@subtitle\@empty
    \global\let\@extratitle\@empty
    \global\let\@frontispiece\@empty
    \global\let\@titlehead\@empty
    \global\let\@subject\@empty
    \global\let\@publishers\@empty
    \global\let\@uppertitleback\@empty
    \global\let\@lowertitleback\@empty
    \global\let\@dedication\@empty
    \global\let\author\relax
    \global\let\title\relax
    \global\let\extratitle\relax
    \global\let\titlehead\relax
    \global\let\subject\relax
    \global\let\publishers\relax
    \global\let\uppertitleback\relax
    \global\let\lowertitleback\relax
    \global\let\dedication\relax
    \global\let\date\relax
  \fi
  \global\let\and\relax
}%
\def\raggedsection{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*\autodot{\if@altsecnumformat\@SepMark\fi}
\renewcommand*\thesection{%
  \expandafter\ifnum\scr@v@is@gt{2.97d}%
    \if@mainmatter\thechapter\@SepMark\fi
  \else
  \thechapter\@SepMark%
  \fi
  \@arabic\c@section
}
\renewcommand*{\thesubsection}{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*{\thesubsubsection}{%
  \thesubsection\@SepMark\@arabic\c@subsubsection
}
\renewcommand*{\theparagraph}{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*{\thesubparagraph}{%
  \theparagraph\@SepMark\@arabic\c@subparagraph
}
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thefigure{\thechapter\@SepMark\@arabic\c@figure}
\fi
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thetable{\thechapter\@SepMark\@arabic\c@table}
\fi
\renewcommand*{\theequation}{%
  \expandafter\ifnum\scr@v@is@gt{2.97d}%
    \if@mainmatter\thechapter\@SepMark\fi
  \else
    \thechapter\@SepMark%
  \fi
  \@arabic\c@equation
}
\renewenvironment{thebibliography}[1]{%
  \if@bib@break@
    \bib@beginhook
  \else
    \ifx\bibpreamble\relax\else\ifx\bibpreamble\@empty\else
        \setchapterpreamble{\bibpreamble}%
    \fi\fi
    \bib@heading
    \bib@beginhook
    \bib@before@hook
  \fi
  \renewcommand{\BreakBibliography}[1]{%
    \@bib@break
    \end{thebibliography}%
    \begingroup ##1\endgroup
    \begin{thebibliography}{#1}
  }%
   \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
   \bidi@@thebibliography@font@hook%
  \list{%
    \@biblabel{\@arabic\c@enumiv}%
  }{%
    \settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \if@bib@break@
      \edef\@tempa{%
        \noexpand\usecounter{enumiv}%
        \noexpand\setcounter{enumiv}{\the\c@enumiv}%
      }\@tempa
      \no@bib@break
    \else
      \usecounter{enumiv}%
    \fi
    \let\p@enumiv\@empty
    \renewcommand*\theenumiv{\@arabic\c@enumiv}%
  }%
  \sloppy\clubpenalty4000 \widowpenalty4000
  \sfcode`\.=\@m
}{%
  \if@bib@break@
    \def\@noitemerr{%
      \@latex@warning{%
        \string\BreakBibliography\space at begin of `thebibliography'
        environment\MessageBreak
        or following \string\BreakBibliography}%
    }%
  \else
    \def\@noitemerr{%
      \@latex@warning{%
        Empty `thebibliography' environment or
        \string\BreakBibliography\MessageBreak
        before end of `thebibliography' environment}%
    }%
  \fi
  \endlist
  \if@bib@break@
  \else
    \bib@after@hook
    \let\bib@before@hook\@empty
    \let\bib@after@hook\@empty
  \fi
  \bib@endhook
}
\renewcommand*{\raggeddictum}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand*{\raggeddictumtext}{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*{\raggeddictumauthor}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand\marginline[1]{%
  \marginpar[\if@RTL\raggedright\else\raggedleft\fi{#1}]{\if@RTL\raggedleft\else\raggedright\fi #1}%
}
\renewcommand{\@@makecaption}[3]{%
  \cap@margin
  \begingroup
    \ifonelinecaptions
      \def\stepcounter##1{\advance\value{##1}\@ne}%
      \let\refstepcounter\stepcounter
      \let\label\@gobble
      \let\@footnotetext=\@gobble
      \let\@LTRfootnotetext=\@gobble
      \let\@RTLfootnotetext=\@gobble
      \let\hypertarget\@gobbletwo
      \edef\@xnewline{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xnewline}%
      }%
      \edef\@xcentercr{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xcentercr}%
      }%
      \settowidth{\@tempdima}{\scr@@makesinglelinecaption{#1}{#2}{#3}}%
      \ifdim\@tempdima>\cap@width
        \aftergroup\scr@makemultilinecaption
      \else
        \aftergroup\scr@makesinglelinecaption
      \fi
    \else
      \aftergroup\scr@makemultilinecaption
    \fi
  \endgroup
  {#1}{#2}{#3}%
}
\renewcommand{\scr@makesinglelinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \if@RTL
          \beginR
        \fi
        \scr@@makesinglelinecaption{#1}{#2}{#3}%
        \if@RTL
          \endR
        \fi
        \cap@right
      }\par\kern\dp\strutbox%
    }%
  }\kern-\dp\strutbox
}
\renewcommand{\@makecaption}[2]{%
  \if@captionabove
    \vskip\belowcaptionskip
  \else
    \vskip\abovecaptionskip
  \fi
  \@@makecaption\@firstofone{#1}{#2}%
  \if@captionabove
    \vskip\abovecaptionskip
  \else
    \vskip\belowcaptionskip
  \fi
}

\renewcommand{\scr@@makesinglelinecaption}[3]{%
    {\usekomafont{caption}{\strut\ignorespaces
      #1{{\usekomafont{captionlabel}{#2\captionformat}}}%
      \ignorespaces #3\unskip}}%
}

\renewcommand{\scr@makemultilinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \vbox{\hsize\cap@width\linewidth\hsize
          \scr@ifundefinedorrelax{@captype}{%
            \ClassWarning{\KOMAClassName}{%
              `\string\caption' outside float.\MessageBreak
              Seems you are using `\string\caption' outside a
              float.\MessageBreak
              Maybe you are using a package that uses
              `\string\@makecaption'\MessageBreak
              without setting `\string\@captype' before.\MessageBreak
              Because I cannot detect the caption type, I'm using\MessageBreak
              the empty one.%
            }%
            \let\@captype\@empty
          }{}%
          \scr@ifundefinedorrelax{ragged\@captype caption}{\raggedcaption}{%
            \@nameuse{ragged\@captype caption}%
          }%
          \ifdofullc@p
            \@hangfrom{%
              \strut
              \scr@smashdp{%
                #1{%
                  \usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }%
              }%
            }%
            {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
          \else
            \ifdim\cap@indent<\z@
              \strut
              #1{%
                {\usekomafont{caption}{%
                  \usekomafont{captionlabel}{#2\captionformat}%
                }%
              }\par}%
              \noindent{{\usekomafont{caption}{%
                  \hspace*{-\cap@indent}#3\scr@endstrut
              }}\par}%
            \else
              \if@capbreak
                \strut
                #1{%
                  {\usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }
                }\par}%
                \noindent\@hangfrom{\hspace*{\cap@indent}}%
                {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
              \else
                \@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}%
                {%
                  \hspace{-\cap@indent}%
                  \scr@smashdp{%
                    #1{\usekomafont{caption}{%
                        \usekomafont{captionlabel}{#2\captionformat}%
                      }%
                    }%
                  }%
                  {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
                }%
              \fi
            \fi
          \fi
        }%
        \cap@right
      }\par\kern\dp\strutbox
    }%
  }\kern-\dp\strutbox
}


\bidi@AfterFile{longtable-xetex-bidi.def}{%
  \if@komalongtable
    \renewcommand{\LT@makecaption}[3]{%
      \LT@mcol\LT@cols c{%
        \hbox to\z@{\hss\parbox[t]\linewidth{%
            \if@captionabove\else\vskip\belowcaptionskip\fi
            \@@makecaption{#1}{#2}{#3}%
            \endgraf
            \if@captionabove\vskip\abovecaptionskip\fi
          }%
          \hss
        }%
      }%
    }%
    \renewcommand*{\scr@LT@array}{}%
    \let\scr@LT@array=\LT@array
    \renewcommand*{\LT@array}{%
      \def\@captype{table}%
      \@ifundefined{LTcaptype}{}{%
        \Ifstr{\LTcaptype}{}{}{\let\@captype\LTcaptype}%
      }%
      \csname tocbasic_if_caption_above:TF\endcsname
        {\@captionabovetrue}{\@captionabovefalse}%
      \def\captionabove{\noalign{\global\@captionabovetrue}%
        \LT@caption}%
      \def\captionbelow{\noalign{\global\@captionabovefalse}%
        \LT@caption}%
      \scr@LT@array
    }%
    \ClassInfo{\KOMAClassName}{%
      longtable captions redefined%
    }%
  \fi
}

\CloneTOCEntryStyle{tocline}{part}
\TOCEntryStyleStartInitCode{part}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\hfill}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname[1]{\usekomafont{partentry}{##1}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
    {\usekomafont{partentry}{\usekomafont{partentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{2.25em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{chapter}
\TOCEntryStyleStartInitCode{chapter}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{%
    \if@chapterentrywithdots
      {\usekomafont{chapterentrydots}{\TOCLineLeaderFill}}\relax
    \else
      \hfill
    \fi
  }%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname{\usekomafont{chapterentry}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
    {\usekomafont{chapterentry}{\usekomafont{chapterentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{1.0em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{section}
\TOCEntryStyleStartInitCode{section}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\TOCLineLeaderFill\relax}%
      \expandafter\renewcommand%
      \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
        {\normalfont\normalcolor ##1}}%
}

\CloneTOCEntryStyle{section}{default}

\DeclareSectionCommand[%
  style=chapter,%
  level=\z@,%
  pagestyle=plain,%
  tocstyle=chapter,%
  tocindent=\z@,%
  tocnumwidth=1.5em%
]{chapter}
\DeclareSectionCommand[%
  style=section,%
  level=1,%
  indent=\z@,%
  beforeskip=-3.5ex \@plus -1ex \@minus -.2ex,%
  afterskip=2.3ex \@plus.2ex,%
  tocstyle=section,%
  tocindentfollows=chapter,%
  tocindent=1.5em,%
  tocnumwidth=2.3em%
]{section}
\DeclareSectionCommand[%
  style=part,%
  level=\m@ne,%
  pagestyle=plain,%
  tocstyle=part,%
  toclevel=\m@ne,%
  tocindent=\z@,%
  tocnumwidth=2em%
]{part}
\DeclareSectionCommand[%
  style=section,%
  level=2,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=section,%
  tocindent=3.8em,%
  tocnumwidth=3.2em%
]{subsection}
\DeclareSectionCommand[%
  style=section,%
  level=3,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=section,%
  tocindent=7.0em,%
  tocnumwidth=4.1em%
]{subsubsection}
\DeclareSectionCommand[%
  style=section,%
  level=4,%
  indent=\z@,%
  beforeskip=3.25ex \@plus1ex \@minus.2ex,%
  afterskip=-1em,%
  tocindentfollows=subsubsection,%
  tocstyle=section,%
  tocindent=10em,%
  tocnumwidth=5em%
]{paragraph}
\DeclareSectionCommand[%
  style=section,%
  level=5,%
  indent=\scr@parindent,%
  beforeskip=3.25ex \@plus1ex \@minus .2ex,%
  afterskip=-1em,%
  tocstyle=section,%
  tocindent=12em,%
  tocnumwidth=6em%
]{subparagraph}
%    \end{macrocode}
% \iffalse
%</scrbook-xetex-bidi.def>
%<*scrreprt-xetex-bidi.def>
%\fi
% \section{File \texttt{scrreprt-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{scrreprt-xetex-bidi.def}[2025/09/30 v1.5 bidi adaptations for scrreprt class for XeTeX engine]
\newcommand{\scr@saved@LTRfootnotetext}{}
\newcommand{\scr@saved@RTLfootnotetext}{}
\let\scr@saved@footnotetext\@footnotetext
\let\scr@saved@LTRfootnotetext\@LTRfootnotetext
\let\scr@saved@RTLfootnotetext\@RTLfootnotetext
\renewcommand{\@footnotetext}[1]{%
  \scr@saved@footnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@LTRfootnotetext}[1]{%
  \scr@saved@LTRfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand{\@RTLfootnotetext}[1]{%
  \scr@saved@RTLfootnotetext{#1}%
  \csname FN@mf@prepare\endcsname
}
\renewcommand\deffootnote[4][]{%
  \expandafter\ifnum\scr@v@is@ge{3.22}\relax
    \long\def\@makefntext##1{%
      \ExecuteDoHook{footnote/text/begin}%
      \raggedfootnote
      \if@RTL
        \rightskip
      \else
        \leftskip 
      \fi
      #2
      \l@addto@macro\@trivlist{%
        \ifnum\@listdepth=\@ne
          \if@RTL
            \advance\rightmargin #2\relax
          \else
            \advance\leftmargin #2\relax
          \fi
        \fi
      }%
      \parindent #3\noindent
      \IfArgIsEmpty{#1}{}{%
        \hskip \dimexpr #1-#2\relax
      }%
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
      \ExecuteDoHook{footnote/text/end}%
    }%
  \else
    \ClassInfo{\KOMAClassName}{%
      Using old \string\@makefntext\space due to compatibility
      level\MessageBreak
      less than 3.22}%
    \long\def\@makefntext##1{%
      \setlength{\@tempdimc}{#3}%
      \def\@tempa{#1}\ifx\@tempa\@empty
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#2}%
          \if@RTL
            \parshape \@ne \z@ \@tempdima
          \else
            \parshape \@ne #2 \@tempdima
          \fi
          }%
      \else
        \addtolength{\@tempdimc}{#2}%
        \addtolength{\@tempdimc}{-#1}%
        \@setpar{\@@par
          \@tempdima = \hsize
          \addtolength{\@tempdima}{-#1}%
          \@tempdimb = \hsize
          \addtolength{\@tempdimb}{-#2}%
          \if@RTL
            \parshape \tw@ \z@ \@tempdima \z@ \@tempdimb
          \else
            \parshape \tw@ #1 \@tempdima #2 \@tempdimb
          \fi
        }%
      \fi
      \par
      \parindent\@tempdimc\noindent
      \ftn@font\hbox to \z@{\hss\@@makefnmark}##1%
    }%
  \fi
  \def\@@makefnmark{\hbox{\ftnm@font{#4}}}%
}
\deffootnote[1em]{1.5em}{1em}{\textsuperscript{\thefootnotemark}}
\renewcommand*\left@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  {\usekomafont{footnoterule}{%
      \hrule \@height\ftn@rule@height \@width\ftn@rule@width}}%
  \kern 2.6\p@}
\renewcommand*\right@footnoterule{%
  \normalsize\ftn@rule@test@values
  \kern-\dimexpr 2.6\p@+\ftn@rule@height\relax
  \ifx\@textbottom\relax\else\vskip \z@ \@plus.05fil\fi
  \nointerlineskip
  {\usekomafont{footnoterule}{%
      \hbox to \columnwidth{\hskip \dimexpr\columnwidth-\ftn@rule@width\relax  \leavevmode\leaders\hrule\@height\ftn@rule@height\hfill\kern\z@}}}%
  \kern 2.6\p@}  
\renewcommand*\maketitle[1][1]{%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
  \else
    \def\and{%
      \end{tabular}%
      \hskip 1em \@plus.17fil%
      \begin{tabular}[t]{c}%
    }%
  \fi
  \if@titlepage
    \begin{titlepage}
      \setcounter{page}{%
        #1%
      }%
      \if@titlepageiscoverpage
        \edef\titlepage@restore{%
          \noexpand\endgroup
          \noexpand\global\noexpand\@colht\the\@colht
          \noexpand\global\noexpand\@colroom\the\@colroom
          \noexpand\global\vsize\the\vsize
          \noexpand\global\noexpand\@titlepageiscoverpagefalse
          \noexpand\let\noexpand\titlepage@restore\noexpand\relax
        }%
        \begingroup
        \topmargin=\dimexpr \coverpagetopmargin-1in\relax
        \oddsidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \evensidemargin=\dimexpr \coverpageleftmargin-1in\relax
        \textwidth=\dimexpr
        \paperwidth-\coverpageleftmargin-\coverpagerightmargin\relax
        \textheight=\dimexpr
        \paperheight-\coverpagetopmargin-\coverpagebottommargin\relax
        \headheight=0pt
        \headsep=0pt
        \footskip=\baselineskip
        \@colht=\textheight
        \@colroom=\textheight
        \vsize=\textheight
        \columnwidth=\textwidth
        \hsize=\columnwidth
        \linewidth=\hsize
      \else
        \let\titlepage@restore\relax
      \fi
      \let\footnotesize\small
      \let\right@footnoterule\relax
      \let\left@footnoterule\relax
      \let\textwidth@footnoterule\relax
      \let\footnote\thanks
      \let\LTRfootnote\LTRthanks
      \let\RTLfootnote\RTLthanks
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \ifx\@extratitle\@empty
        \ifx\@frontispiece\@empty
        \else
          \if@twoside\mbox{}\next@tpage\fi
          \noindent\@frontispiece\next@tdpage
        \fi
      \else
        \noindent\@extratitle
        \ifx\@frontispiece\@empty
        \else
          \next@tpage
          \noindent\@frontispiece
        \fi
        \next@tdpage
      \fi
      \setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
      \ifx\@titlehead\@empty \else
        \begin{minipage}[t]{\textwidth}%
          \usekomafont{titlehead}{\@titlehead\par}%
        \end{minipage}\par
      \fi
      \null\vfill
      \begin{center}
        \ifx\@subject\@empty \else
          {\usekomafont{subject}{\@subject\par}}%
          \vskip 3em
        \fi
        {\usekomafont{title}{\huge \@title\par}}%
        \vskip 1em
        {\ifx\@subtitle\@empty\else\usekomafont{subtitle}{\@subtitle\par}\fi}%
        \vskip 2em
        {%
          \usekomafont{author}{%
            \lineskip 0.75em
            \begin{tabular}[t]{c}
              \@author
            \end{tabular}\par
          }%
        }%
        \vskip 1.5em
        {\usekomafont{date}{\@date \par}}%
        \vskip \z@ \@plus3fill
        {\usekomafont{publishers}{\@publishers \par}}%
        \vskip 3em
      \end{center}\par
      \@thanks\global\let\@thanks\@empty
      \vfill\null
      \if@twoside
        \@tempswatrue
        \expandafter\ifnum \@nameuse{scr@v@3.12}>\scr@compatibility\relax
        \else
          \ifx\@uppertitleback\@empty\ifx\@lowertitleback\@empty
            \@tempswafalse
          \fi\fi
        \fi
        \if@tempswa
          \next@tpage
          \begin{minipage}[t]{\textwidth}
            \@uppertitleback
          \end{minipage}\par
          \vfill
          \begin{minipage}[b]{\textwidth}
            \@lowertitleback
          \end{minipage}\par
          \@thanks\global\let\@thanks\@empty
        \fi
      \else
        \ifx\@uppertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\uppertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
        \ifx\@lowertitleback\@empty\else
          \ClassWarning{\KOMAClassName}{%
            non empty \string\lowertitleback\space ignored
            by \string\maketitle\MessageBreak
            in `twoside=false' mode%
          }%
        \fi
      \fi
      \ifx\@dedication\@empty
      \else
        \next@tdpage\null\vfill
        {\centering\usekomafont{dedication}{\@dedication \par}}%
        \vskip \z@ \@plus3fill
        \@thanks\global\let\@thanks\@empty
        \cleardoubleemptypage
      \fi
      \ifx\titlepage@restore\relax\else\clearpage\titlepage@restore\fi
    \end{titlepage}
  \else
    \par
    \@tempcnta=%
    #1%
    \relax\ifnum\@tempcnta=1\else
      \ClassWarning{\KOMAClassName}{%
        Optional argument of \string\maketitle\space ignored\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@uppertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\uppertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \ifx\@lowertitleback\@empty\else
      \ClassWarning{\KOMAClassName}{%
        non empty \string\lowertitleback\space ignored
        by \string\maketitle\MessageBreak
        in `titlepage=false' mode%
      }%
    \fi
    \begingroup
      \let\titlepage@restore\relax
      \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
      \let\@oldmakefnmark\@makefnmark
      \renewcommand*{\@makefnmark}{\rlap\@oldmakefnmark}%
      \next@tdpage
      \if@twocolumn
        \ifnum \col@number=\@ne
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \@makeextratitle
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \@makefrontispiece
            \next@tdpage
          \fi
          \@maketitle
        \else
          \ifx\@extratitle\@empty
            \ifx\@frontispiece\@empty\else\if@twoside\mbox{}\fi\fi
          \else
            \twocolumn[\@makeextratitle]%
          \fi
          \ifx\@frontispiece\@empty
            \ifx\@extratitle\@empty\else\next@tdpage\fi
          \else
            \next@tpage
            \twocolumn[\@makefrontispiece]%
            \next@tdpage
          \fi
          \twocolumn[\@maketitle]%
        \fi
      \else
        \ifx\@extratitle\@empty
          \ifx\@frontispiece\@empty\else \mbox{}\fi
        \else
          \@makeextratitle
        \fi
        \ifx\@frontispiece\@empty
          \ifx\@extratitle\@empty\else\next@tdpage\fi
        \else
          \next@tpage
          \@makefrontispiece
          \next@tdpage
        \fi
        \@maketitle
      \fi
      \ifx\titlepagestyle\@empty\else\thispagestyle{\titlepagestyle}\fi
      \@thanks\global\let\@thanks\@empty
    \endgroup
  \fi
  \setcounter{footnote}{0}%
  \expandafter\ifnum \csname scr@v@3.12\endcsname>\scr@compatibility\relax
    \let\thanks\relax
    \let\LTRthanks\relax
    \let\RTLthanks\relax
    \let\maketitle\relax
    \let\@maketitle\relax
    \global\let\@thanks\@empty
    \global\let\@author\@empty
    \global\let\@date\@empty
    \global\let\@title\@empty
    \global\let\@subtitle\@empty
    \global\let\@extratitle\@empty
    \global\let\@frontispiece\@empty
    \global\let\@titlehead\@empty
    \global\let\@subject\@empty
    \global\let\@publishers\@empty
    \global\let\@uppertitleback\@empty
    \global\let\@lowertitleback\@empty
    \global\let\@dedication\@empty
    \global\let\author\relax
    \global\let\title\relax
    \global\let\extratitle\relax
    \global\let\titlehead\relax
    \global\let\subject\relax
    \global\let\publishers\relax
    \global\let\uppertitleback\relax
    \global\let\lowertitleback\relax
    \global\let\dedication\relax
    \global\let\date\relax
  \fi
  \global\let\and\relax
}%
\def\raggedsection{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*\autodot{\if@altsecnumformat\@SepMark\fi}
\renewcommand*\thesection{%
  \thechapter\@SepMark%
  \@arabic\c@section
}
\renewcommand*{\thesubsection}{\thesection\@SepMark\@arabic\c@subsection}
\renewcommand*{\thesubsubsection}{%
  \thesubsection\@SepMark\@arabic\c@subsubsection
}
\renewcommand*{\theparagraph}{\thesubsubsection\@SepMark\@arabic\c@paragraph}
\renewcommand*{\thesubparagraph}{%
  \theparagraph\@SepMark\@arabic\c@subparagraph
}
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thefigure{\thechapter\@SepMark\@arabic\c@figure}
\fi
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thetable{\thechapter\@SepMark\@arabic\c@table}
\fi
\renewcommand*\theequation{%
  \thechapter\@SepMark%
  \@arabic\c@equation
}
\renewenvironment{thebibliography}[1]{%
  \if@bib@break@
    \bib@beginhook
  \else
    \ifx\bibpreamble\relax\else\ifx\bibpreamble\@empty\else
        \setchapterpreamble{\bibpreamble}%
    \fi\fi
    \bib@heading
    \bib@beginhook
    \bib@before@hook
  \fi
  \renewcommand{\BreakBibliography}[1]{%
    \@bib@break
    \end{thebibliography}%
    \begingroup ##1\endgroup
    \begin{thebibliography}{#1}
  }%
  \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
  \bidi@@thebibliography@font@hook%
  \list{%
    \@biblabel{\@arabic\c@enumiv}%
  }{%
    \settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \if@bib@break@
      \edef\@tempa{%
        \noexpand\usecounter{enumiv}%
        \noexpand\setcounter{enumiv}{\the\c@enumiv}%
      }\@tempa
      \no@bib@break
    \else
      \usecounter{enumiv}%
    \fi
    \let\p@enumiv\@empty
    \renewcommand*\theenumiv{\@arabic\c@enumiv}%
  }%
  \sloppy\clubpenalty4000 \widowpenalty4000
  \sfcode`\.=\@m
}{%
  \if@bib@break@
    \def\@noitemerr{%
      \@latex@warning{%
        \string\BreakBibliography\space at begin of `thebibliography'
        environment\MessageBreak
        or following \string\BreakBibliography}%
    }%
  \else
    \def\@noitemerr{%
      \@latex@warning{%
        Empty `thebibliography' environment or
        \string\BreakBibliography\MessageBreak
        before end of `thebibliography' environment}%
    }%
  \fi
  \endlist
  \if@bib@break@
  \else
    \bib@after@hook
    \let\bib@before@hook\@empty
    \let\bib@after@hook\@empty
  \fi
  \bib@endhook
}
\renewcommand*{\raggeddictum}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand*{\raggeddictumtext}{\if@RTL\raggedleft\else\raggedright\fi}
\renewcommand*{\raggeddictumauthor}{\if@RTL\raggedright\else\raggedleft\fi}
\renewcommand\marginline[1]{%
  \marginpar[\if@RTL\raggedright\else\raggedleft\fi{#1}]{\if@RTL\raggedleft\else\raggedright\fi #1}%
}
\renewcommand{\@@makecaption}[3]{%
  \cap@margin
  \begingroup
    \ifonelinecaptions
      \def\stepcounter##1{\advance\value{##1}\@ne}%
      \let\refstepcounter\stepcounter
      \let\label\@gobble
      \let\@footnotetext=\@gobble
      \let\@LTRfootnotetext=\@gobble
      \let\@RTLfootnotetext=\@gobble
      \let\hypertarget\@gobbletwo
      \edef\@xnewline{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xnewline}%
      }%
      \edef\@xcentercr{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xcentercr}%
      }%
      \settowidth{\@tempdima}{\scr@@makesinglelinecaption{#1}{#2}{#3}}%
      \ifdim\@tempdima>\cap@width
        \aftergroup\scr@makemultilinecaption
      \else
        \aftergroup\scr@makesinglelinecaption
      \fi
    \else
      \aftergroup\scr@makemultilinecaption
    \fi
  \endgroup
  {#1}{#2}{#3}%
}
\renewcommand{\scr@makesinglelinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \if@RTL
          \beginR
        \fi
        \scr@@makesinglelinecaption{#1}{#2}{#3}%
        \if@RTL
          \endR
        \fi
        \cap@right
      }\par\kern\dp\strutbox%
    }%
  }\kern-\dp\strutbox
}
\renewcommand{\@makecaption}[2]{%
  \if@captionabove
    \vskip\belowcaptionskip
  \else
    \vskip\abovecaptionskip
  \fi
  \@@makecaption\@firstofone{#1}{#2}%
  \if@captionabove
    \vskip\abovecaptionskip
  \else
    \vskip\belowcaptionskip
  \fi
}

\renewcommand{\scr@@makesinglelinecaption}[3]{%
    {\usekomafont{caption}{\strut\ignorespaces
      #1{{\usekomafont{captionlabel}{#2\captionformat}}}%
      \ignorespaces #3\unskip}}%
}

\renewcommand{\scr@makemultilinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \vbox{\hsize\cap@width\linewidth\hsize
          \scr@ifundefinedorrelax{@captype}{%
            \ClassWarning{\KOMAClassName}{%
              `\string\caption' outside float.\MessageBreak
              Seems you are using `\string\caption' outside a
              float.\MessageBreak
              Maybe you are using a package that uses
              `\string\@makecaption'\MessageBreak
              without setting `\string\@captype' before.\MessageBreak
              Because I cannot detect the caption type, I'm using\MessageBreak
              the empty one.%
            }%
            \let\@captype\@empty
          }{}%
          \scr@ifundefinedorrelax{ragged\@captype caption}{\raggedcaption}{%
            \@nameuse{ragged\@captype caption}%
          }%
          \ifdofullc@p
            \@hangfrom{%
              \strut
              \scr@smashdp{%
                #1{%
                  \usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }%
              }%
            }%
            {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
          \else
            \ifdim\cap@indent<\z@
              \strut
              #1{%
                {\usekomafont{caption}{%
                  \usekomafont{captionlabel}{#2\captionformat}%
                }%
              }\par}%
              \noindent{{\usekomafont{caption}{%
                  \hspace*{-\cap@indent}#3\scr@endstrut
              }}\par}%
            \else
              \if@capbreak
                \strut
                #1{%
                  {\usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }\par}%
                \noindent\@hangfrom{\hspace*{\cap@indent}}%
                {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
              \else
                \@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}%
                {%
                  \hspace{-\cap@indent}%
                  \scr@smashdp{%
                    #1{\usekomafont{caption}{%
                        \usekomafont{captionlabel}{#2\captionformat}%
                      }%
                    }%
                  }%
                  {{\usekomafont{caption}{#3\scr@endstrut}}\par}%
                }%
              \fi
            \fi
          \fi
        }%
        \cap@right
      }\par\kern\dp\strutbox
    }%
  }\kern-\dp\strutbox
}


\bidi@AfterFile{longtable-xetex-bidi.def}{%
  \if@komalongtable
    \renewcommand{\LT@makecaption}[3]{%
      \LT@mcol\LT@cols c{%
        \hbox to\z@{\hss\parbox[t]\linewidth{%
            \if@captionabove\else\vskip\belowcaptionskip\fi
            \@@makecaption{#1}{#2}{#3}%
            \endgraf
            \if@captionabove\vskip\abovecaptionskip\fi
          }%
          \hss
        }%
      }%
    }%
    \renewcommand*{\scr@LT@array}{}%
    \let\scr@LT@array=\LT@array
    \renewcommand*{\LT@array}{%
      \def\@captype{table}%
      \@ifundefined{LTcaptype}{}{%
        \Ifstr{\LTcaptype}{}{}{\let\@captype\LTcaptype}%
      }%
      \csname tocbasic_if_caption_above:TF\endcsname
        {\@captionabovetrue}{\@captionabovefalse}%
      \def\captionabove{\noalign{\global\@captionabovetrue}%
        \LT@caption}%
      \def\captionbelow{\noalign{\global\@captionabovefalse}%
        \LT@caption}%
      \scr@LT@array
    }%
    \ClassInfo{\KOMAClassName}{%
      longtable captions redefined%
    }%
  \fi
}

\CloneTOCEntryStyle{tocline}{part}
\TOCEntryStyleStartInitCode{part}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\hfill}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname[1]{\usekomafont{partentry}{##1}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
    {\usekomafont{partentry}{\usekomafont{partentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{2.25em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{chapter}
\TOCEntryStyleStartInitCode{chapter}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{%
    \if@chapterentrywithdots
      {\usekomafont{chapterentrydots}{\TOCLineLeaderFill}}\relax
    \else
      \hfill
    \fi
  }%
  \expandafter\renewcommand%
  \csname scr@tso@#1@entryformat\endcsname{\usekomafont{chapterentry}}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
    {\usekomafont{chapterentry}{\usekomafont{chapterentrypagenumber}{##1}}}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@beforeskip\endcsname{1.0em \@plus\p@}%
}

\CloneTOCEntryStyle{tocline}{section}
\TOCEntryStyleStartInitCode{section}{%
  \expandafter\renewcommand%
  \csname scr@tso@#1@linefill\endcsname{\TOCLineLeaderFill\relax}%
      \expandafter\renewcommand%
      \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
        {\normalfont\normalcolor ##1}}%
}

\CloneTOCEntryStyle{section}{default}

\DeclareSectionCommand[%
  style=chapter,%
  level=\z@,%
  pagestyle=plain,%
  tocstyle=chapter,%
  tocindent=\z@,%
  tocnumwidth=1.5em%
]{chapter}
\DeclareSectionCommand[%
  style=section,%
  level=1,%
  indent=\z@,%
  beforeskip=-3.5ex \@plus -1ex \@minus -.2ex,%
  afterskip=2.3ex \@plus.2ex,%
  tocstyle=section,%
  tocindentfollows=chapter,%
  tocindent=1.5em,%
  tocnumwidth=2.3em%
]{section}
\DeclareSectionCommand[%
  style=part,%
  level=\m@ne,%
  pagestyle=plain,%
  tocstyle=part,%
  toclevel=\m@ne,%
  tocindent=\z@,%
  tocnumwidth=2em%
]{part}
\DeclareSectionCommand[%
  style=section,%
  level=2,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=section,%
  tocindent=3.8em,%
  tocnumwidth=3.2em%
]{subsection}
\DeclareSectionCommand[%
  style=section,%
  level=3,%
  indent=\z@,%
  beforeskip=-3.25ex\@plus -1ex \@minus -.2ex,%
  afterskip=1.5ex \@plus .2ex,%
  tocstyle=section,%
  tocindent=7.0em,%
  tocnumwidth=4.1em%
]{subsubsection}
\DeclareSectionCommand[%
  style=section,%
  level=4,%
  indent=\z@,%
  beforeskip=3.25ex \@plus1ex \@minus.2ex,%
  afterskip=-1em,%
  tocindentfollows=subsubsection,%
  tocstyle=section,%
  tocindent=10em,%
  tocnumwidth=5em%
]{paragraph}
\DeclareSectionCommand[%
  style=section,%
  level=5,%
  indent=\scr@parindent,%
  beforeskip=3.25ex \@plus1ex \@minus .2ex,%
  afterskip=-1em,%
  tocstyle=section,%
  tocindent=12em,%
  tocnumwidth=6em%
]{subparagraph}
%    \end{macrocode}
% \iffalse
%</scrreprt-xetex-bidi.def>
%<*sidecap-xetex-bidi.def>
%\fi
% \section{File \texttt{sidecap-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{sidecap-xetex-bidi.def}[2025/01/03 v0.2 bidi adaptations for sidecap package for XeTeX engine]
\RequirePackage{ragged2e}
\renewcommand*{\SC@FLOAT}[2]{\if@RTL%
    \isSC@ODD{{#1}\hspace{\sidecaptionsep}{#2}} {{#2}\hspace{\sidecaptionsep}{#1}}\else%
\isSC@ODD{{#2}\hspace{\sidecaptionsep}{#1}} {{#1}\hspace{\sidecaptionsep}{#2}}\fi}
  \renewcommand*\SC@justify@caption{\if@RTL%
\isSC@ODD{\RaggedLeft}{\RaggedRight}\else%
    \isSC@ODD{\RaggedRight}{\RaggedLeft}\fi}
    
\@ifpackagewith{sidecap}{innercaption}{%
\if@RTL  \renewcommand*{\SC@FLOAT}[2]{%
    \isSC@ODD{{#2}\hspace{\sidecaptionsep}{#1}} {{#1}\hspace{\sidecaptionsep}{#2}}}
  \renewcommand*\SC@justify@caption{%
    \isSC@ODD{\RaggedRight}{\RaggedLeft}}\else
  \renewcommand*{\SC@FLOAT}[2]{%
    \isSC@ODD{{#1}\hspace{\sidecaptionsep}{#2}} {{#2}\hspace{\sidecaptionsep}{#1}}}
  \renewcommand*\SC@justify@caption{%
    \isSC@ODD{\RaggedLeft}{\RaggedRight}}\fi
}{}
    
\@ifpackagewith{sidecap}{rightcaption}{%
  \if@RTL\renewcommand*{\SC@FLOAT}[2]{{#1}\hspace{\sidecaptionsep}{#2}}
  \def\SC@justify@caption{\RaggedLeft}\else%
  \renewcommand*{\SC@FLOAT}[2]{{#2}\hspace{\sidecaptionsep}{#1}}
  \def\SC@justify@caption{\RaggedRight}\fi%
}{}

\@ifpackagewith{sidecap}{leftcaption}{%
\if@RTL  \renewcommand*{\SC@FLOAT}[2]{{#2}\hspace{\sidecaptionsep}{#1}}
  \def\SC@justify@caption{\RaggedRight}\else%
  \renewcommand*{\SC@FLOAT}[2]{{#1}\hspace{\sidecaptionsep}{#2}}
  \def\SC@justify@caption{\RaggedLeft}\fi%
}{}    
%    \end{macrocode}
% \iffalse
%</sidecap-xetex-bidi.def>
%<*soul-xetex-bidi.def>
%\fi
% \section{File \texttt{soul-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{soul-xetex-bidi.def}[2015/10/16 v0.1 bidi adaptations for soul package for XeTeX engine]
\long\def\SOUL@start#1{{%
   \let\bidi@RTL@everypar\@empty
    \let\<\SOUL@lowerthan
    \let\>\empty
    \def\soulomit{\noexpand\soulomit}%
    \gdef\SOUL@eventuallyexhyphen##1{}%
    \let\SOUL@soeventuallyskip\relax
    \SOUL@spaceskip=\fontdimen\tw@\font\@plus\fontdimen\thr@@\font
        \@minus\fontdimen4\font
    \SOUL@ignorespacesfalse
    \leavevmode
    \SOUL@preamble
    \SOUL@lasttoken={}%
    \SOUL@word={}%
    \SOUL@minus\z@
    \SOUL@comma\z@
    \SOUL@apo\z@
    \SOUL@grave\z@
    \SOUL@do{#1}%
    \SOUL@postamble
}}
\def\SOUL@ulunderline#1{{%
    \setbox\z@\hbox{#1}%
    \dimen@=\wd\z@
    \dimen@i=\SOUL@uloverlap
    \advance\dimen@2\dimen@i
    \if@RTL
    \unhcopy\z@
    \llap{%
        \null
        \kern-\dimen@i
        \SOUL@ulcolor{\SOUL@ulleaders\hskip\dimen@}%
    }%
    \else
    \rlap{%
        \null
        \kern-\dimen@i
        \SOUL@ulcolor{\SOUL@ulleaders\hskip\dimen@}%
    }%
    \unhcopy\z@
    \fi
}}
\def\bidi@SOUL@ulleaders{%
    \leaders\hb@xt@0.1pt{\hss\SOUL@ulcolor{\vrule\@depth\SOUL@uldp\@height\SOUL@ulht}\hss}\relax
}
\def\SOUL@uleveryspace#1{%
       \if@RTL
       #1%
       \bidi@SOUL@ulleaders
       \hskip\spaceskip
       \else
    \SOUL@ulcolor{%
        #1%
        \SOUL@ulleaders
        \hskip\spaceskip
    }%
    \fi
    \null
}
%    \end{macrocode}
% \iffalse
%</soul-xetex-bidi.def>
%<*stabular-xetex-bidi.def>
%\fi
% \section{File \texttt{stabular-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{stabular-xetex-bidi.def}[2015/11/07 v0.3 bidi adaptations for stabular package for XeTeX engine]
\def\@stabular{%
   \leavevmode \bgroup \if@RTLtab\beginR \fi
   \let\@acol\@tabacol
   \let\@classz\@tabclassz
   \let\@classiv\@tabclassiv \let\\\@tabularcr\@stabarray}
\def\endstabular{\crcr\egroup\if@RTLtab\egroup\endR\egroup\fi
                 \egroup \if@RTLtab\endR\fi\egroup}
\expandafter \let \csname endstabular*\endcsname = \endstabular
\def\@sarray[#1]#2{%
  \bgroup
  \setbox\@arstrutbox\hbox{%
    \vrule \@height\arraystretch\ht\strutbox
           \@depth\arraystretch \dp\strutbox
           \@width\z@}%
  \@mkpream{#2}%
  \edef\@preamble{%
    \ialign \noexpand\@halignto
      \bgroup \@arstrut \@preamble \tabskip\z@skip \cr}%
  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
  \let\tabularnewline\\%
    \let\@sharp##%
    \set@typeset@protect
    \lineskip\z@skip\baselineskip\z@skip
  \if@RTLtab\hbox\bgroup\beginR\@hboxRconstructtrue\if #1t\vtop \else \vbox \fi\bgroup\fi
    \@preamble}
%    \end{macrocode}
% \iffalse
%</stabular-xetex-bidi.def>
%<*subfigure-xetex-bidi.def>
%\fi
% \section{File \texttt{subfigure-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{subfigure-xetex-bidi.def}[2010/03/01 v0.1 bidi adaptations for subfigure package for XeTeX engine]
\AtBeginDocument{%
\let\p@subfigure=\thefigure
\let\p@subtable=\thetable%
}
%    \end{macrocode}
% \iffalse
%</subfigure-xetex-bidi.def>
%<*tabls-xetex-bidi.def>
%\fi
% \section{File \texttt{tabls-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tabls-xetex-bidi.def}[2015/11/07 v0.3 bidi adaptations for tabls package for XeTeX engine]
\def\endtabular{\endarray $\if@RTLtab\endR\fi\egroup}

\expandafter\let\csname endtabular*\endcsname=\endtabular

\def\endarray{\ifvmode\csname crcr\endcsname % just do \crcr if \\ given
  \else \\[\z@ \global\advance\@arstdepth-\@otarlinesep]%
  \fi\egroup\if@RTLtab\egroup\endR\egroup\fi\@unrecurse\egroup}

\def\@array[#1]#2{%  remember global variables to allow recursion:
 \edef\@unrecurse{\global\@skip@bove\the\@skip@bove
     \global\@arstheight\the\@arstheight\global\@arstdepth\the\@arstdepth}%
 \let\@otarlinesep\@tarlinesep \global\@skip@bove-\@otarlinesep
 \ifx\@classz\@arrayclassz \let\@tarlinesep\arraylinesep
 \else \let\@tarlinesep\tablinesep \fi
 \divide\@tarlinesep\tw@ % half sep is applied to height & depth
 \let\@seesize\relax \let\@rememsize\relax \@mkpream{#2}%
 \@tempdima\arraystretch\ht\strutbox \@tempdimb\arraystretch\dp\strutbox
 \ifdim\@tarlinesep>\z@ % (need \protect for \multicolumn)
   \def\@rememsize{\protect\@r@m@msize}\let\@seesize\@s@@size
   \advance\@tempdima-\@tarlinesep \advance\@tempdimb-\@tarlinesep
 \fi \setbox\@arstrutbox\hbox{% set up smaller strut
    \vrule \@height\@tempdima \@depth\@tempdimb \@width\z@}%
 \let\protect\noexpand
 \edef\@preamble{\ialign \noexpand\@halignto \bgroup
 \unhcopy\@arstrutbox \@preamble \tabskip\z@skip &\@sharp \cr}%
 \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
 \if#1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
 \bgroup \let\par\@empty
 \global\@arstheight\ht\@arstrutbox \global\@arstdepth\dp\@arstrutbox
 \advance\extrarulesep.5\arrayrulewidth
 \let\@sharp##\let\protect\relax \lineskip\z@skip \baselineskip\z@skip
 \if@RTLtab\hbox\bgroup\beginR\@hboxRconstructtrue\if#1t\vtop \else \vbox \fi\bgroup\fi
 \@preamble}
%    \end{macrocode}
% \iffalse
%</tabls-xetex-bidi.def>
%<*tabularx-xetex-bidi.def>
%\fi
% \section{File \texttt{tabularx-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tabularx-xetex-bidi.def}[2014/11/08 v0.1 bidi adaptations for tabularx package for XeTeX engine]
\def\TX@endtabularx{%
   \expandafter\expandafter\expandafter
     \TX@find@endtabularxa\csname end\TX@\endcsname
     \endtabularx\TX@\endtabularx\TX@find@endtabularxa
  \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}%
  \let\verb\TX@verb
  \def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
  \edef\TX@ckpt{\cl@@ckpt}%
  \let\@elt\relax
  \TX@old@table\maxdimen
  \TX@col@width\TX@target
  \global\TX@cols\@ne
  \TX@typeout@
    {\@spaces Table Width\@spaces Column Width\@spaces X Columns}%
  \TX@trial{\def\NC@rewrite@X{%
          \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}%
  \loop
    \TX@arith
    \ifTX@
    \TX@trial{}%
  \repeat
  {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext
   \let\@LTRfootnotetext\TX@LTRftntext\let\@xLTRfootnotenext\TX@xLTRftntext
   \let\@RTLfootnotetext\TX@RTLftntext\let\@xRTLfootnotenext\TX@xRTLftntext
    \csname tabular*\expandafter\endcsname\expandafter\TX@target
      \the\toks@
    \csname endtabular*\endcsname}%
  \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn
  \ifnum0=`{\fi}%
   \expandafter\expandafter\expandafter
   \TX@find@endtabularxbb
    \expandafter\end\expandafter{\TX@}%
    \endtabularx\TX@\endtabularx\TX@find@endtabularxb
}

\def\TX@trial#1{%
  \setbox\@tempboxa\hbox{%
    #1\relax
  \let\@footnotetext\TX@trial@ftn
  \let\@LTRfootnotetext\TX@trial@ftn
  \let\@RTLfootnotetext\TX@trial@ftn
  \let\TX@vwarn\@empty
   \expandafter\let\expandafter\tabularx\csname tabular*\endcsname
   \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname
   \def\write{\begingroup
     \def\let{\afterassignment\endgroup\toks@}%
        \afterassignment\let\count@}%
    \hbadness\@M
    \hfuzz\maxdimen
    \let\hbadness\@tempcnta
    \let\hfuzz\@tempdima
    \expandafter\tabular\the\toks@
    \endtabular}%
  \TX@ckpt
  \TX@typeout@{\@spaces
     \expandafter\TX@align
        \the\wd\@tempboxa\space\space\space\space\space\@@
     \expandafter\TX@align
        \the\TX@col@width\space\space\space\space\space\@@
     \@spaces\the\TX@cols}}

\long\def\TX@LTRftntext#1{%
  \edef\@tempa{\the\TX@ftn\noexpand\LTRfootnotetext
                    [\the\csname c@\@mpfn\endcsname]}%
  \global\TX@ftn\expandafter{\@tempa{#1}}}%
\long\def\TX@xLTRftntext[#1]#2{%
  \global\TX@ftn\expandafter{\the\TX@ftn\LTRfootnotetext[#1]{#2}}}
  
\long\def\TX@RTLftntext#1{%
  \edef\@tempa{\the\TX@ftn\noexpand\RTLfootnotetext
                    [\the\csname c@\@mpfn\endcsname]}%
  \global\TX@ftn\expandafter{\@tempa{#1}}}%
\long\def\TX@xRTLftntext[#1]#2{%
  \global\TX@ftn\expandafter{\the\TX@ftn\RTLfootnotetext[#1]{#2}}}
%    \end{macrocode}
% \iffalse
%</tabularx-xetex-bidi.def>
%<*tabulary-xetex-bidi.def>
%\fi
% \section{File \texttt{tabulary-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tabulary-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for tabulary package for XeTeX engine]
\def\@testpach{\@chclass
 \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
  \ifnum \@lastchclass=7 5 \else
   \ifnum \@lastchclass=8 \tw@ \else
    \ifnum \@lastchclass=9 \thr@@
   \else \z@
   \ifnum \@lastchclass = 10 \else
   \edef\@nextchar{\expandafter\string\@nextchar}%
   \@chnum
   \if \@nextchar c\z@ \else
    \if \@nextchar \if@RTLtab r\else l\fi\@ne \else
     \if \@nextchar \if@RTLtab l\else r\fi\tw@ \else
   \if \@nextchar C7 \else
    \if \@nextchar L8 \else
     \if \@nextchar R9 \else
     \if \@nextchar J10 \else
   \z@ \@chclass
   \if\@nextchar |\@ne \else
    \if \@nextchar !6 \else
     \if \@nextchar @7 \else
      \if \@nextchar <8 \else
       \if \@nextchar >9 \else
  10
  \@chnum
  \if \@nextchar m\thr@@\else
   \if \@nextchar p4 \else
    \if \@nextchar b5 \else
   \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi\fi \fi \fi\fi \fi
     \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi}
%    \end{macrocode}
% \iffalse
%</tabulary-xetex-bidi.def>
%<*tc-xetex-xetex-bidi.def>
%\fi
% \section{File \texttt{tc-xetex-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tc-xetex-xetex-bidi.def}[2014/07/08 v0.1 bidi adaptations for Clipping driver for XeTeX engine]
\def\@cliptoboxdim#1{%
    \setbox#1=\hbox{%
        \Gin@defaultbp\WIDTH{\wd#1}%
        \Gin@defaultbp\DEPTH{\dp#1}%
        \@tempdima\ht#1%
        \advance\@tempdima\dp#1%
        \Gin@defaultbp\TOTALHEIGHT{\@tempdima}%
        \beginL\special{pdf:bcontent }%
        \special{%
            pdf:literal direct
                0 -\DEPTH\space \WIDTH\space \TOTALHEIGHT\space re
        }%
        \special{pdf:literal direct W }%
        \special{pdf:literal direct n }%
            \if@RTL\beginR\fi\box#1\if@RTL\endR\fi%
        \special{pdf:econtent }\endL%
    }%
}
%    \end{macrocode}
% \iffalse
%</tc-xetex-xetex-bidi.def>
%<*tcolorbox-xetex-bidi.def>
%\fi
% \section{File \texttt{tcolorbox-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tcolorbox-xetex-bidi.def}[2018/11/11 v0.2 bidi adaptations for tcolorbox package for XeTeX engine]
\let\endtcb@lrbox=\endminipage
\let\endtcb@savebox=\endtcb@lrbox

\bidi@patchcmd{\tcb@vbox}{%
  \let\@footnotetext\@mpfootnotetext%
}{%
  \let\@footnotetext\@mpfootnotetext%
  \let\@LTRfootnotetext\@mpLTRfootnotetext%
  \let\@RTLfootnotetext\@mpRTLfootnotetext%
}{}{}

\bidi@patchcmd{\endtcb@vbox}{%
    \footnoterule%
}{%
    \bidi@mpfootnoterule%
}{}{}
\bidi@apptocmd\tcb@@icolorbox{%
  \@bidi@list@minipage@parboxfalse
}{}{}
%    \end{macrocode}
% \iffalse
%</tcolorbox-xetex-bidi.def>
%<*thmbox-xetex-bidi.def>
%\fi
% \section{File \texttt{thmbox-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{thmbox-xetex-bidi.def}[2025/09/04 v0.1 bidi adaptations for thmbox package for XeTeX engine]
\renewenvironment{thmbox}[2][]{%
  \parskip\z@%
  \setkeys{thmbox}{#1}%
  \ifx\thmbox@style S\else\ifx\thmbox@style M\else\ifx\thmbox@style L\else%
    \PackageWarning{thmbox}{\thmbox@style\ is not a valid style for
      \string\thmbox, using M}%
    \let\thmbox@style=M%
  \fi\fi\fi%
  \thmbox@head{{#2}}\nobreak\relax%
  \thmbox@dim=\hsize%
  \advance\thmbox@dim-\leftskip%
  \advance\thmbox@dim-\rightskip%
  \setbox\thmbox@box=\vbox\bgroup%
    \if@RTL
      \@hboxRconstructtrue
    \fi
    \hsize=\thmbox@dim%
    \advance\hsize -\thmbox@leftmargin%
    \advance\hsize -\thmbox@rightmargin%
    \textwidth=\hsize%
    \linewidth=\hsize%
    \vskip\thmbox@vskip%
    \begingroup}{\endgroup%
    \vskip\thmbox@vskip%
  \egroup%
  \thmbox@start%
  \ifx\thmbox@style S\else\thmbox@tail\fi%
  \@endparenv}
%    \end{macrocode}
% \iffalse
%</thmbox-xetex-bidi.def>
%<*titlesec-xetex-bidi.def>
%\fi
% \section{File \texttt{titlesec-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{titlesec-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for titlesec package for XeTeX engine]
\renewcommand\filright{%
  \gdef\ttl@filleft##1{\hskip##1}%
  \gdef\ttl@filright##1{\hfill}%
  \let\\\@centercr
  \advance\rightskip\z@ \@plus 1fil
\parfillskip\z@}
\def\ttlh@hang#1#2#3#4#5#6#7#8{%
  \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
  \setlength\leftskip{#6}%
  \setlength\rightskip{#7}%
  \interlinepenalty\@M
  \ttl@changecentercr
  \ttl@beginlongest
  #1{\ifhmode\ttl@hmode@error\fi
     \ttl@glcmds
     \parindent\z@
     \leavevmode
     \begingroup
       \ifttl@label
          \sbox\z@{#2\strut\ttl@calc\hspace{#3}}%
          \if@RTL\advance\rightskip\wd\z@\else\advance\leftskip\wd\z@\fi
          \llap{\box\z@}%
       \fi
       #4{#8}%
       \kern\z@\strut\@@par
     \endgroup
     \nobreak\ttl@midlongest#5\@@par}%
  \ttl@endlongest}
%    \end{macrocode}
% \iffalse
%</titlesec-xetex-bidi.def>
%<*titletoc-xetex-bidi.def>
%\fi
% \section{File \texttt{titletoc-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{titletoc-xetex-bidi.def}[2013/04/10 v0.2 bidi adaptations for titletoc package for XeTeX engine]
\renewcommand\filright{%
  \gdef\ttl@filleft##1{\hskip##1}%
  \gdef\ttl@filright##1{\hfill}%
  \let\\\@centercr
  \advance\rightskip\z@ \@plus 1fil
\parfillskip\z@}
\renewcommand\contentspush[1]{%
  \sbox\z@{#1}%
  \xdef\ttl@b{\advance\if@RTL\rightskip\else\leftskip\fi\the\wd\z@}%
  \aftergroup\ttl@b
  \leavevmode\llap{\box\z@}}
\def\ttl@outnoblock#1#2#3{%
  \begingroup
  \ifnum\ttl@b>\ttl@a
    \nobreak
  \else\ifnum\ttl@b<\ttl@a
    \addpenalty{\@secpenalty}%
  \else
    \addpenalty{\z@}% 
  \fi\fi
  \ttl@contentsstretch
  \nobreak
  \ifcase#1\relax\else\interlinepenalty\@M\fi
  \parindent\z@
  \ifx\@nil#2%
    \PackageError{titletoc}{Unimplemented}%
	    {The optional argument is currently mandatory}%
  \else
    \if@RTL\setlength\rightskip{#2}\else
    \setlength\leftskip{#2}\fi%
  \fi
  \if@RTL\setlength\leftskip{\@pnumwidth}\else\setlength\rightskip{\@pnumwidth}\fi%
  \let\contentsmargin\ttl@margin
  \def\ttl@makeline##1{##1}%
  #3%
  \addtolength{\parfillskip}{-\ttl@corr}%
  \if@RTL\addtolength{\leftskip}{\ttl@corr}\else\addtolength{\rightskip}{\ttl@corr}\fi%
  \let\ttl@leaders\leaders}
\renewcommand\ttl@margin[2][\z@]{%
  \def\ttl@corr{#1}%
  \advance\if@RTL\leftskip\else\rightskip\fi-\@pnumwidth\relax
  \advance\if@RTL\leftskip\else\rightskip\fi#2\relax
  \def\@pnumwidth{#2}}
\let\ttl@savel@part\l@part
\def\l@part{\ttl@lselect{part}}

\let\ttl@savel@chapter\l@chapter
\def\l@chapter{\ttl@lselect{chapter}}
%    \end{macrocode}
% \iffalse
%</titletoc-xetex-bidi.def>
%<*tocbibind-xetex-bidi.def>
%\fi
% \section{File \texttt{tocbibind-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tocbibind-xetex-bidi.def}[2025/01/03 v0.5 bidi adaptations for tocbibind package for XeTeX engine]
\IfClassLoadedT{memoir}{\endinput}
\if@dotocbib
  \ApplyPatchIfPackageLoadedF{natbib}{% natbib not loaded
    \renewcommand{\bibsection}{\t@cb@bchapsec}
    \renewenvironment{thebibliography}[1]{%
      \bibsection
      \begin{thebibitemlist}{#1}}{\end{thebibitemlist}}}
  \renewenvironment{thebibitemlist}[1]{
    \if@RTL\if@LTRbibitems\@RTLfalse\else\fi\else\if@RTLbibitems\@RTLtrue\else\fi\fi
    \bidi@@thebibliography@font@hook%
    \list{\@biblabel{\@arabic\c@enumiv}}%
         {\settowidth\labelwidth{\@biblabel{#1}}%
          \leftmargin\labelwidth
          \advance\leftmargin\labelsep
          \@openbib@code
          \usecounter{enumiv}%
          \let\p@enumiv\@empty
          \renewcommand\theenumiv{\@arabic\c@enumiv}}%
    \sloppy
    \clubpenalty4000
    \@clubpenalty \clubpenalty
    \widowpenalty4000%
    \sfcode`\.\@m}
   {\def\@noitemerr
     {\@latex@warning{Empty `thebibliography' environment}}%
     \endlist}

\ApplyPatchCodeToPackage{chapterbib}{%
  \@ifpackagewith{chapterbib}{sectionbib}%
    {\renewcommand{\sectionbib}[2]{}}%
    {}%
 }

\fi
\if@inltxdoc\else
  \renewenvironment{theindex}%
    {\if@twocolumn
       \@restonecolfalse
     \else
       \@restonecoltrue
     \fi
     \if@bibchapter
        \if@donumindex
          \refstepcounter{chapter}
          \twocolumn[\vspace*{2\topskip}%
                     \@makechapterhead{\indexname}]%
          \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}\indexname}
          \chaptermark{\indexname}
        \else
          \if@dotocind
            \twocolumn[\vspace*{2\topskip}%
                       \@makeschapterhead{\indexname}]%
            \prw@mkboth{\indexname}
            \addcontentsline{toc}{chapter}{\indexname}
          \else
            \twocolumn[\vspace*{2\topskip}%
                       \@makeschapterhead{\indexname}]%
            \prw@mkboth{\indexname}
          \fi
        \fi
     \else
        \if@donumindex
          \twocolumn[\vspace*{-1.5\topskip}%
                     \@nameuse{\@tocextra}{\indexname}]%
          \csname \@tocextra mark\endcsname{\indexname}
        \else
          \if@dotocind
            \twocolumn[\vspace*{-1.5\topskip}%
                       \toc@headstar{\@tocextra}{\indexname}]%
            \prw@mkboth{\indexname}
            \addcontentsline{toc}{\@tocextra}{\indexname}
          \else
            \twocolumn[\vspace*{-1.5\topskip}%
                       \toc@headstar{\@tocextra}{\indexname}]%
            \prw@mkboth{\indexname}
          \fi
        \fi
     \fi
   \thispagestyle{plain}\parindent\z@
   \parskip\z@ \@plus .3\p@\relax
   \let\item\@idxitem}
   {\if@restonecol\onecolumn\else\clearpage\fi}
\fi
%    \end{macrocode}
% \iffalse
%</tocbibind-xetex-bidi.def>
%<*tocloft-xetex-bidi.def>
%\fi
% \section{File \texttt{tocloft-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tocloft-xetex-bidi.def}[2025/01/03 v0.4 bidi adaptations for tocloft package for XeTeX engine]
\IfClassLoadedT{memoir}{\endinput}
\renewcommand{\cftpnumalign}{\if@RTL l\else r\fi}
\let\cftdot\@SepMark
\if@cfthaspart
\renewcommand*{\l@part}[2]{
  \@cftdopartfalse
  \ifnum \c@tocdepth >-2\relax
    \if@cfthaschapter
      \@cftdoparttrue
    \fi
    \ifnum \c@tocdepth >\m@ne
      \if@cfthaschapter\else
        \@cftdoparttrue
      \fi
    \fi
  \fi
  \if@cftdopart
    \if@cfthaschapter
      \addpenalty{-\@highpenalty}
    \else
      \addpenalty\@secpenalty
    \fi
    \addvspace{\cftbeforepartskip}
    \begingroup
      {\if@RTL\rightskip\else\leftskip\fi \cftpartindent\relax
       \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
       \parfillskip -\if@RTL\leftskip\else\rightskip\fi
       \parindent \cftpartindent\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \cftpartnumwidth\relax
       \let\@cftbsnum \cftpartpresnum
       \let\@cftasnum \cftpartaftersnum
       \let\@cftasnumb \cftpartaftersnumb
       \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
       {\cftpartfont \cftpartpresnum #1}
       \cftpartfillnum{#2}}
      \nobreak
      \if@cfthaschapter
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}
      \else
        \if@compatibility
          \global\@nobreaktrue
          \everypar{\global\@nobreakfalse\everypar{}}
        \fi
      \fi
    \endgroup
  \fi}
\fi
\if@cfthaschapter
\renewcommand*{\l@chapter}[2]{
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}
    \vskip \cftbeforechapskip
    {\if@RTL\rightskip\else\leftskip\fi \cftchapindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftchapindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftchapnumwidth\relax
     \let\@cftbsnum \cftchappresnum
     \let\@cftasnum \cftchapaftersnum
     \let\@cftasnumb \cftchapaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftchapfont #1}\nobreak
     \cftchapfillnum{#2}}
  \fi}
\fi
\renewcommand*{\l@section}[2]{%
  \ifnum \c@tocdepth >\z@
    \if@cfthaschapter
      \vskip \cftbeforesecskip
    \else
      \addpenalty\@secpenalty
      \addvspace{\cftbeforesecskip}
    \fi
    {\if@RTL\rightskip\else\leftskip\fi \cftsecindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsecnumwidth\relax
     \let\@cftbsnum \cftsecpresnum
     \let\@cftasnum \cftsecaftersnum
     \let\@cftasnumb \cftsecaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsecfont #1}\nobreak
     \cftsecfillnum{#2}}
  \fi}
\renewcommand*{\l@subsection}[2]{%
  \ifnum \c@tocdepth >\@ne
    \vskip \cftbeforesubsecskip
    {\if@RTL\rightskip\else\leftskip\fi \cftsubsecindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsubsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubsecnumwidth\relax
     \let\@cftbsnum \cftsubsecpresnum
     \let\@cftasnum \cftsubsecaftersnum
     \let\@cftasnumb \cftsubsecaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsubsecfont #1}\nobreak
     \cftsubsecfillnum{#2}}
  \fi}
\renewcommand*{\l@subsubsection}[2]{%
  \ifnum \c@tocdepth >\tw@
    \vskip \cftbeforesubsubsecskip
    {\if@RTL\rightskip\else\leftskip\fi \cftsubsubsecindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsubsubsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubsubsecnumwidth\relax
     \let\@cftbsnum \cftsubsubsecpresnum
     \let\@cftasnum \cftsubsubsecaftersnum
     \let\@cftasnumb \cftsubsubsecaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsubsubsecfont #1}\nobreak
     \cftsubsubsecfillnum{#2}}
  \fi}
\renewcommand*{\l@paragraph}[2]{%
  \ifnum \c@tocdepth >3\relax
    \vskip \cftbeforeparaskip
    {\if@RTL\rightskip\else\leftskip\fi \cftparaindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftparaindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftparanumwidth\relax
     \let\@cftbsnum \cftparapresnum
     \let\@cftasnum \cftparaaftersnum
     \let\@cftasnumb \cftparaaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftparafont #1}\nobreak
     \cftparafillnum{#2}}
  \fi}
\renewcommand*{\l@subparagraph}[2]{%
  \ifnum \c@tocdepth >4\relax
    \vskip \cftbeforesubparaskip
    {\if@RTL\rightskip\else\leftskip\fi \cftsubparaindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsubparaindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubparanumwidth\relax
     \let\@cftbsnum \cftsubparapresnum
     \let\@cftasnum \cftsubparaaftersnum
     \let\@cftasnumb \cftsubparaaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsubparafont #1}\nobreak
     \cftsubparafillnum{#2}}
  \fi}
\renewcommand*{\l@figure}[2]{%
  \ifnum \c@lofdepth >\z@
    \vskip \cftbeforefigskip
    {\if@RTL\rightskip\else\leftskip\fi \cftfigindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftfignumwidth\relax
     \let\@cftbsnum \cftfigpresnum
     \let\@cftasnum \cftfigaftersnum
     \let\@cftasnumb \cftfigaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftfigfont #1}\nobreak
     \cftfigfillnum{#2}}
   \fi
  }
\renewcommand*{\l@table}[2]{%
  \ifnum\c@lotdepth >\z@
    \vskip \cftbeforetabskip
    {\if@RTL\rightskip\else\leftskip\fi \cfttabindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cfttabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cfttabnumwidth\relax
     \let\@cftbsnum \cfttabpresnum
     \let\@cftasnum \cfttabaftersnum
     \let\@cftasnumb \cfttabaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cfttabfont #1}\nobreak
     \cfttabfillnum{#2}}
   \fi
  }
\renewcommand{\@cftl@subfig}{
\renewcommand*{\l@subfigure}[2]{%
  \ifnum \c@lofdepth > \toclevel@subfigure
    \vskip \cftbeforesubfigskip
    {\if@RTL\rightskip\else\leftskip\fi \cftsubfigindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsubfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubfignumwidth\relax
     \let\@cftbsnum \cftsubfigpresnum
     \let\@cftasnum \cftsubfigaftersnum
     \let\@cftasnumb \cftsubfigaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsubfigfont ##1}\nobreak
     \cftsubfigfillnum{##2}}
  \fi
  }
}
\renewcommand{\@cftl@subtab}{
\renewcommand*{\l@subtable}[2]{%
  \ifnum \c@lotdepth > \toclevel@subtable
    \vskip \cftbeforesubtabskip
    {\if@RTL\rightskip\else\leftskip\fi \cftsubtabindent\relax
     \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
     \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent \cftsubtabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubtabnumwidth\relax
     \let\@cftbsnum \cftsubtabpresnum
     \let\@cftasnum \cftsubtabaftersnum
     \let\@cftasnumb \cftsubtabaftersnumb
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {\cftsubtabfont ##1}\nobreak
     \cftsubtabfillnum{##2}}
  \fi
  }
}
\renewcommand{\newlistentry}[4][\@empty]{%
  \@ifundefined{c@#2}{%    check & set the counter
    \ifx \@empty#1\relax
      \newcounter{#2}
    \else
      \@ifundefined{c@#1}{\PackageWarning{tocloft}%
                          {#1 has no counter for use as a `within'}
        \newcounter{#2}}%
      {\newcounter{#2}[#1]%
       \expandafter\edef\csname the#2\endcsname{%
         \expandafter\noexpand\csname the#1\endcsname\@SepMark\noexpand\arabic{#2}}}
    \fi
    \setcounter{#2}{0}
  }
  {\PackageError{tocloft}{#2 has been previously defined}{\@eha}}

  \@namedef{l@#2}##1##2{%
    \ifnum \@nameuse{c@#3depth} > #4\relax
      \vskip \@nameuse{cftbefore#2skip}
      {\if@RTL\rightskip\else\leftskip\fi \@nameuse{cft#2indent}\relax
       \if@RTL\leftskip\else\rightskip\fi \@tocrmarg
       \parfillskip -\if@RTL\leftskip\else\rightskip\fi
       \parindent \@nameuse{cft#2indent}\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \@nameuse{cft#2numwidth}\relax
       \expandafter\let\expandafter\@cftbsnum\csname cft#2presnum\endcsname
       \expandafter\let\expandafter\@cftasnum\csname cft#2aftersnum\endcsname
       \expandafter\let\expandafter\@cftasnumb\csname cft#2aftersnumb\endcsname
       \advance\if@RTL\rightskip\else\leftskip\fi\@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
       {\@nameuse{cft#2font}##1}\nobreak
       \@nameuse{cft#2fillnum}{##2}}
    \fi
  }  % end of \l@#2

  \expandafter\newlength\csname cftbefore#2skip\endcsname
    \setlength{\@nameuse{cftbefore#2skip}}{\z@ \@plus .2\p@}
  \expandafter\newlength\csname cft#2indent\endcsname
  \expandafter\newlength\csname cft#2numwidth\endcsname
  \ifcase #4\relax  % 0
    \setlength{\@nameuse{cft#2indent}}{0em}
    \setlength{\@nameuse{cft#2numwidth}}{1.5em}
  \or               % 1
    \setlength{\@nameuse{cft#2indent}}{1.5em}
    \setlength{\@nameuse{cft#2numwidth}}{2.3em}
  \or               % 2
    \setlength{\@nameuse{cft#2indent}}{3.8em}
    \setlength{\@nameuse{cft#2numwidth}}{3.2em}
  \or               % 3
    \setlength{\@nameuse{cft#2indent}}{7.0em}
    \setlength{\@nameuse{cft#2numwidth}}{4.1em}
  \else             % anything else
    \setlength{\@nameuse{cft#2indent}}{10.0em}
    \setlength{\@nameuse{cft#2numwidth}}{5.0em}
  \fi
  \@namedef{cft#2font}{\normalfont}
  \@namedef{cft#2presnum}{}
  \@namedef{cft#2aftersnum}{}
  \@namedef{cft#2aftersnumb}{}
  \@namedef{cft#2dotsep}{\cftdotsep}
  \@namedef{cft#2leader}{\normalfont\cftdotfill{\@nameuse{cft#2dotsep}}}
  \@namedef{cft#2pagefont}{\normalfont}
  \@namedef{cft#2afterpnum}{}
  \@namedef{toclevel@#2}{#4}
  \@namedef{cft#2fillnum}##1{%
    {\@nameuse{cft#2leader}}\nobreak
    \hb@xt@\@pnumwidth{\hfil\@nameuse{cft#2pagefont}##1}\@nameuse{cft#2afterpnum}\par}
} % end \newlistentry
\renewcommand{\cftchapterprecistoc}[1]{\addtocontents{toc}{%
  {\if@RTL\rightskip\else\leftskip\fi \cftchapindent\relax
   \advance\if@RTL\righskip\else\leftskip\fi \cftchapnumwidth\relax
   \if@RTL\leftskip\else\rightskip\fi \@tocrmarg\relax
   \textit{#1}\protect\par}}}
%    \end{macrocode}
% \iffalse
%</tocloft-xetex-bidi.def>
%<*tocbasic-xetex-bidi.def>
%\fi
% \section{File \texttt{tocbasic-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tocbasic-xetex-bidi.def}[2022/06/15 v0.5 bidi adaptations for tocbasic package for XeTeX engine]
\bidi@undef\scr@dte@def@l@undottedtocline
\bidi@undef\scr@dte@undottedtocline@init
\DeclareTOCEntryStyle{undottedtocline}[{%
  \DefineTOCEntryLengthOption{indent}%
    {scr@tso@}{@indent}{entry indent}%
  \DefineTOCEntryLengthOption{numwidth}%
    {scr@tso@}{@numwidth}{entry number width}%
  \@ifundefined{#1tocdepth}{%
    \Ifstr{#1}{part}{\@namedef{#1tocdepth}{-1}}{%
      \Ifstr{#1}{chapter}{\@namedef{#1tocdepth}{0}}{%
        \Ifstr{#1}{section}{\@namedef{#1tocdepth}{1}}{%
          \Ifstr{#1}{subsection}{\@namedef{#1tocdepth}{2}}{%
            \Ifstr{#1}{subsubsection}{\@namedef{#1tocdepth}{3}}{%
              \Ifstr{#1}{paragraph}{\@namedef{#1tocdepth}{4}}{%
                \Ifstr{#1}{subparagraph}{\@namedef{#1tocdepth}{5}}{%
                  \Ifstr{#1}{figure}{\@namedef{#1tocdepth}{1}}{%
                    \Ifstr{#1}{table}{\@namedef{#1tocdepth}{1}}{%
                      \expandafter\let\csname #1tocdepth\expandafter\endcsname
                      \csname #1numdepth\endcsname
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }%
  }{}%
  \@ifundefined{scr@tso@#1@indent}{%
    \@ifundefined{scr@#1@tocindent}{%
      \Ifstr{#1}{figure}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
        \Ifstr{#1}{table}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
          \Ifstr{#1}{part}{\@namedef{scr@tso@#1@indent}{0em}}{%
            \Ifstr{#1}{chapter}{\@namedef{scr@tso@#1@indent}{0em}}{%
              \scr@ifundefinedorrelax{l@chapter}{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{0pt}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{3.8em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{7em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{10em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{3.8em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{7.0em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{10em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{12em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }{%
      \@namedef{scr@tso@#1@indent}{\@nameuse{scr@#1@tocindent}}%
    }%
  }{}%
  \@ifundefined{scr@tso@#1@numwidth}{%
    \@ifundefined{scr@#1@tocnumwidth}{%
      \Ifstr{#1}{figure}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
        \Ifstr{#1}{table}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
          \Ifstr{#1}{chapter}{\@namedef{scr@tso@#1@numwidth}{1.5em}}{%
            \scr@ifundefinedorrelax{chapter}{%
              \Ifstr{#1}{section}{\@namedef{scr@tso@#1@numwidth}{1.5em}}{%
                \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
                  \Ifstr{#1}{subsubsection}{%
                    \@namedef{scr@tso@#1@numwidth}{3.2em}%
                  }{%
                    \Ifstr{#1}{paragraph}{%
                      \@namedef{scr@tso@#1@numwidth}{4.1em}%
                    }{%
                      \Ifstr{#1}{subparagraph}{%
                        \@namedef{scr@tso@#1@numwidth}{5m}%
                      }{%
                      }%
                    }%
                  }%
                }%
              }%
            }{%
              \Ifstr{#1}{section}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
                \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@numwidth}{3.2em}}{%
                  \Ifstr{#1}{subsubsection}{%
                    \@namedef{scr@tso@#1@numwidth}{3.1em}%
                  }{%
                    \Ifstr{#1}{paragraph}{%
                      \@namedef{scr@tso@#1@numwidth}{5em}%
                    }{%
                      \Ifstr{#1}{subparagraph}{%
                        \@namedef{scr@tso@#1@numwidth}{6em}%
                      }{%
                      }%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }{%
      \@namedef{scr@tso@#1@numwidth}{\@nameuse{scr@#1@tocnumwidth}}%
    }%
  }{}%
}]{%
  \ifnum \c@tocdepth >\numexpr \@nameuse{#1tocdepth}-\@ne\relax
    \ifnum \@nameuse{#1tocdepth}<\@ne
      \scr@ifundefinedorrelax{chapter}{%
        \addpenalty\@secpenalty
        \addvspace{1.0em \@plus\p@}%
      }{%
        \addpenalty{-\@highpenalty}%
        \vskip 1.0em \@plus\p@
      }%
    \else
      \addpenalty\@secpenalty
      \addvspace{1.0em \@plus\p@}%
    \fi
    \setlength\@tempdima{\@nameuse{scr@tso@#1@numwidth}}%
    \begingroup
      \parindent \z@ \bidi@rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \bfseries
      \advance\bidi@leftskip\@tempdima
      \Iftocfeature{\@currext}{noindent}{%
        \hskip -\bidi@leftskip
      }{%
        \advance\bidi@leftskip\@nameuse{scr@tso@#1@indent}%
        \hskip -\dimexpr \bidi@leftskip-\@nameuse{scr@tso@#1@indent}\relax
      }%
      ##1%
      \nobreak
      \hfil \nobreak\hb@xt@\@pnumwidth{\hss ##2}%
      \par
      \penalty\@highpenalty
    \endgroup
  \fi
}

\bidi@undef\scr@dte@def@l@largetocline
\bidi@undef\scr@dte@largetocline@init
\DeclareTOCEntryStyle{largetocline}[{%
  \DefineTOCEntryLengthOption{indent}%
    {scr@tso@}{@indent}{entry indent}%
  \@ifundefined{#1tocdepth}{%
    \Ifstr{#1}{part}{\@namedef{#1tocdepth}{-1}}{%
      \Ifstr{#1}{chapter}{\@namedef{#1tocdepth}{0}}{%
        \Ifstr{#1}{section}{\@namedef{#1tocdepth}{1}}{%
          \Ifstr{#1}{subsection}{\@namedef{#1tocdepth}{2}}{%
            \Ifstr{#1}{subsubsection}{\@namedef{#1tocdepth}{3}}{%
              \Ifstr{#1}{paragraph}{\@namedef{#1tocdepth}{4}}{%
                \Ifstr{#1}{subparagraph}{\@namedef{#1tocdepth}{5}}{%
                  \Ifstr{#1}{figure}{\@namedef{#1tocdepth}{1}}{%
                    \Ifstr{#1}{table}{\@namedef{#1tocdepth}{1}}{%
                      \expandafter\let\csname #1tocdepth\expandafter\endcsname
                      \csname #1numdepth\endcsname
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }%
  }{}%
  \@ifundefined{scr@tso@#1@indent}{%
    \@ifundefined{scr@#1@tocindent}{%
      \Ifstr{#1}{figure}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
        \Ifstr{#1}{table}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
          \Ifstr{#1}{part}{\@namedef{scr@tso@#1@indent}{0em}}{%
            \Ifstr{#1}{chapter}{\@namedef{scr@tso@#1@indent}{0em}}{%
              \scr@ifundefinedorrelax{l@chapter}{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{0pt}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{3.8em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{7em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{10em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{3.8em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{7.0em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{10em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{12em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }{%
      \@namedef{scr@tso@#1@indent}{\@nameuse{scr@#1@tocindent}}%
    }%
  }{}%
}]{%
  \ifnum \c@tocdepth >\numexpr \@nameuse{#1tocdepth}-\@ne\relax
    \ifnum \@nameuse{#1tocdepth}<\@ne
      \scr@ifundefinedorrelax{chapter}{%
        \addpenalty\@secpenalty
        \addvspace{2.25em \@plus\p@}%
      }{%
        \addpenalty{-\@highpenalty}%
        \addvspace{2.25em \@plus\p@}%
      }%
    \else
      \addpenalty\@secpenalty
      \addvspace{2.25em \@plus\p@}%
    \fi
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \bidi@rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \large
      \bfseries
      \Iftocfeature{\@currext}{noindent}{%
      }{%
        \advance\bidi@leftskip\@nameuse{scr@tso@#1@indent}%
      }%
      ##1%
      \hfil \nobreak\hb@xt@\@pnumwidth{\hss ##2}%
      \par
      \nobreak
      \ifnum 0=
        \scr@ifundefinedorrelax{chapter}{\if@compatibility 1\else 0\fi}{1}\relax
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \fi
    \endgroup
  \fi
}

\renewcommand*{\scr@dte@tocline}[3]{%
  \ifnum \@nameuse{#1tocdepth}>\c@tocdepth
  \else
    \tocbasic@DependOnPenaltyAndTOCLevel{#1}%
    \addvspace{\@nameuse{scr@tso@#1@beforeskip}}\relax
    \@nameuse{Ifscr@tso@#1@dynindent}{%
      \expandafter\ifx\csname scr@tso@#1@indentfollows\endcsname\@empty
        \PackageWarning{tocbasic}{`dynindent' for `#1' not available}%
      \else
        \edef\reserved@a{\@nameuse{scr@tso@#1@indentfollows}}%
        \@for \reserved@a:=\reserved@a\do {%
          \scr@trim@spaces\reserved@a
          \ifx\reserved@a\@empty\else
            \scr@ifundefinedorrelax{\reserved@a tocdepth}{%
            }{%
              \ifnum \@nameuse{\reserved@a tocdepth}<\@nameuse{#1tocdepth}%
                \@tempdima\@nameuse{scr@tso@\reserved@a @indent}\relax
                \@nameuse{Ifscr@tso@\reserved@a @dynnumwidth}{%
                  \scr@ifundefinedorrelax
                  {scr@dte@\reserved@a @lastmaxnumwidth}{%
                    \advance\@tempdima
                    \@nameuse{scr@tso@\reserved@a @numwidth}\relax
                  }{%
                    \advance\@tempdima
                    \@nameuse{scr@dte@\reserved@a @lastmaxnumwidth}\relax
                  }%
                }{%
                  \advance\@tempdima
                  \@nameuse{scr@tso@\reserved@a @numwidth}\relax
                }%
                \ifdim \@tempdima>\@nameuse{scr@tso@#1@indent}\relax
                  \expandafter\edef\csname scr@tso@#1@indent\endcsname
                  {\the\@tempdima}%
                \fi
              \fi
            }%
          \fi
        }%
      \fi
    }{}%
    {%
      \Iftocfeature{\@currext}{noindent}{%
        \bidi@leftskip \z@
      }{%
        \bidi@leftskip \@nameuse{scr@tso@#1@indent}\relax
      }%
      \bidi@rightskip \@nameuse{scr@tso@#1@rightindent}\relax
      \parfillskip -\bidi@rightskip
      \@nameuse{Ifscr@tso@#1@raggedpage}{%
        \addtolength{\parfillskip}{\z@ \@plus 1fil}%
      }{}%
      \Iftocfeature{\@currext}{noindent}{%
        \parindent \z@
      }{%
        \parindent \@nameuse{scr@tso@#1@indent}\relax
      }%
      \@afterindenttrue
      \interlinepenalty\@M
      \expandafter\ifx\csname ragged#1entry\endcsname\raggedright
        \addtolength\bidi@rightskip\@flushglue
      \else
        \def\reserved@a{\raggedright}%
        \expandafter\ifx\csname ragged#1entry\endcsname\reserved@a
          \addtolength\bidi@rightskip\@flushglue
        \else
          \renewcommand\reserved@a{\raggedright}%
          \expandafter\ifx\csname ragged#1entry\endcsname\reserved@a
            \addtolength\bidi@rightskip\@flushglue
          \fi
        \fi
      \fi
      \leavevmode
      \@tempdima \@nameuse{scr@tso@#1@numwidth}\relax
      \@nameuse{Ifscr@tso@#1@dynnumwidth}{%
        \scr@ifundefinedorrelax{scr@dte@#1@lastmaxnumwidth}{}{%
          \ifdim \@nameuse{scr@dte@#1@lastmaxnumwidth}>\@tempdima
            \@tempdima\@nameuse{scr@dte@#1@lastmaxnumwidth}\relax
          \fi
        }%
      }{}%
      \advance\bidi@leftskip \@tempdima
      \null\nobreak\hskip -\bidi@leftskip
      {%
        \usetocbasicnumberline
        \let\scr@dte@numberline@box\numberline@box
        \def\numberline@box##1{%
          \sbox\scr@dte@tocline@numbox{\@nameuse{scr@tso@#1@numberformat}{##1}}%
          \global\scr@dte@tocline@numberwidth
          \dimexpr\wd\scr@dte@tocline@numbox+\@nameuse{scr@tso@#1@numsep}\relax
          \relax
          \ifdim \scr@dte@tocline@numberwidth
                >\@nameuse{scr@dte@#1@maxnumwidth}\relax
            \global\@nameuse{scr@dte@#1@maxnumwidth}\scr@dte@tocline@numberwidth
          \fi
          \@nameuse{Ifscr@tso@#1@dynnumwidth}{}{%
            \ifdim \scr@dte@tocline@numberwidth
                  >\dimexpr \@nameuse{scr@tso@#1@numwidth}%
                           +\@nameuse{scr@tso@#1@numsep}\relax\relax
              \PackageWarning{tocbasic}{%
                number width of #1 toc entries should be
                increased!\MessageBreak
                Currently used number width =
                \the\wd\scr@dte@tocline@numbox,\MessageBreak
                Wanted number separation
                \space\space\space =
                \the\dimexpr\@nameuse{scr@tso@#1@numsep}\relax,\MessageBreak
                Reserved number width \space\space\space\space\space\space =
                \the\dimexpr\@nameuse{scr@tso@#1@numwidth}\relax%
              }%
            \fi
          }%
          \scr@dte@numberline@box{\@nameuse{scr@tso@#1@numberformat}{##1}}%
          \@nameuse{Ifscr@tso@#1@breakafternumber}{%
            {\parfillskip\@flushglue\par}\nobreak\hskip-\bidi@leftskip
          }{}%
        }%
        {\@nameuse{scr@tso@#1@entryformat}{%
          #2%
          \nobreak
          {%
            \normalfont\normalsize\@nameuse{scr@tso@#1@linefill}%
            \nobreak
            \expandafter\let\expandafter\scr@dte@pagenumberwidth
            \csname scr@tso@#1@pagenumberwidth\endcsname
            \@nameuse{scr@tso@#1@pagenumberbox}{%
              \@nameuse{scr@tso@#1@pagenumberformat}{#3}%
            }%
          }%
        }}\@par
      }%
    }%
    \tocbasic@SetPenaltyByTOCLevel{#1}%
  \fi
}


\bidi@undef\scr@dte@def@l@tocline
\bidi@undef\scr@dte@tocline@init
\DeclareTOCEntryStyle{tocline}[{%
  \DefineTOCEntryLengthOption{beforeskip}%
    {scr@tso@}{@beforeskip}{vertical skip before the entry}%
  \DefineTOCEntryIfOption{breakafternumber}%
    {scr@tso@}{@breakafternumber}{line break after number flag}%
  \DefineTOCEntryIfOption{dynnumwidth}%
    {scr@tso@}{@dynnumwidth}{dynamic number width flag}%
  \DefineTOCEntryListOption{indentfollows}%
    {scr@tso@}{@indentfollows}{list of levels that define the indent}%
  \DefineTOCEntryIfOption{dynindent}%
    {scr@tso@}{@dynindent}{dynamic indent width flag}%
  \DefineTOCEntryCommandOption{entryformat}%
    {scr@tso@}{@entryformat}[1]{entry format}%
  \DefineTOCEntryCommandOption{entrynumberformat}%
    {scr@tso@}{@numberformat}[1]{entry number format}%
  \DefineTOCEntryCommandOption{linefill}[\TOCLineLeaderFill]%
    {scr@tso@}{@linefill}{filling between text and page number}%
  \DefineTOCEntryLengthOption{numsep}%
    {scr@tso@}{@numsep}{entry number separation}%
  \DefineTOCEntryCommandOption{onstarthigherlevel}%
    {scr@tso@}{@LastTOCLevelWasLower}{start higher level entry hook}%
  \DefineTOCEntryCommandOption{onstartlowerlevel}%
    {scr@tso@}{@LastTOCLevelWasHigher}{start lower level entry hook}%
  \DefineTOCEntryCommandOption{onstartsamelevel}%
    {scr@tso@}{@LastTOCLevelWasSame}{start same level entry hook}%
  \DefineTOCEntryCommandOption{pagenumberbox}%
    {scr@tso@}{@pagenumberbox}[1]{page number box}%
  \DefineTOCEntryCommandOption{pagenumberformat}%
    {scr@tso@}{@pagenumberformat}[1]{page number format}%
  \DefineTOCEntryLengthOption{pagenumberwidth}%
    {scr@tso@}{@pagenumberwidth}{width of page number box}%
  \DefineTOCEntryLengthOption{rightindent}%
    {scr@tso@}{@rightindent}{entry's text right indent}%
  \DefineTOCEntryOption{raggedentrytext}[true]{%
    \FamilySetBool{KOMAarg}{raggedentrytext}{@tempswa}{##1}%
    \ifx\FamilyKeyState\FamilyKeyStateProcessed
      \if@tempswa
        \expandafter\let\csname ragged\scr@dte@current entry\endcsname
        \raggedright
      \else
        \expandafter\let\csname ragged\scr@dte@current entry\endcsname
        \relax
      \fi
    \fi
  }%
  \DefineTOCEntryIfOption{raggedpagenumber}%
    {scr@tso@}{@raggedpage}{page number ragged flag}%
  \DefineTOCEntryLengthOption{indent}%
    {scr@tso@}{@indent}{entry indent}%
  \DefineTOCEntryLengthOption{numwidth}%
    {scr@tso@}{@numwidth}{entry number width}%
  \scr@ifundefinedorrelax{#1tocdepth}{%
    \Ifstrstart{#1}{sub}{%
      \scr@ifundefinedorrelax{\scr@dte@nosub{#1}tocdepth}{}{%
        \expandafter\edef\csname #1tocdepth\endcsname{%
          \the\numexpr \noexpand\@nameuse{\scr@dte@nosub{#1}tocdepth}+\@ne\relax
        }%
      }%
    }{}%
  }{}%
  \@ifundefined{#1tocdepth}{%
    \Ifstr{#1}{part}{\@namedef{#1tocdepth}{-1}}{%
      \Ifstr{#1}{chapter}{\@namedef{#1tocdepth}{0}}{%
        \Ifstr{#1}{section}{\@namedef{#1tocdepth}{1}}{%
          \Ifstr{#1}{subsection}{\@namedef{#1tocdepth}{2}}{%
            \Ifstr{#1}{subsubsection}{\@namedef{#1tocdepth}{3}}{%
              \Ifstr{#1}{paragraph}{\@namedef{#1tocdepth}{4}}{%
                \Ifstr{#1}{subparagraph}{\@namedef{#1tocdepth}{5}}{%
                  \Ifstr{#1}{figure}{\@namedef{#1tocdepth}{1}}{%
                    \Ifstr{#1}{table}{\@namedef{#1tocdepth}{1}}{%
                      \expandafter\let\csname #1tocdepth\expandafter\endcsname
                      \csname #1numdepth\endcsname
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }%
  }{}%
  \scr@ifundefinedorrelax{scr@tso@#1@indent}{%
    \@ifundefined{scr@#1@tocindent}{%
      \Ifstrstart{#1}{sub}{%
        \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@indent}{%
          \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@numwidth}{}{%
            \expandafter\edef\csname scr@tso@#1@indent\endcsname{%
              \glueexpr \noexpand\@nameuse{scr@tso@\scr@dte@nosub{#1}@numwidth}%
              \relax
            }%
          }%
        }{%
          \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@numwidth}{%
            \expandafter\edef\csname scr@tso@#1@indent\endcsname{%
              \glueexpr \noexpand\@nameuse{scr@tso@\scr@dte@nosub{#1}@indent}%
              \relax
            }%
          }{%
            \expandafter\edef\csname scr@tso@#1@indent\endcsname{%
              \glueexpr \noexpand\@nameuse{scr@tso@\scr@dte@nosub{#1}@indent}%
                       +\noexpand\@nameuse{scr@tso@\scr@dte@nosub{#1}@numwidth}%
              \relax
            }%
          }%
        }%
      }{}%
    }{%
      \@namedef{scr@tso@#1@indent}{\@nameuse{scr@#1@tocindent}}%
    }%
  }{}%
  \scr@ifundefinedorrelax{scr@tso@#1@pagenumberwidth}{%
    \Ifstrstart{#1}{sub}{%
      \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@pagenumberwidth}{%
        \@namedef{scr@tso@#1@pagenumberwidth}{\@pnumwidth}%
      }{%
        \expandafter\let
        \csname scr@tso@#1@pagenumberwidth\expandafter\endcsname
        \csname scr@tso@\scr@dte@nosub{#1}@pagenumberwidth\endcsname
      }%
    }{%
      \@namedef{scr@tso@#1@pagenumberwidth}{\@pnumwidth}%
    }%
  }{}%
  \scr@ifundefinedorrelax{scr@tso@#1@rightindent}{%
    \Ifstrstart{#1}{sub}{%
      \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@rightindent}{%
        \@namedef{scr@tso@#1@rightindent}{\@tocrmarg}%
      }{%
        \expandafter\let
        \csname scr@tso@#1@rightindent\expandafter\endcsname
        \csname scr@tso@\scr@dte@nosub{#1}@rightindent\endcsname
      }%
    }{%
      \@namedef{scr@tso@#1@rightindent}{\@tocrmarg}%
    }%
  }{}%
  \@ifundefined{scr@tso@#1@indent}{%
      \Ifstr{#1}{figure}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
        \Ifstr{#1}{table}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
          \Ifstr{#1}{part}{\@namedef{scr@tso@#1@indent}{0em}}{%
            \Ifstr{#1}{chapter}{\@namedef{scr@tso@#1@indent}{0em}}{%
              \scr@ifundefinedorrelax{l@chapter}{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{0pt}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{3.8em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{7em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{10em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }{%
                \Ifstr{#1}{section}{\@namedef{scr@tso@#1@indent}{1.5em}}{%
                  \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@indent}{3.8em}}{%
                    \Ifstr{#1}{subsubsection}{%
                      \@namedef{scr@tso@#1@indent}{7.0em}%
                    }{%
                      \Ifstr{#1}{paragraph}{%
                        \@namedef{scr@tso@#1@indent}{10em}%
                      }{%
                        \Ifstr{#1}{subparagraph}{%
                          \@namedef{scr@tso@#1@indent}{12em}%
                        }{%
                        }%
                      }%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
  }{}%
  \scr@ifundefinedorrelax{scr@tso@#1@numwidth}{%
    \scr@ifundefinedorrelax{scr@#1@tocnumwidth}{%
      \Ifstrstart{#1}{sub}{%
        \scr@ifundefinedorrelax{scr@tso@\scr@dte@nosub{#1}@numwidth}{}{%
          \expandafter\edef\csname scr@tso@#1@numwidth\endcsname{%
            \glueexpr \noexpand\@nameuse{scr@tso@\scr@dte@nosub{#1}@numwidth}%
                     +.9em%
            \relax
          }%
        }%
      }{}%
    }{%
      \@namedef{scr@tso@#1@numwidth}{\@nameuse{scr@#1@tocnumwidth}}%
    }%
  }{}%
  \@ifundefined{scr@tso@#1@numwidth}{%
      \Ifstr{#1}{figure}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
        \Ifstr{#1}{table}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
          \Ifstr{#1}{chapter}{\@namedef{scr@tso@#1@numwidth}{1.5em}}{%
            \scr@ifundefinedorrelax{chapter}{%
              \Ifstr{#1}{section}{\@namedef{scr@tso@#1@numwidth}{1.5em}}{%
                \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
                  \Ifstr{#1}{subsubsection}{%
                    \@namedef{scr@tso@#1@numwidth}{3.2em}%
                  }{%
                    \Ifstr{#1}{paragraph}{%
                      \@namedef{scr@tso@#1@numwidth}{4.1em}%
                    }{%
                      \Ifstr{#1}{subparagraph}{%
                        \@namedef{scr@tso@#1@numwidth}{5m}%
                      }{%
                      }%
                    }%
                  }%
                }%
              }%
            }{%
              \Ifstr{#1}{section}{\@namedef{scr@tso@#1@numwidth}{2.3em}}{%
                \Ifstr{#1}{subsection}{\@namedef{scr@tso@#1@numwidth}{3.2em}}{%
                  \Ifstr{#1}{subsubsection}{%
                    \@namedef{scr@tso@#1@numwidth}{3.1em}%
                  }{%
                    \Ifstr{#1}{paragraph}{%
                      \@namedef{scr@tso@#1@numwidth}{5em}%
                    }{%
                      \Ifstr{#1}{subparagraph}{%
                        \@namedef{scr@tso@#1@numwidth}{6em}%
                      }{%
                      }%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
  }{}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@LastTOCLevelWasLower\endcsname{\LastTOCLevelWasLower}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@LastTOCLevelWasSame\endcsname{\LastTOCLevelWasSame}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@LastTOCLevelWasHigher\endcsname{\LastTOCLevelWasHigher}%
  \@ifundefined{scr@tso@#1@beforeskip}{%
    \Ifstr{#1}{part}{%
      \@namedef{scr@tso@#1@beforeskip}{\glueexpr 2.25em \@plus\p@\relax}%
    }{%
      \Ifstr{#1}{chapter}{%
        \@namedef{scr@tso@#1@beforeskip}{\glueexpr 1.0em \@plus\p@\relax}%
      }{%
        \Ifstr{#1}{section}{%
          \scr@ifundefinedorrelax{l@chapter}{%
            \@namedef{scr@tso@#1@beforeskip}{\glueexpr 1.0em \@plus\p@\relax}%
          }{}%
        }{}%
      }%
    }%
    \expandafter\renewcommand\expandafter*%
    \csname scr@tso@#1@beforeskip\endcsname{\glueexpr \z@ plus .2\p@\relax}%
  }{}%
  \@ifundefined{scr@dte@#1@maxnumwidth}{%
    \expandafter\newlength\csname scr@dte@#1@maxnumwidth\endcsname
    \setlength{\@nameuse{scr@dte@#1@maxnumwidth}}{\z@}%
  }{}%
  \renewcommand*{\scr@dte@donumwidth}{}%
  \g@addto@macro{\scr@dte@donumwidth}{\do{#1}}%
  \expandafter\renewcommand\expandafter*%
  \csname scr@tso@#1@numsep\endcsname{.4em}%
  \expandafter\renewcommand%
  \csname scr@tso@#1@numberformat\endcsname[1]{##1}%
  \Ifstr{#1}{part}{%
    \expandafter\providecommand%
    \csname scr@tso@#1@entryformat\endcsname[1]{\large\bfseries ##1}%
  }{%
    \Ifstr{#1}{chapter}{%
      \expandafter\providecommand%
      \csname scr@tso@#1@entryformat\endcsname[1]{\bfseries ##1}%
    }{%
      \scr@ifundefinedorrelax{l@chapter}{%
        \Ifstr{#1}{section}{%
          \expandafter\providecommand%
          \csname scr@tso@#1@entryformat\endcsname[1]{\bfseries ##1}%
        }{}%
      }{}%
      \expandafter\providecommand%
      \csname scr@tso@#1@entryformat\endcsname[1]{##1}%
    }%
  }%
  \expandafter\renewcommand
  \csname Ifscr@tso@#1@breakafternumber\endcsname[2]{##2}%
  \@ifundefined{scr@tso@#1@linefill}{%
    \Ifstr{#1}{part}{%
      \@namedef{scr@tso@#1@linefill}{\hfill}%
    }{%
      \Ifstr{#1}{chapter}{%
        \@namedef{scr@tso@#1@linefill}{\hfill}%
      }{%
        \scr@ifundefinedorrelax{l@chapter}{%
          \Ifstr{#1}{section}{%
            \@namedef{scr@tso@#1@linefill}{\hfill}%
          }{}%
        }{}%
        \expandafter\renewcommand%
        \csname scr@tso@#1@linefill\endcsname{\TOCLineLeaderFill\relax}%
      }%
    }%
  }{}%
  \expandafter\renewcommand\csname Ifscr@tso@#1@raggedpage\endcsname[2]{##2}%
  \Ifstr{#1}{part}{%
    \expandafter\providecommand%
    \csname scr@tso@#1@pagenumberformat\endcsname[1]{\large\bfseries ##1}%
  }{%
    \Ifstr{#1}{chapter}{%
      \expandafter\providecommand%
      \csname scr@tso@#1@pagenumberformat\endcsname[1]{\bfseries ##1}%
    }{%
      \scr@ifundefinedorrelax{l@chapter}{%
        \Ifstr{#1}{section}{%
          \expandafter\providecommand%
          \csname scr@tso@#1@pagenumberformat\endcsname[1]{\bfseries ##1}%
        }{}%
      }{}%
      \expandafter\providecommand%
      \csname scr@tso@#1@pagenumberformat\endcsname[1]{%
        {\normalfont\normalcolor ##1}}%
    }%
  }%
  \expandafter\renewcommand%
  \csname scr@tso@#1@pagenumberbox\endcsname[1]{%
    \hb@xt@\@nameuse{scr@dte@pagenumberwidth}{\hfil ##1}}%
  \expandafter\renewcommand\csname Ifscr@tso@#1@dynnumwidth\endcsname[2]{##2}%
  \expandafter\renewcommand\csname Ifscr@tso@#1@dynindent\endcsname[2]{##2}%
  \scr@ifundefinedorrelax{scr@tso@#1@indentfollows}{%
    \Ifstrstart{#1}{sub}{%
      \expandafter\edef\csname scr@tso@#1@indentfollows\endcsname{%
        \scr@dte@nosub{#1}%
      }%
    }{%
      \expandafter\let\csname scr@tso@#1@indentfollows\endcsname\@empty
    }%
  }{}%
}]{%
  \scr@dte@tocline{#1}{##1}{##2}%
}

\if@bidi@csdef{scr@tso@figure@pagenumberformat}{%
  \renewcommand*{\scr@tso@figure@pagenumberformat}[1]{%
     {\normalfont\normalcolor #1}%
   }%
}{}

\if@bidi@csdef{scr@tso@table@pagenumberformat}{%
  \renewcommand*{\scr@tso@table@pagenumberformat}[1]{%
     {\normalfont\normalcolor #1}%
   }%
}{}
 
%    \end{macrocode}
% \iffalse
%</tocbasic-xetex-bidi.def>
%<*tocstyle-xetex-bidi.def>
%\fi
% \section{File \texttt{tocstyle-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{tocstyle-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for tocstyle package for XeTeX engine]
\renewcommand*{\tocstyle@dottedtocline}[5]{%
  \let\numberline\tocstyle@numberline
  \ifnum #1>\c@tocdepth \else
    \if@tocstyle@penalties
      \begingroup
        \@tempcnta 20010
        \advance \@tempcnta by -#1
        \ifnum \@tempcnta>\lastpenalty
          \aftergroup\penalty\aftergroup\@lowpenalty
        \fi
      \endgroup
    \fi
    \edef\tocstyledepth{#1}%
    \tocstyle@activate@features
    \ifx\tocstyle@feature@entryvskip\relax
      \vskip \z@ \@plus.2\p@
    \else
      \addvspace{\tocstyle@feature@entryvskip}%
    \fi
    {%
      \parskip \z@ \parindent \z@ \if@RTL\rightskip\else\leftskip\fi \z@ \if@RTL\leftskip\else\rightskip\fi \z@
      \tocstyle@feature@raggedhook
      \@tempdima #3\relax
      \@tempdimb #2\relax
      \typeout{m (\tocstyleTOC, \tocstyledepth): \the\@tempdima}%
      \ifnum #1>\z@\relax
        \@tempcnta #1\relax \advance\@tempcnta \m@ne
        \ifcsname tocstyle@skipwidth@\tocstyleTOC @\the\@tempcnta\endcsname
          \ifcsname tocstyle@numwidth@\tocstyleTOC @\the\@tempcnta\endcsname
            \@tempdimb
            \csname tocstyle@skipwidth@\tocstyleTOC @\the\@tempcnta\endcsname
            \advance\@tempdimb
            \csname tocstyle@numwidth@\tocstyleTOC @\the\@tempcnta\endcsname
          \fi
        \fi
      \fi
      \typeout{C (\tocstyleTOC, \tocstyledepth): \the\@tempdimb}%
      \ifcsname tocstyle@skipwidth@\tocstyleTOC @#1\endcsname
        \ifdim \@tempdimb>
        \csname tocstyle@skipwidth@\tocstyleTOC @#1\endcsname\relax
          \expandafter\xdef\csname tocstyle@skipwidth@\tocstyleTOC
          @#1\endcsname{\the\@tempdimb}%
        \fi
      \else
        \expandafter\xdef\csname tocstyle@skipwidth@\tocstyleTOC
        @#1\endcsname{\the\@tempdimb}%
      \fi
      \iftocstyle@autolength
        \ifcsname tocstyle@maxskipwidth@\tocstyleTOC @#1\endcsname
          \@tempdimb \csname tocstyle@maxskipwidth@\tocstyleTOC @#1\endcsname
          \relax
        \fi
        \ifcsname tocstyle@maxnumwidth@\tocstyleTOC @#1\endcsname
          \@tempdima \csname tocstyle@maxnumwidth@\tocstyleTOC @#1\endcsname
          \relax
        \fi
        \typeout{a (\tocstyleTOC, \tocstyledepth): \the\@tempdima}%
        \typeout{A (\tocstyleTOC, \tocstyledepth): \the\@tempdimb}%
      \else
        \@tempdimb #2\relax
        \typeout{M (\tocstyleTOC, \tocstyledepth): \the\@tempdimb}%
      \fi
      \ifcsname tocstyle@unumwidth@\tocstyleTOC @\endcsname
        \ifdim \@tempdima>
        \csname tocstyle@unumwidth@\tocstyleTOC @\endcsname\relax
          \expandafter\xdef\csname tocstyle@unumwidth@\tocstyleTOC
          @\endcsname{\the\@tempdima}%
        \fi
      \else
        \expandafter\xdef\csname tocstyle@unumwidth@\tocstyleTOC
        @\endcsname{\the\@tempdima}%
      \fi
      \ifcase\tocstyle@indentstyle\relax\else
        \@tempdimb \z@
        \ifcsname tocstyle@maxunumwidth@\tocstyleTOC @\endcsname
          \@tempdima \csname tocstyle@maxunumwidth@\tocstyleTOC @\endcsname
          \relax
        \fi
        \typeout{s (\tocstyleTOC, \tocstyledepth): \the\@tempdima}%
        \typeout{S (\tocstyleTOC, \tocstyledepth): \the\@tempdimb}%
      \fi
      \advance\parindent \@tempdimb\@afterindenttrue
      \advance\if@RTL\rightskip\else\leftskip\fi \parindent
      \advance\if@RTL\leftskip\else\rightskip\fi \@tocrmarg
      \parfillskip -\if@RTL\leftskip\else\rightskip\fi
      \ifx\tocstyle@feature@parfillskip\relax\else
        \advance\parfillskip \tocstyle@feature@parfillskip\relax
      \fi
      \interlinepenalty\@M
      \leavevmode
      \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima
      \null\nobreak
      \iftocstyle@indentnotnumbered\else
        \hskip -\if@RTL\rightskip\else\leftskip\fi
      \fi
      \tocstyle@feature@entryhook
      {#4}\nobreak
      \ifx\tocstyle@feature@leaders\relax
        \leaders\hbox{$\m@th
          \mkern \@dotsep mu\hbox{\tocstyle@feature@dothook .}%
          \mkern \@dotsep mu$}\hfill
      \else
        \tocstyle@feature@leaders
      \fi
      \nobreak
      \ifx\tocstyle@feature@pagenumberbox\relax
        \hb@xt@\@pnumwidth{\hfil\tocstyle@feature@pagenumberhook #5}%
      \else
        \tocstyle@feature@pagenumberbox{\tocstyle@feature@pagenumberhook #5}%
      \fi
      \par
    }%
    \if@tocstyle@penalties
      \bgroup
        \@tempcnta 20009
        \advance\@tempcnta by -#1
        \edef\reserved@a{\egroup\penalty\the\@tempcnta\relax}%
      \reserved@a
    \fi
  \fi}
\renewcommand*{\tocstyle@numberline}[1]{%
  \begingroup
    \ifx\tocstyle@feature@spaceafternumber\relax
      \settowidth\@tempdima{\tocstyle@@numberline{#1}\enskip}%
    \else
      \settowidth\@tempdima{\tocstyle@@numberline{#1}}%
      \advance \@tempdima \tocstyle@feature@spaceafternumber\relax
    \fi
    \ifcsname tocstyle@numwidth@\tocstyleTOC @\tocstyledepth\endcsname
      \ifdim \@tempdima >
      \csname tocstyle@numwidth@\tocstyleTOC @\tocstyledepth\endcsname\relax
        \expandafter\xdef\csname tocstyle@numwidth@\tocstyleTOC
        @\tocstyledepth\endcsname{\the\@tempdima}%
      \fi
    \else
      \expandafter\xdef\csname tocstyle@numwidth@\tocstyleTOC
      @\tocstyledepth\endcsname{\the\@tempdima}%
    \fi
  \endgroup
  \iftocstyle@indentnotnumbered
    \hskip -\if@RTL\rightskip\else\leftskip\fi
  \fi
  \ifcase \tocstyle@indentstyle
    \hb@xt@\@tempdima{\tocstyle@@numberline{#1}\hfil}%
  \or
    \hb@xt@\@tempdima{\tocstyle@@numberline{#1}\hfil}%
  \else
    \ifx\tocstyle@feature@spaceafternumber\relax
      \hbox{\tocstyle@@numberline{#1}\enskip}%
    \else
      \hbox{\tocstyle@@numberline{#1}\hskip
        \tocstyle@feature@spaceafternumber\relax}%
    \fi
  \fi
}
\AtBeginDocument{%
  \ifcsname l@part\endcsname
    \ifcsname l@chapter\endcsname
      \setbox\@tempboxa\vbox{\hsize\maxdimen
        \l@part{\tocstyle@l@define{part}{-1}}{}}%
    \else
      \setbox\@tempboxa\vbox{\hsize\maxdimen
        \l@part{\tocstyle@l@define{part}{0}}{}}%
    \fi
  \fi
  \ifcsname l@chapter\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@chapter{\tocstyle@l@define{chapter}{0}}{}}%
  \fi
  \ifcsname l@section\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@section{\tocstyle@l@define{section}{1}}{}}%
  \fi
  \ifcsname l@subsection\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@subsection{\tocstyle@l@define{subsection}{2}}{}}%
  \fi
  \ifcsname l@subsubsection\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@subsubsection{\tocstyle@l@define{subsubsection}{3}}{}}%
  \fi
  \ifcsname l@paragraph\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@paragraph{\tocstyle@l@define{paragraph}{4}}{}}%
  \fi
  \ifcsname l@subparagraph\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@subparagraph{\tocstyle@l@define{subparagraph}{5}}{}}%
  \fi
  \ifcsname l@table\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@table{\tocstyle@l@define{table}{1}}{}}%
  \fi
  \ifcsname l@figure\endcsname
    \setbox\@tempboxa\vbox{\hsize\maxdimen
      \l@figure{\tocstyle@l@define{figure}{1}}{}}%
  \fi
  \def\@tempa#1#2#3#4#5{%
    \ifnum #1>\c@tocdepth \else
      \vskip \z@ \@plus.2\p@
      {\if@RTL\rightskip\else\leftskip\fi #2\relax \if@RTL\leftskip\else\rightskip\fi \@tocrmarg \parfillskip -\if@RTL\leftskip\else\rightskip\fi
       \parindent #2\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima #3\relax
       \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
       {#4}\nobreak
       \leaders\hbox{$\m@th
          \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
          mu$}\hfill
       \nobreak
       \hb@xt@\@pnumwidth{{\hfil \normalfont \normalcolor #5}}%
       \par}%
    \fi}%
  \ifx\@dottedtocline\@tempa\else
    \tocstyle@macrochangewarning\@dottedtocline
  \fi
  \let\tocstyle@saved@dottedtocline\@dottedtocline
  \def\@tempa#1{\hb@xt@\@tempdima{#1\autodot\hfil}}%
  \ifx\numberline\@tempa\else
    \def\@tempa#1{\hb@xt@\@tempdima{#1\hfil}}%
    \ifx\numberline@tempa\else
      \tocstyle@macrochangewarning\numberline
    \fi
  \fi
  \let\tocstyle@saved@numberline\numberline
}
\renewcommand*{\tocstyle@l@define}[2]{%
  \advance\if@RTL\rightskip\else\leftskip\fi-\@tempdima
  \edef\@tempa{%
    \noexpand\global\noexpand\let
    \expandafter\noexpand\csname tocstyle@saved@l@#1\endcsname
    \expandafter\noexpand\csname l@#1\endcsname
    \noexpand\gdef
    \expandafter\noexpand\csname tocstyle@l@#1\endcsname{%
      \noexpand\@dottedtocline{#2}{\the\if@RTL\rightskip\else\leftskip\fi}{\the\@tempdima}}%
    \noexpand\g@addto@macro\noexpand\tocstyle@activate@all@l{%
      \noexpand\let\expandafter\noexpand\csname l@#1\endcsname
      \expandafter\noexpand\csname tocstyle@l@#1\endcsname
    }%
  }%
  \PackageInfo{tocstyle}{prepare \expandafter\string
    \csname l@#1\endcsname\space for redefinition}%
  \@tempa
}
%    \end{macrocode}
% \iffalse
%</tocstyle-xetex-bidi.def>
%<*todonotes-xetex-bidi.def>
%\fi
% \section{File \texttt{todonotes-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{todonotes-xetex-bidi.def}[2016/11/08 v0.4 bidi adaptations for todonotes package for XeTeX engine]
\newif\if@bidi@todonotes@textdirection@RTL
\newif\if@bidi@todonotes@figposition@right
\newcommand{\@bidi@todonotes@align}{}%
\define@key{todonotes}{align}{\renewcommand{\@bidi@todonotes@align}{#1}}%
\newcommand{\@bidi@todonotes@textdirection}{}%
\define@choicekey{todonotes}{textdirection}[\bidi@todonotes@tempa\bidi@todonotes@tempb]{righttoleft,lefttoright}{%
  \ifcase\bidi@todonotes@tempb\relax
    \@bidi@todonotes@textdirection@RTLtrue
    \let\@bidi@todonotes@textdirection\RLE
  \or
    \@bidi@todonotes@textdirection@RTLfalse
    \let\@bidi@todonotes@textdirection\LRE
  \fi}
\define@choicekey{todonotes}{figposition}[\bidi@todonotes@tempa\bidi@todonotes@tempb]{right,left}{%
  \ifcase\bidi@todonotes@tempb\relax
    \@bidi@todonotes@figposition@righttrue
  \or
    \@bidi@todonotes@figposition@rightfalse
  \fi}
\if@todonotes@disabled%
\else % \if@todonotes@disabled
\renewcommand{\@todonotes@drawInlineNote}{%
    \if@todonotes@dviStyle%
        {\par\noindent\begin{tikzpicture}[remember picture]%
            \draw node[inlinenotestyle] {};\end{tikzpicture}\par}%
            \if@todonotes@authorgiven%
                {\noindent \@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
            \else%
                {\noindent \@todonotes@sizecommand \@todonotes@text}%
            \fi
        {\par\noindent\begin{tikzpicture}[remember picture]%
            \draw node[inlinenotestyle] {};\end{tikzpicture}\par}%
    \else%
        {\par\noindent\begin{tikzpicture}[remember picture]%
           \if@bidi@todonotes@textdirection@RTL\setRTL\fi%
            \draw node[inlinenotestyle,font=\@todonotes@sizecommand,align=\@bidi@todonotes@align]{%
                \if@todonotes@authorgiven%
                    {\noindent \@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
                \else%
                    {\noindent \@todonotes@sizecommand \@todonotes@text}%
                \fi};%
            \end{tikzpicture}\par}%
    \fi}%
\renewcommand{\@todonotes@drawMarginNoteWithLine}{%
\begin{tikzpicture}[remember picture, overlay, baseline=-0.75ex]%
    \node [coordinate] (inText) {};%
\end{tikzpicture}%
\marginpar[{% Draw note in left margin
    \@todonotes@drawMarginNote%
    \if@RTL\@todonotes@drawLineToRightMargin\else\@todonotes@drawLineToLeftMargin\fi%
}]{% Draw note in right margin
    \@todonotes@drawMarginNote%
    \if@RTL\@todonotes@drawLineToLeftMargin\else\@todonotes@drawLineToRightMargin\fi%
}%
}%  
\renewcommand{\@todonotes@drawMarginNote}{%
\if@todonotes@dviStyle%
    \begin{tikzpicture}[remember picture]%
        \draw node[notestyle] {};%
    \end{tikzpicture}\\%
    \begin{minipage}{\@todonotes@textwidth}%
    \if@todonotes@authorgiven%
      \@todonotes@sizecommand \@todonotes@author \@todonotes@text%
    \else%
      \@todonotes@sizecommand \@todonotes@text%
    \fi%
    \end{minipage}\\%
    \begin{tikzpicture}[remember picture]%
        \draw node[notestyle] (inNote) {};%
    \end{tikzpicture}%
\else%
    \let\originalHbadness\hbadness%
    \hbadness 100000%
    \begin{tikzpicture}[remember picture,baseline=(X.base)]%
       \if@bidi@todonotes@textdirection@RTL\setRTL\fi%
        \node(X){\vphantom{X}};%
        \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north,align=\@bidi@todonotes@align] (inNote) at (X.north)%
            {\@todonotes@text};%
        \if@todonotes@authorgiven%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north,align=\@bidi@todonotes@align] (inNote) at (X.north)%
                {\@todonotes@sizecommand\@todonotes@author};%
            \node(Y)[below=of X]{};%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north,align=\@bidi@todonotes@align] (inNote) at (X.south)%
                {\@todonotes@text};%
        \else%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north,align=\@bidi@todonotes@align] (inNote) at (X.north)%
                {\@todonotes@text};%
        \fi%
    \end{tikzpicture}%
    \hbadness \originalHbadness%
\fi}%
\renewcommand{\missingfigure}[2][]{%
\setkeys{todonotes}{#1}%
\addcontentsline{tdo}{todo}{\@todonotes@MissingFigureText: #2}%
\par
\noindent
\begin{tikzpicture}
\draw[fill=\@todonotes@currentfigcolor, draw = black!40, line width=2pt]
    (-2, -2.5) rectangle +(\@todonotes@currentfigwidth, \@todonotes@currentfigheight);
\if@bidi@todonotes@figposition@right%
\begin{scope}[xshift=\@todonotes@currentfigwidth-4cm]
\fi%
\draw[red, fill=white, rounded corners = 5pt, line width=10pt]
    (30:2cm) -- (150:2cm) -- (270:2cm) -- cycle;
\if@bidi@todonotes@figposition@right%
\end{scope}
\begin{scope}[xshift=-3.8cm]
\fi%
\if@bidi@todonotes@textdirection@RTL\setRTL\fi%
\draw (2, -0.3) node[right, text
    width=\@todonotes@currentfigwidth-4.5cm,align=\@bidi@todonotes@align] {#2};
\if@bidi@todonotes@figposition@right%
\end{scope}
\begin{scope}[xshift=\@todonotes@currentfigwidth-4cm]
\fi%
\draw (0, 0.3) node[align=\@bidi@todonotes@align] {\@bidi@todonotes@textdirection{\@todonotes@MissingFigureUp}};
\draw (0, -0.3) node[align=\@bidi@todonotes@align] {\@bidi@todonotes@textdirection{\@todonotes@MissingFigureDown}};
\if@bidi@todonotes@figposition@right%
\end{scope}
\fi%
\end{tikzpicture}\hfill
}% Ending \missingfigure command
\fi % Ending \@todonotes@ifdisabled
\presetkeys%
    {todonotes}%
    {align=left,%
    textdirection=lefttoright,%
    figposition=left}{}%
%    \end{macrocode}
% \iffalse
%</todonotes-xetex-bidi.def>
%<*wrapfig-xetex-bidi.def>
%\fi
% \section{File \texttt{wrapfig-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{wrapfig-xetex-bidi.def}[2014/04/23 v0.3 bidi adaptations for wrapfig package for XeTeX engine]
\let\WF@@everypar\bidi@n@everypar
\def\WF@putfigmaybe{%
\ifinner
  \vskip-\parskip \global\WF@floatfalse
  \let\pagetotal\maxdimen % kludge flag for "not top of page"
\else % outer page
  \@tempdima\pagedepth % save page depth
   {\advance\parskip\@tempdima\if@RTL\advance\parskip\baselineskip\fi\vskip-\parskip}% back up to baseline
   \penalty\interlinepenalty % update pg. parameters
   \@tempdimb\pagegoal \advance\@tempdimb-\pagetotal % room left on page
   \ifdim\@tempdimb<\z@ % \WF@info{Page overfull already;}%
      \global\WF@floatfalse
      \ifdim-\@tempdimb>\pageshrink \else \pagebreak \fi
   \else
      \ifdim\WF@size>\@tempdimb
         \ifWF@float \dimen@.5\baselineskip \else \dimen@ 2\baselineskip\fi
         \ifdim\pagestretch>\dimen@ \dimen@\pagestretch \fi
         \ifdim\pagefilstretch>\z@ \dimen@\@tempdimb \fi
         \ifdim\pagefillstretch>\z@ \dimen@\@tempdimb \fi
         \advance\dimen@.5\baselineskip
         \ifdim\dimen@>\@tempdimb % \WF@info{Page nearly full; can stretch}%
            \global\WF@floatfalse \pagebreak
         \fi
      \else % \WF@info{Fits in \the\@tempdimb;}%
         \global\WF@floatfalse
   \fi\fi
   \vskip\@tempdima\relax % (return erased page depth)
\fi
\noindent
\ifWF@float
  \WF@fltmes
\else % putting here;
  \WF@info{Put \WF@wfname here:}%
  {\ifodd\if@twoside\c@page\else\@ne\fi % assign l/r to i/o placement
    \lccode`i`l\lccode`o`r\else \lccode`i`r\lccode`o`l\fi
    \xdef\WF@place{\the\lccode\lccode\WF@place}}% twice to get only l or r
  \hbox to\z@{% llap or rlap depending on {l} or {r}; calc effective width
   \@tempdima\wd\WF@box \@tempdimb\WF@ovh
   \advance\@tempdima-\@tempdimb \advance\@tempdima\columnsep
   \@tempdimb\hsize \advance\@tempdimb-\@tempdima
   \xdef\WF@adjlw{\the\@tempdima}%
   \ifnum `l=\WF@place % fig on left
    \if@RTL%
     \kern\@tempdimb \kern\columnsep
    \def\@tempa{\hss}% position to left of the gap
     \else%
    \hss % figure overlaps space to the left
    \def\@tempa{\kern\columnsep}% position to left of the gap
    \fi%
   \else  %  fig on right
    \if@RTL%
     \hss
      \@tempdima\z@
      \def\@tempa{\kern\columnsep}
     \else%
    \@tempdima\z@ % no left indentation
    \kern\@tempdimb \kern\columnsep
    \def\@tempa{\hss}% figure overlaps space to the right
    \fi%
   \fi
   \ifdim\@tempdimb<\hsize
    \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}% indentation and length
    \xdef\WF@adjtlm{\the\@tempdima}%
   \else
    \xdef\WF@wrapil{\z@ \the\hsize}%
    \xdef\WF@adjlw{\z@}\xdef\WF@adjtlm{\z@}%
   \fi
   \ifdim\pagetotal=\z@ % \WF@info{Put \WF@wfname at top of p.\thepage}%
    \global\advance\WF@size-\intextsep
   \else % \WF@info{Putting \WF@wfname in middle of page}%
    \setbox\WF@box\hbox{\lower\intextsep\box\WF@box}%
   \fi \dp\WF@box\z@ \box\WF@box \@tempa
  }% end \hbox to 0pt
  \aftergroup\WF@startwrapping % after the \endgroup which immediately follows
\fi}
%    \end{macrocode}
% \iffalse
%</wrapfig-xetex-bidi.def>
%<*xcolor-xetex-bidi.def>
%\fi
% \section{File \texttt{xcolor-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{xcolor-xetex-bidi.def}[2022/06/13 v0.3 bidi adaptations for xcolor package for XeTeX engine]
\long\def\color@b@x#1#2#3%
 {\leavevmode\ifmmode\else\if@RTL\beginL\fi\fi
  \setbox\z@\hbox{\kern\fboxsep{\set@color\if@RTL\beginR\fi#3\if@RTL\endR\fi}\kern\fboxsep}%
  \dimen@\ht\z@\advance\dimen@\fboxsep\ht\z@\dimen@
  \dimen@\dp\z@\advance\dimen@\fboxsep\dp\z@\dimen@
  {#1{#2\color@block{\wd\z@}{\ht\z@}{\dp\z@}\box\z@}}\ifmmode\else\if@RTL\endL\fi\fi}
\protected\def\normalcolor{\let\current@color\default@color\ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\set@color\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi}
\DeclareRobustCommand\color
 {\ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\@ifnextchar[\@undeclaredcolor\@declaredcolor}
\def\@undeclaredcolor[#1]#2%
 {\begingroup
  \let\@@cls\@empty
  \XC@getmodclr12{#1}{#2}{}%
   {\ifblendcolors
      \ifx\colorblend\@empty\else
        \edef\@@mix{\expandafter\@gobble\colorblend}\@tempswafalse
        \XC@coremodel\@@mod\@@clr\@xcolor@{}{}\@@mod\@@clr
      \fi
    \fi
    \ifconvertcolorsU
      \edef\@@tmp{\XC@tgt@mod{\@@mod}}%
      \convertcolorspec\@@mod\@@clr\@@tmp\@@clr \let\@@mod\@@tmp
    \fi
    \ifmaskcolors
      \convertcolorspec\@@mod\@@clr\XC@mmod\@@clr
      \let\@@mod\XC@mmod
      \XC@inflate\@@mod\XC@mclr\@@clr\@@tmp
      \expandafter\XC@mul\@@tmp,\@@clr
    \fi
    \edef\@@tmp{\noexpand\XC@undeclaredcolor{\@@mod}{\@@clr}}%
    \expandafter\endgroup\@@tmp}}
\def\@declaredcolor#1%
 {\XC@edef\XC@@tmp{#1}\XC@@tstfalse
  \ifcase\XC@type\XC@@tmp\relax \XC@@tsttrue\or \relax\else
    \ifblendcolors\XC@@tsttrue\fi \ifmaskcolors\XC@@tsttrue\fi
    \ifconvertcolorsU\XC@@tsttrue\fi
  \fi
  \ifXC@@tst
    \expandafter\XC@declaredcolor\else
    \expandafter\XC@declaredc@lor\fi}
\def\XC@undeclaredcolor#1#2%
 {\@ifundefinedmodel{#1}%
   {\c@lor@error{model `#1'}}%
   {\@nameuse{color@#1}\current@color{#2}%
    \edef\XC@current@color{\noexpand\xcolor@{}{\current@color}{#1}{#2}}%
    \XC@display}\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi\ignorespaces}
\def\XC@declaredc@lor
 {\XC@let@Nc\XC@current@color{\string\color@\XC@@tmp}%
  \edef\current@color{\XC@current@color}%
  \XC@display\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi\ignorespaces}
\DeclareRobustCommand\bidicolor
 {\@ifnextchar[\@bidiundeclaredcolor\@bidideclaredcolor}
\def\@bidiundeclaredcolor[#1]#2%
 {\begingroup
  \let\@@cls\@empty
  \XC@getmodclr12{#1}{#2}{}%
   {\ifblendcolors
      \ifx\colorblend\@empty\else
        \edef\@@mix{\expandafter\@gobble\colorblend}\@tempswafalse
        \XC@coremodel\@@mod\@@clr\@xcolor@{}{}\@@mod\@@clr
      \fi
    \fi
    \ifconvertcolorsU
      \edef\@@tmp{\XC@tgt@mod{\@@mod}}%
      \convertcolorspec\@@mod\@@clr\@@tmp\@@clr \let\@@mod\@@tmp
    \fi
    \ifmaskcolors
      \convertcolorspec\@@mod\@@clr\XC@mmod\@@clr
      \let\@@mod\XC@mmod
      \XC@inflate\@@mod\XC@mclr\@@clr\@@tmp
      \expandafter\XC@mul\@@tmp,\@@clr
    \fi
    \edef\@@tmp{\noexpand\XC@bidiundeclaredcolor{\@@mod}{\@@clr}}%
    \expandafter\endgroup\@@tmp}}
\def\XC@bidiundeclaredcolor#1#2%
 {\@ifundefinedmodel{#1}%
   {\c@lor@error{model `#1'}}%
   {\@nameuse{color@#1}\current@color{#2}%
    \edef\XC@current@color{\noexpand\xcolor@{}{\current@color}{#1}{#2}}%
    \XC@display}}
\def\@bidideclaredcolor#1%
 {\XC@edef\XC@@tmp{#1}\XC@@tstfalse
  \ifcase\XC@type\XC@@tmp\relax \XC@@tsttrue\or \relax\else
    \ifblendcolors\XC@@tsttrue\fi \ifmaskcolors\XC@@tsttrue\fi
    \ifconvertcolorsU\XC@@tsttrue\fi
  \fi
  \ifXC@@tst
    \expandafter\XC@bidideclaredcolor\else
    \expandafter\XC@bidideclaredc@lor\fi}
\def\XC@bidideclaredcolor
 {\XC@split\XC@@tmp
  \edef\@@tmp{\noexpand\@bidiundeclaredcolor[\@@mod]{\@@clr}}%
  \expandafter\endgroup\@@tmp}
\def\XC@bidideclaredc@lor
 {\XC@let@Nc\XC@current@color{\string\color@\XC@@tmp}%
  \edef\current@color{\XC@current@color}%
  \XC@display}
\def\color@box#1#2{\color@b@x\relax{\bidicolor#1{#2}}}
\def\color@fbox#1#2#3#{\protect\color@fb@x{#1}{#2}{#3}}
\def\color@fb@x#1#2#3#4%
 {\color@b@x{\fboxsep\z@\bidicolor#1{#2}\XC@fbox}%
   {\@ifxempty{#3}{\bidicolor#1}{\bidicolor#3}{#4}}}
\def\color@setgroup{\begingroup\ifhmode\if@RTL\beginL\aftergroup\endR\fi\fi\set@color\ifhmode\if@RTL\beginR\aftergroup\endL\fi\fi}
%    \end{macrocode}
% \iffalse
%</xcolor-xetex-bidi.def>
%<*latex-xetex-bidi.def>
%\fi
% \section{File \texttt{latex-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{latex-xetex-bidi.def}[2025/10/28 v1.5.4 bidi adaptations  for `latex.ltx' for XeTeX engine]
\newcommand{\TeXXeTOn}{\TeXXeTstate\@ne}
\newcommand{\TeXXeTOff}{\TeXXeTstate\z@}
\TeXXeTOn
\def\bidi@RTL@everypar{{\setbox\z@\lastbox\if@RTL\beginR\else\beginL\fi\ifvoid\z@\else\usebox\z@\fi}}
   \let\bidi@o@everypar=\everypar
   \newtoks\bidi@n@everypar
   \bidi@n@everypar\expandafter{\the\bidi@o@everypar}
   \bidi@o@everypar{\bidi@RTL@everypar\the\bidi@n@everypar}
   \let\everypar=\bidi@n@everypar
\def\moreLRE{\bracetext \aftergroup\endL \beginL\@RTLfalse}
\def\moreRLE{\bracetext \aftergroup\endR \beginR\@RTLtrue}
\protected\def\hboxR{\hbox\bgroup
 \everyhbox{%
  \aftergroup\egroup
  \everyhbox{}%
  \beginR
  \@hboxRconstructtrue
  \bgroup
  \aftergroup\endR
  \aftergroup\egroup
 }\hbox}
\protected\def\hboxL{\hbox\bgroup
 \everyhbox{%
  \aftergroup\egroup
  \everyhbox{}%
  \beginL
  \@hboxRconstructfalse
  \bgroup
  \aftergroup\endL
  \aftergroup\egroup
 }\hbox}
\protected\def\vboxR{\vbox\bgroup
 \everyvbox{%
  \aftergroup\egroup
  \everyvbox{}%
  \@RTLtrue
  \@RTLtabtrue
  \bgroup
  \aftergroup\egroup
 }\vbox}
\protected\def\vboxL{\vbox\bgroup
 \everyvbox{%
  \aftergroup\egroup
  \everyvbox{}%
  \@RTLfalse
  \@RTLtabfalse
  \bgroup
  \aftergroup\egroup
 }\vbox}
\newcommand*{\bidi@leftskip}{\if@RTL\rightskip\else\leftskip\fi}
\newcommand*{\bidi@rightskip}{\if@RTL\leftskip\else\rightskip\fi}
\def\LTR{\par\@RTLfalse\@RTL@footnotefalse\@RTLtabfalse\hsize\linewidth\parshape\z@\bidi@beamer@ragged}
\def\endLTR{\par}
\newenvironment{LTR*}{\LTR
  \everypar{%
    {\setbox\z@\lastbox
      \ifvoid\z@
        \kern-\parindent
    \fi}%
  }%
}{\endLTR\@endpetrue}
\def\RTL{\par\@RTLtrue\@RTL@footnotetrue\@RTLtabtrue\hsize\linewidth\parshape\z@\bidi@beamer@ragged}
\def\endRTL{\par}
\newenvironment{RTL*}{\RTL
  \everypar{%
    {\setbox\z@\lastbox
      \ifvoid\z@
        \kern-\parindent
    \fi}%
  }%
}{\endRTL\@endpetrue}
\def\setRTL{\@RTLtrue\@RTL@footnotetrue\@RTLtabtrue\bidi@beamer@ragged}
\def\setLTR{\@RTLfalse\@RTL@footnotefalse\@RTLtabfalse\bidi@beamer@ragged}
\let\unsetRTL=\setLTR
\let\unsetLTR=\setRTL
\let\LR=\LRE
\let\RL=\RLE
\def\@ensure@RTL#1{\if@RTL#1\else\RLE{#1}\fi}
\def\@ensure@LTR#1{\if@RTL\LRE{#1}\else#1\fi}
\let\@ensure@RL=\@ensure@RTL
\let\@ensure@LR=\@ensure@LTR
\def\@ensure@dir#1{\if@RTL\RLE{#1}\else{#1}\fi}
\let\@ensure@maindir=\@ensure@dir
\def\@@RTL{RTL}
\def\@@LTR{LTR}
\def\save@dir{\if@RTL\gdef\saved@@dir{RTL}\else\gdef\saved@@dir{LTR}\fi}
\def\reset@dir{\ifx\saved@@dir\@@RTL\setRTL\else\ifx\saved@@dir\@@LTR\setLTR\else\relax\fi\fi}
\let\@@TeX\TeX
\def\TeX{\@ensure@LTR{\@@TeX}}
\let\@@LaTeX\LaTeX
\def\LaTeX{\@ensure@LTR{\@@LaTeX}}
\let\@@LaTeXe\LaTeXe
\def\LaTeXe{\@ensure@LTR{\@@LaTeXe}}
\long\def\bidi@reflect@box#1{%
  \leavevmode
  \setbox\z@\hbox{{#1}}%
  \setbox\tw@\hbox{\special{x:gsave}\special{x:scale -1 1}\rlap{\copy\z@}\special{x:grestore}}%
  \hb@xt@\wd\z@{\kern\wd\z@\box\tw@\hss}%
}
\if@bidi@csundef{XeTeX}{%
\bidi@newrobustcmd*{\XeTeX}{\LR{\leavevmode$\smash{\hbox{X\lower.5ex
  \hbox{\kern-.125em\bidi@reflect@box{E}}\kern-.1667em \TeX}}$}}%
}{%
\let\@bidi@orig@XeTeX\XeTeX
\bidi@renewrobustcmd*{\XeTeX}{\LR{\@bidi@orig@XeTeX}}%
}
\if@bidi@csundef{XeLaTeX}{%
\bidi@newrobustcmd*{\XeLaTeX}{\LR{\leavevmode$\smash{\hbox{X\lower.5ex
  \hbox{\kern-.125em\bidi@reflect@box{E}}\kern-.1667em \LaTeX}}$}}%
}{%
\let\@bidi@orig@XeLaTeX\XeLaTeX
\bidi@renewrobustcmd*{\XeLaTeX}{\LR{\@bidi@orig@XeLaTeX}}%
}
\let\setRL=\setRTL
\let\setLR=\setLTR
\let\unsetRL=\setLTR
\def\bidi@tabular@RTLcases{\let\@halignto\@empty\@bidi@tabular@RTLcases}
\ApplyPatchIfPackageLoaded{array}{%
\def\@bidi@tabular@RTLcases{\@RTLtabtrue%
  \leavevmode
  \hbox \bgroup $\left.\col@sep\tabcolsep \let\d@llarbegin\begingroup
                                    \let\d@llarend\endgroup
  \@tabarray}
\def\endbidi@tabular@RTLcases{\endarray \right\rbrace$\egroup}
}{%
\def\@bidi@tabular@RTLcases{\@RTLtabtrue%
   \leavevmode \hbox \bgroup 
   $\left.\let\@acol\@tabacol
   \let\@classz\@tabclassz
   \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray}

\def\endbidi@tabular@RTLcases{\crcr\egroup\if@RTLtab\egroup\endR\egroup\fi
                 \egroup\right\rbrace $\egroup}}
\def\RTLcases#1{\left.\vcenter{\normalbaselines\m@th
    \ialign{$##\hfil$&\quad{##}\hfil\crcr#1\crcr}}\,\right\}}
\renewenvironment{RTLcases}{%
  \bidi@matrix@check\RTLcases\env@RTLcases
}{%
  \endbidi@tabular@RTLcases%
}
\def\env@RTLcases{%
  \let\@ifnextchar\bidi@new@ifnextchar
  \def\arraystretch{1.2}%
  \bidi@tabular@RTLcases{@{}r@{\quad}r@{}}%
}
\def\SepMark#1{\gdef\@SepMark{#1}}
\SepMark{.}
\def\@thmcountersep{\@SepMark}
\def\setRTLbibitems{\@RTLbibitemstrue\@LTRbibitemsfalse}
\def\setLTRbibitems{\@LTRbibitemstrue\@RTLbibitemsfalse}
\def\setdefaultbibitems{\@RTLbibitemsfalse\@LTRbibitemsfalse}
\newcommand*{\bidi@@thebibliography@font@hook}{}
\def\list#1#2{%
  \ifnum \@listdepth >5\relax
    \@toodeep
  \else
    \global\advance\@listdepth\@ne
  \fi
  \rightmargin\z@
  \listparindent\z@
  \itemindent\z@
  \csname @list\romannumeral\the\@listdepth\endcsname
  \def\@itemlabel{#1}%
  \let\makelabel\@mklab
  \@nmbrlistfalse
  #2\relax
  \@trivlist
  \parskip\parsep
  \parindent\listparindent
  \advance\linewidth -\rightmargin
  \advance\linewidth -\leftmargin
  \if@bidi@list@minipage@parbox
  \if@RTL
  \advance\@totalleftmargin \leftmargin
  \else
  \advance\@totalleftmargin \rightmargin
  \fi
  \else
  \if@hboxRconstruct
  \if@bidi@list@minipage@parbox@not@nob
  \if@RTL
    \advance\@totalleftmargin \rightmargin
  \else
    \advance\@totalleftmargin \leftmargin
  \fi
  \else
  \if@RTL
  \advance\@totalleftmargin \leftmargin
  \else
  \advance\@totalleftmargin \rightmargin
  \fi\fi
  \else
  \if@RTL
    \advance\@totalleftmargin \rightmargin
  \else
    \advance\@totalleftmargin \leftmargin
  \fi\fi\fi
  \parshape \@ne \@totalleftmargin \linewidth
  \ignorespaces}
\long\def\@iiiparbox#1#2[#3]#4#5{%
  \leavevmode
  \@pboxswfalse
  \if@hboxRconstruct
    \@bidi@list@minipage@parbox@not@nobtrue
  \fi
  \if@RTL
    \ifx#1t%
      \@bidi@list@minipage@parboxtrue
    \else
      \ifx#1b%
        \@bidi@list@minipage@parboxtrue
      \fi
    \fi
  \fi
  \setlength\@tempdima{#4}%
  \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
    \ifx\relax#2\else
      \setlength\@tempdimb{#2}%
      \edef\@parboxto{to\the\@tempdimb}%
    \fi
    \if#1b\vbox
    \else\if #1t\vtop
    \else\ifmmode\vcenter
    \else\@pboxswtrue $\vcenter
    \fi\fi\fi
    \@parboxto{\let\hss\vss\let\unhbox\unvbox
       \csname bm@#3\endcsname}%
    \if@pboxsw \m@th$\fi
  \@end@tempboxa}
\newenvironment{LTRitems}
                 {\par\@RTLfalse\@RTLtabfalse\bidi@beamer@ragged
                  \if@bidi@list@minipage@parbox
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth
                  \else \if@hboxRconstruct\if@bidi@list@minipage@parbox@not@nob
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\else
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\fi
                  \else \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\fi\fi
                  \ignorespaces}{\vskip\z@}
\newenvironment{RTLitems}
                 {\par\@RTLtrue\@RTLtabtrue\bidi@beamer@ragged
                  \if@bidi@list@minipage@parbox
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth
                  \else \if@hboxRconstruct\if@bidi@list@minipage@parbox@not@nob
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\else
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\fi
                  \else \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\fi\fi
                  \ignorespaces}{\vskip\z@}
\newenvironment{LTRbibitems}
                 {\par\@RTLfalse\@RTLtabfalse\bidi@beamer@ragged
                  \if@bidi@list@minipage@parbox
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth
                  \else \if@hboxRconstruct\if@bidi@list@minipage@parbox@not@nob
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\else
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\fi
                  \else \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\fi\fi
                  \ignorespaces}{\vskip\z@}
\newenvironment{RTLbibitems}
                 {\par\@RTLtrue\@RTLtabtrue\bidi@beamer@ragged
                  \if@bidi@list@minipage@parbox
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth
                  \else \if@hboxRconstruct\if@bidi@list@minipage@parbox@not@nob
                  \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\else
                  \parshape \@ne \dimexpr(\@totalleftmargin+\leftmargin) \linewidth\fi
                  \else \parshape \@ne \dimexpr(\@totalleftmargin-\leftmargin) \linewidth\fi\fi
                  \ignorespaces}{\vskip\z@}
\def\raggedright{%
  \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip
  \leftskip\z@skip
  \parindent\z@\parfillskip\z@skip}
\let\bidi@orig@raggedleft\raggedleft
\let\bidi@orig@raggedright\raggedright
\renewcommand\raggedleft{\if@bidi@list@minipage@parbox\bidi@orig@raggedright\else\if@hboxRconstruct\bidi@orig@raggedright\else\bidi@orig@raggedleft\fi\fi}
\renewcommand\raggedright{\if@bidi@list@minipage@parbox\bidi@orig@raggedleft\else\if@hboxRconstruct\bidi@orig@raggedleft\else\bidi@orig@raggedright\fi\fi}
\newcommand{\bidi@raggedright}{\if@RTL\raggedleft\else\raggedright\fi}
\newcommand{\bidi@raggedleft}{\if@RTL\raggedright\else\raggedleft\fi}
\DeclareRobustCommand\centerline[1]{%
\if@RTL\@@line{\hss\beginR#1\endR\hss}
\else\@@line{\hss#1\hss}\fi}
\def\bidi@orig@leftline#1{%
\if@RTL\@@line{\beginR#1\endR\hss}
\else\@@line{#1\hss}\fi}
\def\bidi@orig@rightline#1{%
\if@RTL\@@line{\hss\beginR#1\endR}
\else\@@line{\hss#1}\fi}
\DeclareRobustCommand\leftline[1]{\ifhmode\if@RTL\bidi@orig@rightline{#1}\else\bidi@orig@leftline{#1}\fi\else\if@bidi@list@minipage@parbox\bidi@orig@rightline{#1}\else\if@hboxRconstruct\bidi@orig@rightline{#1}\else\bidi@orig@leftline{#1}\fi\fi\fi}
\DeclareRobustCommand\rightline[1]{\ifhmode\if@RTL\bidi@orig@leftline{#1}\else\bidi@orig@rightline{#1}\fi\else\if@bidi@list@minipage@parbox\bidi@orig@leftline{#1}\else\if@hboxRconstruct\bidi@orig@leftline{#1}\else\bidi@orig@rightline{#1}\fi\fi\fi}
\DeclareRobustCommand\bidirlap[1]{\hb@xt@\z@{\if@RTL\hss\fi#1\if@RTL\else\hss\fi}}
\DeclareRobustCommand\bidillap[1]{\hb@xt@\z@{\if@RTL\else\hss\fi#1\if@RTL\hss\fi}}
\def\@hangfrom#1{\setbox\@tempboxa\hbox{{#1}}%
      \hangindent \if@RTL-\else\fi\wd\@tempboxa\noindent\box\@tempboxa}
\def\narrower{%
  \advance\if@RTL\rightskip\else\leftskip\fi\parindent
  \advance\if@RTL\leftskip\else\rightskip\fi\parindent}
\DeclareRobustCommand\underline[1]{%
  \relax
  \ifmmode\@@underline{#1}%
  \else
\if@RTL $\@@underline{\hbox{\beginR#1\endR}}\m@th$\relax
\else
$\@@underline{\hbox{#1}}\m@th$\relax\fi\fi}
\if@compatibility
   \let\undertext=\underline
\fi
\def\@tabular{%
   \leavevmode \hbox \bgroup \if@RTLtab\beginR \fi
   $\let\@acol\@tabacol
   \let\@classz\@tabclassz
   \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray}
\def\endtabular{\crcr\egroup\if@RTLtab\egroup\endR\egroup\fi
                 \egroup $\if@RTLtab\endR\fi\egroup}
\expandafter \let \csname endtabular*\endcsname = \endtabular
\def\@array[#1]#2{%
  \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
  \bgroup
  \setbox\@arstrutbox\hbox{%
    \vrule \@height\arraystretch\ht\strutbox
           \@depth\arraystretch \dp\strutbox
           \@width\z@}%
  \@mkpream{#2}%
  \edef\@preamble{%
    \ialign \noexpand\@halignto
      \bgroup \@arstrut \@preamble \tabskip\z@skip \cr}%
  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
  \let\tabularnewline\\%
    \let\par\@empty
    \let\@sharp##%
    \set@typeset@protect
    \lineskip\z@skip\baselineskip\z@skip
    \ifhmode \@preamerr\z@ \@@par\fi
  \if@RTLtab\hbox\bgroup\beginR\@hboxRconstructtrue\if #1t\vtop \else \vbox \fi\bgroup\fi
    \@preamble}
\def\array{\let\@acol\@arrayacol \let\@classz\@arrayclassz
 \let\@classiv\@arrayclassiv
 \let\\\@arraycr\let\@halignto\@empty\@RTLtabfalse\@tabarray}
\def\@testpach#1{\@chclass \ifnum \@lastchclass=\tw@ 4 \else
    \ifnum \@lastchclass=3 5 \else
     \z@ \if #1c\@chnum \z@ \else
                              \if \if@RTLtab#1r\else#1l\fi\@chnum \@ne \else
                              \if \if@RTLtab#1l\else#1r\fi\@chnum \tw@ \else
          \@chclass \if #1|\@ne \else
                    \if #1@\tw@ \else
                    \if #1p3 \else \z@ \@preamerr 0\fi
  \fi  \fi  \fi  \fi  \fi  \fi
\fi}
\def\bm@l{\if@RTL\hss\unhbox\@tempboxa\else\unhbox\@tempboxa\hss\fi}
\def\bm@r{\if@RTL\unhbox\@tempboxa\hss\else\hss\unhbox\@tempboxa\fi}
\def\bm@t{\unhbox\@tempboxa\hss}
\def\bm@b{\hss\unhbox\@tempboxa}
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\if@RTL\rightskip\else\leftskip\fi #2\relax \if@RTL\leftskip\else\rightskip\fi \@tocrmarg \parfillskip -\if@RTL\leftskip\else\rightskip\fi
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\if@RTL\rightskip\else\leftskip\fi \@tempdima \null\nobreak\hskip -\if@RTL\rightskip\else\leftskip\fi
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{{\hfil\normalfont \normalcolor #5}}%
     \par}%
  \fi}
  
\newcount\bidi@column@check@number

\def\bidi@column@status#1{\gdef\bidi@current@column@status{#1}}

\def\bidi@set@column@status#1#2{%
   \global\expandafter\let\csname #1\endcsname\bidi@current@column@status}

\if@twocolumn
\newcommand\DetectColumn[3][1]{%
 \ifx\bidi@firstcolumn@status@write\relax
     \PackageError{bidi}%
      {Option 'DetectColumn' not selected}%
      {\string\DetectColumn\space
       requires the use of the 'DetectColumn'
       option on the package}%
 \fi
 \global\advance\bidi@column@check@number\@ne
 \edef\bidi@column@type{\expandafter\ifx
               \csname bidi@column-\the\bidi@column@check@number\endcsname\relax
                  0\else
                  \csname bidi@column-\the\bidi@column@check@number\endcsname
               \fi}%
 \ifcase \bidi@column@type\relax
     \ifcase #1\or #2\or#3\fi   % 0 not known use first column as default
  \or
     #2%  % 1 First column
  \or
     #3%  % 2 Second (Last column)
  \else
    \ERROR
  \fi
  \edef\next{\write\@auxout
     {\string\bidi@set@column@status{bidi@column-\the\bidi@column@check@number}%
                               {\bidi@column@type}}}%
  \next
}
 
\AtEndDocument{\def\bidi@set@column@status#1#2{%
     \ifnum #2=\bidi@current@column@status\else
       \@tempswatrue
     \fi}%
}
\fi

\def\RTL@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
       \hskip \columnwidth
       \hfil
       {\normalcolor\vrule \@width\columnseprule}%
       \hfil
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hskip -\textwidth
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}%
       \hskip \columnsep
      \hskip \columnwidth }}%
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
    \endgroup
  \fi}%

\def\LTR@outputdblcol{%
  \if@firstcolumn
    \global\@firstcolumnfalse
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth\maxdimen
    \vbadness\maxdimen
     \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
     \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \toks@\expandafter{\topmark}%
    \xdef\@firstcoltopmark{\the\toks@}%
    \toks@\expandafter{\splitfirstmark}%
    \xdef\@firstcolfirstmark{\the\toks@}%
    \ifx\@firstcolfirstmark\@empty
      \global\let\@setmarks\relax
    \else
      \gdef\@setmarks{%
        \let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
  \else
    \global\@firstcolumntrue
    \setbox\@outputbox\vbox{%
     \hb@xt@\textwidth{%
        \hb@xt@\columnwidth{%
        \bidi@firstcolumn@status@write%
        \box\@leftcolumn \hss}%
        \hfil
        {\normalcolor\vrule \@width\columnseprule}%
        \hfil
       \hb@xt@\columnwidth{%
       \bidi@lastcolumn@status@write%
       \box\@outputbox \hss}}}%
  \@combinedblfloats
    \@setmarks
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi{\@outputpage
     \@startdblcolumn}%
    \endgroup
  \fi}%


\renewcommand{\@outputdblcol}{\if@RTLmain\RTL@outputdblcol\else\LTR@outputdblcol\fi}
\newcommand{\RTLdblcol}{\renewcommand{\@outputdblcol}{\RTL@outputdblcol}}
\newcommand{\LTRdblcol}{\renewcommand{\@outputdblcol}{\LTR@outputdblcol}}

\bidi@appto\@outputbox@appendfootnotes{%
  \ifvoid\@bidi@copyins@
  \else
    \@outputbox@append{%
      \vskip \skip\@bidi@copyins@
      \color@begingroup
      \normalcolor
      \unvbox \@bidi@copyins@
      \color@endgroup
    }%
  \fi
}

\def\LTRmarginpar{%
  \ifhmode
    \@bsphack
    \@floatpenalty -\@Mii
  \else
    \@floatpenalty-\@Miii
  \fi
  \ifinner
    \@parmoderr
    \@floatpenalty\z@
  \else
    \@next\@currbox\@freelist{}{}%
    \@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
       {\@floatpenalty\z@
        \@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
  \fi
  \@ifnextchar [\@LTRxmpar\@LTRympar}
\long\def\@LTRxmpar[#1]#2{%
  \@LTRsavemarbox\@marbox{#1}%
  \@LTRsavemarbox\@currbox{#2}%
  \@xympar}
\long\def\@LTRympar#1{%
  \@LTRsavemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\long\def \@LTRsavemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@LTRmarginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\def \@LTRmarginparreset {%
        \reset@font
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\beginL}%
}
\def\RTLmarginpar{%
  \ifhmode
    \@bsphack
    \@floatpenalty -\@Mii
  \else
    \@floatpenalty-\@Miii
  \fi
  \ifinner
    \@parmoderr
    \@floatpenalty\z@
  \else
    \@next\@currbox\@freelist{}{}%
    \@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
       {\@floatpenalty\z@
        \@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
  \fi
  \@ifnextchar [\@RTLxmpar\@RTLympar}
\long\def\@RTLxmpar[#1]#2{%
  \@RTLsavemarbox\@marbox{#1}%
  \@RTLsavemarbox\@currbox{#2}%
  \@xympar}
\long\def\@RTLympar#1{%
  \@RTLsavemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\long\def \@RTLsavemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@RTLmarginparreset
        #2%
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\def \@RTLmarginparreset {%
        \reset@font
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\beginR}%
}
\def\@addmarginpar{\@next\@marbox\@currlist{\@cons\@freelist\@marbox
    \@cons\@freelist\@currbox}\@latexbug\@tempcnta\@ne
    \if@twocolumn
        \if@firstcolumn \@tempcnta\m@ne \fi
    \else
      \if@mparswitch
         \ifodd\c@page \else\@tempcnta\m@ne \fi
      \fi
      \if@reversemargin \@tempcnta -\@tempcnta \fi
    \fi
    \ifnum\@tempcnta <\z@  \global\setbox\@marbox\box\@currbox \fi
    \@tempdima\@mparbottom
    \advance\@tempdima -\@pageht
    \advance\@tempdima\ht\@marbox
    \ifdim\@tempdima >\z@
      \@latex@warning@no@line {Marginpar on page \thepage\space moved}%
    \else
      \@tempdima\z@
    \fi
    \global\@mparbottom\@pageht
    \global\advance\@mparbottom\@tempdima
    \global\advance\@mparbottom\dp\@marbox
    \global\advance\@mparbottom\marginparpush
    \advance\@tempdima -\ht\@marbox
    \global\setbox \@marbox
                   \vbox {\vskip \@tempdima
                          \box \@marbox}%
    \global \ht\@marbox \z@
    \global \dp\@marbox \z@
    \kern -\@pagedp
    \nointerlineskip
    \hb@xt@\columnwidth
      {\if@RTL\if@LTRmarginpar\beginL\else\beginR\fi\else\if@RTLmarginpar\beginR\else\beginL\fi\fi\ifnum \@tempcnta >\z@
          \hskip\columnwidth \hskip\marginparsep
       \else
          \hskip -\marginparsep \hskip -\marginparwidth
       \fi
       \box\@marbox \hss\if@RTL\if@LTRmarginpar\endL\else\endR\fi\else\if@RTLmarginpar\endR\else\endL\fi\fi}%
    \nointerlineskip
    \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}}
\long\def\@ympar#1{%
  \@savemarbox\@marbox{\if@RTL\if@LTRmarginpar\@RTLfalse\else\@RTLtrue\fi\else\if@RTLmarginpar\@RTLtrue\else\@RTLfalse\fi\fi#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}
\def\setRTLmarginpar{\@RTLmarginpartrue\@LTRmarginparfalse}
\def\setLTRmarginpar{\@LTRmarginpartrue\@RTLmarginparfalse}
\def\setdefaultmarginpar{\@RTLmarginparfalse\@LTRmarginparfalse}
\def\@stopline{\unskip\@stopfield\if@rjfield \global\@rjfieldfalse
   \@tempdima\@totalleftmargin \advance\@tempdima\linewidth
\hbox to\@tempdima{\if@RTL\beginR\fi\@itemfudge\hskip\dimen\@curtabmar
   \box\@curline\hfil\box\@curfield\if@RTL\endR\fi}\else\@addfield
   \hbox to\linewidth{\if@RTL\beginR\fi\@itemfudge
   \hskip\dimen\@curtabmar\box\@curline\hfil\if@RTL\endR\fi}%
\fi}

\newcommand*{\bidi@font@@outputpage}{}

\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \let \protect \noexpand
  \@resetactivechars
  \global\let\@@if@newlist\if@newlist
  \global\@newlistfalse
  \@parboxrestore
  \global\let\bidi@BeforeOutputPageShipOut\@firstofone
  \bidi@beforeoutputpageshipouthook
  \shipout \vbox{%
    \set@typeset@protect
    \aftergroup \endgroup
    \aftergroup \set@typeset@protect
                                % correct? or just restore by ending
                                % the group?
  \if@specialpage
    \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
  \fi
  \if@twoside
    \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
       \if@RTLmain
          \let\@themargin\evensidemargin
        \else
          \let\@themargin\oddsidemargin
        \fi
    \else \let\@thehead\@evenhead \let\@thefoot\@evenfoot 
       \if@RTLmain
         \let\@themargin\oddsidemargin
       \else
         \let\@themargin\evensidemargin
       \fi
    \fi
    \ifx\@thehead\@empty \let\@thehead\hfil \fi
    \ifx\@thefoot\@empty \let\@thefoot\hfil \fi
    \else %% not @twoside
    \ifx\@oddhead\@empty \let\@thehead\hfil \fi
    \ifx\@oddfoot\@empty \let\@thefoot\hfil \fi
  \fi
  \reset@font
  \normalsize
  \bidi@font@@outputpage
  \normalsfcodes
  \let\label\@gobble
  \let\index\@gobble
  \let\glossary\@gobble
  \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
    \@begindvi
    \vskip \topmargin
    \moveright\@themargin \vbox {%
      \global\let\bidi@BeforeHeader\@firstofone
      \bidi@beforeheaderhook
      \setbox\@tempboxa \vbox to\headheight{%
        \vfil
        \color@hbox
          \normalcolor
          \hb@xt@\textwidth{\if@RTLmain\@RTLtrue\beginR\else\@RTLfalse\beginL\fi\@thehead\if@RTLmain\endR\else\endL\fi}%
        \color@endbox
        }%                        %% 22 Feb 87
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \global\let\bidi@BeforeOutputBoxOutputPage\@firstofone
      \bidi@beforeoutputboxoutputpagehook
      \box\@outputbox
      \global\let\bidi@AfterOutputBoxOutputPage\@firstofone
      \bidi@afteroutputboxoutputpagehook
      \global\let\bidi@BeforeFooter\@firstofone
      \bidi@beforefooterhook
      \baselineskip \footskip
      \color@hbox
        \normalcolor
        \hb@xt@\textwidth{\if@RTLmain\@RTLtrue\beginR\else\@RTLfalse\beginL\fi\@thefoot\if@RTLmain\endR\else\endL\fi}%
      \color@endbox
      \global\let\bidi@AfterFooter\@firstofone
      \bidi@afterfooterhook
      }%
    }%
  \global\let\bidi@AfterOutputPageShipOut\@firstofone
  \bidi@afteroutputpageshipouthook
  \global\let\if@newlist\@@if@newlist
  \global \@colht \textheight
  \stepcounter{page}%
  \let\firstmark\botmark
  \global\let\bidi@AtEndOutputPage\@firstofone
  \bidi@atendoutputpagehook
}
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    \if@RTL\beginR\fi#1: #2\if@RTL\endR\fi\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\if@RTL\beginR\fi\hfil\box\@tempboxa\hfil\if@RTL\endR\fi}%
  \fi
  \vskip\belowcaptionskip}
\let\bidi@saved@eqno=\eqno
\let\bidi@saved@leqno=\leqno
\def\eqno{\ifnum\predisplaydirection<\z@ \bidi@saved@leqno \else \bidi@saved@eqno \fi}
\def\leqno{\ifnum\predisplaydirection<\z@ \bidi@saved@eqno \else \bidi@saved@leqno \fi}
\ApplyPatchIfPackageLoadedF{amsmath}{
\def\@eqnnum{{\normalfont \normalcolor \if@RTL\beginR\fi(\theequation)\if@RTL\endR\fi}}
}
\input{footnote-xetex-bidi.def}
\if@twocolumn
  \let\autofootnoterule\relax
  \let\leftfootnoterule\relax
  \let\rightfootnoterule\relax
  \textwidthfootnoterule
\fi
\if@bidi@csundef{@idxitem}{}{%
\renewcommand\@idxitem{\par\hangindent \if@RTL-\fi40\p@}%
}

\ApplyPatchToClassesIfPackageLoadedF{%
  book, %
  report %
}{flowfram}

\ApplyPatchToPackageIfPackageLoadedF{float}{floatrow}

\ApplyPatchToFilesIfPackageLoadedF{amsmath}{%
  fleqn, %
  leqno%
}[clo]

\ApplyPatchToClasses{%
  amsart, %
  amsbook, %
  article, %
  artikel1, %
  artikel2, %
  artikel3, %
  beamer, %
  boek, %
  boek3, %
  bookest, %
  combine, %
  extbook, %
  extletter, %
  extarticle, %
  extreport, %
  imsproc, %
  letter, %
  memoir, %
  rapport1, %
  rapport3, %
  refrep, %
  scrartcl, %
  scrbook, %
  scrreprt %
}

\ApplyPatchToPackages{%
  algorithm2e, %
  amsmath, %
  amstext, %
  amsthm, %
  array, %
  arydshln, %
  beamerbaseauxtemplates, %
  beamerbaseboxes, %
  beamerbasecolor, %
  beamerbasecompatibility, %
  beamerbaseframecomponents, %
  beamerbaseframesize, %
  beamerbaselocalstructure, %
  beamerbasemisc, %
  beamerbasenavigation, %
  beamerbaseoverlay, %
  beamerinnerthemecircles, %
  beamerinnerthemedefault, %
  beamerinnerthemefocus, %
  beamerinnerthemeinmargin, %
  beamerinnerthememetropolis, %
  beamerinnerthemerectangles, %
  beamerinnerthemerounded, %
  beamerouterthemedefault, %
  beamerouterthemefocus, %
  beamerouterthemeinfolines, %
  beamerouterthememetropolis, %
  beamerouterthememiniframes, %
  beamerouterthemesidebar, %
  beamerouterthemesplit, %
  beamerouterthemeshadow, %
  beamerouterthemesmoothbars, %
  beamerouterthemesmoothtree, %
  beamerouterthemetree, %
  beamerthemeHannover, %
  beamerthemeSingapore, %
  breqn, %
  cals, %
  caption, %
  caption3, %
  color, %
  colortbl, %
  crop, %
  cuted, %
  cutwin, %
  dblfnote, %
  diagbox, %
  draftwatermark, %
  eso-pic, %
  empheq, %
  fancybox, %
  fancyhdr, %
  fix2col, %
  float, %
  floatrow, %
  flowfram, %
  fnpct, %
  footnotebackref, %
  framed, %
  ftnright, %
  geometry, %
  graphicx, %
  hvfloat, %
  hyperref, %
  lettrine, %
  lineno, %
  listings, %
  longtable, %
  lscape, %
  mathtools, %
  mdframed, %
  media9, %
  midfloat, %
  minitoc, %
  multicol, %
  adjmulticol, %
  multienum, %
  natbib, %
  newfloat, %
  nicematrix, %
  ntheorem, %
  ntheorem-hyper, %
  overpic, %
  pdfbase, %
  pdflscape, %
  pgfsys, %
  picinpar, %
  quotchap, %
  ragged2e, %
  rotating, %
  sidecap, %
  soul, %
  stabular, %
  subfigure, %
  tabls, %
  tabularx, %
  tabulary, %
  tcolorbox, %
  thmbox, %
  titlesec, %
  titletoc, %
  tocbasic, %
  tocbibind, %
  tocloft, %
  tocstyle, %
  todonotes, %
  wrapfig, %
  xcolor, %
  xltxtra %
}

\ApplyPatchToFiles{%
  pgfcorescopes.code, %
  pstricks %
}[tex]

\ApplyPatchToFiles{%
  hgeneric-testphase, %
  tc-xetex %
}

%    \end{macrocode}
% \iffalse
%</latex-xetex-bidi.def>
%<*xltxtra-xetex-bidi.def>
%\fi
% \section{File \texttt{xltxtra-xetex-bidi.def}}
%    \begin{macrocode}
\ProvidesFile{xltxtra-xetex-bidi.def}[2010/07/25 v0.1 bidi adaptations for xltxtra package for XeTeX engine]
\let\@@XeTeX\XeTeX
\def\XeTeX{\@ensure@LTR{\@@XeTeX}}
\let\@@XeLaTeX\XeLaTeX
\def\XeLaTeX{\@ensure@LTR{\@@XeLaTeX}}
%    \end{macrocode}
% \iffalse
%</xltxtra-xetex-bidi.def>
%\fi
%
% \Finale
%
%
%\iffalse
%<*bidi-logo.tex>
\documentclass{minimal}
\usepackage{pstricks}
\begin{document}
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(644,645)
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(336.4,15.6)
\curveto(336.4,7.6)(329.9,1.201)(322,1.201)
\curveto(314,1.201)(307.6,7.701)(307.6,15.6)
\curveto(307.6,23.5)(314.1,30)(322,30)
\curveto(329.9,30)(336.4,23.6)(336.4,15.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(368.4,18.8)
\curveto(369.2,10.901)(363.5,3.8)(355.599,2.901)
\curveto(347.7,2.1)(340.599,7.8)(339.7,15.701)
\curveto(338.9,23.6)(344.599,30.701)(352.5,31.6)
\curveto(360.5,32.5)(367.6,26.7)(368.4,18.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(400,25.3)
\curveto(401.7,17.5)(396.7,9.8)(388.9,8.2)
\curveto(381.099,6.5)(373.4,11.5)(371.799,19.3)
\curveto(370.099,27.1)(375.099,34.8)(382.9,36.401)
\curveto(390.6,38.1)(398.3,33.1)(400,25.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(430.7,35.1)
\curveto(433.2,27.5)(429,19.401)(421.4,16.901)
\curveto(413.799,14.401)(405.7,18.6)(403.2,26.201)
\curveto(400.7,33.801)(404.9,41.901)(412.5,44.401)
\curveto(420.1,46.901)(428.2,42.7)(430.7,35.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(460.2,48.1)
\curveto(463.4,40.8)(460.2,32.3)(452.9,29)
\curveto(445.599,25.8)(437.099,29)(433.799,36.3)
\curveto(430.599,43.6)(433.799,52.1)(441.099,55.3)
\curveto(448.4,58.6)(456.9,55.3)(460.2,48.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(488.2,64)
\curveto(492.2,57.1)(489.8,48.3)(482.9,44.3)
\curveto(476,40.3)(467.2,42.7)(463.2,49.6)
\curveto(459.2,56.5)(461.599,65.3)(468.5,69.3)
\curveto(475.401,73.3)(484.2,70.9)(488.2,64)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(514.3,82.8)
\curveto(519,76.401)(517.6,67.3)(511.1,62.6)
\curveto(504.6,57.901)(495.6,59.3)(490.901,65.8)
\curveto(486.201,72.3)(487.701,81.3)(494.1,86)
\curveto(500.6,90.7)(509.6,89.3)(514.3,82.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(538.4,104.2)
\curveto(543.7,98.3)(543.299,89.099)(537.299,83.8)
\curveto(531.4,78.5)(522.199,79)(516.9,84.901)
\curveto(511.6,90.8)(512.1,100)(518,105.3)
\curveto(523.9,110.7)(533.1,110.2)(538.4,104.2)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(560.1,128.1)
\curveto(566,122.8)(566.5,113.6)(561.201,107.701)
\curveto(555.901,101.801)(546.701,101.301)(540.801,106.6)
\curveto(534.902,111.901)(534.402,121.1)(539.701,127)
\curveto(545,132.9)(554.2,133.4)(560.1,128.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(579.2,154)
\curveto(585.7,149.3)(587.099,140.3)(582.4,133.8)
\curveto(577.7,127.3)(568.7,125.901)(562.2,130.6)
\curveto(555.7,135.3)(554.3,144.3)(559,150.8)
\curveto(563.7,157.3)(572.7,158.7)(579.2,154)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(595.4,181.8)
\curveto(602.299,177.8)(604.7,169)(600.7,162.1)
\curveto(596.7,155.201)(587.9,152.8)(581,156.8)
\curveto(574.1,160.8)(571.7,169.6)(575.7,176.5)
\curveto(579.7,183.5)(588.5,185.8)(595.4,181.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(608.7,211.2)
\curveto(616,208)(619.3,199.4)(616,192.099)
\curveto(612.8,184.799)(604.2,181.599)(596.9,184.799)
\curveto(589.6,188)(586.3,196.6)(589.6,203.9)
\curveto(592.9,211.2)(601.4,214.5)(608.7,211.2)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(618.8,241.8)
\curveto(626.401,239.3)(630.5,231.2)(628.1,223.6)
\curveto(625.6,216)(617.5,211.901)(609.901,214.3)
\curveto(602.3,216.8)(598.201,224.901)(600.6,232.5)
\curveto(603.1,240.1)(611.2,244.3)(618.8,241.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(625.7,273.3)
\curveto(633.5,271.7)(638.5,264)(636.8,256.2)
\curveto(635.2,248.4)(627.5,243.4)(619.7,245.099)
\curveto(611.9,246.799)(606.9,254.4)(608.599,262.2)
\curveto(610.2,270)(617.9,274.9)(625.7,273.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(629.2,305.3)
\curveto(637.099,304.5)(642.9,297.401)(642,289.401)
\curveto(641.2,281.501)(634.1,275.701)(626.1,276.6)
\curveto(618.201,277.401)(612.401,284.5)(613.3,292.5)
\curveto(614.2,300.4)(621.3,306.1)(629.2,305.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(629.4,337.5)
\curveto(637.4,337.5)(643.9,331)(643.799,323.1)
\curveto(643.799,315.1)(637.299,308.7)(629.4,308.7)
\curveto(621.4,308.7)(615,315.2)(615,323.1)
\curveto(615,331.1)(621.4,337.5)(629.4,337.5)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(626.2,369.6)
\curveto(634.099,370.4)(641.2,364.7)(642.099,356.8)
\curveto(642.9,348.9)(637.2,341.8)(629.299,340.9)
\curveto(621.4,340.1)(614.299,345.8)(613.499,353.8)
\curveto(612.5,361.7)(618.3,368.8)(626.2,369.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(619.7,401.1)
\curveto(627.5,402.8)(635.2,397.8)(636.8,390)
\curveto(638.5,382.2)(633.5,374.5)(625.7,372.9)
\curveto(617.9,371.2)(610.2,376.2)(608.599,384)
\curveto(606.9,391.8)(611.9,399.5)(619.7,401.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(609.9,431.8)
\curveto(617.5,434.3)(625.599,430.1)(628.099,422.5)
\curveto(630.599,414.9)(626.4,406.8)(618.799,404.3)
\curveto(611.199,401.8)(603.099,406)(600.599,413.6)
\curveto(598.099,421.2)(602.3,429.4)(609.9,431.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(596.9,461.4)
\curveto(604.2,464.7)(612.7,461.4)(615.9,454.1)
\curveto(619.2,446.8)(615.9,438.3)(608.599,435)
\curveto(601.299,431.8)(592.799,435)(589.499,442.3)
\curveto(586.4,449.6)(589.6,458.1)(596.9,461.4)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(581,489.3)
\curveto(587.9,493.3)(596.7,490.9)(600.7,484)
\curveto(604.7,477.1)(602.3,468.3)(595.4,464.3)
\curveto(588.5,460.3)(579.7,462.7)(575.7,469.6)
\curveto(571.7,476.5)(574.1,485.3)(581,489.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(562.2,515.5)
\curveto(568.599,520.2)(577.7,518.8)(582.4,512.3)
\curveto(587.099,505.9)(585.7,496.8)(579.2,492.1)
\curveto(572.7,487.4)(563.7,488.9)(559,495.3)
\curveto(554.3,501.8)(555.7,510.8)(562.2,515.5)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(540.8,539.6)
\curveto(546.7,544.9)(555.901,544.5)(561.2,538.5)
\curveto(566.5,532.6)(566.099,523.5)(560.099,518.1)
\curveto(554.2,512.8)(544.999,513.3)(539.7,519.2)
\curveto(534.3,525.1)(534.8,534.2)(540.8,539.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(516.9,561.3)
\curveto(522.2,567.2)(531.4,567.7)(537.299,562.4)
\curveto(543.199,557.1)(543.699,547.9)(538.4,542)
\curveto(533.099,536.1)(523.9,535.6)(518,540.9)
\curveto(512.1,546.2)(511.6,555.3)(516.9,561.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(491,580.3)
\curveto(495.7,586.8)(504.7,588.2)(511.2,583.5)
\curveto(517.7,578.8)(519.099,569.8)(514.4,563.3)
\curveto(509.7,556.9)(500.7,555.4)(494.2,560.1)
\curveto(487.7,564.9)(486.3,573.9)(491,580.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(463.1,596.6)
\curveto(467.1,603.5)(475.901,605.9)(482.8,601.9)
\curveto(489.7,597.9)(492.1,589.1)(488.1,582.2)
\curveto(484.1,575.3)(475.3,572.9)(468.401,576.9)
\curveto(461.5,580.9)(459.2,589.7)(463.1,596.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(433.8,609.9)
\curveto(437,617.2)(445.6,620.5)(452.901,617.2)
\curveto(460.201,614)(463.501,605.4)(460.201,598.1)
\curveto(457.001,590.8)(448.401,587.6)(441.1,590.8)
\curveto(433.8,594)(430.5,602.6)(433.8,609.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(403.2,620)
\curveto(405.7,627.6)(413.8,631.7)(421.4,629.3)
\curveto(429,626.8)(433.099,618.7)(430.7,611.1)
\curveto(428.2,603.5)(420.099,599.4)(412.5,601.8)
\curveto(404.9,604.3)(400.7,612.4)(403.2,620)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(371.7,626.9)
\curveto(373.3,634.7)(381,639.7)(388.8,638)
\curveto(396.6,636.3)(401.6,628.7)(399.901,620.9)
\curveto(398.201,613.1)(390.6,608.1)(382.8,609.8)
\curveto(375,611.4)(370.1,619)(371.7,626.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(339.7,630.4)
\curveto(340.5,638.3)(347.6,644.1)(355.6,643.2)
\curveto(363.5,642.4)(369.3,635.3)(368.5,627.3)
\curveto(367.7,619.4)(360.5,613.6)(352.6,614.5)
\curveto(344.6,615.4)(338.8,622.5)(339.7,630.4)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(307.5,630.6)
\curveto(307.5,638.6)(314,645)(321.9,645)
\curveto(329.9,645)(336.299,638.5)(336.299,630.6)
\curveto(336.299,622.6)(329.799,616.2)(321.9,616.2)
\curveto(313.9,616.1)(307.5,622.6)(307.5,630.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(275.4,627.4)
\curveto(274.5,635.3)(280.3,642.4)(288.2,643.3)
\curveto(296.1,644.1)(303.2,638.4)(304.1,630.5)
\curveto(304.9,622.6)(299.2,615.5)(291.2,614.7)
\curveto(283.3,613.7)(276.2,619.4)(275.4,627.4)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(243.9,620.8)
\curveto(242.2,628.7)(247.2,636.3)(255,638)
\curveto(262.8,639.7)(270.5,634.7)(272.1,626.9)
\curveto(273.8,619.1)(268.8,611.4)(261,609.8)
\curveto(253.2,608.1)(245.5,613)(243.9,620.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(213.2,611.1)
\curveto(210.7,618.7)(214.9,626.8)(222.5,629.3)
\curveto(230.1,631.8)(238.2,627.6)(240.7,620)
\curveto(243.2,612.4)(239,604.3)(231.4,601.8)
\curveto(223.8,599.3)(215.6,603.5)(213.2,611.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(183.6,598.1)
\curveto(180.3,605.4)(183.6,613.9)(190.9,617.2)
\curveto(198.2,620.4)(206.7,617.2)(210,609.9)
\curveto(213.2,602.6)(209.9,594.1)(202.7,590.9)
\curveto(195.4,587.5)(186.9,590.8)(183.6,598.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(155.7,582.2)
\curveto(151.7,589.1)(154.1,597.9)(161,601.9)
\curveto(167.9,605.9)(176.7,603.5)(180.7,596.6)
\curveto(184.7,589.7)(182.3,580.9)(175.4,576.9)
\curveto(168.5,572.9)(159.7,575.2)(155.7,582.2)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(129.5,563.4)
\curveto(124.8,569.8)(126.3,578.9)(132.7,583.6)
\curveto(139.2,588.3)(148.2,586.9)(152.9,580.4)
\curveto(157.6,574)(156.1,564.9)(149.7,560.2)
\curveto(143.2,555.5)(134.2,556.9)(129.5,563.4)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(105.4,541.9)
\curveto(100,547.8)(100.6,557)(106.5,562.3)
\curveto(112.4,567.6)(121.5,567.2)(126.9,561.2)
\curveto(132.2,555.3)(131.7,546.1)(125.8,540.8)
\curveto(119.9,535.5)(110.8,536)(105.4,541.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(83.7,518.1)
\curveto(77.7,523.4)(77.3,532.6)(82.6,538.5)
\curveto(87.9,544.4)(97,544.9)(103,539.6)
\curveto(108.9,534.3)(109.4,525.1)(104,519.2)
\curveto(98.8,513.2)(89.7,512.8)(83.7,518.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(64.7,492.1)
\curveto(58.2,496.8)(56.8,505.8)(61.5,512.3)
\curveto(66.2,518.8)(75.2,520.2)(81.7,515.5)
\curveto(88.1,510.8)(89.6,501.8)(84.9,495.3)
\curveto(80.1,488.9)(71.1,487.4)(64.7,492.1)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(48.4,464.3)
\curveto(41.5,468.3)(39.1,477.1)(43.1,484)
\curveto(47.1,490.9)(55.9,493.3)(62.8,489.3)
\curveto(69.7,485.3)(72.1,476.5)(68,469.6)
\curveto(64.1,462.7)(55.3,460.3)(48.4,464.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(35.1,435)
\curveto(27.8,438.2)(24.5,446.8)(27.8,454.1)
\curveto(31,461.4)(39.6,464.7)(46.9,461.4)
\curveto(54.2,458.2)(57.4,449.6)(54.2,442.3)
\curveto(51,435)(42.4,431.7)(35.1,435)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(25,404.4)
\curveto(17.4,406.8)(13.3,415)(15.8,422.6)
\curveto(18.3,430.2)(26.4,434.3)(34,431.9)
\curveto(41.6,429.4)(45.7,421.3)(43.2,413.7)
\curveto(40.8,406.1)(32.6,401.9)(25,404.4)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(18.1,372.9)
\curveto(10.3,374.5)(5.4,382.2)(7,390)
\curveto(8.6,397.8)(16.3,402.8)(24.1,401.1)
\curveto(31.9,399.4)(36.9,391.8)(35.2,384)
\curveto(33.6,376.2)(26,371.2)(18.1,372.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(14.6,340.9)
\curveto(6.7,341.7)(0.9,348.8)(1.8,356.8)
\curveto(2.6,364.7)(9.7,370.5)(17.7,369.7)
\curveto(25.6,368.9)(31.4,361.7)(30.5,353.8)
\curveto(29.6,345.8)(22.5,340)(14.6,340.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(14.4,308.6)
\curveto(6.4,308.6)(0,315.1)(0,323)
\curveto(0,331)(6.5,337.4)(14.5,337.4)
\curveto(22.4,337.4)(28.9,330.9)(28.9,322.9)
\curveto(28.9,315.1)(22.4,308.6)(14.4,308.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(17.6,276.6)
\curveto(9.7,275.701)(2.6,281.5)(1.7,289.401)
\curveto(0.9,297.3)(6.6,304.401)(14.6,305.3)
\curveto(22.5,306.1)(29.6,300.401)(30.4,292.401)
\curveto(31.3,284.5)(25.6,277.4)(17.6,276.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(24.1,245)
\curveto(16.3,243.3)(8.6,248.3)(7,256.1)
\curveto(5.3,263.901)(10.3,271.5)(18.1,273.201)
\curveto(25.9,274.801)(33.6,269.901)(35.2,262.1)
\curveto(36.9,254.4)(32,246.7)(24.1,245)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(33.9,214.3)
\curveto(26.3,211.8)(18.2,216)(15.7,223.6)
\curveto(13.2,231.201)(17.4,239.3)(25,241.8)
\curveto(32.6,244.3)(40.7,240.1)(43.2,232.5)
\curveto(45.7,224.9)(41.5,216.8)(33.9,214.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(46.9,184.8)
\curveto(39.6,181.5)(31.1,184.8)(27.8,192.1)
\curveto(24.5,199.401)(27.8,207.901)(35.1,211.201)
\curveto(42.4,214.401)(50.9,211.1)(54.1,203.801)
\curveto(57.5,196.6)(54.2,188.1)(46.9,184.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(62.8,156.8)
\curveto(55.9,152.8)(47.1,155.2)(43.1,162.1)
\curveto(39.1,169)(41.5,177.8)(48.4,181.8)
\curveto(55.3,185.8)(64.1,183.401)(68.1,176.5)
\curveto(72.1,169.7)(69.8,160.8)(62.8,156.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(81.6,130.7)
\curveto(75.2,126)(66.1,127.4)(61.5,133.9)
\curveto(56.8,140.299)(58.2,149.4)(64.7,154.099)
\curveto(71.1,158.799)(80.2,157.299)(84.8,150.9)
\curveto(89.5,144.4)(88.1,135.4)(81.6,130.7)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(103.1,106.6)
\curveto(97.2,101.2)(88,101.7)(82.7,107.7)
\curveto(77.4,113.599)(77.8,122.7)(83.8,128.099)
\curveto(89.7,133.4)(98.9,132.9)(104.2,126.999)
\curveto(109.5,121.1)(109,111.9)(103.1,106.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(126.9,84.9)
\curveto(121.6,79)(112.4,78.5)(106.5,83.799)
\curveto(100.6,89.098)(100.1,98.199)(105.4,104.199)
\curveto(110.7,110.098)(119.9,110.598)(125.8,105.199)
\curveto(131.8,100)(132.2,90.8)(126.9,84.9)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(152.9,65.8)
\curveto(148.2,59.3)(139.2,57.901)(132.7,62.6)
\curveto(126.2,67.3)(124.8,76.3)(129.5,82.8)
\curveto(134.2,89.2)(143.2,90.7)(149.7,86)
\curveto(156.1,81.3)(157.6,72.3)(152.9,65.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(180.7,49.6)
\curveto(176.7,42.701)(167.9,40.3)(161,44.3)
\curveto(154.1,48.3)(151.7,57.1)(155.7,64)
\curveto(159.7,70.9)(168.5,73.2)(175.4,69.2)
\curveto(182.3,65.3)(184.7,56.5)(180.7,49.6)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(210,36.3)
\curveto(206.8,29)(198.2,25.7)(190.9,29)
\curveto(183.6,32.2)(180.3,40.8)(183.6,48.1)
\curveto(186.8,55.401)(195.4,58.6)(202.7,55.401)
\curveto(210,52.1)(213.3,43.6)(210,36.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(240.6,26.2)
\curveto(238.2,18.599)(230,14.5)(222.4,16.9)
\curveto(214.8,19.4)(210.7,27.5)(213.1,35.099)
\curveto(215.6,42.7)(223.7,46.799)(231.3,44.299)
\curveto(238.9,41.9)(243.1,33.8)(240.6,26.2)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(272.1,19.3)
\curveto(270.5,11.5)(262.8,6.5)(255,8.2)
\curveto(247.2,9.8)(242.2,17.5)(243.9,25.3)
\curveto(245.6,33.1)(253.2,38.1)(261,36.401)
\curveto(268.8,34.8)(273.8,27.1)(272.1,19.3)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.7764706 0.78431374 0.79215688}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(304.1,15.8)
\curveto(303.3,7.901)(296.2,2.1)(288.2,3)
\curveto(280.3,3.8)(274.5,10.9)(275.3,18.9)
\curveto(276.1,26.799)(283.3,32.599)(291.2,31.7)
\curveto(299.2,30.8)(305,23.7)(304.1,15.8)
\closepath
}
}
{
\newrgbcolor{curcolor}{0.60784316 0.50588238 0.34117648}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(291.4,500.2)
\curveto(301.1,484.1)(307,462.5)(307,439.8)
\curveto(307,435.5)(306.8,431.2)(306.3,426.9)
\curveto(314.6,418.4)(321.3,409.1)(326,401.8)
\curveto(327.6,410.1)(328.4,418.8)(328.4,427.4)
\curveto(328.4,463.9)(314.9,501.1)(293.6,519.1)
\curveto(284,522)(276.8,520.1)(274.4,519.3)
\curveto(280.9,514.7)(286.6,508.1)(291.4,500.2)
\closepath
\moveto(302.4,527.6)
\curveto(319.6,526.4)(337.6,516.9)(351.3,499.5)
\curveto(365,482.1)(374.5,457.9)(374.5,430.5)
\curveto(374.5,400.5)(363.1,368.7)(333.6,336.2)
\curveto(340,335.8)(346.1,333.4)(350.5,329.8)
\curveto(351.6,330)(352.7,330.1)(353.8,330.1)
\lineto(354.5,330.1)
\curveto(383.3,356.7)(394.6,389.2)(394.6,420.6)
\curveto(394.6,450)(384.6,478.3)(369.5,499.2)
\curveto(354.5,520.1)(334.6,533.4)(315.1,533.3)
\curveto(308.3,533.3)(295.201,530)(288.6,526.5)
\curveto(289.1,526.4)(294.5,528.1)(302.4,527.6)
\closepath
\moveto(372.7,501.3)
\curveto(388.2,479.8)(398.4,450.8)(398.5,420.6)
\curveto(398.5,389.2)(387.4,356.4)(359.4,329.5)
\curveto(365.4,328.2)(370.7,325)(373.9,320.8)
\curveto(374.299,320.2)(374.7,319.6)(375,319)
\curveto(407,346.7)(419.5,380.5)(419.5,413.6)
\curveto(419.5,446.6)(406.9,478.8)(388.4,502.7)
\curveto(370,526.6)(345.8,542)(323,541.9)
\curveto(312.4,541.9)(301.9,538.6)(292.3,531.1)
\curveto(299.7,535.1)(307.401,537)(315.1,537)
\curveto(336.4,536.9)(357.2,522.7)(372.7,501.3)
\closepath
\moveto(282.7,533.4)
\curveto(277,534)(271.1,533.9)(265.2,533)
\curveto(270.2,533)(275,532.1)(279.6,530.4)
\curveto(280.5,531.4)(281.5,532.5)(282.7,533.4)
\closepath
\moveto(258.7,497.6)
\curveto(264.6,487.7)(268.1,475)(268.1,463)
\curveto(268.1,459.9)(267.9,456.8)(267.4,453.9)
\curveto(272.3,451.7)(277.8,448.9)(283.8,445.1)
\curveto(284,447.5)(284.1,449.9)(284.1,452.4)
\curveto(284.1,468)(279.8,484.7)(272.5,497.4)
\curveto(265.2,510.2)(255.1,518.7)(243.7,518.7)
\curveto(238.8,518.7)(233.6,517.1)(228.1,513.6)
\curveto(230.3,514.3)(232.5,514.6)(234.6,514.6)
\curveto(244.5,514.6)(252.9,507.5)(258.7,497.6)
\closepath
\moveto(274.7,498.6)
\curveto(282.2,485.4)(286.6,468.4)(286.6,452.4)
\curveto(286.6,449.4)(286.4,446.5)(286.1,443.6)
\curveto(289.6,441.3)(293.3,438.6)(297.1,435.6)
\curveto(299.6,433.6)(301.9,431.5)(304.1,429.3)
\curveto(304.4,432.8)(304.6,436.4)(304.6,439.9)
\curveto(304.6,462.1)(298.8,483.4)(289.3,499)
\curveto(279.8,514.6)(266.9,524.5)(252.7,524.5)
\curveto(247.3,524.5)(241.6,523.1)(235.8,519.9)
\curveto(238.5,520.7)(241.2,521.1)(243.8,521.1)
\curveto(256.5,521.1)(267.2,511.7)(274.7,498.6)
\closepath
\moveto(247.5,460.9)
\curveto(251.3,459.7)(257.4,458.1)(265,454.9)
\curveto(265.4,457.5)(265.6,460.2)(265.6,463)
\curveto(265.6,474.5)(262.2,486.9)(256.6,496.4)
\curveto(251,505.9)(243.2,512.2)(234.6,512.1)
\curveto(229.7,512.1)(224.3,510.1)(218.6,505.1)
\curveto(235.7,512.7)(255.7,492)(247.5,460.9)
\closepath
\moveto(273.9,519.8)
\curveto(274.4,521.3)(275.6,524.8)(278,528.3)
\curveto(273.9,529.7)(269.6,530.5)(265.1,530.5)
\curveto(259.2,530.5)(253,529.2)(246.5,526.3)
\curveto(248.6,526.7)(250.7,526.9)(252.7,526.9)
\curveto(260.3,526.9)(267.4,524.3)(273.9,519.8)
\closepath
\moveto(428.7,500)
\curveto(430.9,497.5)(432.599,495.4)(434.599,492.7)
\curveto(435.499,495.7)(437.499,498.8)(437.499,501.7)
\curveto(441.499,499.1)(448.099,497.9)(451.699,493.7)
\lineto(451.899,493.7)
\curveto(458.999,503.7)(476.699,494.6)(472.899,484.5)
\lineto(471.699,482.3)
\curveto(469.699,479.4)(467.199,478.3)(464.899,478.2)
\curveto(461.798,478.3)(459.298,480.2)(459.298,483.7)
\curveto(459.298,485.2)(459.798,486.5)(460.399,487.5)
\curveto(461.098,488.4)(461.899,488.9)(462.598,488.9)
\curveto(463.199,488.9)(463.798,488.7)(464.498,487.9)
\curveto(465.298,487.1)(465.498,486.5)(465.498,486.1)
\curveto(465.498,485.7)(465.298,485.2)(464.898,484.9)
\curveto(464.498,484.6)(463.998,484.4)(463.797,484.4)
\lineto(463.697,484.4)
\curveto(463.096,484.2)(462.297,484.5)(461.997,483.9)
\curveto(461.697,483.3)(461.897,482.5)(462.497,482.2)
\lineto(462.497,482.2)
\curveto(462.897,482)(463.297,481.9)(463.697,481.9)
\curveto(465.596,482)(467.797,483.5)(467.897,486.1)
\curveto(467.897,487.3)(467.296,488.5)(466.197,489.6)
\curveto(465.096,490.7)(463.797,491.3)(462.497,491.3)
\curveto(458.997,491.2)(456.697,487.6)(456.697,483.7)
\curveto(456.697,481.3)(457.596,479.2)(459.197,477.8)
\curveto(460.697,476.4)(462.697,475.7)(464.897,475.7)
\lineto(464.897,475.7)
\curveto(467.596,475.7)(470.497,477)(472.796,479.6)
\curveto(484.496,464.8)(484.096,446.4)(479.897,438.1)
\curveto(527.7,488.7)(462.8,525.4)(428.7,500)
\closepath
\moveto(422.2,266.6)
\curveto(441,286.901)(460.2,314.6)(465.5,356.201)
\curveto(466.4,363.401)(466.8,370.401)(466.8,377.401)
\curveto(466.8,386.501)(466.1,395.401)(464.7,404.101)
\lineto(464.7,401.101)
\curveto(464.7,354.901)(443.599,311.801)(407.599,284.101)
\lineto(407.599,282.902)
\curveto(407.599,282.202)(407.599,281.502)(407.499,280.902)
\curveto(412.299,276.601)(415.799,269.801)(415.799,261.702)
\curveto(415.799,261.101)(415.799,260.502)(415.699,259.902)
\curveto(417.9,262)(420,264.2)(422.2,266.6)
\closepath
\moveto(442.8,496)
\curveto(441.7,496.6)(440.5,497)(439.3,497.6)
\curveto(439,496.1)(438.6,495.6)(438.1,494.1)
\curveto(437.6,492.8)(437.201,491.3)(436.901,490.1)
\curveto(439.8,486.5)(441.701,483.8)(443.3,481.3)
\curveto(444,480)(446.7,474.8)(449.8,468.9)
\curveto(453.3,462.1)(457.3,454.3)(458.901,450.6)
\curveto(459.1,450.1)(459.6,449.9)(460.001,449.9)
\curveto(460.201,449.9)(460.301,449.9)(460.501,450)
\curveto(461.101,450.3)(461.401,451)(461.101,451.6)
\curveto(458.501,457.6)(450.402,473.1)(446.902,479.7)
\curveto(447.002,484.2)(448.002,488.2)(449.601,491.4)
\curveto(447.7,493.3)(445.3,494.8)(442.8,496)
\closepath
\moveto(412.1,505.1)
\curveto(432.1,480.1)(446.5,447.4)(446.5,412)
\curveto(446.5,376.4)(431.8,338.2)(393.9,302.9)
\curveto(394.099,302.4)(394.2,302)(394.4,301.5)
\curveto(399,299.8)(402.299,296.9)(404.4,293.8)
\curveto(405.7,291.901)(406.5,289.901)(407,288.1)
\curveto(443,314.8)(461.1,355.3)(461.1,401.201)
\curveto(461.1,411.501)(460,421.901)(457.8,432.301)
\curveto(449.3,457.501)(435.5,479.901)(419,498.101)
\curveto(416.7,500.5)(414.4,502.8)(412.1,505.1)
\closepath
\moveto(468.7,321.6)
\curveto(467.9,321.6)(467.099,321.6)(466.3,321.701)
\curveto(463.8,314.401)(460.8,307.501)(457.5,301.201)
\curveto(473.7,307.1)(489.7,314.001)(500.3,327.301)
\curveto(520.2,352.201)(520.8,405.201)(472.901,407.401)
\curveto(473.6,403.401)(474.1,399.401)(474.501,395.301)
\lineto(474.501,395.301)
\curveto(474.501,395.301)(475.101,390.601)(475.201,387.201)
\curveto(476.701,384.301)(477.301,381.701)(477.301,379.301)
\curveto(477.301,376.301)(476.301,373.501)(474.701,370.901)
\lineto(474.701,366.701)
\curveto(477.6,370.301)(479.801,374.401)(479.801,379.301)
\curveto(479.801,382.401)(478.501,386.201)(476.402,389.801)
\curveto(476.402,389.801)(476.301,390.101)(476.502,390.401)
\curveto(481.202,396.101)(486.302,398.301)(494.002,398.001)
\curveto(495.902,394.801)(496.002,387.401)(495.902,382.801)
\curveto(486.301,379.201)(483.702,371.901)(483.801,364.601)
\curveto(483.801,357.801)(485.701,350.701)(485.701,344.901)
\curveto(485.701,341.301)(485.001,338.401)(483.001,336.401)
\curveto(482.501,335.901)(482.501,335.101)(483.001,334.701)
\curveto(483.201,334.501)(483.601,334.301)(483.901,334.301)
\curveto(484.201,334.301)(484.501,334.401)(484.8,334.701)
\curveto(487.5,337.401)(488.3,341.101)(488.3,344.901)
\curveto(488.3,351.101)(486.401,358.201)(486.401,364.601)
\curveto(486.501,371.801)(487.501,377.901)(497.1,381.201)
\curveto(497.3,381.301)(498.701,381.301)(499.1,381.301)
\curveto(505.6,381.101)(510.901,374.201)(510.901,374.201)
\curveto(492.2,375.9)(515.8,321.6)(468.7,321.6)
\closepath
\moveto(200.6,450.7)
\lineto(200.6,448.7)
\lineto(200.6,448.5)
\lineto(200.6,448.3)
\curveto(200.6,448.2)(200.5,447.7)(200.3,446.9)
\curveto(205.2,447.9)(210.7,448.4)(216.8,448.4)
\curveto(249.8,448.4)(297.4,431.9)(320.5,377.2)
\curveto(323.1,380.4)(325.6,383.6)(327.9,387)
\curveto(327.799,387.1)(327.7,387.2)(327.599,387.3)
\curveto(323.7,394.3)(310.9,416.4)(293.299,430.6)
\curveto(283.399,438.6)(274.399,443.8)(266.799,447.3)
\curveto(244.899,456.8)(221.599,459.5)(200.099,458.5)
\curveto(200.6,456)(200.6,453.5)(200.6,450.7)
\closepath
\moveto(391.4,504.8)
\curveto(410.299,480.3)(423.2,447.4)(423.2,413.5)
\curveto(423.2,380)(410.5,345.4)(378.7,317.2)
\curveto(382.3,316)(385.5,313.8)(388,311.4)
\curveto(389.6,309.799)(391,308.099)(392.1,306.299)
\curveto(428.8,340.799)(442.701,377.599)(442.701,411.899)
\curveto(442.701,449.199)(426.201,483.599)(404.001,508.799)
\curveto(397.901,515.699)(391.401,521.899)(384.701,527.199)
\curveto(365.401,539.699)(345.301,546.699)(327.901,546.699)
\curveto(320.501,546.699)(313.701,545.499)(307.401,542.999)
\curveto(312.501,544.599)(317.8,545.399)(323.1,545.399)
\curveto(347.6,545.5)(372.5,529.3)(391.4,504.8)
\closepath
\moveto(287.4,329.7)
\curveto(289.7,330.4)(291.9,330.8)(294.1,330.8)
\curveto(295,330.8)(295.9,330.7)(296.7,330.6)
\curveto(298.3,332.3)(300.4,333.5)(302.5,334.4)
\curveto(305.8,335.7)(309.5,336.4)(313.2,336.4)
\curveto(316.7,336.3)(320.099,335.9)(323.099,334.3)
\curveto(325.599,335.5)(328.299,336.1)(330.999,336.3)
\curveto(359.999,368.6)(370.899,401.5)(370.899,430.6)
\curveto(370.899,457.2)(361.699,480.6)(348.499,497.3)
\curveto(337.699,511)(318.899,524)(301.599,524.2)
\curveto(309.899,521.3)(319.799,519.9)(333.699,500.8)
\curveto(345.598,484.3)(354.699,460.9)(354.699,438.2)
\curveto(354.699,428.8)(353.098,419.2)(349.598,409.8)
\curveto(339.699,383.7)(322.899,365.9)(305.898,348.7)
\curveto(299.6,342.4)(293.4,336.2)(287.4,329.7)
\closepath
\moveto(343.5,419.6)
\curveto(352.3,470.2)(320.7,503.9)(303.8,514.5)
\curveto(302.5,515.3)(301.2,516)(299.9,516.7)
\curveto(319.2,496.8)(330.8,461.9)(330.9,427.5)
\curveto(330.9,417.8)(330,408.1)(328,398.8)
\curveto(329.4,396.5)(330.6,394.5)(331.5,392.9)
\curveto(335.3,399)(338.6,405.6)(341.3,412.8)
\curveto(342.2,415)(342.9,417.3)(343.5,419.6)
\closepath
\moveto(259.7,291.3)
\lineto(259.7,291.3)
\lineto(259.7,291.3)
\lineto(259.7,291.3)
\closepath
\moveto(396,240.9)
\curveto(398.4,243.2)(399.1,244.5)(401.9,247.599)
\lineto(403.799,250.4)
\lineto(404.299,251.4)
\curveto(406.4,255.099)(407.099,258.5)(407.099,261.7)
\curveto(407.2,268.099)(403.599,273.4)(400.299,275.5)
\lineto(397.199,277.5)
\lineto(398.699,280.9)
\lineto(398.699,281)
\curveto(398.699,281.1)(398.799,281.2)(398.799,281.4)
\curveto(398.9,281.799)(398.9,282.299)(398.9,282.9)
\curveto(398.9,284.7)(398.4,287)(397.099,289)
\curveto(395.7,291)(393.599,292.9)(389.4,294)
\lineto(386.2,294.8)
\lineto(386.2,298.1)
\curveto(386.3,299.1)(384.9,302.6)(382.099,305.1)
\curveto(379.299,307.8)(375.7,309.6)(372.099,309.6)
\lineto(367.799,309.6)
\lineto(367.799,314)
\curveto(367.799,314)(367.699,314.6)(367.099,315.4)
\curveto(366.499,316.2)(365.4,317.299)(363.999,318.2)
\curveto(361.199,320)(357.299,321.4)(353.999,321.4)
\curveto(352.799,321.4)(351.699,321.2)(350.699,320.9)
\lineto(348.199,320.099)
\lineto(346.399,321.9)
\curveto(343.598,324.799)(337.598,327.5)(332.399,327.5)
\curveto(329.699,327.5)(327.298,326.9)(325.399,325.5)
\lineto(322.399,323.4)
\lineto(319.8,326)
\curveto(319.3,326.7)(316.5,327.7)(313.2,327.7)
\curveto(310.599,327.7)(307.8,327.2)(305.8,326.4)
\curveto(303.7,325.6)(302.7,324.4)(302.7,324.2)
\lineto(301.1,320.099)
\lineto(297,321.7)
\curveto(296.3,322)(295.3,322.2)(294.1,322.2)
\curveto(290.2,322.2)(285.1,320.2)(282.4,315.2)
\lineto(281.2,313)
\lineto(273.4,313)
\curveto(268.4,306.4)(263.8,299.2)(259.8,291.3)
\lineto(259.8,291.3)
\lineto(259.8,291.3)
\curveto(259.8,291.3)(258,288.8)(255.8,283.901)
\curveto(266.3,301.001)(284,315.201)(311.6,315.3)
\curveto(320.401,315.3)(330.1,313.901)(340.901,310.6)
\curveto(374.8,300.5)(383.501,280.8)(383.501,262)
\curveto(383.501,244.3)(376.001,227.3)(375.201,219.6)
\curveto(375.1,218.6)(375.001,217.701)(375.001,216.8)
\curveto(375.001,206.401)(381.601,201.6)(387.701,201.6)
\curveto(391.701,201.6)(395.401,203.6)(397.301,207.5)
\curveto(397.101,207.3)(396.902,207.2)(396.701,207)
\curveto(395.1,205.9)(393.201,205.4)(391.201,205.4)
\curveto(389.001,205.4)(386.501,206.099)(384.6,207.9)
\curveto(382.6,209.7)(379.401,213.799)(380.701,220.599)
\curveto(382,227.3)(388.6,233.7)(396,240.9)
\closepath
\moveto(214.3,227)
\curveto(219.4,223.4)(225.2,220.3)(230.1,219.2)
\curveto(223.6,228.599)(218.3,240.2)(215.7,254.3)
\curveto(213.2,255)(210.9,255.5)(208.9,255.901)
\curveto(208.8,256.001)(208.6,256.201)(208.5,256.3)
\curveto(208.6,255.7)(208.6,255.1)(208.6,254.5)
\curveto(208.6,250.2)(207,243.5)(201.1,239.5)
\curveto(202.8,236.7)(208.1,231.4)(214.3,227)
\closepath
\moveto(261.2,156.2)
\curveto(269.1,159.8)(269.7,169.599)(269.7,174)
\curveto(269.7,175.7)(268.6,178.1)(266.6,180)
\curveto(265.3,181.3)(263.6,182.4)(261.8,183)
\curveto(260,183.2)(258.2,183.5)(256.5,183.9)
\curveto(254.4,184.4)(252.5,184.599)(250.7,184.599)
\curveto(242.7,184.599)(238.1,179.7)(233.1,174.999)
\curveto(232.6,173.399)(232.2,171.399)(232.2,169.199)
\curveto(232.2,165.098)(233.3,160.499)(236,156.999)
\curveto(238.1,154.399)(241,152.299)(245.2,151.399)
\curveto(248.8,150.999)(255.6,152.699)(261.2,155.899)
\lineto(261.2,156.2)
\closepath
\moveto(234.1,155.6)
\curveto(230.9,159.701)(229.7,164.8)(229.7,169.3)
\curveto(229.7,170.3)(229.8,171.3)(229.9,172.2)
\curveto(226.3,169.099)(222.2,166.5)(216.3,166)
\curveto(213.3,165.8)(210.2,165.7)(207.1,165.7)
\curveto(204.5,165.7)(201.9,165.7)(199.3,165.8)
\curveto(196.7,165.8)(194.2,165.901)(191.7,165.901)
\curveto(178.1,165.901)(166.8,164.401)(166.7,153.501)
\curveto(166.8,148.501)(169.1,141.601)(174.5,132.101)
\curveto(174.5,132.101)(175.3,130.801)(176.8,128.902)
\curveto(175.4,132.301)(174.6,135.801)(174.6,139.402)
\curveto(174.6,142.902)(175.4,146.402)(177.2,149.502)
\curveto(178.7,152.102)(181.1,153.702)(183.8,154.502)
\curveto(186.5,155.302)(189.4,155.502)(192.5,155.502)
\curveto(196.5,155.502)(200.7,155.202)(204.7,155.202)
\curveto(210.8,155.202)(216.2,156.002)(219.5,159.402)
\lineto(219.5,159.402)
\curveto(220.2,160.101)(221.4,160.101)(222.1,159.402)
\curveto(222.8,158.702)(222.8,157.502)(222.1,156.801)
\curveto(217.5,152.201)(211,151.501)(204.6,151.501)
\curveto(200.4,151.501)(196.2,151.901)(192.4,151.801)
\curveto(189.5,151.801)(186.8,151.601)(184.8,150.902)
\curveto(182.7,150.202)(181.3,149.301)(180.3,147.601)
\curveto(178.9,145.202)(178.2,142.402)(178.2,139.402)
\curveto(178.2,134.402)(180.1,129.002)(183.2,124.702)
\curveto(186.3,120.402)(190.4,117.502)(194.7,116.902)
\curveto(195.6,116.801)(196.5,116.702)(197.2,116.702)
\curveto(201.8,116.802)(204,118.502)(205.7,121.402)
\curveto(207.4,124.301)(208.1,128.601)(208.7,132.702)
\curveto(208.8,133.202)(209.1,133.702)(209.6,134.002)
\curveto(220.6,140.802)(221.6,145.802)(224.9,149.102)
\curveto(225.6,149.802)(226.8,149.802)(227.5,149.102)
\curveto(228.2,148.403)(228.2,147.203)(227.5,146.502)
\curveto(225.4,144.502)(223.2,138.202)(212.3,131.302)
\curveto(211.7,127.302)(211,123.102)(209,119.502)
\curveto(207.2,116.202)(204.1,113.602)(199.5,113.002)
\curveto(203.2,112.102)(207.2,111.902)(211.5,112.602)
\curveto(228.1,120.302)(238.5,140.002)(242.8,149.403)
\curveto(239.1,150.8)(236.1,153)(234.1,155.6)
\closepath
\moveto(178.4,227)
\curveto(182.2,223.2)(191.4,221.9)(195.9,226.3)
\curveto(198,221.1)(212,186.6)(270.9,187.401)
\curveto(264.4,189.401)(255.1,193.6)(245.2,202.201)
\curveto(241,205.901)(236.9,210.1)(233.1,215.1)
\curveto(226.3,215.401)(218.7,219.401)(212.1,224)
\curveto(206,228.4)(200.9,233.2)(198.4,236.8)
\curveto(195.7,236.1)(193.2,235.8)(191,235.8)
\curveto(185.4,235.8)(181,237.8)(178.1,240.901)
\curveto(175.2,244.001)(173.9,248.001)(173.9,251.8)
\curveto(173.9,254)(174.3,256.1)(175.2,258)
\curveto(171.3,255.5)(168.2,252.6)(166.7,250.6)
\curveto(133.8,254.701)(116.2,252.3)(109.6,246.8)
\curveto(104.4,236.3)(100,215.901)(133.4,206.2)
\curveto(132.1,207.5)(132.3,208.8)(133.1,210)
\curveto(129,211)(125.4,212.6)(122.4,214.7)
\curveto(116.7,218.7)(113.4,224.599)(113.4,231.599)
\curveto(113.4,232.099)(113.4,232.599)(113.5,233.099)
\curveto(113.7,236.9)(115.5,239.7)(118.2,241.2)
\curveto(120.9,242.7)(124.2,243.099)(127.8,243.099)
\curveto(134.7,243.099)(143.1,241.599)(150.6,241.599)
\curveto(158.5,241.599)(165,243.099)(168.6,248.7)
\lineto(168.6,248.7)
\curveto(169.2,249.599)(170.3,249.8)(171.2,249.2)
\curveto(172.1,248.599)(172.3,247.5)(171.7,246.599)
\curveto(167,239.4)(158.8,237.799)(150.6,237.799)
\curveto(142.6,237.799)(134.2,239.299)(127.8,239.299)
\curveto(124.5,239.299)(121.7,238.9)(120,237.9)
\curveto(118.3,236.9)(117.4,235.7)(117.2,232.799)
\lineto(117.2,231.499)
\curveto(117.2,225.699)(119.7,221.099)(124.6,217.599)
\curveto(129.3,214.299)(136.3,212.299)(145.2,212.2)
\curveto(148.4,215.599)(149.9,219.099)(149.8,221.5)
\curveto(149.8,222.1)(149.7,222.6)(149.6,223)
\curveto(149.4,223.7)(149.6,224.4)(150.1,224.9)
\curveto(151.3,226.099)(152.8,226.5)(154.2,226.799)
\curveto(155.7,227.099)(157.3,227.4)(159,227.9)
\curveto(162.4,228.9)(166.2,230.599)(170.1,235.7)
\curveto(170.7,236.5)(171.9,236.7)(172.7,236.099)
\curveto(173.5,235.499)(173.7,234.299)(173.1,233.499)
\curveto(166.6,224.799)(159,224.099)(155.1,223.199)
\curveto(154.4,223.098)(153.9,222.899)(153.5,222.699)
\curveto(153.6,222.299)(153.6,221.899)(153.6,221.499)
\curveto(153.6,217.499)(151.4,213.099)(147.3,209.099)
\curveto(147.1,208.9)(146.8,208.7)(146.5,208.599)
\curveto(146.5,207.9)(146.2,207.2)(145.4,206.4)
\curveto(153.2,205.7)(163.5,203.299)(168.5,208.299)
\curveto(173.4,213.3)(174.9,223.5)(178.4,227)
\closepath
\moveto(137.5,369.6)
\curveto(138.8,371.1)(150.4,383.1)(157.7,388.3)
\curveto(150.7,386.6)(139.4,380.6)(129.8,372.9)
\curveto(131.7,371.5)(135.2,369.9)(137.5,369.6)
\closepath
\moveto(139.8,354.8)
\curveto(144.9,360)(162.2,379.5)(161.1,383.3)
\curveto(155.1,377.5)(150.2,373.2)(147.6,370.2)
\curveto(143.7,365.7)(141,361.9)(139.8,354.8)
\closepath
\moveto(112.4,270.4)
\curveto(112.4,281.4)(130.8,280)(133.9,291.9)
\curveto(137.4,305.2)(123.1,305.799)(129.8,316.2)
\curveto(120.1,322.7)(110.1,319.099)(110.1,327.2)
\curveto(110.1,335.4)(128.6,339.3)(135.6,363.3)
\curveto(135.6,363.3)(133.7,358.2)(128.3,353.7)
\curveto(113.3,341.3)(96,340.4)(95.4,324)
\curveto(94.7,306.2)(114.8,294.5)(107.6,287.3)
\curveto(100.6,280.3)(108.9,273.9)(112.4,270.4)
\closepath
\moveto(191.5,437.6)
\curveto(197.2,430.6)(211.2,411.6)(211.2,392.9)
\curveto(211.2,385.5)(208.9,378)(202.9,371.7)
\curveto(245.8,352.7)(214.3,317.599)(219.2,256.099)
\curveto(223.3,232.4)(235.3,215.9)(247.7,204.999)
\curveto(259.6,194.499)(270.3,187.999)(279.2,187.999)
\curveto(279.4,187.999)(280.4,188.199)(280.6,188.299)
\curveto(267.1,193.199)(254.7,205.299)(248.9,216.799)
\curveto(246.1,222.4)(243.7,229.299)(242.6,235.099)
\curveto(241.6,240.599)(241.5,243.299)(241.5,249.999)
\curveto(241.5,277.999)(252,295.099)(252,295.099)
\curveto(264.7,320.299)(282.8,337.599)(299.7,354.7)
\curveto(306,361)(312.099,367.4)(317.7,374)
\curveto(295.5,428.5)(248.9,444.7)(216.7,444.7)
\curveto(210.1,444.7)(204.2,444)(199.2,442.9)
\lineto(199.2,442.9)
\curveto(198.9,442.8)(198.6,442.8)(198.3,442.9)
\curveto(196.9,441.1)(194.8,439.1)(191.5,437.6)
\closepath
\moveto(351.3,167.9)
\curveto(347.7,163.4)(341.1,158.9)(329.7,155.5)
\curveto(316.8,151.7)(304.7,149.7)(294,149.7)
\curveto(283.8,149.7)(274.7,151.5)(267,155)
\curveto(266.1,154.3)(265.1,153.6)(264,153)
\curveto(261.7,148.3)(258.3,145.3)(253.8,143.4)
\curveto(294.6,128)(363.6,139.299)(381.7,155.2)
\lineto(381.7,156.4)
\curveto(381.7,159.099)(381.8,161.5)(382,163.7)
\lineto(381,163.7)
\curveto(368.4,163.7)(358.6,165.7)(351.3,167.9)
\closepath
\moveto(396,161.5)
\curveto(399.4,161.5)(402.8,162.1)(405.9,163.2)
\curveto(413.9,164.8)(421.4,168.099)(427.099,171)
\curveto(409.599,165.8)(394.999,163.9)(382.9,163.7)
\curveto(386.4,162.4)(390.7,161.5)(396,161.5)
\closepath
\moveto(414.5,154.1)
\curveto(410.6,140.5)(433.7,139.6)(443.2,141.701)
\curveto(441.5,142.701)(440.099,144.301)(439.3,146.801)
\curveto(438.2,150.201)(439.401,153.402)(441.401,155.601)
\curveto(435,158.9)(418.3,167.3)(414.5,154.1)
\closepath
\moveto(553,374.7)
\curveto(550.8,446.1)(503.9,525.6)(428.7,533.7)
\curveto(423.099,527.5)(418.2,521.4)(413.9,515.4)
\curveto(417.799,511.7)(421.599,507.9)(425.299,503.8)
\curveto(425.499,503.6)(425.699,503.3)(425.9,503.1)
\curveto(426.5,503.6)(427.2,504.1)(427.799,504.6)
\curveto(445.999,517.4)(483.099,519.7)(498.699,487.7)
\curveto(514.098,456.1)(484.899,432.1)(484.899,432.1)
\curveto(481.598,429.2)(475.699,426.3)(468.798,424.9)
\curveto(469.998,420.5)(470.998,416.1)(471.899,411.6)
\lineto(472.098,411.6)
\curveto(491.598,413.1)(513.498,401.4)(517.498,373.2)
\curveto(525.298,318)(470.098,296.3)(452.198,290.099)
\curveto(449.597,288.9)(448.798,287.099)(448.798,287.099)
\curveto(453.498,286.4)(457.598,282.7)(460.098,277.7)
\curveto(461.298,275.2)(461.798,273)(461.798,271)
\curveto(461.798,266.2)(458.698,262.6)(454.399,260.1)
\curveto(450.098,257.6)(444.499,256.401)(440.499,256.401)
\curveto(438.699,256.401)(437.099,256.701)(436.199,257.1)
\curveto(435.699,257.3)(435.399,257.5)(435.299,257.701)
\curveto(435.4,258.1)(435.499,258.6)(435.699,259.001)
\curveto(439.199,266.801)(458.199,258.001)(454.799,275.301)
\curveto(453.699,280.701)(450.699,283.101)(446.599,283.501)
\curveto(431.499,261.501)(413.599,246.301)(401.7,234.801)
\curveto(394.4,227.902)(388.8,223.301)(387.599,219.701)
\curveto(387.2,218.501)(386.2,214.901)(388.499,212.501)
\curveto(389.099,211.901)(389.999,211.101)(390.899,211.001)
\curveto(396.999,210.001)(397.699,216.801)(397.699,216.801)
\curveto(398.699,215.501)(399.299,214.001)(399.299,212.402)
\curveto(399.299,212.002)(399.199,211.601)(399.199,211.202)
\lineto(399.199,210.902)
\curveto(398.199,204.002)(392.899,200.402)(387.399,200.402)
\lineto(387.3,200.402)
\curveto(383.901,200.402)(380.401,201.801)(377.7,204.502)
\curveto(375,207.302)(373.3,211.402)(373.3,216.902)
\curveto(373.3,217.801)(373.401,218.801)(373.5,219.801)
\curveto(374.4,227.902)(381.8,244.701)(381.8,262.101)
\curveto(381.8,280.501)(373.6,299.402)(340.1,309.501)
\curveto(329.401,312.701)(319.8,314.101)(311.1,314.101)
\curveto(279.5,314.101)(261.1,295.101)(251.8,274.702)
\curveto(249.7,268.002)(247.8,259.402)(247.3,248.902)
\curveto(247.1,244.502)(247.5,239.202)(248,235.301)
\curveto(248.6,231.301)(251.1,222.902)(253.8,217.301)
\curveto(259.6,205.701)(268.2,194.601)(279.7,189.801)
\lineto(281.5,189.101)
\curveto(287.4,190.402)(290.8,191.601)(297.2,193.902)
\lineto(298.7,194.402)
\curveto(308.9,198.101)(318.5,201.601)(327.8,201.601)
\curveto(333.8,201.601)(339,200.301)(343.7,197.301)
\curveto(344.3,197.001)(344.8,196.601)(345.3,196.201)
\lineto(348.2,193.901)
\lineto(348.2,193.901)
\lineto(348.9,193.201)
\curveto(352.5,189.401)(355.2,183.901)(354.799,178.1)
\curveto(354.599,175.701)(353.9,172.901)(352.199,170.1)
\curveto(359.199,168)(368.499,166.201)(380.499,166.201)
\curveto(394.799,166.201)(413.099,168.801)(435.899,176.701)
\lineto(435.999,176.701)
\curveto(436.099,176.701)(436.099,176.801)(436.099,176.801)
\curveto(474.299,176.801)(459.099,152.101)(454.9,157.001)
\curveto(450.299,162.201)(439.4,154.801)(442.5,146.301)
\curveto(447.2,133.101)(468.7,144.801)(471,153.501)
\curveto(466.6,124.701)(421.8,137.001)(411.5,138.401)
\curveto(399.4,140.1)(394.5,128.901)(396.2,118.6)
\curveto(397.599,110.1)(392.3,102.3)(389.9,100)
\curveto(407,96.7)(415.099,111.2)(421.799,115.8)
\curveto(428.599,120.5)(453.199,118.2)(467.099,128.901)
\curveto(481,139.5)(479.2,165.1)(479.2,168.1)
\curveto(482.4,169.401)(493.2,173.8)(493.2,186.201)
\curveto(493.2,197.001)(485.2,202.401)(477,201.401)
\curveto(467.9,200.3)(465.2,189.1)(475.5,188.901)
\curveto(473.2,191.201)(475.9,194.701)(479,193.001)
\curveto(483.7,190.401)(478.4,182.601)(468.7,184.201)
\curveto(465.3,184.801)(457.599,185.901)(450.3,186.901)
\curveto(505.7,215.9)(556.1,275.2)(553,374.7)
\closepath
\moveto(435.5,254.8)
\curveto(436.9,254.2)(438.7,254)(440.8,254)
\curveto(445.401,254)(451.2,255.3)(456,258)
\curveto(460.8,260.7)(464.7,265.1)(464.7,271)
\curveto(464.7,273.4)(464.099,276)(462.7,278.8)
\curveto(462,280.2)(461.3,281.3)(460.4,282.3)
\curveto(465.2,278.6)(467.599,275)(468.599,271.8)
\curveto(468.799,271)(468.999,270.2)(469.2,269.5)
\curveto(469.3,268.7)(469.4,268)(469.4,267.3)
\curveto(469.4,264.8)(468.799,262.6)(468.099,260.901)
\curveto(464.7,251.5)(455.8,247.1)(445.9,247)
\curveto(444.299,247)(442.599,247.1)(441,247.4)
\curveto(438.3,248.9)(435.9,251.7)(435.4,255)
\curveto(435.4,254.8)(435.4,254.8)(435.5,254.8)
\closepath
\moveto(436.1,245.8)
\curveto(439.3,244.901)(442.6,244.5)(445.8,244.5)
\lineto(445.901,244.5)
\curveto(456.401,244.5)(466.401,249.4)(470.3,259.8)
\curveto(470,250.5)(465.3,246.401)(458.901,243.1)
\curveto(452.3,239.701)(444.001,237.6)(438.001,232.6)
\curveto(433.201,228.6)(431.201,223.701)(431.201,218.8)
\curveto(431.201,211.8)(435.1,204.8)(440.1,199)
\curveto(405,220.5)(420.6,241.6)(436.1,245.8)
\closepath
\moveto(452.6,224.5)
\curveto(439.8,220.2)(441.8,205.1)(443.201,199.1)
\curveto(437.801,204.901)(433.701,212.1)(433.701,218.701)
\curveto(433.701,222.901)(435.301,227.001)(439.6,230.6)
\curveto(445,235.201)(453.1,237.3)(460,240.8)
\curveto(466.9,244.3)(472.8,249.7)(472.8,260.401)
\curveto(472.8,263.201)(472.401,266.3)(471.6,269.8)
\curveto(470.701,275.8)(466.201,282.8)(453.8,289.401)
\curveto(463.901,288.701)(482.7,284.201)(486,265.001)
\curveto(489.7,243.8)(468.7,229.9)(452.6,224.5)
\closepath
\moveto(281.2,184.7)
\curveto(276.6,183.599)(272,182.9)(267.3,182.8)
\curveto(267.7,182.5)(268,182.2)(268.4,181.901)
\curveto(270.7,179.6)(272.2,176.901)(272.3,174.1)
\curveto(272.3,170.8)(272.1,164.1)(268.3,159)
\curveto(270.5,156.8)(281.7,154.5)(281.7,154.5)
\curveto(283.1,154.3)(284,154.4)(285,154.4)
\curveto(288.3,154.4)(290.7,156.2)(292.5,159.099)
\curveto(294.2,161.999)(295.1,165.999)(295.1,169.799)
\curveto(295.1,170.799)(295,171.9)(294.9,172.9)
\curveto(293.8,180.5)(289.1,184.9)(281.9,184.9)
\curveto(281.6,184.7)(281.4,184.7)(281.2,184.7)
\closepath
\moveto(298.9,190.4)
\curveto(295.1,189)(291.3,187.599)(287.4,186.4)
\curveto(292.9,184.5)(296.6,179.599)(297.4,173)
\curveto(297.5,171.9)(297.6,170.8)(297.6,169.6)
\curveto(297.6,165.401)(296.6,161)(294.6,157.6)
\curveto(293.7,156.1)(292.6,154.8)(291.3,153.8)
\curveto(298.5,153.6)(305.7,154.3)(312.5,155.5)
\lineto(312.5,155.5)
\curveto(320.6,156.6)(325.2,166.3)(325.2,174.5)
\curveto(325.2,175.6)(325.099,176.7)(324.9,177.7)
\curveto(323.7,185.099)(316.599,193.3)(307.4,193.3)
\curveto(304.7,192.5)(301.8,191.4)(298.9,190.4)
\closepath
\moveto(342.3,194)
\curveto(337.901,196.9)(333.2,198)(328.3,198)
\curveto(323.401,198)(318.2,196.9)(312.8,195.2)
\curveto(320.8,192.7)(326.3,185.3)(327.5,178.3)
\curveto(327.7,177.1)(327.8,175.901)(327.8,174.6)
\curveto(327.8,168.701)(325.6,161.8)(321.3,157.5)
\curveto(323.901,158.1)(326.3,158.8)(328.7,159.5)
\curveto(337.9,162.2)(351.099,169)(351.8,178.4)
\lineto(351.8,178.299)
\curveto(351.8,178.699)(351.901,178.999)(351.901,179.4)
\curveto(351.7,186.1)(346.1,191.3)(342.3,194)
\closepath
\moveto(124.6,372.3)
\curveto(139.1,383.8)(159.7,393.3)(163.6,389.4)
\curveto(167.5,385.5)(151.7,361.4)(135,344.7)
\curveto(148.8,344.7)(163.4,347.4)(194.7,374.5)
\curveto(198.5,380.2)(200,386.1)(200,392)
\curveto(200.1,410.6)(184.6,429)(178.3,435.6)
\curveto(170.3,436.8)(167.6,442.5)(167.5,442.8)
\lineto(167.4,443.1)
\lineto(167.3,443.4)
\curveto(167.3,443.6)(166.4,448.1)(166.9,454.1)
\curveto(145,449.2)(128.2,441.5)(121.7,436.1)
\curveto(121.7,436.1)(123.6,433.7)(122.8,428.8)
\curveto(126.4,427.3)(132.4,435.8)(140.9,432.2)
\curveto(148.2,429)(154.9,422.4)(162.3,423.4)
\lineto(163,420.3)
\curveto(155,418)(147.7,426)(140.2,428.8)
\curveto(132.4,431.8)(126.3,423.4)(122.1,425.9)
\curveto(121.8,424.9)(121.3,423.7)(120.7,422.5)
\curveto(121.3,418.1)(124.1,412.6)(128.3,409.3)
\curveto(128.4,409.2)(128.5,409)(128.5,408.8)
\curveto(128.5,408.6)(128.4,408.4)(128.3,408.3)
\curveto(125.1,405.7)(106.6,392.3)(101.8,387.6)
\curveto(102.1,387.4)(102.4,387.2)(102.8,387)
\curveto(109.4,382.9)(117.4,378.9)(122.4,378.9)
\lineto(123.3,378.9)
\curveto(125.9,381)(147.7,395.5)(160.4,395.6)
\curveto(164.4,395.6)(167.7,394)(168.7,389.9)
\curveto(168.8,389.6)(168.6,389.2)(168.3,389.1)
\curveto(168,389)(167.6,389.2)(167.5,389.5)
\curveto(166.6,392.9)(164.1,394.2)(160.4,394.2)
\curveto(148.2,394.3)(124.9,378.7)(124,377.7)
\curveto(123.9,377.6)(123.8,377.5)(123.6,377.5)
\curveto(123.2,377.5)(122.8,377.4)(122.4,377.4)
\curveto(112.4,377.5)(94.5,390.6)(90.8,393.4)
\curveto(93.6,385.4)(108,374.8)(124.6,372.3)
\closepath
\moveto(136,408.7)
\curveto(126.6,410.2)(125.5,420.7)(125.5,420.7)
\curveto(127.8,426.2)(141.1,427.3)(148.8,416.8)
\curveto(148.8,416.8)(143.4,407.5)(136,408.7)
\closepath
\moveto(184.9,262.5)
\curveto(180.7,260.4)(177.7,256.6)(177.7,251.9)
\curveto(177.8,245.9)(181.7,239.599)(191.1,239.5)
\curveto(193.1,239.5)(195.4,239.8)(198,240.5)
\curveto(204.4,243.5)(206.2,250.2)(206.2,254.4)
\curveto(206.2,255.2)(206.1,255.9)(206,256.4)
\curveto(205.8,257.299)(205.6,258.2)(205.3,258.9)
\curveto(198.4,263.9)(191.2,264.2)(184.9,262.5)
\closepath
\moveto(100.7,388.4)
\curveto(105.3,392.9)(122.3,405.4)(126.8,408.8)
\curveto(122.9,412.1)(120.4,416.5)(119.7,420.8)
\curveto(119.4,420.2)(119,419.5)(118.5,418.9)
\curveto(112.3,409.2)(98.6,401.4)(90.8,395)
\curveto(91.5,394.5)(95.5,391.5)(100.6,388.2)
\curveto(100.7,388.3)(100.7,388.4)(100.7,388.4)
\closepath
\moveto(208.7,392.9)
\curveto(208.8,410.9)(194.2,430.5)(189,436.7)
\curveto(188.5,436.6)(188.1,436.4)(187.6,436.3)
\curveto(185.6,435.8)(183.7,435.6)(181.9,435.5)
\curveto(189,427.6)(202.4,410.4)(202.5,392.1)
\curveto(202.5,386)(201,379.9)(197.2,374)
\curveto(198.3,373.6)(199.4,373.2)(200.4,372.8)
\lineto(200.4,372.8)
\curveto(206.5,378.7)(208.7,385.7)(208.7,392.9)
\closepath
\moveto(159.6,456.1)
\curveto(157.3,460.5)(152.9,464.6)(140.5,471)
\curveto(133.4,463.1)(132.9,454)(134.1,447)
\curveto(141.3,450.6)(149.9,453.7)(159.6,456.1)
\closepath
\moveto(186.9,439.3)
\curveto(196.7,441.7)(197.5,448.8)(197.5,448.8)
\curveto(197.5,457.5)(198.9,461.8)(183.6,477.1)
\curveto(165.7,466.7)(170.3,444.2)(170.3,444.2)
\curveto(170.3,444.2)(174,436.1)(186.9,439.3)
\closepath
}
}
\end{pspicture}
\end{document}
%</bidi-logo.tex>
%<*bidisample2e.tex>
\documentclass{article}      % Specifies the document class
\usepackage[RTLdocument]{bidi}
                             % The preamble begins here.
\title{An Example Document}  % Declares the document's title.
\author{Leslie Lamport}      % Declares the author's name.
\date{January 21, 1994}      % Deleting this command produces today's date.

\newcommand{\ip}[2]{(#1, #2)}
                             % Defines \ip{arg1}{arg2} to mean
                             % (arg1, arg2).

                             % This is an alternative definition of
                             % \ip that is commented out.

\begin{document}             % End of preamble and beginning of text.

\maketitle                   % Produces the title.

This is an example input file.  Comparing it with
the output it generates can show you how to
produce a simple document of your own.

\section{Ordinary Text}      % Produces section heading.  Lower-level
                             % sections are begun with similar
                             % \subsection and \subsubsection commands.

The ends  of words and sentences are marked
  by   spaces. It  doesn't matter how many
spaces    you type; one is as good as 100.  The
end of   a line counts as a space.

One   or more   blank lines denote the  end
of  a paragraph.

Since any number of consecutive spaces are treated
like a single one, the formatting of the input
file makes no difference to
      \LaTeX,                % The \LaTeX command generates the LaTeX logo.
but it makes a difference to you.  When you use
\LaTeX, making your input file as easy to read
as possible will be a great help as you write
your document and when you change it.  This sample
file shows how you can add comments to your own input
file.

Because printing is different from typewriting,
there are a number of things that you have to do
differently when preparing an input file than if
you were just typing the document directly.
Quotation marks like
       ``this''
have to be handled specially, as do quotes within
quotes:
       ``\,`this'            % \, separates the double and single quote.
        is what I just
        wrote, not  `that'\,''.

Dashes come in three sizes: an
       intra-word
dash, a medium dash for number ranges like
       1--2,
and a punctuation
       dash---like
this.

A sentence-ending space should be larger than the
space between words within a sentence.  You
sometimes have to type special commands in
conjunction with punctuation characters to get
this right, as in the following sentence.
       Gnats, gnus, etc.\ all  % `\ ' makes an inter-word space.
       begin with G\@.         % \@ marks end-of-sentence punctuation.
You should check the spaces after periods when
reading your output to make sure you haven't
forgotten any special cases.  Generating an
ellipsis
       \ldots\               % `\ ' is needed after `\ldots' because TeX
                             % ignores spaces after command names like \ldots
                             % made from \ + letters.
                             %
                             % Note how a `%' character causes TeX to ignore
                             % the end of the input line, so these blank lines
                             % do not start a new paragraph.
                             %
with the right spacing around the periods requires
a special command.

\LaTeX\ interprets some common characters as
commands, so you must type special commands to
generate them.  These characters include the
following:
       \$ \& \% \# \{ and \}.

In printing, text is usually emphasized with an
       \emph{italic}
type style.

\begin{em}
   A long segment of text can also be emphasized
   in this way.  Text within such a segment can be
   given \emph{additional} emphasis.
\end{em}

It is sometimes necessary to prevent \LaTeX\ from
breaking a line where it might otherwise do so.
This may be at a space, as between the ``Mr.''\ and
``Jones'' in
       ``Mr.~Jones'',        % ~ produces an unbreakable interword space.
or within a word---especially when the word is a
symbol like
       \mbox{\emph{itemnum}}
that makes little sense when hyphenated across
lines.

Footnotes\footnote{This is an example of a footnote.}
pose no problem.

\LaTeX\ is good at typesetting mathematical formulas
like
       \( x-3y + z = 7 \)
or
       \( a_{1} > x^{2n} + y^{2n} > x' \)
or
       \( \ip{A}{B} = \sum_{i} a_{i} b_{i} \).
The spaces you type in a formula are
ignored.  Remember that a letter like
       $x$                   % $ ... $  and  \( ... \)  are equivalent
is a formula when it denotes a mathematical
symbol, and it should be typed as one.

\section{Displayed Text}

Text is displayed by indenting it from the left
margin.  Quotations are commonly displayed.  There
are short quotations
\begin{quote}
   This is a short quotation.  It consists of a
   single paragraph of text.  See how it is formatted.
\end{quote}
and longer ones.
\begin{quotation}
   This is a longer quotation.  It consists of two
   paragraphs of text, neither of which are
   particularly interesting.

   This is the second paragraph of the quotation.  It
   is just as dull as the first paragraph.
\end{quotation}
Another frequently-displayed structure is a list.
The following is an example of an \emph{itemized}
list.
\begin{itemize}
   \item This is the first item of an itemized list.
         Each item in the list is marked with a ``tick''.
         You don't have to worry about what kind of tick
         mark is used.

   \item This is the second item of the list.  It
         contains another list nested inside it.  The inner
         list is an \emph{enumerated} list.
         \begin{enumerate}
            \item This is the first item of an enumerated
                  list that is nested within the itemized list.

            \item This is the second item of the inner list.
                  \LaTeX\ allows you to nest lists deeper than
                  you really should.
         \end{enumerate}
         This is the rest of the second item of the outer
         list.  It is no more interesting than any other
         part of the item.
   \item This is the third item of the list.
\end{itemize}
You can even display poetry.
\begin{verse}
   There is an environment
    for verse \\             % The \\ command separates lines
   Whose features some poets % within a stanza.
   will curse.

                             % One or more blank lines separate stanzas.

   For instead of making\\
   Them do \emph{all} line breaking, \\
   It allows them to put too many words on a line when they'd rather be
   forced to be terse.
\end{verse}

Mathematical formulas may also be displayed.  A
displayed formula
is
one-line long; multiline
formulas require special formatting instructions.
   \[  \ip{\Gamma}{\psi'} = x'' + y^{2} + z_{i}^{n}\]
Don't start a paragraph with a displayed equation,
nor make one a paragraph by itself.

\end{document}               % End of document.
%</bidisample2e.tex>
%<*bidismall2e.tex>
\documentclass{article}        % Your input file must contain these two lines
\usepackage[RTLdocument]{bidi}
\begin{document}               % plus the \end{document} command at the end.

\section{Simple Text}          % This command makes a section title.

Words are separated by one or more spaces.  Paragraphs are separated by
one or more blank lines.  The output is not affected by adding extra
spaces or extra blank lines to the input file.

Double quotes are typed like this: ``quoted text''.
Single quotes are typed like this: `single-quoted text'.

Long dashes are typed as three dash characters---like this.

Emphasized text is typed like this: \emph{this is emphasized}.
Bold       text is typed like this: \textbf{this is bold}.

\subsection{A Warning or Two}  % This command makes a subsection title.

If you get too much space after a mid-sentence period---abbreviations
like etc.\ are the common culprits)---then type a backslash followed by
a space after the period, as in this sentence.

Remember, don't type the 10 special characters (such as dollar sign and
backslash) except as directed!  The following seven are printed by
typing a backslash in front of them:  \$  \&  \#  \%  \_  \{  and  \}.
The manual tells how to make other symbols.

\end{document}                 % The input file ends with this command.
%</bidismall2e.tex>
%<*test1-colortbl.tex>
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=farsidigits,Script=Arabic]{XB Kayhan}
\usepackage{hhline}
\usepackage{colortbl}
\usepackage[RTLdocument]{bidi}
\begin{document}
این فقط یک آزمایش است
\begin{center}
\setlength\arrayrulewidth{5pt}
\setlength\doublerulesep{5pt}
 \renewcommand{\arraystretch}{2}
 \definecolor{orange}{cmyk}{0,0.61,0.87,0}
 \definecolor{indigo}{cmyk}{0.8,0.9,0,0}
 \definecolor{violet}{cmyk}{0.6,0.9,0,0}
 \newcommand\rainbowline[1]{%
 \hhline{%
   >{\arrayrulecolor   {red}\doublerulesepcolor[rgb]{.3,.3,1}}%
   |#1:=%
   >{\arrayrulecolor{orange}\doublerulesepcolor[rgb]{.4,.4,1}}%
   =%
   >{\arrayrulecolor{yellow}\doublerulesepcolor[rgb]{.5,.5,1}}%
   =%
   >{\arrayrulecolor {green}\doublerulesepcolor[rgb]{.6,.6,1}}%
   =%
   >{\arrayrulecolor  {blue}\doublerulesepcolor[rgb]{.7,.7,1}}%
  =%
   >{\arrayrulecolor{indigo}\doublerulesepcolor[rgb]{.8,.8,1}}%
   =%
   >{\arrayrulecolor{violet}\doublerulesepcolor[rgb]{.9,.9,1}}%
   =:#1|%
   }}
 \arrayrulecolor{red}
 \doublerulesepcolor[rgb]{.3,.3,1}
 \begin{tabular}{||*7{>{\columncolor[gray]{.9}}c}||}
 \rainbowline{t}%
 \arrayrulecolor{violet}\doublerulesepcolor[rgb]{.9,.9,1}
 وفا&خلیقی&یک&دانشجوی&ریاضی&است&
 \multicolumn{1}{>{\columncolor[gray]{.9}}c||}{حرف آخر}\\
 \rainbowline{}%
 1&2&3&4&5&6&
 \multicolumn{1}{>{\columncolor[gray]{.9}}c||}{7}\\
 \rainbowline{b}%
 \end{tabular}
 \end{center}
این صرفاً یک آزمایش است
\end{document}
%</test1-colortbl.tex>
%<*test1-wrapfig.tex>
\documentclass{article}
\usepackage{wrapfig}
\usepackage{bidi}
\newcommand\sample{Some text for our page
  that might get reused over and over again. }
\begin{document}
\section{LTR}
The starting place for the wrapfigure
environment was manually determined in
the current ex-

\begin{wrapfigure}[7]{r}[0.2\width]{0pt}
  \centering
  \fbox{This is ``wrapfigure''.}
  \caption{An example of the
    \texttt{wrapfigure} environment}
\end{wrapfigure}
sample by first setting the text without
the figure to find the linebreaks.

\sample \sample \sample\sample \sample \sample\sample

\section{RTL}

\setRTL
The starting place for the wrapfigure
environment was manually determined in
the current ex-

\begin{wrapfigure}[7]{l}[0.2\width]{0pt}
  \centering
  \fbox{This is ``wrapfigure''.}
  \caption{An example of the
    \texttt{wrapfigure} environment}
\end{wrapfigure}
sample by first setting the text without
the figure to find the linebreaks.

\sample \sample \sample\sample \sample \sample\sample
\end{document}
%</test1-wrapfig.tex>
%<*test2-colortbl.tex>
\documentclass{article}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{colortbl}
\setmainfont[Scale=1,Script=Arabic,Mapping=farsidigits]{XB Kayhan}
\usepackage[RTLdocument]{bidi}
\begin{document}
این فقط یک آزمایش است

\setlength{\extrarowheight}{2mm}
\setlength{\tabcolsep}{2mm}
\begin{center}
\begin{tabular}{|l|%
>{\columncolor{yellow}}c|c|>{\columncolor{yellow}}c|c|%
>{\columncolor{red}\bfseries}c<{\textsc{GBP}}|}
\hline
\multicolumn{3}{>{\columncolor{red}}r}{\color{white}\textbf{لَنْدَنْ}}
&\multicolumn{3}{>{\columncolor{red}}l}{\color{white}\textbf{قیمت}}
\\[1pt]
\hline
سیدنی & OG4G &سشنبه ۱۰ اکتبر &دوشنبه ۲۱ اکتبر یا ۲۸‌ام &11 یا ۱۸ روز &999\\
& &سشنبه ۱۷ اکتبر &دوشنبه ۲۱ اکتبر یا ۲۸‌ام & 4 یا ۱۱ روز &999\\
& OG7A &یکشنبه ۱۱ اکتبر &دوشنبه ۲۱ اکتبر یا ۲۸‌ام & 8 یا ۱۵ روز &999\\
& &یکشنبه ۲۰ اکتبر &دوشنبه ۲۸ اکتبر & 8 روز &999\\
\hline
\end{tabular}
\end{center}
\end{document}
%</test2-colortbl.tex>
%<*test2-wrapfig.tex>
\documentclass{article}
\usepackage{wrapfig}
\usepackage{bidi}
\newcommand\sample{Some text for our page
  that might get reused over and over again. }
\begin{document}
\section{LTR}
\begin{wraptable}[4]{l}{4cm}
 \centering
\fbox{This is ``wraptable''.}
 \caption{The Caption}\label{T1}
\end{wraptable}

\sample \sample Reference to Table~\ref{T1}.
\sample

\section{RTL}
\setRTL

\begin{wraptable}[4]{r}{4cm}
 \centering
\fbox{This is ``wraptable''.}
 \caption{The Caption}\label{T2}
\end{wraptable}

\sample \sample Reference to Table~\ref{T2}.
\sample
\end{document}
%</test2-wrapfig.tex>
%<*test3-wrapfig.tex>
\documentclass[a4paper,12pt]{article}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{bidi}
\begin{document}
\section{LTR}
\subsection*{Wrapfig test}


Gulls are birds in the family Laridae. They are most closely
 related to the terns (family Sternidae), auks and skimmers,
and more distantly to the waders. Most gulls belong to the
large genus Larus.

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{gull}
  \end{center}
  \caption{A gull}
\end{wrapfigure}

They are in general medium to large birds, typically grey or white,
often with black markings on the head or wings. They have stout,
longish bills and webbed feet.

Most gulls, particularly Larus species, are ground nesting carnivores,
which will take live food or scavenge opportunistically. The live food
often includes crabs and small fish. Apart from the kittiwakes, gulls
are typically coastal or inland species, rarely venturing far out to sea.
The large species take up to four years to attain full adult plumage,
but two years is typical for small gulls.

Gulls---the larger species in particular---are resourceful and
highly intelligent birds, demonstrating complex methods of communication
and a highly developed social structure. Certain species (e.g. the
Herring Gull) have exhibited tool use behaviour. Many species of gull have
learned to co-exist successfully with man and have thrived in human habitats.
Others rely on kleptoparasitism to get their food.

\newpage
\section{RTL}

\setRTL
\subsection*{Wrapfig test}


Gulls are birds in the family Laridae. They are most closely
 related to the terns (family Sternidae), auks and skimmers,
and more distantly to the waders. Most gulls belong to the
large genus Larus.

\begin{wrapfigure}{l}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{gull}
  \end{center}
  \caption{A gull}
\end{wrapfigure}

They are in general medium to large birds, typically grey or white,
often with black markings on the head or wings. They have stout,
longish bills and webbed feet.

Most gulls, particularly Larus species, are ground nesting carnivores,
which will take live food or scavenge opportunistically. The live food
often includes crabs and small fish. Apart from the kittiwakes, gulls
are typically coastal or inland species, rarely venturing far out to sea.
The large species take up to four years to attain full adult plumage,
but two years is typical for small gulls.

Gulls---the larger species in particular---are resourceful and
highly intelligent birds, demonstrating complex methods of communication
and a highly developed social structure. Certain species (e.g. the
Herring Gull) have exhibited tool use behaviour. Many species of gull have
learned to co-exist successfully with man and have thrived in human habitats.
Others rely on kleptoparasitism to get their food.
\end{document}
%</test3-wrapfig.tex>
%<*test-arydshln.tex>
\documentclass{article}
\usepackage{arydshln}
\usepackage{bidi}
\title{Testing \textsf{arydshln} Package in LTR and RTL modes}
\author{}
\date{}
\begin{document}
\maketitle
\section{LTR Mode}
\begin{center}
\begin{tabular}{|l::c;{2pt/2pt}r|}\hline
A&B&C\\\hdashline[1pt/1pt]
AAA&BBB&CCC\\\cdashline{1-2}[.4pt/1pt]
\multicolumn{2}{|l;{2pt/2pt}}{AB}&C\\\hdashline\hdashline
\end{tabular}
\end{center}
\section{RTL Mode}
\begin{RTL}
\begin{center}
\begin{tabular}{|r::c;{2pt/2pt}l|}\hline
A&B&C\\\hdashline[1pt/1pt]
AAA&BBB&CCC\\\cdashline{1-2}[.4pt/1pt]
\multicolumn{2}{|r;{2pt/2pt}}{AB}&C\\\hdashline\hdashline
\end{tabular}
\end{center}
\end{RTL}
\end{document}
%</test-arydshln.tex>
%<*test-bidi.tex>
\documentclass{article}
\usepackage{bidi}
\title{Testing Basic Bidi Direction Change}
\author{Vafa Khalighi}
\begin{document}
\maketitle
In this document we test bidi direction change in \textsf{RTL} and \textsf{LTR}. These tests includes \texttt{flushleft}, \texttt{flushright} environments and \verb|\centerline{...}|, \verb|\leftline{...}|,\verb|\rightline{...}|,\verb|\raggedleft| and \verb|\raggedright| macros.
\section{RTL Test}
\setRTL
\begin{flushleft}
This is left in RTL
\end{flushleft}
\begin{flushright}
This is right in RTL
\end{flushright}
\centerline{This is center in RTL}

\leftline{This is left in RTL}

\rightline{This is right in RTL}

\raggedleft This is raggedleft in RTL

\raggedright This is raggedright in RTL

\setLTR
\section{LTR Test}
\begin{flushleft}
This is left in LTR
\end{flushleft}
\begin{flushright}
This is right in LTR
\end{flushright}
\centerline{This is center in LTR}

\leftline{This is left in LTR}

\rightline{This is right in LTR}

\raggedleft This is raggedleft in LTR

\raggedright This is raggedright in LTR
\end{document}
%</test-bidi.tex>
%<*test-brochure.tex>
\documentclass[a4paper]{report}

\usepackage[landscape,margin=1in]{geometry}
\usepackage{color}
\usepackage[RL]{flowfram}% we enable `RL' option for RTL multicolumn typesetting (see flowfram package documentation)
\usepackage[colorlinks,setpagesize=false]{hyperref}

\usepackage[RTLdocument]{bidi}
% adjust \textheight so that it is an integer multiple of
% \baselineskip
\adjustheight{\textheight}

% set up pagelayout. One column for title page
% two columns for the rest.
\onecolumninarea[1,2]{0.6\textwidth}{\textheight}{0.4\textwidth}{0pt}
\twocolumninarea[>2]{0.6\textwidth}{\textheight}{0.4\textwidth}{0pt}

% Set up dynamic frame on the left. This is where
% the headings will go.

\newdynamicframe{0.4\textwidth}{\textheight}{0pt}{0pt}[left]

% put the chapter headings in this frame
\dfchaphead*{left}
% Modify the default style
\renewcommand{\DFchapterstyle}[1]{%
\raggedright\Huge\slshape\MakeUppercase{#1}\par}

% Make static frames for background (only for page 1)
\vtwotone[1]{0.6\paperwidth}{[cmyk]{0.65,0.13,0,0}}{backleft}%
{0.4\paperwidth}{[cmyk]{0.94,0.54,0,0}}{backright}

% Make a border along the top of each page
\vtwotonetop{1cm}{0.6\paperwidth}{[cmyk]{0.65,0.13,0,0}}{topleft}%
{0.4\paperwidth}{[cmyk]{0.94,0.54,0,0}}{topright}

% make a static frame for the logo
\newstaticframe{0.2\textwidth}{0.25\textheight}{0pt}{0pt}[logo]

% empty page style, because I am going to make my own
\pagestyle{empty}

% Each new chapter sets \thispagestyle{\chapterfirstpagestyle}, change this empty as well
\renewcommand{\chapterfirstpagestyle}{empty} 

% Now make a frame in which to put my own customized footer
\newdynamicframe[>1]{\textwidth}{\headheight}{0pt}{-\footskip}[footer]

% set the contents of the frame:
\setdynamiccontents*{footer}{%
School of Computing Sciences, University of East Anglia\hfill
http://www.cmp.uea.ac.uk/\hfill
page \thepage\ of \pageref*{lastpage}}


\newcommand{\env}[1]{\texttt{#1}}
\newcommand{\cmdname}[1]{\texttt{\symbol{92}#1}}
\newcommand{\meta}[1]{\textnormal{\textless\textit{#1}\textgreater}}

\begin{document}

% not a very interesting logo
\setstaticcontents*{logo}{\sffamily{\Huge\slshape FLF} Flowfram}

{\noindent
\slshape\Huge\MakeUppercase{A Sample Brochure}\par
\vskip0.5in
\noindent\large\MakeUppercase{Nicola Talbot}\\
}


\chapter{Introduction}

The \textsl{flowfram} package is designed to enable you to create
frames in a document such that the 
contents of the \env{document} environment flow from one 
frame to the next in the order that they were defined.  
This is useful for creating posters
or magazines or any other form of document that does not 
conform to the standard one or two column layout.

This is a modified version of the manual for the \textsl{flowfram} package.
It is intended to illustrated what can be done. See the full 
manual (ffuserguide.pdf) for
a comprehensive description, as some parts of this document
may now be out of date.
If the columns are very narrow, it may be better to
use \cmdname{raggedright}, otherwise \TeX\ may have a
problem working out the line breaks.

This is column~\thedisplayedframe.

The main type of frame is the flow frame. This is described on
column~\ref{flow:flowframe} on page~\pageref{flow:flowframe}.
The order used to draw the contents of each frame on the page
is described in column~\ref{flow:stacking} on 
page~\pageref{flow:stacking}. Floats are describe in 
column~\ref{flow:floats} on page~\pageref{flow:floats}.

\chapter{Setting up Frames}

This is column~\thedisplayedframe.

The \textsl{flowfram} package provides three types of frame:
{flow frames}, {static 
frames} and {dynamic frames}.

\section*{Flow Frames}

\labelflow{flow:flowframe}
The flow frame is the principle type of frame.
The text of the \env{document} environment will flow from 
one frame to the next in order of definition. Each 
flow frame has an associated width, height, 
position on the page, and optionally a border.

It is recommended that all the flow frames in a document
have the same width, otherwise problems may occur
when a paragraph spans to flow frames of unequal
widths. This is because \TeX's output routine does not
register the change in \cmdname{hsize} until it reaches
a paragraph break. If it is absolutely necessary for 
flow frames to have unequal widths, judicious use of
\cmdname{framebreak} is required.

\section*{Static Frames}

A static frame is a rectangular area in which text neither
flows into, nor flows out of.  The contents must be set
explicitly, and once set, the contents of the static frame will
remain the same on each page until it is explicitly 
changed.  Thus, a static frame can be used, for example, to make 
a company logo appear in the same place on every page.

\section*{Dynamic Frames}

A dynamic frame is similar to a static frame, but its contents
are re-typeset on each page. (A static frame stores its 
contents in a savebox, whereas a dynamic frame stores its
contents in a macro).

This is column~\thedisplayedframe.

\chapter{Frame Attributes}
\label{sec:modattr}

Once you have defined the {flow frames}, {static frames} and 
{dynamic frames}, their attributes can be changed. 
The three types of frame mostly have the 
same set of attributes, but some are specific to a certain type.
The available attributes are as follows
(\textsuperscript{\textbf{F}} indicates the key is
only available for {flow frames}, 
\textsuperscript{\textbf{S}} indicates the key is only available 
for {static frames}
and \textsuperscript{\textbf{D}} indicates the key
is only available for {dynamic frames}):

\begin{description}
\item[width=\meta{length}]\mbox{}\par  The width of the frame.

\item[height=\meta{length}]\mbox{}\par The height of the frame.

\item[x=\meta{length}]\mbox{}\par The x-coordinate of the frame.

\item[y=\meta{length}]\mbox{}\par The y-coordinate of the frame.

\item[border=\meta{style}]\mbox{}\par The style of the border around the 
frame, this can take the values: \texttt{none} (no border),
\texttt{plain} (plain border) or the name of a \LaTeX\ 
frame making command without the preceding backslash. 
The value \texttt{fbox} is equivalent to \texttt{plain}.

\item[offset=\meta{offset}]\mbox{}\par The border offset, if it is a 
user-defined border.  This is the distance from the outer
edge of the left hand border to the left edge of the
bounding box of the text inside the border.  The \textsl{flowfram}
package is able to compute the border for 
known frame making commands. 
If you define your own frame making command, you may need to 
specify the offset explicitly, or the frames 
may end up shifted to the right or left.

\item[bordercolor=\meta{colour}]\mbox{}\par The colour of the border
if you are using a standard frame making command.
The colour can either be specified as, e.g.\ \texttt{green},
or including the colour model, for example 
\verb/[rgb]{0,1,0}/.

\item[textcolor=\meta{colour}]\mbox{}\par The text colour for that 
frame. Again, the colour can either be specified as, 
e.g.\ \texttt{green}, or including the colour model, 
for example \verb/[rgb]{0,1,0}/.

\item[pages=\meta{page list}]\mbox{}\par The {list of 
pages} for which the frame
should appear. This can either have the values: \texttt{all},
\texttt{even}, \texttt{odd} or \texttt{none} (the latter 
removes the frame from that point on---useful if you
have multiple pages with the same number), or it can be a 
comma-separated list of single pages, or 
{page ranges}.

\item[margin=\meta{side}\textsuperscript{F}]\mbox{}\par The side of
the flow frame that its corresponding margin should go on. This
can take the values \texttt{left} or \texttt{right}.

\item[clear=\meta{boolean}\textsuperscript{S}] If this value
is set, the static frame will be cleared at the start of the
next page.

\item[style=\meta{cmd}\textsuperscript{D}]\mbox{}\par This should be
the name of a command \emph{without} the preceding backslash, 
to be applied to the contents of the specified dynamic frame. 
The command may either be a declaration, for example \verb/style=large/
which will set the contents of all the dynamic frames in a
large font, or it can be a command that takes a single argument,
for example \verb/style=textbf/
which will make the text for all the dynamic frames come out in 
bold.  To unset a style, do \verb/style=none/.

\end{description}

\chapter{Miscellaneous}

\section*{Page Layout}

The \textsl{flowfram} package has the package option \texttt{draft}
which will draw the {bounding boxes} for
each frame defined.  At the bottom right of each
bounding box (except for the bounding box denoting the 
typeblock), a marker will be shown to indictate the type
of frame, its IDN and its IDL.

You can see the layout for the current page (irrespective of
whether or not the \texttt{draft} option has been set) using
the command:\newline 
\cmdname{flowframeshowlayout}

The headers and footers will appear as usual (but will not
be shown in draft mode), according to the format given by 
\cmdname{pagestyle}.

\section*{Frame Stacking Order}

\labelflow{flow:stacking}
The material on each page is placed in the following order:
\begin{enumerate}
\item Each static frame defined for that page in ascending
order of IDN.

\item Each flow frame defined for that page in ascending
order of IDN.

\item Each dynamic frame defined for that page in ascending
order of IDN.

\item {Bounding boxes} if the \texttt{draft}
package option has been used.
\end{enumerate}

This ordering can be used to determine if you want something
to overlay or underlay everything else on the page. 

\section*{Prematurely Ending a Flow Frame}

You can force text to move immediately to the next defined
flow frame using one of the standard \LaTeX\ page breaking commands
which  work in an analogous way to the way they
work in standard two column mode. 

The command \cmdname{framebreak} is provided for situations
where a paragraph spans two flow frames
of different widths, as \TeX's output routine does not 
adjust to the new value of \cmdname{hsize} until the last 
paragraph of the previous frame has ended. As a 
result, the end of the paragraph at the beginning of the new
flow frame retains the width of the previous flow frame.

If you want to start a new page, rather than simply move to the 
next frame, use the command\newline
\cmdname{finishthispage}.

\section*{Floats}

\labelflow{flow:floats}
Since floats (such as figures and tables) can only go in 
{flow frames}, this package provides
the additional environments: 
\env{staticfigure} and  
\env{statictable} which can be used in static frames
and dynamic frames. Unlike their \env{figure} and
\env{table} counterparts, they are fixed in place, and
so do not take an optional placement specifier. The 
\cmdname{caption} and \cmdname{label} commands can 
be used within \env{staticfigure} and \env{statictable} as
usual.

The standard \env{figure} and \env{table} commands will 
behave as usual in the flow frames, but their starred versions,
\env{figure*} and \env{table*} behave no differently
from \env{figure} and \env{table}.

\section*{Global Values}

The following macros can be changed using\linebreak \cmdname{renewcommand}:

\begin{itemize}
\item \cmdname{setffdraftcolor} 

This sets the colour of the bounding box
when it is displayed in draft mode.

\item 
\cmdname{setffdrafttypeblockcolor} 

This sets the colour of
the bounding box of the typeblock when it is displayed
in draft mode.

\item \cmdname{fflabelfont}

This sets the font size for the bounding box markers in 
draft mode.

\end{itemize}

The following are lengths, which can be changed using
\cmdname{setlength}:

\begin{itemize}
\item \cmdname{fflabelsep}

This is the distance from the right hand side of the
bounding box at which to place the bounding box marker.

\item \cmdname{flowframesep}

This is the gap between the text of the frame and
its border, for the standard border types. 

\item \cmdname{flowframerule}

This is the width of the frame's border, if using
a border given by a frame making command that uses \cmdname{fboxsep}
to set its border width.

\item \cmdname{columnsep}

This is the horizontal distance between flow frames when using one of the
\cmdname{Ncolumn} type of commands

\item \cmdname{vcolumnsep}

This is the vertical distance between the flow frames and the static or
dynamic frame when using one of the \cmdname{Ncolumntop} type of commands.
\end{itemize}

\label{lastpage}
\end{document}
%</test-brochure.tex>
%<*test-casualcv.tex>
\documentclass[11pt,a4paper]{bidimoderncv}
\cvtheme[orange]{bidicasual} % you can use orange, red, green and blue as options
\usepackage[scale=0.8]{geometry}
\usepackage{fontspec}
\usepackage[RTLdocument]{bidi}
\def\refname{تألیفات}
\setmainfont[Script=Arabic,Mapping=parsidigits]{XB Niloofar}
\newfontfamily\rmfamily[Mapping=tex-text]{Linux Libertine}
\AtBeginDocument{\recomputelengths}
\resumename{رزومه}
\firstname{سید محمد}
\familyname{یزدی اصفهانی}
\title{رزومهٔ من}
\address{تهران، خیابان آزادی پلاک ۹}
\mobile{۰۹۱۸۹۶۹۴۹۶}
\phone{۹۸۹۰۸۳۴۱}
\fax{۹۸۹۰۸۳۴۲}
\email{me@somedomain.com}
\extrainfo{اطلاعات اضافی}
\photo[64pt]{picture}
\quote{نقل قول}
\begin{document}
\maketitle
\section{تحصیلات}
\cventry{سال--سال}{درجه}{دانشگاه}{شهر}{\textit{نمره}}{توضیح}   % arguments 3 to 6 are optional
\cventry{سال--سال}{درجه}{دانشگاه}{شهر}{\textit{نمره}}{توضیح}  % arguments 3 to 6 are optional

\section{پایان‌نامهٔ کارشناسی ارشد}
\cvline{عنوان}{\emph{عنوان}}
\cvline{استاد راهنما}{استاد راهنما}
\cvline{توضیح}{\small چکیده کوچک پایان‌نامه}

\section{تجربیات}
\subsection{عنوان}
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح}                % arguments 3 to 6 are optional
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح}                % arguments 3 to 6 are optional
\subsection{متفرقه}
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح خط ۱\newline{}توضیح خط ۲}% arguments 3 to 6 are optional

\section{زبانها}
\cvlanguage{زبان ۱}{درجه مهارت}{نظر}
\cvlanguage{زبان ۲}{درجه مهارت}{نظر}
\cvlanguage{زبان ۳}{درجه مهارت}{نظر}

\section{مهارتهای رایانه‌ای}
\cvcomputer{طبقه ۱}{یک، دو، سه}{طبقه ۴}{یک، دو، سه}
\cvcomputer{طبقه ۲}{یک، دو، سه}{طبقه ۵}{یک، دو، سه}
\cvcomputer{طبقه ۳}{یک، دو، سه}{طبقه ۶}{یک، دو، سه}

\section{علاقه‌ها}
\cvline{علاقه ۱}{\small توضیح}
\cvline{علاقه ۲}{\small توضیح}
\cvline{علاقه ۳}{\small توضیح}

\renewcommand{\listitemsymbol}{-} % change the symbol for lists

\section{بعدی ۱}
\cvlistitem{شماره ۱}
\cvlistitem{شماره ۲}
\cvlistitem[+]{شماره ۳}            % optional other symbol

\section{بعدی ۲}
\cvlistdoubleitem[\Neutral]{شماره ۱}{شماره ۴}
\cvlistdoubleitem[\Neutral]{شماره ۲}{شماره ۵}
\cvlistdoubleitem[\Neutral]{شماره ۳}{}

\nocite{*}
\bibliographystyle{plain}
\bibliography{publications}       % 'publications' is the name of a BibTeX file

\end{document}
%</test-casualcv.tex>
%<*test-classiccv.tex>
\documentclass[11pt,a4paper]{bidimoderncv}
\cvtheme[green]{bidiclassic} % you can use orange, red, green, grey and blue as options
\usepackage[scale=0.8]{geometry}
\usepackage{fontspec}
\setmainfont[Script=Arabic,Mapping=parsidigits]{XB Zar}
\newfontfamily\rmfamily[Mapping=tex-text]{Linux Libertine}
\def\refname{تألیفات}
\usepackage[RTLdocument]{bidi}
\AtBeginDocument{\recomputelengths}
\resumename{رزومه}
\firstname{وفا}
\familyname{خلیقی}
\title{رزومهٔ من}
\address{تهران، خیابان آزادی پلاک ۹}
\mobile{۰۹۱۸۹۶۹۴۹۶}
\phone{۹۸۹۰۸۳۴۱}
\fax{۹۸۹۰۸۳۴۲}
\email{me@somedomain.com}
\extrainfo{اطلاعات اضافی}
\photo[64pt]{picture}
\quote{نقل قول}
\begin{document}
\maketitle
\section{تحصیلات}
\cventry{سال--سال}{درجه}{دانشگاه}{شهر}{\textit{نمره}}{توضیح}   % arguments 3 to 6 are optional
\cventry{سال--سال}{درجه}{دانشگاه}{شهر}{\textit{نمره}}{توضیح}  % arguments 3 to 6 are optional

\section{پایان‌نامهٔ کارشناسی ارشد}
\cvline{عنوان}{\emph{عنوان}}
\cvline{استاد راهنما}{استاد راهنما}
\cvline{توضیح}{\small چکیده کوچک پایان‌نامه}

\section{تجربیات}
\subsection{عنوان}
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح}                % arguments 3 to 6 are optional
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح}                % arguments 3 to 6 are optional
\subsection{متفرقه}
\cventry{سال--سال}{نام شغل}{صاحب کار}{شهر}{}{توضیح خط ۱\newline{}توضیح خط ۲}% arguments 3 to 6 are optional

\section{زبانها}
\cvlanguage{زبان ۱}{درجه مهارت}{نظر}
\cvlanguage{زبان ۲}{درجه مهارت}{نظر}
\cvlanguage{زبان ۳}{درجه مهارت}{نظر}

\section{مهارتهای رایانه‌ای}
\cvcomputer{طبقه ۱}{یک، دو، سه}{طبقه ۴}{یک، دو، سه}
\cvcomputer{طبقه ۲}{یک، دو، سه}{طبقه ۵}{یک، دو، سه}
\cvcomputer{طبقه ۳}{یک، دو، سه}{طبقه ۶}{یک، دو، سه}

\section{علاقه‌ها}
\cvline{علاقه ۱}{\small توضیح}
\cvline{علاقه ۲}{\small توضیح}
\cvline{علاقه ۳}{\small توضیح}

\renewcommand{\listitemsymbol}{-} % change the symbol for lists

\section{بعدی ۱}
\cvlistitem{شماره ۱}
\cvlistitem{شماره ۲}
\cvlistitem[+]{شماره ۳}            % optional other symbol

\section{بعدی ۲}
\cvlistdoubleitem[\Neutral]{شماره ۱}{شماره ۴}
\cvlistdoubleitem[\Neutral]{شماره ۲}{شماره ۵}
\cvlistdoubleitem[\Neutral]{شماره ۳}{}

\nocite{*}
\bibliographystyle{plain}
\bibliography{publications}       % 'publications' is the name of a BibTeX file

\end{document}
%</test-classiccv.tex>
%<*test-color.tex>
\documentclass{article}
\usepackage{fontspec}
\usepackage{xecolour} % for RTL coloured texts that spans more than a line
\usepackage{fullpage}
\usepackage{colortbl}
\setmainfont[Scale=1,Script=Arabic,Mapping=farsidigits]{XB Kayhan}
\usepackage{xcolor}
\usepackage[RTLdocument]{bidi}
\begin{document}
این یک آزمایش است.

\bigskip
\fcolorbox{red}{yellow}{\begin{minipage}{0.8\textwidth}
این یک متن است که من آن را داخل یک جعبهٔ زردرنگ قرار می‌دهم. این یک متن است که من آن را داخل یک جعبهٔ زردرنگ قرار می‌دهم
\end{minipage}}

این {\color{red} رنگ قرمز} است و این هم \textcolor{blue}{رنگ آبی} است همانطور که می‌بینید.

\bigskip
من اسم خودم {\color{red}  وفا خلیقی} را با رنگ قرمز می‌نویسم.

\bigskip
من اسم خودم \textcolor{blue}{وفا خلیقی} را با رنگ آبی می‌نویسم.

\bigskip
\colorbox{yellow}{\begin{minipage}{0.8\textwidth}
این یک متن است که من آن را داخل یک جعبهٔ زردرنگ قرار می‌دهم. این یک متن است که من آن را داخل یک جعبهٔ زردرنگ قرار می‌دهم
\end{minipage}}

\bigskip
این یک پاراگراف با \blue{رنگ آبی اول است و همینطور و همینطور ما می‌توانیم از رنگاهی مختلف استفاده کنیم} و حالا
\red{این روزها حجم اخبار و مطالب مرتبط با ایران و مسایل مربوط به آن بسیار زیاد شده وابزارهایی مانند گوگل ریدر برای مرور لیست بلند بالایی از سایتها و وبلاگ های به روز شده ، بیشتر مورد استفاده قرار میگیرد.} و حالا هم
\darkred{یکی از مشکلاتی که در استفاده از گوگل ریدر داشتم، نامناسب بودن فونت فارسی آن بود. اگر چه عمده وبلاگها و سایتها از فونت تاهوما (مانند فونتی که این مطالب با آن نوشته شده است) استفاده می کنند اما تعدادی از وبلاگها از فونتهای دیگری که بعضی وقتها خیلی ریز هم هستند }استفاده می کنند که خواندن آن در گوگل ریدر بسیار دشوار است. متاسفانه در گوگل ریدر بخشی برای تغییر فونت وجود ندارد و نمیتوان نوع فونت یا اندازه مطالب آن را تغییر داد. بعد از کمی جستجو بر روی اینترنت راه حل جالبی را پیدا کردم که با کمی تغییر برای مطالب فارسی هم قابل استفاده است.
اگر از فایرفاکس برای مرور مطالب جدید در گوگل ریدر استفاده می کنید، این راه حل را باری حل این مشکل به شما پیشنهاد میکنم

\bigskip
حالا نوبت جعبه‌های رنگی است یعنی مثلاً \colorbox{red}{{\color{white}سلام}} و \fcolorbox{yellow}{red}{{\color{white}این یک متن داخل جعبه رنگی است که کمی طولانی است}}






\end{document}
%</test-color.tex>
%<*test-supertabular.tex>
\documentclass{article}
\usepackage{supertabular}
\usepackage{bidi}
\title{Testing \textsf{supertabular} package in RTL and LTR}
\author{Vafa Khalighi}
\begin{document}
\maketitle
\section{LTR}
\tablecaption{The ISOGRK3 entity set}
\tablehead
   {\bfseries Entity&\bfseries  Unicode Name&\bfseries Unicode\\ \hline}
\tabletail
   {\hline \multicolumn{3}{r}{\emph{Continued on next page}}\\}
\tablelasttail{\hline}
\begin{supertabular}{lll}
alpha              & GREEK SMALL LETTER ALPHA            & 03B1\\
beta               & GREEK SMALL LETTER BETA             & 03B2\\
chi                & GREEK SMALL LETTER CHI              & 03C7\\
Delta              & GREEK CAPITAL LETTER DELTA          & 0394\\
delta              & GREEK SMALL LETTER DELTA            & 03B4\\
epsi               & GREEK SMALL LETTER EPSILON          & 03B5\\
epsis              & GREEK LUNATE EPSILON SYMBOL         & 03F5\\
\empty
epsiv              & GREEK SMALL LETTER EPSILON          & 03B5\\
eta                & GREEK SMALL LETTER ETA              & 03B7\\
Gamma              & GREEK CAPITAL LETTER GAMMA          & 0393\\
gamma              & GREEK SMALL LETTER GAMMA            & 03B3\\
gammad             & GREEK SMALL LETTER DIGAMMA          & 03DD\\
iota               & GREEK SMALL LETTER IOTA             & 03B9\\
kappa              & GREEK SMALL LETTER KAPPA            & 03BA\\
kappav             & GREEK KAPPA SYMBOL                  & 03F0\\
Lambda             & GREEK CAPITAL LETTER LAMDA          & 039B\\
lambda             & GREEK SMALL LETTER LAMDA            & 03BB\\
mu                 & GREEK SMALL LETTER MU               & 03BC\\
nu                 & GREEK SMALL LETTER NU               & 03BD\\
Omega              & GREEK CAPITAL LETTER OMEGA          & 03A9\\
omega              & GREEK SMALL LETTER OMEGA            & 03C9\\
Phi                & GREEK CAPITAL LETTER PHI            & 03A6\\
phis               & GREEK PHI SYMBOL                    & 03D5\\
phiv               & GREEK SMALL LETTER PHI              & 03C6\\
Pi                 & GREEK CAPITAL LETTER PI             & 03A0\\
pi                 & GREEK SMALL LETTER PI               & 03C0\\
piv                & GREEK PI SYMBOL                     & 03D6\\
Psi                & GREEK CAPITAL LETTER PSI            & 03A8\\
psi                & GREEK SMALL LETTER PSI              & 03C8\\
rho                & GREEK SMALL LETTER RHO              & 03C1\\
rhov               & GREEK RHO SYMBOL                    & 03F1\\
Sigma              & GREEK CAPITAL LETTER SIGMA          & 03A3\\
sigma              & GREEK SMALL LETTER SIGMA            & 03C3\\
sigmav             & GREEK SMALL LETTER FINAL SIGMA      & 03C2\\
tau                & GREEK SMALL LETTER TAU              & 03C4\\
Theta              & GREEK CAPITAL LETTER THETA          & 0398\\
thetas             & GREEK SMALL LETTER THETA            & 03B8\\
thetav             & GREEK THETA SYMBOL                  & 03D1\\
Upsi               & GREEK UPSILON WITH HOOK SYMBOL      & 03D2\\
upsi               & GREEK SMALL LETTER UPSILON          & 03C5\\
Xi                 & GREEK CAPITAL LETTER XI             & 039E\\
xi                 & GREEK SMALL LETTER XI               & 03BE\\
zeta               & GREEK SMALL LETTER ZETA             & 03B6\\
\end{supertabular}
\section{RTL}

\setRTL
\tablecaption{The ISOGRK3 entity set}
\tablehead
   {\bfseries Entity&\bfseries  Unicode Name&\bfseries Unicode\\ \hline}
\tabletail
   {\hline \multicolumn{3}{l}{\emph{Continued on next page}}\\}
\tablelasttail{\hline}
\begin{supertabular}{rrr}
alpha              & GREEK SMALL LETTER ALPHA            & 03B1\\
beta               & GREEK SMALL LETTER BETA             & 03B2\\
chi                & GREEK SMALL LETTER CHI              & 03C7\\
Delta              & GREEK CAPITAL LETTER DELTA          & 0394\\
delta              & GREEK SMALL LETTER DELTA            & 03B4\\
epsi               & GREEK SMALL LETTER EPSILON          & 03B5\\
epsis              & GREEK LUNATE EPSILON SYMBOL         & 03F5\\
\empty
epsiv              & GREEK SMALL LETTER EPSILON          & 03B5\\
eta                & GREEK SMALL LETTER ETA              & 03B7\\
Gamma              & GREEK CAPITAL LETTER GAMMA          & 0393\\
gamma              & GREEK SMALL LETTER GAMMA            & 03B3\\
gammad             & GREEK SMALL LETTER DIGAMMA          & 03DD\\
iota               & GREEK SMALL LETTER IOTA             & 03B9\\
kappa              & GREEK SMALL LETTER KAPPA            & 03BA\\
kappav             & GREEK KAPPA SYMBOL                  & 03F0\\
Lambda             & GREEK CAPITAL LETTER LAMDA          & 039B\\
lambda             & GREEK SMALL LETTER LAMDA            & 03BB\\
mu                 & GREEK SMALL LETTER MU               & 03BC\\
nu                 & GREEK SMALL LETTER NU               & 03BD\\
Omega              & GREEK CAPITAL LETTER OMEGA          & 03A9\\
omega              & GREEK SMALL LETTER OMEGA            & 03C9\\
Phi                & GREEK CAPITAL LETTER PHI            & 03A6\\
phis               & GREEK PHI SYMBOL                    & 03D5\\
phiv               & GREEK SMALL LETTER PHI              & 03C6\\
Pi                 & GREEK CAPITAL LETTER PI             & 03A0\\
pi                 & GREEK SMALL LETTER PI               & 03C0\\
piv                & GREEK PI SYMBOL                     & 03D6\\
Psi                & GREEK CAPITAL LETTER PSI            & 03A8\\
psi                & GREEK SMALL LETTER PSI              & 03C8\\
rho                & GREEK SMALL LETTER RHO              & 03C1\\
rhov               & GREEK RHO SYMBOL                    & 03F1\\
Sigma              & GREEK CAPITAL LETTER SIGMA          & 03A3\\
sigma              & GREEK SMALL LETTER SIGMA            & 03C3\\
sigmav             & GREEK SMALL LETTER FINAL SIGMA      & 03C2\\
tau                & GREEK SMALL LETTER TAU              & 03C4\\
Theta              & GREEK CAPITAL LETTER THETA          & 0398\\
thetas             & GREEK SMALL LETTER THETA            & 03B8\\
thetav             & GREEK THETA SYMBOL                  & 03D1\\
Upsi               & GREEK UPSILON WITH HOOK SYMBOL      & 03D2\\
upsi               & GREEK SMALL LETTER UPSILON          & 03C5\\
Xi                 & GREEK CAPITAL LETTER XI             & 039E\\
xi                 & GREEK SMALL LETTER XI               & 03BE\\
zeta               & GREEK SMALL LETTER ZETA             & 03B6\\
\end{supertabular}
\end{document}
%</test-supertabular.tex>
%<*test-tabular.tex>
\documentclass{article}
\usepackage{bidi}
\title{Testing \LaTeX's Default Tabular in \textsf{RTL} and \textsf{LTR}}
\author{Vafa Khalighi}
\newcommand{\rb}[1]{\raisebox{1.5ex}[0mm]{#1}}
\begin{document}
\maketitle
In this document we test \LaTeX's default tabular in \textsf{RTL} and \textsf{LTR}.
\section{LTR}
\begin{center}\small
\begin{tabular}{|l||c|l|c|l|c|l|}
\hline
& \multicolumn{2}{c|}{6.15--7.15 pm} & \multicolumn{2}{c|}{7.20--8.20 pm}
& \multicolumn{2}{c|}{8.30--9.30 pm} \\ \cline{2-7}
&& Teacher && Teacher && Teacher \\ \cline{3-3}\cline{5-5}\cline{7-7}
\rb{Day} & \rb{Subj.} & Room & \rb{Subj.} & Room & \rb{Subj.} & Room\\
   \hline\hline
&& Dr.~Smith && Ms.~Clark && Mr.~Mills\\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Mon.} & \rb{UNIX} & Comp. Ctr & \rb{Fortran} & Hall A
  & \rb{Math.} & Hall A \\ \hline
&& Miss Baker && Ms.~Clark && Mr.~Mill\\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Tues.} & \rb{\LaTeX} & Conf.~Room & \rb{Fortran} & Conf~Room
  & \rb{Math.} & Hall A \\ \hline
&& Dr.~Smith && Dr.~Jones && Dr.~Jones \\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Wed.} & \rb{UNIX} & Comp. Ctr & \rb{C} & Hall A
  & \rb{ComSci.} & Hall A \\ \hline
&& Miss Baker && Ms. Clark & \multicolumn{2}{c|}{} \\
\cline{3-3}\cline{5-5}
\rb{Fri.} & \rb{\LaTeX} & Conf.~Room & \rb{C++} & Conf.~Room
& \multicolumn{2}{c|}{\rb{canceled}}\\ \hline
\end{tabular}\end{center}
\section{RTL}

\setRTL
\begin{center}\small
\begin{tabular}{|r||c|r|c|r|c|r|}
\hline
& \multicolumn{2}{c|}{6.15--7.15 pm} & \multicolumn{2}{c|}{7.20--8.20 pm}
& \multicolumn{2}{c|}{8.30--9.30 pm} \\ \cline{2-7}
&& Teacher && Teacher && Teacher \\ \cline{3-3}\cline{5-5}\cline{7-7}
\rb{Day} & \rb{Subj.} & Room & \rb{Subj.} & Room & \rb{Subj.} & Room\\
   \hline\hline
&& Dr.~Smith && Ms.~Clark && Mr.~Mills\\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Mon.} & \rb{UNIX} & Comp. Ctr & \rb{Fortran} & Hall A
  & \rb{Math.} & Hall A \\ \hline
&& Miss Baker && Ms.~Clark && Mr.~Mill\\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Tues.} & \rb{\LaTeX} & Conf.~Room & \rb{Fortran} & Conf~Room
  & \rb{Math.} & Hall A \\ \hline
&& Dr.~Smith && Dr.~Jones && Dr.~Jones \\
\cline{3-3}\cline{5-5}\cline{7-7}
\rb{Wed.} & \rb{UNIX} & Comp. Ctr & \rb{C} & Hall A
  & \rb{ComSci.} & Hall A \\ \hline
&& Miss Baker && Ms. Clark & \multicolumn{2}{c|}{} \\
\cline{3-3}\cline{5-5}
\rb{Fri.} & \rb{\LaTeX} & Conf.~Room & \rb{C++} & Conf.~Room
& \multicolumn{2}{c|}{\rb{canceled}}\\ \hline
\end{tabular}\end{center}
\end{document}
%</test-tabular.tex>
%<*test-tabularx.tex>
\documentclass{article}
\usepackage{tabularx}
\usepackage{bidi}
\title{Testing \textsf{tabularx} Package in RTL and LTR}
\author{Vafa Khalighi}
\begin{document}
\maketitle
\section{LTR}
\begin{tabularx}{\linewidth}{|l|p{1.25cm}|p{1.5cm}|X|}\hline
\multicolumn{1}{|c|}{\textbf{Animal}}
  & \textbf{Hair Colour}
  & \multicolumn{2}{c|}{\textbf{Favourite foods}} \\\hline\hline
Elephant & Gray & Peanuts
  & Unshelled, prepared in Sea Salt, and warmed over hot stone grill \\\cline{3-4}
  &  & Cabbage and Greens
  & Sun dried until lightly browned (2-3 days minimum);
    seasoned with Hyperchem super feed \\\cline{4-4}
  & & & Boiled to British standard \\\hline\hline
Lion & Yellow & Elephants & Tartare \\\cline{4-4}
& & & Must be served warm, with no trace of
  buckshot. Gaiminess considered desireable. \\\hline
\end{tabularx}
\section{RTL}

\setRTL
\begin{tabularx}{\linewidth}{|r|p{1.25cm}|p{1.5cm}|X|}\hline
\multicolumn{1}{|c|}{\textbf{Animal}}
  & \textbf{Hair Colour}
  & \multicolumn{2}{c|}{\textbf{Favourite foods}} \\\hline\hline
Elephant & Gray & Peanuts
  & Unshelled, prepared in Sea Salt, and warmed over hot stone grill \\\cline{3-4}
  &  & Cabbage and Greens
  & Sun dried until lightly browned (2-3 days minimum);
    seasoned with Hyperchem super feed \\\cline{4-4}
  & & & Boiled to British standard \\\hline\hline
Lion & Yellow & Elephants & Tartare \\\cline{4-4}
& & & Must be served warm, with no trace of
  buckshot. Gaiminess considered desireable. \\\hline
\end{tabularx}
\end{document}
%</test-tabularx.tex>
%<*test-tabulary.tex>
\documentclass{article}
\usepackage{tabulary}
\setlength\tymin{10pt}
\setlength\tymax{\maxdimen}
\usepackage{bidi}
\title{Testing \textsf{tabulary} package in RTL and LTR}
\author{Vafa Khalighi}
\begin{document}
\maketitle
\section{LTR}
\begin{tabulary}{200pt}{|C|C|C|C|}
 a & b b b b &
 c c c c c c c c c c c c c c c c c c &
 d d d d d d d d d d d d d d d d d d
\empty
 d d d d d d d d d d d d d d
 d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d
 \end{tabulary}
\section{RTL}

\setRTL
\begin{tabulary}{200pt}{|C|C|C|C|}
 a & b b b b &
 c c c c c c c c c c c c c c c c c c &
 d d d d d d d d d d d d d d d d d d
\empty
 d d d d d d d d d d d d d d
 d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d
 \end{tabulary}
\end{document}
%</test-tabulary.tex>
%\fi
%
% \typeout{*************************************************************}
% \typeout{*}
% \typeout{* To finish the installation you have to move the following}
% \typeout{* file into a directory searched by TeX:}
% \typeout{*}
% \typeout{* \space\space\space all *.cls, *.sty and *.def  files}
% \typeout{*}
% \typeout{* \space\space\space and bidi-bibitem.pdf  file}
% \typeout{*************************************************************}
%
\endinput

